akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int h, w;
  cin>>h>>w;
  int ch, cw, dh, dw;
  cin>>ch>>cw>>dh>>dw;
  ch--; cw--; dh--; dw--;
  vector<string> s(h);
  REP(i, h) cin>>s[i];
  
  
  vector<vector<int>> dist(h, vector<int>(w, -1));
  typedef pair<int, int> P;
  typedef pair<int, P> dP;
  priority_queue<dP> q;
  dist[ch][cw] = 0;
  q.push(dP(0, P(ch, cw)));
  int dx[] = {1, 0, -1, 0};
  int dy[] = {0, 1, 0, -1};
  auto valid = [&](int x, int y) -> bool {
    return 0 <= x && x < h && 0 <= y && y < w;
  };
  while(!q.empty()){
    dP now = q.top();
    int d = 0 - now.first;
    int x = now.second.first, y = now.second.second;
    q.pop();
    REP(k, 4){
      int nx = x + dx[k];
      int ny = y + dy[k];
      if(!valid(nx, ny)) continue;
      if(s[nx][ny] == '#') continue;
      if(dist[nx][ny] >= 0 && d >= dist[nx][ny]) continue;
      dist[nx][ny] = d;
      q.push(dP(-dist[nx][ny], P(nx, ny)));
    }
    for(int i = -2; i <= 2; i++){
      for(int j = -2; j <= 2; j++){
        int nx = x + i;
        int ny = y + j;
        if(!valid(nx, ny)) continue;
        if(s[nx][ny] == '#') continue;
        if(dist[nx][ny] >= 0 && d + 1 >= dist[nx][ny]) continue;
        dist[nx][ny] = d + 1;
        q.push(dP(-dist[nx][ny], P(nx, ny)));
      }
    }
  }
  long long ans = dist[dh][dw];
  cout << ans << endl;  
  return 0;
}

Measured memory_bytes: 9596
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public class ABC
{
    //          long[] sp = Console.ReadLine().Split().Select(long .Parse).ToArray();
    //          int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
    //          int N =  int.Parse(Console.ReadLine());
    public static void Main()
    {
        string[] odd = { "R","U","D" };
        string[] even = { "L", "U", "D" };

        string output = "Yes";
        string s = Console.ReadLine();
        for (int i = 0; i < s.Length; i++)
        {
            if ((i ) % 2 == 0)
            {
                if (s[i] == 'L') output = "No";
            }
            else
            {
                if (s[i] == 'R') output = "No";
            }
        }
        Console.WriteLine(output);
    }

}





Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	ll x;
	cin >> x;
	for (ll i = -1000; i <= 1000; i++) {
		for (ll j = -1000; j <= 1000; j++) {
			if (i*i*i*i*i - j*j*j*j*j == x) {
				cout << i << " " << j << endl;
				return 0;
			}
		}
	}
}


Measured memory_bytes: 3652
#include <stdio.h>
#include <string.h>
#define N 200000000
#define INF 2000000001
 
int size;
int h[N];
 
void swap(int* a, int* b){
  int tmp = *a;
  *a = *b;
  *b = tmp;
}
 
void maxHeapify(i){
  int l = 2*i;
  int r = 2*i+1;
  int valM;
  if(l <= size && h[l] > h[i]) valM = l;
  else valM = i;
  if(r <= size && h[r] > h[valM]) valM = r;
  if(valM != i){
    swap(&h[i], &h[valM]);
    maxHeapify(valM);
  }
}
 
void hIncreaseKey(int i, int key){
  if(key < h[i]) return;
  h[i] = key;
  while(i>1 && h[i/2]<h[i]){
    swap(&h[i], &h[i/2]);
    i = i/2;
  }
}
 
void maxHeapInsert(int key){
  size++;
  h[size] = -INF;
  hIncreaseKey(size, key);
}
 
int heapExtractMax(){
  int valM;
  if(size < 1) return 0;
  valM = h[1];
  h[1] = h[size--];
  maxHeapify(1);
  return valM;
}
 
int main(){
  char input[20];
  size = 0;
  while(scanf("%s", input)){
    if(!strcmp(input, "end")) break;
    if(!strcmp(input, "extract")) printf("%d\n", heapExtractMax());
    else{
      char val[20];
      scanf("%s", val);
      maxHeapInsert(atoi(val));
    }
  }
  return 0;
}

Measured memory_bytes: 4636
# (a+b+c) mod n = (((a mod n)+b mod n )+c) mod n
from itertools import accumulate

def main():
    N = int(input())
    A = list(map(int,input().split()))

    acc = list(accumulate(A))
    mod = 10**9 + 7

    ans = 0

    for i in range(N-1):
        ans += A[i]*(acc[-1]-acc[i])
        ans %= mod

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 31396
#include<cstdio>

const int A = 1e9 + 7;
int n;
int dp[98][64];

