akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

const long long int MOD = 1e9 + 7;

long long int dfs(const int &K, const vector<vector<int>> &graph, int now, int from){

    int can_use_color_num;
    if(from == -1){
        can_use_color_num = K - 1;
    }else{
        can_use_color_num = K - 2;
    }

    if(K < graph[now].size()){
        return 0;
    }else{
        long long int case_num = 1;
        //現在地から子の方向に繋がっているnodeの数を積の形で数えてる
        for(auto e: graph[now]){
            if(e == from) continue;

            case_num *= can_use_color_num;
            can_use_color_num--;
            case_num %= MOD;
        }
        //dfsでさらに深く潜る
        for(auto e: graph[now]){
            if(e == from) continue;
            case_num *= dfs(K, graph, e, now);
            case_num %= MOD;
        }
        return case_num;
    }
}

int main(){
    int N, K; cin >> N >> K;

    vector<vector<int>> graph(N);
    for(int i = 0; i < N - 1; i++){
        int a, b; cin >> a >> b;a--, b--;

        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    long long int answer = K * dfs(K, graph, 0, -1);
    answer %= MOD;
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 11520
#include<stdio.h>

int main()
{
    int N, a=0, b=0, i, bucket;
    scanf("%d", &N);
    int arr[N], arr2[N];

    for(i=0; i<N; i++)
    {
        scanf("%d", &arr[i]);
    }
    for(i=0; i<N-1; i++)
    {
        if(arr[i+1]<arr[i])
        {
            if(a==0)arr2[a] = i;
            else arr2[a] = i+1;
            a++;
        }
    }
    if(a==0)printf("YES");
    else if(a==2)
    {
        bucket = arr[arr2[0]];
        arr[arr2[0]] = arr[arr2[1]];
        arr[arr2[1]] = bucket;

        for(i=0; i<N-1; i++)
        {
            if(arr[i+1]<arr[i])
            {
                b++;
                break;
            }
        }
        if(b==0)printf("YES");
        else printf("NO");
    }
    else printf("NO");

    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<vector>
#include<stack> 
#include<queue>
#include<map>
#define LL long long
#define N 100005
#define MOD 1000000007
#define FOR(i,l,r) for (int i = (l); i <= (r); i ++)
#define CLR(a,x) memset(a,x,sizeof(a))
#define INF 0x7fffffff
#define pb push_back
#define X first
#define Y second
using namespace std;
int a[N];
int main(){
	FOR(i,1,3) scanf("%d",&a[i]);
	sort(a + 1,a + 1 + 3);
 	LL res = (LL)a[1] * a[2];
 	if (a[3] & 1) printf("%lld\n",res);
 	else printf("0\n");
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
const int N=3e5+9,mod=1e9+7;
vector<pair<int,int> > g[N];
int vis[N],a[N],b[N];
vector<int> ans;
int dfs(int u){
    vis[u]=1;
    int ret=b[u];
	for(int i=0;i<g[u].size();i++){
		pair<int,int> x=g[u][i];
		int v=x.first;
        if(!vis[v]){
            int k=dfs(v);
            if(k)ans.push_back(x.second);
            ret^=k;
        }
    }
    return ret;
}
pair<int,int> c[N];
int main(){
	int n=read(),q=read();
    for(int i=1;i<=n;i++)
		c[i].first=read(),c[i].second=read();
    sort(c+1,c+n+1);
    for(int i=1;i<=n;i++)
		a[i]=c[i].first,b[i]=c[i].second;
    for(int i=n+1;i;i--)
		b[i]=b[i-1]^b[i];
    for(int i=1;i<=q;i++){
        int l=read(),r=read();
        int u=lower_bound(a+1,a+n+1,l)-a;
        if(u==n+1 or a[u]>r)
			continue;
        int v=upper_bound(a+1,a+n+1,r)-a;
        g[u].push_back(make_pair(v,i)),g[v].push_back(make_pair(u,i));
    }
    for(int i=1;i<=n+1;i++)
    	if(!vis[i] and dfs(i))
			return puts("-1"),0;
    sort(ans.begin(),ans.end());
    printf("%d\n",ans.size());
	for(int i=0;i<ans.size();i++)
		printf("%d ",ans[i]);
	return 0;
}

Measured memory_bytes: 24444
n, t = map(int, input().split())
 
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
 
a = []
b = []
for ai, bi in ab:
    a.append(ai)
    b.append(bi)
 
dp = [[0 for _ in range(t)] for _ in range(n+1)]
 
for i in range(n):
    for j in range(t):
        if j + a[i] <= t-1:
            if dp[i+1][j + a[i]] < dp[i][j] + b[i]:
                dp[i+1][j + a[i]] = dp[i][j] + b[i]
        if dp[i+1][j] < dp[i][j]:
            dp[i+1][j] = dp[i][j]
 
ans = 0
for i in range(n):
    ans = max(ans,dp[i][t-1]+b[i])
    
print(ans)


Measured memory_bytes: 124376
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

priority_queue<Int,vector<Int>,greater<Int> > R;
priority_queue<Int> L;
int Q;

int main(void) {
    cin>>Q;
    Int sum = 0;
    for(int i = 0;i < Q;i++) {
        int q;
        cin>>q;
        if(q == 1) {
            Int a,b;
            cin>>a>>b;
            sum += b;
            L.push(a);
            R.push(a);

            Int left,right;
            left = L.top();
            right = R.top();
            if(left > right) {
                L.pop();
                R.pop();
                sum += abs(left-right);
                L.push(right);
                R.push(left);
            }
        } else {
            cout<<L.top()<<" "<<sum<<endl;
        }
    }

    return 0;
}


Measured memory_bytes: 4716
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int MAX = min(a, b);
  int MIN = max(0, a+b-n);
  cout << MAX << " " << MIN << endl;
  return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<string> vec(n);
  int ac = 0;
  int wa = 0;
  int tle = 0;
  int re = 0;
  for(int i = 0; i < n; i++) cin >> vec.at(i);
  for(int i = 0; i < vec.size(); i++){
    if(vec.at(i) == "AC") ac++;
    if(vec.at(i) == "WA") wa++;
    if(vec.at(i) == "TLE") tle++;
    if(vec.at(i) == "RE") re++;
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}


Measured memory_bytes: 5268
fun main(args: Array<String>) {
        val (s, t) = readLine()!!.split(" ")
        var (a, b) = readLine()!!.split(" ").map { it.toInt() }
        val u = readLine()!!

        if (u == s) {
            a--
        } else {
            b--
        }

        println("$a $b")
    }

Measured memory_bytes: 37844
#include <algorithm>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
int main() {
    using VertexId = std::uint32_t;
    using EdgeId = std::uint64_t;
    using EdgeWeight = std::uint64_t;

    const auto invalid_distance = std::numeric_limits<EdgeWeight>::max();

    auto n = VertexId(0);
    auto m = EdgeId(0);
    auto r = VertexId(0);
    std::cin >> n >> m >> r;

    auto perm = std::vector<VertexId>();
    for (auto i_ = 0; i_ < r; ++i_) {
        auto v = VertexId(0);
        std::cin >> v;

        perm.emplace_back(v - 1);
    }

    auto distance_map = std::vector<std::vector<EdgeWeight>>(n, std::vector<EdgeWeight>(n, invalid_distance));
    for (auto i_ = 0; i_ < m; ++i_) {
        auto source = VertexId(0);
        auto target = VertexId(0);
        auto weight = EdgeWeight(0);
        std::cin >> source >> target >> weight;

        distance_map[source - 1][target - 1] = weight;
        distance_map[target - 1][source - 1] = weight;
    }

    for (auto k = 0; k < n; ++k) {
        for (auto i = 0; i < n; ++i) {
            for (auto j = 0; j < n; ++j) {
                if ((distance_map[k][i] != invalid_distance && distance_map[k][j] != invalid_distance) &&
                    (distance_map[k][i] + distance_map[k][j] < distance_map[i][j])) {
                    distance_map[i][j] = distance_map[k][i] + distance_map[k][j];
                    distance_map[j][i] = distance_map[k][i] + distance_map[k][j];
                }
            }
        }
    }

    std::sort(perm.begin(), perm.end());

    auto min_distance = invalid_distance;
    do {
        auto sum_distance = EdgeWeight(0);
        for (auto i = 0; i < r - 1; ++i) {
            sum_distance += distance_map[perm[i]][perm[i + 1]];
        }

        if (sum_distance < min_distance) min_distance = sum_distance;
    } while (std::next_permutation(perm.begin(), perm.end()));

    std::cout << min_distance << std::endl;

    return 0;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline

import math
from collections import defaultdict
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""

a=ii()
b=math.ceil(a/1000)
print(b*1000-a)

Measured memory_bytes: 65068
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vecll>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define endl "\n"
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
#define MM " "
#define INF 100000000
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}


    
void go();

main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);cout<<fixed<<setprecision(15);
    int tc=1;
    // tc=in();
    while(tc--){
        go();
    }
    return 0;
}

vector< int > z_algorithm(const vec &s) {
  vector< int > prefix(s.size());
  for(int i = 1, j = 0; i < s.size(); i++) {
    if(i + prefix[i - j] < j + prefix[j]) {
      prefix[i] = prefix[i - j];
    } else {
      int k = max(0, j + prefix[j] - i);
      while(i + k < s.size() && s[k] == s[i + k]) ++k;
      prefix[i] = k;
      j = i;
    }
  }
  prefix[0] = (int) s.size();
  return prefix;
}
void go(){
    int n=in();
    vec aa,bb,a,b;
    rep(i,n)aa.pb(in());
    rep(i,n-1)a.pb(aa[i]^aa[i+1]); a.pb(aa[0]^aa.back());
    rep(j,n)bb.pb(in());
    rep(i,n-1)b.pb(bb[i]^bb[i+1]); b.pb(bb[0]^bb.back());
    rep(ii,2){
        rep(i,n)b.pb(a[i]);
    }
    // print(b);
    auto s = z_algorithm(b);
    vec ans;
    rep2(i,n,n*2-1){
        if(s[i]>=n) cout<<i-n<<" "<<(aa[i-n]^bb[0])<<endl;
    }
    // print(a);print(b);
    
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

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

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

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int x;
	cin >> x;

	int c5 = (x % 500) / 5;
	int c500 = x / 500;

	ll ans = c500 * 1000 + c5 * 5;

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

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

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

    int N,K;
    cin >> N >> K;
    int count = 0;
    rep(i,N){
        int h;
        cin >> h;
        
        if(h >= K) count++;
    }
    
    cout << count << endl;

    return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;

const int INF = 1 << 30;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100;

struct Node {
	int key;
	Node *parent, *left, *right;
};
Node *root;

void insertKey(int k) {
	Node *z = (Node*)malloc(sizeof(Node));
	z->key = k;
	z->left = NULL;
	z->right = NULL;
	Node *y = NULL;
	Node *x = root;
	while (x) {
		y = x;
		if (z->key < x->key)
			x = x->left;
		else
			x = x->right;
	}
	z->parent = y;

	if (y == NULL)
		root = z;
	else if (z->key < y->key)
		y->left = z;
	else
		y->right = z;
}

void findKey(int k) {
	Node *p = NULL;
	Node *c = root;
	while (c) {
		p = c;
		if (k == c->key) {
			cout << "yes" << endl;
			return;
		}
		else if (k < c->key)
			c = c->left;
		else
			c = c->right;
	}
	cout << "no" << endl;
}

void inParse(Node *n) {
	if (n == NULL) return;
	inParse(n->left);
	cout << ' ' << n->key;
	inParse(n->right);
}

void preParse(Node *n) {
	if (n == NULL) return;
	cout << ' ' << n->key;
	preParse(n->left);
	preParse(n->right);
}	

void printKey() {
	inParse(root);
	cout << endl;
	preParse(root);
	cout << endl;
}

int main() {
	int n; cin >> n;
	string com;
	rep(i, n) {
		cin >> com;
		if (com == "insert") {
			int k; cin >> k;
			insertKey(k);
		}
		else if (com == "print")
			printKey();
		else if (com == "find") {
			int k; cin >> k;
			findKey(k);
		}
	}
}



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

int main(void){
  int n,m;
  int i,j;
  int sn[101],sm[101];
  int s;
  while(true){
    cin >> n >> m;
    if(n == 0) break;
    memset(sn,0,sizeof(sn));
    memset(sm,0,sizeof(sm));
    s = 0;
    for(i = 0;i < n;i++){
      cin >> j;
      s += j;
      sn[j]++;
    }
    for(i = 0;i < m;i++){
      cin >> j;
      s -= j;
      sm[j]++;
    }
if(s%2) s = 100000;
s /= 2;
    for(i = 0;i < 101;i++){
      if(sn[i] && i-s >= 0 && i-s <= 100){
	if(sm[i-s]){
	  cout << i << " " << i-s << endl;
	  break;
	}
      }
      if(i == 100) cout << -1 << endl;
    }
  }
}

Measured memory_bytes: 1160
#include<iostream>
using namespace std;
int main(){
  int count=0;
  int A,B,C,X;
  cin >> A >> B >> C >> X;
  int i,j,r;
  for(i=0;i<=A;i++){
    for(j=0;j<=B;j++){
      r=X-i*500-j*100;
      if((r>=0)&&((r%50==0)&&(r/50<=C))){
        count+=1;
      }
    }
  }
  cout << count;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define Z 1000000000
using namespace std;
int main(void){
    long long s, a, b, c, d, ad, bc;
    cin >> s;
    if(s == (long long)Z*Z){
        a = d = Z;
        b = c = 0;
    }else{
        b = 1;
        c = Z - s%Z;
        a = Z;
        d = 1 + s/Z;
    }
    //cout << abs(a*d-b*c) << endl;
    cout << 0 << " " << 0 << " " << a << " " << b << " " << c << " " << d << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int (i)=0;(i) < (N); (i)++)
#define all(V) V.begin(), V.end()
using i64 = int_fast64_t;
using P = pair<int,int>;

int main(){
    long double a, b, x;
    cin >> a >> b >> x;
    const long double Vol = a*a*b; 

    long double ng = 0;
    long double ok = M_PI / 2.0;
    for(int i = 0; i < 100000; i++){
        long double mid = (ok + ng) / 2.0;
        long double water_max = (a *  tan(mid) > b ?  a * b * b  / tan(mid) / 2.0 : Vol - a * a * a * tan(mid) / 2.0);
        if(x > water_max) ok = mid;
        else ng = mid;
    }
    cout << fixed << setprecision(10) << ok * 180 / M_PI  << endl;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $N);
$weights = fgets(STDIN);
$weights_array = explode(" ", $weights, $N);

$s1 = 0;
$s2 = array_sum($weights_array);
$Balance = array();


for($i=0;$i<$N;$i++){
  $s1 = $s1 + $weights_array[$i];
  $s2 = $s2 - $weights_array[$i];
  $Balance[$i] = abs($s2 - $s1);
  if($i>0){
    if($Balance[$i] > $Balance[$i-1]){
      echo min($Balance);
      return;
    }
  }
}

?>

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define REP(i, a) for(int i=0; i<int(a); i++)
#define ALL(x) begin(x), end(x)
#define VI vector<int>
using namespace std;
typedef long long LL;

const int MAX_N=100005;

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

    if(n == 1 && m == 1) {
        cout << 1 << endl;
        return 0;
    }

    if(n > m) swap(n, m);

    if(n == 1 && m >= 2) {
        cout << m - 2 << endl;
        return 0;
    }

    if(n == 2) {
        cout << 0 << endl;
        return 0;
    }
    cout << (n-2) * (m-2) << endl;
    return 0; 
}



Measured memory_bytes: 256
import math
n = int(input())
n_c, n_f = math.ceil(n/1.08), math.floor(n/1.08)
if math.floor(n_c*1.08) == n:
    print(n_c)
elif math.floor(n_f*1.08) == n:
    print(n_f)
else:
    print(':(')


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

#define OnlineJudge1

#define loop(x,a,n) for(int x = a;x < n;x++)
#define NumofDigits(n) ((int)log10(n)+1)
#define CountofNumber(array,n,x)  (upper_bound(array, array+n, x)-lower_bound(array, array+n, x))
#define readline(s) getline(cin,s)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define EPS 1e-7
#define modulo ll (1e9 + 7)
const long double PI = 3.141592653589793238L;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,ll> pill;
typedef pair<ll,ll> pll;

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

#define time__(d) \
    for ( \
        auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); \
        blockTime.second; \
        debug("%s: %lld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false \
    )

void init(){
    cin.tie(0);
    ios::sync_with_stdio(0);
#ifdef OnlineJudge
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif
}


int main(){
    init();

    ll n, k;    cin >> n >> k;
    ll ans = k;
    for(int i = 0;i < n - 1;i++)
        ans *= k - 1;
    cout << ans;
}

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

#define R (long long)(1e9 + 7)
#define INF (long long)(1e16L + 5)
#define ll long long
#define grid vector<vector<ll>>

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s, t;
    cin >> s >> t;
    int n = s.length();
    int m = t.length();
    long long ans = INF;
    for(int i = 0; i <= n - m; i++)
    {
        string temp = s.substr(i, m);
        long long cnt = 0;
        for(int j = 0; j < m; j++)
            cnt = cnt + (temp[j] != t[j]);
        ans = min(ans, cnt);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    long long x, y, ans = 0;

    cin >> x >> y;

    while(x <= y){
        if(x <= y)  ++ans;
        x *= 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
 
using vd=vector<double>;
using vvd=vector<vd>;
 
 
int main(){
    int h,w;
    cin>>h>>w;
    vvi f(h+2,vi(w+2,1));
    vvi walk(h+2,vi(w+2,0));
    int gy,gx,y=0,x=0,v=0;
    range(i,1,h+1)range(j,1,w+1){
        char c;
        cin>>c;
        switch(c){
            case 'G': gy=i,gx=j,f[i][j]=0; break;
            case '.': f[i][j]=0;break;
            case '#': break;
            case '^': y=i,x=j,v=0,f[i][j]=0; break;
            case '>': y=i,x=j,v=1,f[i][j]=0; break;
            case 'v': y=i,x=j,v=2,f[i][j]=0; break;
            case '<': y=i,x=j,v=3,f[i][j]=0; break;
        }
    }
    walk[y][x]=1;
    rep(loop,2646){
        vvi vec={{-1,0},{0,1},{1,0},{0,-1}};
        if(f[y+vec[(v+1)%4][0]][x+vec[(v+1)%4][1]]==0){ //右手が道なら右に曲がって前に進む
            //cout<<"hoge";
            v=(v+1)%4;
            y+=vec[v][0], x+=vec[v][1];
            walk[y][x]=1;
        }else if(f[y+vec[v][0]][x+vec[v][1]]==1){ //（右が壁で、）正面が壁なら左に回る
            //cout<<"fuga";
            v=(v+3)%4;
        }else{ //そうでないならまえに進む
            //cout<<"zako";
            y+=vec[v][0],x+=vec[v][1];
            walk[y][x]=1;
        }
        if(y==gy&&x==gx){
            break;
        }
        // cout<<y<<","<<x<<","<<v<<endl;
        // rep(i,h+2){
        //     rep(j,w+2){
        //         if(i==y&&j==x){
        //             cout<<"^>v<"[v];
        //         }else{
        //             cout<<".#"[f[i][j]];
        //         }
        //     }
        //     cout<<endl;
        // }
    }
    if(y==gy&&x==gx){
        int ans=0;
        rep(i,h+2)rep(j,w+2)ans+=walk[i][j];
        cout<<ans<<endl;
    }else cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 3192
#min query から初期化を0にしてminを+に変えただけ
#minquery の方は0-indexだったがこっちは1-index
n,q = map(int,input().split( ))
s = 1
while s < n:
    s*=2

A = [0]*(2*s-1)

def query(a,b,k,l,r):#区間[a,b)について[l,r)を担当するkが答える
    if r<=a or b<=l:#はみ出る
        return 0
    if a<=l and r<=b:#含まれる
        return A[k]
    else:#ノード追うのが大変,##+1,+2
        c1 = query(a,b,2*k+1,l,(l+r)//2)    
        c2 = query(a,b,2*k+2,(l+r)//2,r)
        return c1+c2

for _ in range(q):
    c,x,y = map(int, input().split( ))
    if not c:
        x += (s-1)###-1
        x -=1###
        A[x] += y
        while x>0:
            x =(x-1)//2
            A[x] = A[x*2+1]+A[x*2+2]##+1,+2
        #print(A)
            
    else:
        print(query(x-1,y,0,0,s))
        #pass


Measured memory_bytes: 10736
def is_kaibunn(word):
  new_word = ''.join(list(reversed(word)))
  return word == new_word
  
S = input()
N = len(list(S))
if is_kaibunn(S) and is_kaibunn(S[0:int((N-1)/2)]) and is_kaibunn(S[int((N+3)/2 - 1):N]):
  print("Yes")
else:
  print("No")

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    priority_queue<ll> p;
    for(int i=0;i<n;i++){
        ll x;
        cin>>x;
        p.push(x);
    }
    for(int i=0;i<m;i++){
        ll x = p.top();
        p.pop();
        x /= 2;
        p.push(x);
    }
    ll ans = 0;
    while(!p.empty()){
        ans += p.top();
        p.pop();
    }
    cout<<ans<<"\n";
    return 0;

}




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

#define rep(i, n) for(int i = 0; i < n; i++)

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    int N; cin >> N;
    ll A[N]; rep(i, N) cin >> A[i];
    ll ans = 0;
    ll ruiseki[120] = {};
    rep(i, N){
        ll val = 1;
        rep(j, 60){
            if((val & A[i]) == val){
                ruiseki[(j<<1)]++;
            }
            else ruiseki[(j<<1)+1]++;
            val <<= 1;
        }
    }
    ll val = 1;
    rep(i, 60){
        ans = (ans + ((val%mod)*(ruiseki[(i<<1)]*ruiseki[(i<<1)+1] % mod) % mod)) % mod;
        val <<= 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
 
#define lint long long
#define VI vector<int>
#define VL vector<lint>
#define VB vector<bool>
#define VC vector<char>
#define VS vector<string>
#define VVI vector<VI>
#define VVL vector<VL>
#define rep(i, n) for(int i = 0 ; i < n ; i++)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main(){
    string o, e;
    cin >> o >> e;
    rep(i, e.size()){
        cout << o[i] << e[i];
    }
    if(o.size() != e.size()){
        cout << o[o.size() - 1];
    }
    cout << endl;
    return 0;
}

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

int main(){
int n, q;
    cin >> n >> q;
    vector<int> ve(n), ho(n);
    auto ans = long(n - 2) * (n - 2);
    for (int vl = n, hl = n; q--;) {
      int tp, x;
      cin >> tp >> x;
      if (tp == 1) {
        if (x < vl) {
          while (vl > x) {
            ve[--vl] = hl;
          }
          ans -= hl - 2;
        } else {
          ans -= ve[x] - 2;
        }
      } else {
        if (x < hl) {
          while (hl > x) {
            ho[--hl] = vl;
          }
          ans -= vl - 2;
        } else {
          ans -= ho[x] - 2;
        }
      }
    }
    cout << ans << endl;
}


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

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define int long long
#define pb push_back
#define pii pair<int,int>
#define ppii pair<pii,pii>
#define fr(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define ccM 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int32_t main()
{   fastio;
    int n;
    cin>>n;
    int arr[n];
    map<int , int>mp;
    for(int i=0; i<n; i++) {
        cin>>arr[i];
        mp[arr[i]]++;
    }
    for(int i=1; i <= n; i++)
    {
        if(mp.find(i) != mp.end())cout<<mp[i]<<endl;
        else cout<<0<<endl;
    }
}

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

const int maxn = 20;

char s[maxn];
typedef long long LL;
LL cal(int L,int R)
{
    LL res = 0;
    for(int i = L;i <= R;++i)
        res = res*10 + (s[i]-'0');
    return res;
}

int main()
{
    //freopen("./test.txt","r",stdin);
    scanf("%s",s);
    int sz = strlen(s);
    sz--;
    LL res = 0;
    for(int msk = 0;msk < (1 << sz);++msk)
    {
        vector<int> V;
        for(int i = 0;i < sz;++i)
            if(msk & (1 << i))
                V.push_back(i);

        int L = 0;
        LL num = 0;
        for(int i = 0;i < V.size();++i)
        {
            int R = V[i];
           // printf("[%d,%d]\n",L,R);

            num += cal(L,R);
            L = R+1;

        }
        num += cal(L,sz);
        res += num;
    }
    printf("%lld\n",res);

    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
priority_queue<long long>q1,q2;
long long a[300010],f1[300010],f2[300010];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	long long n,s1=0,s2=0,ans=-9e18;
	cin>>n;
	for(long long i=1;i<=3*n;i++){
		cin>>a[i];
		if(i<=n){
			s1+=a[i];
			q1.push(-a[i]);
		}
		if(i>2*n){
			s2+=a[i];
			q2.push(a[i]);
		}
	}
	f1[n]=s1;
	for(long long i=n+1;i<=2*n;i++)
	if(-q1.top()<a[i]){
		s1+=a[i]-(-q1.top());
		q1.pop();
		q1.push(-a[i]);
		f1[i]=s1;
	}
	else f1[i]=s1;
	f2[n*2]=s2;
	for(long long i=n*2-1;i>=n;i--)
	if(q2.top()>a[i+1]){
		s2+=a[i+1]-q2.top();
		q2.pop();
		q2.push(a[i+1]);
		f2[i]=s2;
	}
	else f2[i]=s2;
	for(long long i=n;i<=2*n;i++)
	ans=max(ans,f1[i]-f2[i]);
	cout<<ans<<"\n";
	return 0;
}
 

Measured memory_bytes: 7796
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define itn int
#define fi first
#define se second
#define be begin()
#define en end()
#define reverse
const int mod=1000000007;
const int INFi=2147483647;
const long long INFl=9223372036854775807LL;
template<typename T> T abs(T a,T b){
  return max(a,b)-min(a,b);
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int k,a,b,f=0;
  cin>>k>>a>>b;
  for(int i=a;i<=b;i++){
    if(i%k==0) f=1;
  }
  if(f) cout<<"OK\n";
  else cout<<"NG\n";
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string S;
    cin >> S;
    int count1 = 1;
    int count2 = 0;
    char c;
    for (int i = 1; i < 4; i++)
        if (S[0] == S[i])
            count1++;
        else if (c == S[i])
            count2++;
        else {
            c = S[i];
            count2 = 1;
        }
    
    if (count1 == 2 && count2 == 2)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


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++)
const long long INF = numeric_limits<long long>::max();

int main(){
    ll n;
    cin >> n;
    ll ans=0;
    for (ll z = 2; z<=sqrt(n); z++){
        if (n%z != 0)
            continue;
        ll num = 0;
        while (n%z == 0){
            n=n/z;
            num++;
        }
        for (ll j=1; ;j++){
            if (num>=j){
                num -= j;
                ans++;
            }
            else
                break;
        }
    }
    if (n != 1)
        ans++;
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) ( ((x)&1)==0?0:1 )
#define SIGN(x) ( ((x) > 0) - ((x) < 0)  )
#define dbg(x) cerr << #x"= " << x << endl


inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(bool _local){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    if (_local)
        freopen ("in.txt", "r", stdin);
#endif
}

struct cmp{
    bool operator()(const vi &a,const vi &b)const{
        if (a[0]==b[0]) return a[1]<b[1];
        return a[0]>b[0];
    }
};
int n;
vector<vii> g;
int solve(){
    vector<map<int,int>> dist(n+1);
    for(int i=2;i<=n;++i){
        for(ii e:g[i]) dist[i][e.second]++;
        auto it=dist[i].begin();
        while(it!=dist[i].end()){
            if (it->second>1) {it->second=INF;++it;}
            else it=dist[i].erase(it);
        }
        dist[i][-1]=INF;
    }
    vector<int> mnd(n+1,INF);
    mnd[1]=0;
    priority_queue<vi,vvi, cmp> q;
    q.push(vi{0,1,-1});
    while(!q.empty()){
        auto v=q.top();q.pop();
        if (v[1]==n) return v[0];
        if (mnd[v[1]] < v[0]) continue;
        for(ii ch:g[v[1]]){
            if (mnd[ch.first] < v[0]) continue;
            int d = v[0] + (v[2]!=ch.second);
            auto it= (ch.second==-1? dist[ch.first].begin():dist[ch.first].find(ch.second));
            if (it==dist[ch.first].end()){
                if (dist[ch.first].begin()->second <= d) continue;
                dist[ch.first].begin()->second = d;
                q.push(vi{d,ch.first,-1});
                mnd[ch.first]=min(mnd[ch.first],d);
            }
            else if (it->second>d){
                it->second=d;
                q.push(vi{d,ch.first,ch.second});
                mnd[ch.first]=min(mnd[ch.first],d);
            }
        }
    }
    return -1;
}


int main() {
    READ(0);
    int m;cin>>n>>m;
    g.resize(n+1);
    FOR(i,m){
        int u,v,c;cin>>u>>v>>c;
        g[u].emplace_back(v,c);
        g[v].emplace_back(u,c);
    }
    cout << solve();
    return 0;
}

Measured memory_bytes: 30560
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,A[2001];
	int Asum=0;
	scan(N);
	rep(i,N){
		scan(A[i]);
		Asum+=A[i];
	}
	bitset<4000001> dp;
	dp.set(0);
	rep(i,N){
		bitset<4000001> pd;
		pd |= dp;
		pd |= dp<<A[i];
		dp = pd;
	}
	for(int i=Asum/2+Asum%2;;i++){
		if(dp[i]){
			prin(i);
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 2176
"""
問題: https://atcoder.jp/contests/abc130/tasks/abc130_e
解説: https://drken1215.hatenablog.com/entry/2019/06/21/230200

共通部分列を数え上げる問題．
"""


def main1():
    """LCS (Longest Common Sequence)を改良する．

    LCSでは最長部分列の長さを求めるが，今回は個数を求める．
    重複して数えている分を引けば良い．
    """
    N, M = map(int, input().split())
    S = list(map(int, input().split()))
    T = list(map(int, input().split()))

    dp = [[0] * (M + 1) for _ in range(N + 1)]
    MOD = 10 ** 9 + 7

    for i in range(N + 1):
        dp[i][0] = 1

    for j in range(M + 1):
        dp[0][j] = 1

    for i in range(N):
        for j in range(M):
            if S[i] == T[j]:
                dp[i + 1][j + 1] += dp[i][j]
            dp[i + 1][j + 1] += dp[i][j + 1] + dp[i + 1][j] - dp[i][j]
            dp[i + 1][j + 1] %= MOD

    print(dp[-1][-1])


def main2():
    N, M = map(int, input().split())
    S = list(map(int, input().split()))
    T = list(map(int, input().split()))

    dp = [[0] * (M + 1) for _ in range(N + 1)]
    sdp = [[0] * (M + 2) for _ in range(N + 2)]
    MOD = 10 ** 9 + 7

    dp[0][0] = 1
    sdp[1][1] = 1

    for i in range(N + 1):
        for j in range(M + 1):
            if i == 0 and j == 0:
                continue
            if i >= 1 and j >= 1 and S[i - 1] == T[j - 1]:
                dp[i][j] = sdp[i][j]
            sdp[i + 1][j + 1] = (sdp[i + 1][j] + sdp[i][j + 1] - sdp[i][j]
                                 + dp[i][j])
            sdp[i + 1][j + 1] %= MOD

    print(sdp[-1][-1])


if __name__ == "__main__":
    # main1()
    main2()


Measured memory_bytes: 137268
ans = 'Yes'
n = int(input())
for _ in range(n):
    t, x, y = map(int, input().split())
    if t < x + y:
        ans = 'No'
        break
    if  t % 2 != 0 and (x - y) % 2 == 0:
        ans = 'No'
        break
    elif t % 2 == 0 and (x - y) % 2 != 0:
        ans = 'No'
        break

print(ans)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
   char x,y;
   cin>>x>>y;
   if((int)x<(int)y)cout<<'<'<<endl;
   if((int)x>(int)y)cout<<'>'<<endl;
   if((int)x == (int)y)cout<<'='<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll long long
#define int long long
#define pb push_back
#define x first
#define ld long double
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) a.begin(),a.end()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector <int> a(n);
    int x = 0;
    for (auto &i : a) {
        cin >> i;
        x ^= i;
    }
    for (auto &i : a) {
        cout << (x ^ i) << ' ';
    }
    cout << '\n';
}


Measured memory_bytes: 4820
let () =
  let n = Scanf.sscanf (input_line stdin) "%d" (fun a -> a) in
  let rec loop i =
    if i > 9 then "No"
    else if n mod i = 0 then
      if n / i <= 9 then "Yes" else loop (i + 1)
    else loop (i + 1)
  in
  print_string (loop 1);
  print_newline ()


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int f_N = 0;
  
  f_N += N / 100000000;
  
  for (int i = 0; i < 7; i++) {
    int j = 1;
    
    for (int k = 0; k < i; k++) {
      j *= 10;
    }

    f_N += (N % (100 * j)) / (10 * j);
  }
  
  f_N += N % 10;

  if (N % f_N == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
}

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

signed main() {
  int h,w,a,b;
    scanf("%d%d%d%d",&h,&w,&a,&b);
    	string s(a,'0');
    	string t(w-a,'1');
        string ans=s+t;
  		string S(a,'1');
  		string T(w-a,'0');
  		string Ans=S+T;
  for(int i=0;i<h;i++){
    if(i<b){
    	printf("%s\n",ans.c_str());
    }
    else{
    	printf("%s\n",Ans.c_str());
    }
  }
}

Measured memory_bytes: 1280
#include<iostream>
using namespace std;
int main()
{
 /* int n;cin>>n;
  while(n>=0)
 {
    if(n%10==7)
    {
      cout<<"Yes"<<endl;
      return 0;
    }
    n=n/10;
 }*/
  
  char nums[3];
 int i=0;
 while(i<3)
 {
         cin>>nums[i];
         if(nums[i]=='7')
         {
                 cout<<"Yes"<<endl;
                 return 0;
         }
         i++;
 }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
typedef pair<char, bool> pi; //0 left, 1 right
#define f first
#define s second

long long n, q;
pi spells[200005];
string ss;
long long upper, lower, mid, ri, le;

long long __attribute__((optimize("Ofast"), target("arch=sandybridge"))) bsta(long long guess) {
	long long pos = guess;
	for (long long i = 0; i < q; i++) {
		if (spells[i].f == ss[pos]) {
			if (spells[i].s) pos++;
			else pos--;
		}
		if (pos < 0) return -1; //Felong long off left side
		else if (pos >= n) return 1; //Felong long off right side
	}
	return 0;
}

int __attribute__((optimize("Ofast"), target("arch=sandybridge"))) main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	cin >> n >> q >> ss;
	for (long long i = 0; i < q; i++) {
		char x;
		cin >> spells[i].f >> x;
		if (x == 'L') spells[i].s = 0;
		else spells[i].s = 1;
	}
	lower = -1, upper = n;
	while (upper - lower > 1) {
		mid = ((upper + lower)>>1);
		if (bsta(mid) == -1) lower = mid;
		else upper = mid;
	}
	le = upper;
	lower = -1, upper = n;
	while (upper - lower > 1) {
		mid = ((upper + lower)>>1);
		if (bsta(mid) == 1) upper = mid;
		else lower = mid;
	}
	ri = lower;
	cout << ri - le + 1;
}


Measured memory_bytes: 976
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define deb(x) cout << #x << "-->" << x << endl;
#define deb1a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
    {                             \
        cout << it << " ";        \
    }                             \
    cout << endl;
#define deb2a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
    {                             \
        for (auto it1 : it)       \
        {                         \
            cout << it1 << " ";   \
        }                         \
        cout << endl;             \
    }
    #define mod 1000000007

vec p(12);

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    
    int ans = 0;
    fo(i,m)
    {
        int x;
        cin >> x;
        n -= x;
       
    }
    if(n<=0)
        cout << "Yes";
        else
        {
            cout << "No";
        }
        


}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

vector<vector<int>> to;
vector<int> cnt;
void dfs(int i,int pre,int c){
    cnt[i]+=c;
    for(auto e:to[i]){
        if(e==pre) continue;
        dfs(e,i,cnt[i]);
    }
}
int main(){
    int N,Q;cin>>N>>Q;
    to.resize(N);
    cnt.resize(N,0);
    REP(i,N-1){
        int a,b; cin>>a>>b;
        a--;b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    REP(i,Q){
        int p,x;cin>>p>>x;
        p--;
        cnt[p]+=x;
    }
    dfs(0,-1,0);
    REP(i,N) cout<<cnt[i]<<" \n"[i==N-1];
}

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

 
int main() {
  int n;
  cin >> n;
  vector<vector<int>> g(n, vector<int>(0));
  rep (i, n) {
    int x, k;
    cin >> x >> k;
    g[i].resize(k);
    rep (j, k) {
      cin >> x;
      g[i][j] = x - 1;
    }
  }

  queue<int> que;
  vector<int> d(n, -1);
  d[0] = 0;

  for (int x : g[0]) {
    que.push(x);
    d[x] = 1;
  }
  while (!que.empty()) {
    int v = que.front(); que.pop();
    for (int vn : g[v]) {
      if (d[vn] != -1) continue;
      d[vn] = d[v] + 1;
      que.push(vn);
    }
  }

  

  rep (i, n) {
    printf("%d %d\n", i + 1, d[i]);
  }
}


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

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define pb(i) push_back(i)
#define INF 100100100
#define EPS 1e-9
#define itn int
typedef long long ll;
typedef vector<int> vi;
typedef map<string, int> msi;


template<typename T, typename U>
T gcd(T a, T b) {return (b ? gcd(b, a%b) : a);}

template<typename T, typename U>
T lcm(T a, T b) {return (a * b / gcd(a, b));}


int in() {int x; cin >> x; return x;}

int main()
{
    int a, b, c;

    cin >> a >> b;
    cout << (a % b == 0 ? 0 : 1) << endl;

    return (0);
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<vector>
#include<queue>
using namespace std;
vector<pair<int,int> > g[110000];
vector<pair<int,int> > G[310000];
int v[310000];
int ijk[310000];
int main(){
    int a,b;scanf("%d%d",&a,&b);
    for(int i=0;i<b;i++){
        int p,q,r;scanf("%d%d%d",&p,&q,&r);
        p--;q--;
        g[p].push_back(make_pair(r,i));
        g[q].push_back(make_pair(r,i));
        G[i].push_back(make_pair(b+p,0));
        G[i].push_back(make_pair(b+q,0));
        G[b+p].push_back(make_pair(i,1));
        G[b+q].push_back(make_pair(i,1));
    }
    for(int i=0;i<a;i++){
        if(g[i].size()==0)continue;
        std::sort(g[i].begin(),g[i].end());
        int st=0;
        for(int j=0;j<g[i].size();j++){
            if(j&&g[i][j].first!=g[i][j-1].first){
                for(int k=st;k<j-1;k++){
                    G[g[i][k].second].push_back(make_pair(g[i][k+1].second,0));
                }
                G[g[i][j-1].second].push_back(make_pair(g[i][st].second,0));
                st=j;
            }
        }
        for(int k=st;k<g[i].size()-1;k++){
            G[g[i][k].second].push_back(make_pair(g[i][k+1].second,0));
        }
        G[g[i][g[i].size()-1].second].push_back(make_pair(g[i][st].second,0));
    }
    for(int i=0;i<310000;i++)ijk[i]=999999999;
    ijk[b]=0;
    priority_queue<pair<int,int> > Q;
    Q.push(make_pair(0,b));
    while(Q.size()){
        int cost=-Q.top().first;
        int at=Q.top().second;
        Q.pop();
        if(v[at])continue;
        v[at]=1;
        for(int i=0;i<G[at].size();i++){
            int to=G[at][i].first;
            int tc=cost+G[at][i].second;
            if(!v[to]&&ijk[to]>tc){
                ijk[to]=tc;Q.push(make_pair(-tc,to));
            }
        }
    }
    if(ijk[b+a-1]>99999999)printf("-1\n");
    else printf("%d\n",ijk[b+a-1]);
}

Measured memory_bytes: 37368
let () =
  let n = Scanf.scanf "%d\n" (fun a -> a) in
  let read () = Array.init n (fun _ -> Scanf.scanf "%f " (fun a -> a)) in
  let x = read () and y = read () in
  let abs_s = Array.mapi (fun i x -> abs_float (x -. y.(i))) x in
  let cal_distance p = (Array.fold_left (fun e x -> e +. x ** p) 0. abs_s) ** (1. /. p) in
  Printf.printf "%10f\n%10f\n%10f\n%10f\n" (cal_distance 1.) (cal_distance 2.) (cal_distance 3.) (Array.fold_left (fun e x -> max e x) 0. abs_s) ;;


Measured memory_bytes: 2604
import itertools

n,m,Q = map(int,input().split())
q = []
number = [i for i in range(1,m+1)]
kouho = itertools.combinations_with_replacement(number, n)
for i in range(Q):
    q.append(list(map(int,input().split())))

ans = []

for i in kouho:
    tmpans = 0
    for j in q:
        if i[j[1] - 1] - i[j[0] - 1] == j[2]:
            tmpans +=j[3]
    ans.append(tmpans)

print(max(ans))

Measured memory_bytes: 72012
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main()
{
  int n,a[100],sum=0;
  cin>>n;
  rep(i,n)
  {
    cin>>a[i];
    sum+=a[i];
  }
  sort(a,a+n);
  int ans=sum;

  if(sum%10==0)
  {
    rep(i,n)
    {
      if(a[i]%10!=0)
      {
        ans-=a[i];
        break;
      }
    }
    if(ans==sum) ans=0;
  }
  else ans=sum;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<string>
#include<queue>
#include<iostream>
using namespace std;
int my_strcmp(char *a,char *b);
int main()
{
    int n,i,j,m,n1,m1;
    char s[1100][1100],t[1100];
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        for(i=0;i<n;i++)
        {
            scanf("%s",s[i]);
        }
        for(i=0; i<n-1; i++)
        {
            for(j=i+1; j<n; j++)
            {
                if(my_strcmp(s[i],s[j])<0)
                {
                    strcpy(t,s[i]);
                    strcpy(s[i],s[j]);
                    strcpy(s[j],t);
                }
            }
        }
        for(i=0; i<n; i++)
            printf("%s",s[i]);
        printf("\n");
    }
    return 0;
}
int my_strcmp(char *a,char *b)
{
    char a0[310],b0[310];
    int i,len_a,len_b;
    len_a=strlen(a);
    len_b=strlen(b);
    for(i=0;a[i];i++)
    {
        a0[i]=a[i];
        b0[i+len_b]=a[i];
    }
     for(i=0;b[i];i++)
    {
        b0[i]=b[i];
        a0[i+len_a]=b[i];
    }
    a0[len_a+len_b]='\0';
    b0[len_a+len_b]='\0';
    if(strcmp(a0,b0)>0)
    {
        return -1;
    }
    else return 0;

}


Measured memory_bytes: 384