int main() {
    scanf("%d", &n);
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 4; k++) {
               dp[0][16 * i + 4 * j + k] = 1;
            }
        }
    }
    dp[0][9]--;
    dp[0][49]--;
    dp[0][6]--;
    for (int i = 1; i < n - 2; i++) {
        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 4; k++) {
                for (int l = 0; l < 4; l++) {
                    for (int m = 0; m < 4; m++) {
                        if (16 * j + 4 * l + m == 9) continue;
                        if (16 * l + 4 * k + m == 9) continue;
                        if (16 * j + 4 * k + m == 9) continue;
                        if (16 * k + 4 * m + l == 9) continue;
                        if (16 * k + 4 * l + m == 9) continue;
                        dp[i][16 * k + 4 * l + m] += dp[i - 1][16 * j + 4 * k + l];
                        dp[i][16 * k + 4 * l + m] %= A;
                    }
                }
            }
        }
    }

    int sum = 0;
    for (int i = 0; i < 64; i++) {
        sum += dp[n - 3][i];
        sum %= A;
    }
    printf("%d\n", sum);
    return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=set()
c=0
for i in range(n):
    if a[i]<400:
        b.add(1)
    elif a[i]<800:
        b.add(2)
    elif a[i]<1200:
        b.add(3)
    elif a[i]<1600:
        b.add(4)
    elif a[i]<2000:
        b.add(5)
    elif a[i]<2400:
        b.add(6)
    elif a[i]<2800:
        b.add(7)
    elif a[i]<3200:
        b.add(8)
    elif a[i]>=3200:
        c+=1
print(max(1,len(b)),len(b)+c,sep=" ")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
const int N = 2e6+5;
int trie[N][60];
string s[N];
int sz;
int zero = 30;
void add(int idx){
    int root = 1;
    int z = s[idx].size();
    int cnt[33] = {};
    for(int i=0;i<z;i++){
        cnt[s[idx][i]-'a']++;
    }
    for(int i=0;i<26;i++){
        if(cnt[i]>0)trie[root][i+zero]++;
    }
    for(int i=0;i<z;i++){
        if(trie[root][s[idx][i]-'a']==0){
           trie[root][s[idx][i]-'a'] = ++sz;
        }
        root = trie[root][s[idx][i]-'a'];
        cnt[s[idx][i]-'a']--;
        for(int j=0;j<26;j++){
            if(cnt[j]>0)trie[root][j+zero]++;
        }
    }
}
ll ans = 0;
void get(int idx){
    int root = 1;
    int z = s[idx].size();
    for(int i=0;i<z-1;i++){
        root = trie[root][s[idx][i]-'a'];
    }
    int x = s[idx][z-1]-'a';
    ans+=trie[root][x+zero];
}
void solve(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>s[i];
        reverse(s[i].begin(),s[i].end());
    }
    sz = 1;
    for(int i=1;i<=n;i++){
        add(i);
    }
    for(int i=1;i<=n;i++){
        get(i);
    }
    cout<<ans-n<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 301216
n,k = map(int,input().split())

sample = list(range(n+1))

count = 0
current = sum(sample[-k:])-sum(sample[:k])+1

for i in range(k,n+2):
    
    # count += sum(sample[-i:])-sum(sample[:i])+1
    count += current
    current = current - i + (n+1-i) - 1

print(count%1000000007)

Measured memory_bytes: 18496
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

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

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, M, Q;
	cin >> N >> M >> Q;

	vector<vector<int>> v(Q, vector<int>(4));
	for (int i = 0; i < Q; i++) {
		cin >> v[i][0] >> v[i][1] >> v[i][2] >> v[i][3];
		v[i][0]--, v[i][1]--;
	}

	auto dfs = [&](auto &&f, int ind, int now, vector<int> num) -> int {
		
		num[ind] = now;

		if (ind == N) {
			int sum = 0;
			for (int i = 0; i < Q; i++) {
				if (num[v[i][1]] - num[v[i][0]] == v[i][2]) sum += v[i][3];
			}
			return sum;
		}
		
		int res = 0;
		for (int i = now; i <= M; i++) {
			chmax(res, f(f, ind + 1, i, num));
		}

		return res;
	};

	int ans = 0;
	for (int i = 1; i <= M; i++) {
		chmax(ans, dfs(dfs, 0, i, vector<int>(11)));
	}

	cout << ans << "\n";


	return 0;
}

Measured memory_bytes: 3620
int main(void) {

	int W,H,x,y,r;
    int top,bot,left,right;

	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

	top = y+r;
	bot = y-r;
	left = x-r;
	right = x+r;

	if(top>H)printf("No\n");
	else if(bot<0)printf("No\n");
	else if(left<0)printf("No\n");
	else if(right>W)printf("No\n");
	else printf("Yes\n");

	return 0;

}

Measured memory_bytes: 584
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <regex>
#include <iomanip>
#include <climits>
#include <utility>
#include <queue>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;
const dd PI = 3.1415926435;

class UnionFind
{
public:
    UnionFind(int N) : par(N)
    {
        for (ll i = 0; i < N; i++)
        {
            par[i] = i;
        }
    }

    int root(int x)
    {
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry)
            return;
        par[rx] = ry;
    }

    bool same(int x, int y)
    {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

private:
    vector<int> par;
};

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

ll fact(ll n)
{
    if (n == 0)
    {
        return 1;
    }
    if (n == 1)
    {
        return 1;
    }
    return n * fact(n - 1) % MOD;
}

ll pow_fast(ll n, ll k)
{
    if (k == 0)
    {
        return 1;
    }
    if (k == 1)
    {
        return n;
    }

    if (k % 2 == 0)
    {
        ll tmp = pow_fast(n, k / 2LL);
        return tmp * tmp % MOD;
    }
    else
    {
        ll tmp = pow_fast(n, k / 2LL);
        tmp *= tmp;
        tmp %= MOD;
        return tmp * n % MOD;
    }
}

map<ll, ll> sosuu(ll n)
{
    map<ll, ll> res;
    for (ll i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            res[i] += 1;
            n /= i;
        }
    }
    if (n != 1)
    {
        res[n] += 1;
    }
    return res;
}

struct Dish
{
    ll time;
    ll taste;
};

int main()
{
    ll N, K;
    cin >> N >> K;
    vector<ll> fruits(N);
    for (ll i = 0; i < N; i++)
    {
        cin >> fruits[i];
    }
    sort(fruits.begin(), fruits.end());

    ll sum = 0;
    for (ll i = 0; i < K; i++)
    {
        sum += fruits[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 3600
"use strict";
const main = (input) => {
  const str = input.trim();
  const str1 = str.replace(/H/g, "1");
  const str2 = str1.replace(/D/g, "-1");
  const [a, b] = str2.split(" ").map(Number);
  const result = a * b;
  if (result === 1) {
    return "H";
  } else {
    return "D";
  }
};

// ※この行以降は編集しない (標準入力から一度に読み込みMainを呼び出します)
console.log(main(require("fs").readFileSync("/dev/stdin", "utf8")));


Measured memory_bytes: 29508
#include <cstdio>
#include <vector>
#include <array>
#include <algorithm>
using namespace std;


const int inf = (int)1e8;

struct Edge {
	int to, rev, cap;
};

struct Graph {

	vector<vector<Edge> > g;
	int gs, gt;

	void initialize(int n, int s, int t)
	{
		g.resize(n);
		fill(g.begin(), g.end(), vector<Edge>());
		gs = s;
		gt = t;
	}

	void add_edge(int a, int b)
	{
		g[a].push_back({b, (int)g[b].size(), 1});
		g[b].push_back({a, (int)g[a].size() - 1, 1});
	}

	bool flow_dfs(int v, int t, vector<bool> &used)
	{
		if(v == t)
			return true;
		used[v] = true;

		for(auto &e : g[v]) {

			if(used[e.to] || e.cap <= 0)
				continue;

			const bool f = flow_dfs(e.to, t, used);
			if(!f)
				continue;

			e.cap -= 1;
			g[e.to][e.rev].cap += 1;

			return true;
		}

		return false;
	}

	int max_flow_step(int s, int t)
	{
		static vector<bool> used;

		if(g.size() > used.size())
			used.resize(g.size());
		fill(used.begin(), used.end(), false);

		return flow_dfs(s, t, used);
	}

	int max_flow()
	{
		int flow = 0;

		while(true) {

			const bool f = max_flow_step(gs, gt);
			if(f)
				flow += 1;
			else
				break;
		}

		return flow;
	}

	void restore_edge(int a, int b)
	{
		for(auto &e : g[a]) {
			if(e.to != b)
				continue;
			auto &re = g[b][e.rev];
			e.cap += 1;
			re.cap += 1;
			return;
		}

		add_edge(a, b);
	}

	int reflow(Edge &e, Edge &re)
	{
		const int from = re.to;
		const int to = e.to;
		const int f = max_flow_step(from, to);

		if(f >= 1) {
			re.cap -= 2;
			return 0;
		}

		max_flow_step(from, gs);
		max_flow_step(gt, to);
		re.cap -= 2;

		return 1;
	}

	int remove_edge(int a, int b)
	{
		for(auto &e : g[a]) {

			if(e.to != b)
				continue;

			auto &re = g[b][e.rev];

			if(e.cap >= 1 && re.cap >= 1) {

				e.cap -= 1;
				re.cap -= 1;
				return 0;
			}

			if(e.cap == 0)
				return reflow(e, re);
			else
				return reflow(re, e);
		}

		return 0;
	}
};




int main()
{
	int n, e, q;
	Graph g;

	scanf("%d%d%d", &n, &e, &q);
	const int gs = 0, gt = n - 1;
	g.initialize(n, gs, gt);

	for(int i = 0; i < e; ++i) {
		int f, t;
		scanf("%d%d", &f, &t);
		f -= 1; t -= 1;
		g.add_edge(f, t);
	}

	int flow = g.max_flow();

	for(int query_num = 0; query_num < q; ++query_num) {

		int m, a, b;

		scanf("%d%d%d", &m, &a, &b);
		a -= 1; b -= 1;

		if(m == 1) {

			g.restore_edge(a, b);
			flow += g.max_flow();

		} else {

			flow -= g.remove_edge(a, b);
		}

		printf("%d\n", flow);
	}

	return 0;
}

Measured memory_bytes: 1720
//package com.company;
import java.util.*;
import java.lang.*;
import java.io.*;
//****Use Integer Wrapper Class for Arrays.sort()****
public class Main{
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    public static void main(String[] Args)throws Exception{
        FastReader scan=new FastReader(System.in);
        int t=1;
//        t=scan.nextInt();
        while(t-->0){
            int n=scan.nextInt();
            long d=scan.nextInt();
            int c=0;
            for(int i=0;i<n;i++){
                long x=scan.nextInt();
                long y=scan.nextInt();
                if(x*x+y*y<=d*d){
                    c++;
                }
            }
            out.println(c);
        }
        out.flush();
        out.close();
    }
    static class FastReader {

        byte[] buf = new byte[2048];
        int index, total;
        InputStream in;

        FastReader(InputStream is) {
            in = is;
        }

        int scan() throws IOException {
            if (index >= total) {
                index = 0;
                total = in.read(buf);
                if (total <= 0) {
                    return -1;
                }
            }
            return buf[index++];
        }

        String next() throws IOException {
            int c;
            for (c = scan(); c <= 32; c = scan()) ;
            StringBuilder sb = new StringBuilder();
            for (; c > 32; c = scan()) {
                sb.append((char) c);
            }
            return sb.toString();
        }

        int nextInt() throws IOException {
            int c, val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
        long nextLong() throws IOException {
            int c;
            long val = 0;
            for (c = scan(); c <= 32; c = scan()) ;
            boolean neg = c == '-';
            if (c == '-' || c == '+') {
                c = scan();
            }
            for (; c >= '0' && c <= '9'; c = scan()) {
                val = (val << 3) + (val << 1) + (c & 15);
            }
            return neg ? -val : val;
        }
    }
}


Measured memory_bytes: 34476
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a<=b){
			System.out.println(a);
		}else{
			System.out.println(a-1);
		}
	}

}


Measured memory_bytes: 21716
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <array>
#include <deque>
#include <bitset>
typedef long long ll;
using namespace std;
#define trace(x) cerr << #x << " is " << x << endl;

int dp[210][210];
int gcd(int a, int b) {
    if (dp[a][b]) return dp[a][b];
    if (b == 0) return a;
    return dp[a][b] = gcd(b, a % b);
}
int gcd(int a, int b, int c) {
    return gcd(gcd(a, b),c);
}
ll f(int k) {
    ll res = 0;
    for (int a = 1; a <= k; a++) {
        for (int b = 1; b <= k; b++) {
            for (int c = 1; c <= k; c++) {
                res += gcd(a, b, c);
            }
        }
    }
    return res;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k;
    cin >> k;
    cout << f(k) <<endl;
    return 0;
}

Measured memory_bytes: 3776
#include <bits/stdc++.h>                                           
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;                             
 
 
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 221;
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;
 
 

int t, n, a[N], d[N];
string s;

void add (int x) {
	for (int i = 59; i >= 0; --i)
		if (x & (1ll << i)) {
			if (!d[i]) 
				d[i] = x;
			x ^= d[i];
		}
}

main () {
	cin >> t;
	while (t--) {
		cin >> n;
		for (int i = 1; i <= n; ++i)
			cin >> a[i];

		cin >> s;
		
		for (int i = 0; i < 60; ++i)
			d[i] = 0;	
		
		s = "#" + s;

		bool ans = 0;
		for (int i = n; i > 0; --i)	
			if (s[i] == '0') 
				add(a[i]);
			else {
				for (int j = 59; j >= 0; --j) 
					if (a[i] & (1ll << j)) 
						a[i] ^= d[j];					
				if (a[i]) {
					ans = 1;
					break;
				}
			}

		cout << ans << endl;
	}
}

Measured memory_bytes: 3592
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
#include <functional>
#include <random>
#include <thread>
#include <chrono>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vvvl> vvvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
typedef vector<vvpl> vvvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    sort(ALL(vec));
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
//friend bool operator<(const stc& lhs, const stc& rhs){
//    return std::tie(lhs.l, lhs.r) < std::tie(rhs.l, rhs.r);
//}

map<ll, ll> prime_factor(int64_t n) {
    map<ll, ll> ret;
    for(ll i = 2; i * i <= n; i++) {
        while(n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if(n != 1) ret[n] = 1;
    return ret;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll A, B; cin >> A >> B;
    ll g = gcd(A, B);
    auto pf = prime_factor(g);
    cout << pf.size()+1 << endstr;
    return 0;
}


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

#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, n, m) for(int (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
// constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;

int N, M, Q;
vector<int> a, b, c, d;
ll ans = 0;
vector<int> A;

void dfs(int idx, int pre){
  if(idx == N){
    ll sum = 0;
    REP(i, Q){
      if(A[b[i]] - A[a[i]] == c[i]){
        sum += d[i];
      }
    }
    ans = max(ans, sum);
    return;
  }
  FOR(i, pre, M+1){
    A[idx] = i;
    dfs(idx+1, i);
  }
}

int main(){
  cin >> N >> M >> Q;
  a.resize(Q), b.resize(Q), c.resize(Q), d.resize(Q);
  A.resize(N);
  REP(i, Q){
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--, b[i]--;
  }
  dfs(0, 1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int mod = 1e9 + 7;
const int inf = 2e18;

signed main() {
    string S;
    int K;
    cin >> S >> K;
    int N = S.length();
    vector<vector<vector<int>>> dp(N + 1, vector<vector<int>>(4, vector<int>(2, 0)));
    dp[0][0][0] = 1;
    for (int i = 0; i < N; i++) for (int j = 0; j < 4; j++) for (int k = 0; k < 2; k++) {
        int base = S[i] - '0';
        for (int digit = 0; digit < 10; digit++) {
            int nexti = i + 1, nextj = j, nextk = k;
            if (digit != 0) ++nextj;
            if (nextj > K) continue;
            if (k == 0) {
                if (digit > base) continue;
                if (digit < base) nextk = 1;
            }
            dp[nexti][nextj][nextk] += dp[i][j][k];
        }
    }
    cout << dp[N][K][0] + dp[N][K][1] << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int N, K, Q; cin >> N >> K >> Q;
    vector<int> A(N, K);
    for (int i = 0; i < Q; ++i) {
        int a = 0; cin >> a;
        A[a - 1]++;
    }
    for (int i = 0; i < N; ++i) {
        A[i] -= Q;
        if (A[i] <= 0) printf("%s\n", "No");
        else printf("%s\n", "Yes");
    }
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstring>
#include<bitset>
using namespace std;
typedef long long int LL;
int t[2][55];
bool tb[55];
bool tc[55][55];
bool td[55];
int ts;
int main(){
	int n;
	int a,b,c;
	int i,j,k,p,q;
	LL s=0;
	bool fin=false;
	cin>>n;
	for(i=0;i<2;i++){
		for(j=0;j<n;j++){
			cin>>t[i][j];
		}
	}
	for(a=0,i=0;i<n;i++){
		if(t[0][i]==t[1][i])a++;
	}
	if(a==n){
		cout<<0<<endl;
		return 0;
	}
	for(i=0;i<n;i++)tc[i][t[0][i]]=true;
	while(!fin){
		//cout<<bitset<50>(s)<<endl;
		if(ts==n)break;
		for(i=1;i<=50;i++){
			if(s&((LL)1<<i)){
				fin=true;
				break;
			}
			c=0;
			for(j=0;j<n;j++,c++){
				if(td[j])continue;
				for(k=0;k<=t[0][j];k++)tb[k]=tc[j][k];
				for(k=i;k>0;k--){
					for(p=t[0][j];p>=k;p--){
						if(!tb[p])continue;
						tb[p%k]=true;
					}
					if(tb[t[1][j]])break;
				}
				if(!tb[t[1][j]])break;
			}
			if(c==n){
				for(j=0;j<n;j++){
					if(td[j])continue;
					for(k=t[0][j];k>=i;k--){
						if(!tc[j][k])continue;
						tc[j][k%i]=true;
					}
					if(tc[j][t[1][j]])td[j]=true,ts++;
				}
				s+=((LL)1<<i);
				break;
			}
		}
		if(i==51)s=-1,fin=true;
	}
	cout<<s<<endl;
	return 0;
}
	


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#define mm(a,x) memset(a,x,sizeof(a))
#define sync std::ios::sync_with_stdio(false);std::cin.tie(0)
#define ll long long
using namespace std;
struct A{
    int id;
    ll a;
    bool operator<(const A &o)const{
        return a>o.a;
    }
}a[2010];
ll dp[2010][2010];
int main(void)
{
    sync;
    int n;
    cin>>n;
    for(int i=1;i<=n;++i)
    {
        cin>>a[i].a;
        a[i].id=i;
    }
    sort(a+1,a+1+n);
    for(int i=0;i<=n;++i)
    {
        for(int j=0;i+j<=n;++j)
        {
            int k=i+j+1;
            ll v=a[k].a;
            int p=a[k].id;
            dp[i+1][j]=max(dp[i+1][j],dp[i][j]+v*abs(p-i-1));
            dp[i][j+1]=max(dp[i][j+1],dp[i][j]+v*abs(p-(n-j)));
        }
    }
    ll res=0;
    for(int i=0;i<=n;++i)
        res=max(res,dp[i][n-i]);
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 26340
A,B = map(int,input().split())
card=[2,3,4,5,6,7,8,9,10,11,12,13,1]
if card.index(A) > card.index(B):
	print('Alice')
elif card.index(A) == card.index(B):
	print('Draw')
else:
	print('Bob')

Measured memory_bytes: 3060
class UnionFind():
    def __init__(self, n):
        self.parents = [-1]*n
        self.rank = [0]*n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            return self.find(self.parents[x])

    def size(self, x):
        return -self.parents[self.find(x)]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1


N, M = list(map(int, input().split()))
L = [None]*M
for j in range(M):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    L[j] = (a, b)
L = L[::-1]

ans = [0]*(M+1)
ans[0] = (N*(N-1))//2
uf = UnionFind(N)

for j in range(M):
    a, b = L[j]
    if uf.find(a) == uf.find(b):
        ans[j+1] = ans[j]
    else:
        va = uf.size(a)
        vb = uf.size(b)
        ans[j+1] = ans[j]-va*vb
    uf.union(a, b)
# print(ans)
ans = ans[::-1]
for j in range(1, M+1):
    print(ans[j])


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int n ; 
  cin >> n ;
  map<string,int> score ;
  
  rep(i,n){
    string s ;
    cin >> s ;
    score[s] ++;
  }
  
  int ans = score.size();
 cout <<  ans ;
  

}


Measured memory_bytes: 19224
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
int fact(int n){
  int m;
  if (n == 0)
      return 1;
  m = fact(n - 1);    
  return n * m;       
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,u,k,node;
  cin>>n;
  vector<vector<int> > ma(n,vector<int>(n));
  rep(i,n){
      cin>>u>>k;
      rep(j,k){
	  cin>>node;
	  ma[u-1][node-1]=1;
      }
  }
  rep(i,n){
      rep(j,n){
	  cout<<ma[i][j]<<(j!=n-1 ? " " : "");
      }
      cout<<'\n';
  }
  return(0);
}



Measured memory_bytes: 3208
#include <stdio.h>
int main()
{
  int box[10],i,n,a;
  for(i=0;i<10;i++)
  {
    scanf("%d",&box[i]);
  }
  for(i=0;i<10;i++)
  {
    for(n=i+1;n<10;n++)
    {
      if(box[i]>box[n])
      {
        a=box[i];
        box[i]=box[n];
        box[n]=a;
      }
    }
  }
  for(i=9;i>=7;i--)
  {
    printf("%d\n",box[i]);
  }
  return 0;
}

Measured memory_bytes: 600
/*input
1 5 5
1 3
RRRRR
LLLUU
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
string s,t;
int main(){
	IOS;
	int n,m,q;
	cin>>n>>m>>q;
	int x,y;
	cin>>x>>y;
	x--;y--;
	cin>>s>>t;

	int l=0,r=m,d=0,u=n;

	for(int i=q-1;i>=0;i--){
		if(t[i]=='L'){
			r++;
			if(r>m) r--;
		}
		else if(t[i]=='R'){
			l--;
			if(l<0) l++;
		}
		else if(t[i]=='U'){
			u++;
			if(u>n) u--;
		}
		else{
			d--;
			if(d<0) d=0;
		}

		if(s[i]=='L'){
			l++;
		}
		else if(s[i]=='R'){
			r--;
		}
		else if(s[i]=='U'){
			d++;
		}
		else{
			u--;
		}

		if(d==u||l==r){
			cout<<"NO\n";
			return 0;
		}
		// cout<<d<<' '<<u<<' '<<l<<' '<<r<<'\n';
	}
	if(d<=x&&x<u&&l<=y&&y<r){
		cout<<"YES\n";
	}
	else cout<<"NO\n";
	return 0;
}


Measured memory_bytes: 920
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int N;
vector<int> s;
bool f[10100];
int main(){
	cin>>N;
	for(int i=0;i<N;i++){
		int t;
		cin>>t;
		s.push_back(t);
	}
	f[0]=true;
	for(int i=0;i<N;i++){
		for(int j=10000;j>=0;j--){
			if(f[j]==true)f[j+s[i]]=true;
		}
	}
	for(int i=10000;i>=0;i--){
		if(i%10!=0&&f[i]){
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 256
k,n=map(int,raw_input().split())
a=map(int,raw_input().split())
s=0
m=a[1]-a[0]
for i in range(1,n):
	d=a[i]-a[i-1]
	s+=	d
	m=max(m,d)

m=max(m,k-a[-1]+a[0])
s+=(k-a[-1])+a[0]

print s-m

Measured memory_bytes: 20056
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <cstring>
#include <map>
#include <queue>
#include <string>
#define pb push_back
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define inf (int)(1e9)
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;

int main(void){
  int t1,t2,t3;
  t1=t2=t3=0;
  int n,a;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    if(a%4==0) t3++;
    else if(a%2==0) t2++;
    else t1++;
  }
  t2%=2;
  if(t2==1){
    if(t3>=t1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  else{
    if(t3>=t1-1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast","no-stack-protector","unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define F(i,L,R) for(int i=L;i<R;++i)
#define FE(i,L,R) for(int i=L;i<=R;++i)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define debug(x) cout<<(#x)<<"="<<x<<"\n";
#define qq cout<<"QQ\n";
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define f first
#define s second
#define ll long long
#define INF 2000000000
int a[200005];
int main(){
	int k,n;
	while(~getII(k,n)){
		F(i,0,n) getI(a[i]);
		int ans=k,maxV=1;
		F(i,1,n) maxV=max(maxV,a[i]-a[i-1]);
		int last=k-a[n-1]+a[0];
		maxV=max(maxV,last);
		printf("%d\n",ans-maxV);
	}
}


Measured memory_bytes: 1024
e=Hash.new [];n=gets.to_i;(n-1).times{|i|a,b=gets.split;e[a]+=[i];e[b]+=[i]};a=[0]*(n-1);(1..n).map{|w|u={};e[v=w.to_s].map{|j|u[a[j]]=1};t=1;e[v].map{|j|1>a[j]&&(t+=1until u[t].nil?;a[j]=t;t+=1)}};p a.max;a.map{|i|p i}

Measured memory_bytes: 185940
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
        n: usize,
        s: [String; n],
    }
    let mut ac = 0;
    let mut wa = 0;
    let mut tle = 0;
    let mut re = 0;
    for si in s {
        match si.as_str() {
            "AC" => ac += 1,
            "WA" => wa += 1,
            "TLE" => tle += 1,
            "RE" => re += 1,
            _ => {}
        }
    }
    println!("AC x {}", ac);
    println!("WA x {}", wa);
    println!("TLE x {}", tle);
    println!("RE x {}", re);
}


Measured memory_bytes: 7868
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <list>
#include <stack>
#include <queue>
#include <utility>
 
using namespace std;
 
 
#define ll long long
#define MOD 1000000007
#define rep(i, n) for(int i = 0;i < n;i++)

int main()
{
    int n,m;
    cin >> n >> m;
    vector<int> left(m);
    vector<int> right(m);

    for (int i = 0; i < m; i++)
    {
        cin >> left[i] >> right[i];
    }
    
    sort(left.begin(),left.end());
    sort(right.begin(),right.end());
    if (right[0]-left[m-1]>=0)
    {
        cout << right[0]-left[m-1]+1 << endl;
    }else
    {
        cout << 0 << endl;
    }
    
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  int ans = 0;
  for (int i = 0; i <= 100; i++) {
    if (A <= i && i < B && C <= i && i < D) {
      ans++;
    }
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let a = get!();
    let b = get!();
    
    if a > 8 || b > 8 {
    	println!(":(");
    } else {
    	println!("Yay!");
    }
    
}

Measured memory_bytes: 4352
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);       
		int n = sc.nextInt();
        int k = sc.nextInt();
        String s = sc.next();
        int b = (int) s.charAt(k-1);
        b+=32;
		System.out.println(s.substring(0,k-1)+(char)b+s.substring(k,n));
  }
}

Measured memory_bytes: 23764
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<57;
const double pi=acos(-1);
const double eps=1e-6;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,1,1,1,0},DY[8]={1,0,-1,-1,-1,0,1,1};
 
vl a;
 
class Graph{
	private:
	int V,r;
	vvi List;
	vb used;
	bool dfs(int v){
		used[v]=1;
		ll sum=0,M=0;
		for(int i=0;i<List[v].size();i++){
			int u=List[v][i];
			if(!used[u]){
				if(!dfs(u)) return 0;
				sum+=a[u];
				M=max(M,a[u]);
			}
		}
		if(v==r||List[v].size()==1) return 1;
		ll x=2*a[v]-sum;
		if(x<0||x>a[v]||a[v]-x>(M>sum/2?sum-M:sum/2)) return 0;
		a[v]=x;
		return 1;
	}
	public:
	Graph(int v){
		V=v;
		List=vvi(v);
	}
	void add_edge(int s,int t){
		List[s].push_back(t);
		List[t].push_back(s);
	}
	void solve(){
		for(int i=0;i<V;i++) if(List[i].size()==1) r=i;
		used=vb(V);
		bool flag=dfs(r);
		if(a[r]!=a[List[r][0]]) flag=0;
		if(flag) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
};
 
int n;
 
int main(){
	cin>>n;
	Graph g(n);
	a=vl(n);
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=1;i<n;i++){
		int s,t;
		cin>>s>>t;
		g.add_edge(s-1,t-1);
	}
	g.solve();
}

Measured memory_bytes: 11520
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
y=[]
import bisect
for i in range(n):
	y.append(bisect.bisect_left(a,b[i]))
ans=0
q=[]
for i in range(n):
	p=bisect.bisect_left(b,c[i])
	q.append(p)
k=sum(y[0:q[0]])
for i in range(n-1):
	ans+=k
	if q[i+1]!=q[i]:
		k+=sum(y[q[i]:q[i+1]])
ans+=k
print(ans)



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

using namespace std;
using ll = long long;

const ll MOD = 1000000007;

const int MAXN = 200000;

int tree[MAXN] = {};

void add(int idx, int v) {
  for (; idx < MAXN; idx = (idx | (idx + 1))) {
    tree[idx] += v;
  }
}

int sum(int idx) {
  int res = 0;
  for (; idx >= 0; idx = (idx & (idx + 1)) - 1) {
    res += tree[idx];
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<int> ar(n);
  for (auto& v: ar) {
    cin >> v;
  }
  ll cnt = 0;
  for (int i = 0; i < k; ++i) {
    cnt += i - sum(ar[i]);
    add(ar[i], 1);
  }
  int ans = 1;
  bool orig = !cnt;
  for (int i = k; i < n; ++i) {
    bool change = false;
    if (sum(ar[i - k]) > 1) {
      change = true;
    }
    add(ar[i - k], -1);
    cnt -= sum(ar[i - k]);
    add(ar[i], 1);
    cnt += k - sum(ar[i]);
    if (sum(ar[i]) != k) {
      change = true;
    }
    if (cnt == 0) {
      if (orig) {
        change = false;
      }
      orig = true;
    }
    ans += change;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
const double pi = acos(-1);
const double eps = 1e-9;
int main(void){
    int r;
    cin >> r;
    double x = 0, y = 0;
    for(int k=0;;k++){
        x += cos(pi/180*r*k);
        y += sin(pi/180*r*k);
        // cout << x << " " << y << endl;
        if(abs(x) < eps && abs(y) < eps){
            cout << k+1 << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int a[20][20];
int b[20];
int m,n;
int c[20];
int vis[20];
int p[20];
int ans=0;
int cs=0;
void dfs(int pos,int c[])
{
     if(pos==n+1)
     {
         int f=1;
         for(int i=0;i<m;i++)
         {   int s=0;
             for(int j=0;j<b[i];j++)
                 if(c[a[i][j]]==1)
                        s++;
             if(s%2!=p[i])
                 {
                      f=0;
                      break;
                 }
         }
         if(f)
           ans++;
         return ;
     }
       c[pos]=1;
      dfs(pos+1,c);
      c[pos]=0;
      dfs(pos+1,c);
}
int main()
{

    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        cin>>b[i];
        for(int j=0;j<b[i];j++)
        cin>>a[i][j],vis[a[i][j]]++;
    }
    for(int i=0;i<m;i++)
        cin>>p[i];
    dfs(1,c);
    cout<<ans<<endl;
  
    return 0;
}


Measured memory_bytes: 256
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<ctime>
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<deque>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<algorithm>
#include<complex>
#pragma GCC optimize ("O0")
using namespace std;
template<class T> inline T read(T&x){
    T data=0;
	int w=1;
    char ch=getchar();
    while(!isdigit(ch))
    {
		if(ch=='-')
			w=-1;
		ch=getchar();
	}
    while(isdigit(ch))
        data=10*data+ch-'0',ch=getchar();
    return x=data*w;
}
typedef long long ll;
typedef pair<int,int>pii;

const int MAXN=1e5+7;

int n;
map<ll,int>M;
queue<pii>Q;
set<int>l[MAXN];
int fa[MAXN];

int find(int x)
{
	return fa[x]==x?x:fa[x]=find(fa[x]);
}

ll getid(int x,int y)
{
	if(x>y)
		swap(x,y);
	return (ll)x*n+y;
}

void link(int x,int y)
{
	l[x].insert(y);
	l[y].insert(x);
	ll v=getid(x,y);
	++M[v];
/*	if(M[v]==3)
	{
		printf("NO\n");
		exit(0);
	}*/
	if(M[v]==2)
		Q.push(pii(x,y));
}

int main()
{
//  freopen(".in","r",stdin);
//  freopen(".out","w",stdout);
	read(n);
	for(int i=1;i<=n;++i)
		fa[i]=i;
	for(int i=1;i<=2*n-2;++i)
	{
		int x,y;
		read(x);read(y);
		link(x,y);
	}
	for(int i=1;i<n;++i)
	{
		int x,y;
		while(1)
		{
			if(Q.empty())
			{
				printf("NO\n");
				return 0;
			}
			x=Q.front().first,y=Q.front().second;
			Q.pop();
			x=find(x),y=find(y);
			if(x!=y)
				break;
		}
		if(l[x].size()>l[y].size())
			swap(x,y);
		fa[x]=y;
		M.erase(getid(x,y));
		l[y].erase(x);
		for(auto v:l[x])
		{
			v=find(v);
			if(v==y)
				continue;
			M.erase(getid(x,v));
			link(v,y);
			l[v].erase(x);
			l[x].erase(v);
		}
	}
	printf("YES\n");
//  fclose(stdin);
//  fclose(stdout);
    return 0;
}



Measured memory_bytes: 36608
N, K,Q = [int(x) for x in input().split()]
quiz = []
for i in range(Q):
  quiz.append(int(input()))
score = [K-Q]*N
for i in range(len(quiz)):
  score[quiz[i]-1] += 1
for i in range(len(score)):
  if score[i]<=0:
    print("No")
  else:
    print("Yes")

Measured memory_bytes: 56024
#include<iostream>
#include<bits/stdc++.h>
#include<vector>

using namespace std;

int main()
{
	int n,num;
	cin>>n;
	vector<int> height;
	for(int i=0;i<n;i++)
	{
		cin>>num;
		height.push_back(num);
	}
	int dp[n];
	dp[0]=height[0];
	//cout<<dp[0]<<endl;
	if(n==1)
	{
		cout<<height[0];
		return 0;
	}
	dp[1]=abs(height[1]-height[0]);
	if(n==2)
	{
		cout<<dp[1];
		return 0;
	}
	dp[2]=min(abs(height[2]-height[0]),abs(height[2]-height[1])+dp[1]);
	if(n==3)
	{
	    cout<<dp[2];
		return 0;
	}
	//cout<<dp[1]<<endl;
	
	for(int i=3;i<n;i++)
	{
		dp[i]=min(dp[i-1]+abs(height[i]-height[i-1]),dp[i-2]+abs(height[i]-height[i-2]));
		//cout<<dp[i]<<endl;
	}
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 4140