akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
#define MAX_N 100005
 
ull B=5575777;
ull mem[MAX_N];
 
ull pow(int x){
  assert(0<=x && x<MAX_N);
 
  if(x==0)return 1;
  if(mem[x]>0)return mem[x];
  if(x&1)return mem[x]=pow(x-1)*B;
  mem[x]=pow(x/2);
  mem[x]*=mem[x];
  return mem[x];
}
 
int n,q,l,r,t;
char s[MAX_N];
ull p[MAX_N];
 
ull get(int l,int r){
  if(l==r)return 0;
 
  return p[r]-p[l]*pow(r-l);
}
 
ull get(int l,int r,int x,char ch){
  if(l==r)return 0;
 
  ull res=p[r]-p[l]*pow(r-l);
  if(l<=x&&x<r){
    int dist=r-x-1;
    res-=pow(dist)*s[x];
    res+=pow(dist)*ch;
  }
  return res;
}
 
bool eq(int a,int b,int l,int r){
  assert(b-a==r-l);
  assert(a!=l);
  return ( get(a,b) == get(l,r) );
}
 
bool eq(int a,int b,int l,int r, int x,char ch){
  assert(b-a==r-l);
  assert(a!=l);
  return ( get(a,b,x,ch) == get(l,r,x,ch) );
}
 
bool calc(int a,int b,int l,int r){
  assert(b-a==r-l);
  assert(a!=l);
 
  if(b-a!=r-l)return false;
  int L=0,R=b-a+1,M;
  while(R-L>1){
    M=(L+R)/2;
    if( eq(a,a+M,l,l+M) ){
      L=M;
    }else{
      R=M;
    }
  }
  if(L==b-a)return true;
  return ( eq(a,b,l,r, l+L, s[a+L])  );
  //return ( eq(a,b,l,r, l+L, s[a+L]) || eq(a,b,l,r, a+L, s[l+L] )  );
}
 
bool intersect(int a,int b,int l,int r){
  if( b<=l || r<=a ) return false;
  else return true;
}
 
bool solve(){
  int len=r-l;
  if(t==len)return true;
  if(t*2>=len){
    return ( calc(l,l+(len-t),r-(len-t),r)   ||  calc(r-(len-t),r,l,l+(len-t)) );
  }
 
 
  if(len%t==0){
    return ( calc(l,r-t,l+t,r) || calc(l+t,r,l,r-t) );
  }
  int as=len%t;
 
  //  calc(l+as,r-t,l+as+t,r);
  //  if ( calc(l+as,r-t ,l+as+t,r) && ( eq(l,l+as,r-t,r-t+as) || eq(l,l+as,r-t-t,r-t-t+as) ) )return true;
  //if ( eq(l+as,r-t ,l+as+t,r) && ( calc(l,l+as,r-t,r-t+as) || calc(l,l+as,r-t-t,r-t-t+as) ) )return true;
  
  //if ( calc(l,r-as-t ,l+t,r-as) && (eq(l,l+as,r-as,r) ||eq(l+t,l+t+as,r-as,r) ) )return true;
  //if ( eq(l,r-as-t ,l+t,r-as) && ( calc(l,l+as,r-as,r) || calc(l+t,l+t+as,r-as,r) ) )return true;
 
 
  if ( calc(l,r-as-t ,l+t,r-as) && eq(l,l+as,r-as,r)  )return true;
  if ( calc(l+t,r-as ,l,r-as-t) && eq(l+t,l+t+as,r-as,r)  )return true;
  if ( eq(l,r-as-t ,l+t,r-as) && calc(l,l+as,r-as,r)  )return true;
 
  return false;
}
 
int main(){
  scanf("%s",s);
  n=strlen(s);
 
  p[0]=0;
  for(int i=1;i<=n;i++){
    p[i]=p[i-1]*B+s[i-1];
  }
 
  scanf("%d",&q);
  while(q--){
    scanf("%d %d %d",&l,&r,&t);
 
    l--;
 
    if(solve())printf("Yes\n");
    else printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 2836
N,M = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(M)]

ans = 0
for i in range(M):
    ab2 = ab[:i] + ab[i+1:]
    connect = [[] for _ in range(N+1)]
    for a,b in ab2:
        connect[a].append(b)
        connect[b].append(a)
    V = [-1] * (N+1)
    V[0] = 0
    V[1] = 0
    q = [1]
    for j in q:
        for k in connect[j]:
            if V[k] == -1:
                V[k] = V[j] + 1
                q.append(k)
    
    for v in V[1:]:
        if v == -1:
            ans += 1
            break
print(ans)

Measured memory_bytes: 3064
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<vector>
#define MN 100000
#define pa pair<int,int>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
inline int Ran()
{
	static int x=23333;
	x^=(x<<13);x^=(x>>17);x^=(x<<5);
	return x;	
}
vector<int> v[MN+5];
int X,n,m,a[MN+5],R[MN+5],t[MN+5],Ans[MN+5],l[MN+5],K[MN+5];
int r[MN+5],tag[MN+5],val[MN+5],rk[MN+5],Fa[MN+5],rt,top,q[MN+5];
bool cmp(int x,int y){return a[x]<a[y];}
inline void Add(int x,int v){if(x)a[x]+=v,val[x]+=v;}
inline void Mark(int x,int v){if(x)tag[x]=1,a[x]=val[x]=v;}
inline void pushdown(int x)
{
	if(tag[x]) Mark(l[x],val[x]),Mark(r[x],val[x]),tag[x]=0,val[x]=0;
	else if(val[x]) Add(l[x],val[x]),Add(r[x],val[x]),val[x]=0;
}
int Merge(int x,int y)
{
	if(!x||!y) return x|y;
	if(K[x]<K[y])
	{
		pushdown(x);
		r[x]=Merge(r[x],y);Fa[r[x]]=x;
		return x;
	}
	else 
	{
		pushdown(y);
		l[y]=Merge(x,l[y]);Fa[l[y]]=y;
		return y;	
	}
}
pa Split(int x,int v)
{
	if(!x) return make_pair(0,0);
	pushdown(x);
	if(a[x]<=v)
	{
		Fa[r[x]]=0;pa b=Split(r[x],v);
		r[x]=b.first;Fa[r[x]]=x;b.first=x;
		return b;
	}
	else
	{
		Fa[l[x]]=0;pa b=Split(l[x],v);
		l[x]=b.second;Fa[l[x]]=x;b.second=x;
		return b;
	}
}
int main()
{
	X=read();n=read();
	for(int i=1;i<=n;++i) R[i]=read();if(R[n]<1e9) R[++n]=1e9;
	m=read();
	for(int i=1;i<=m;++i)
	{
		t[i]=read(),a[i]=read();rk[i]=i;K[i]=Ran(); 
		v[upper_bound(R+1,R+n+1,t[i])-R-1].push_back(i);
	}
	sort(rk+1,rk+m+1,cmp);
	for(int i=1;i<=m;++i) rt=Merge(rt,rk[i]);
	for(int i=0;i<=n;++i)
	{
		if(i)
		{
			int len=min(X,R[i]-R[i-1]);
			if(i&1)
			{
				pa b=Split(rt,len);
				Mark(b.first,0);Add(b.second,-len); 
				rt=Merge(b.first,b.second);
			}
			else
			{
				pa b=Split(rt,X-len);
				Add(b.first,len);Mark(b.second,X);
				rt=Merge(b.first,b.second);
			}
		}
		for(int j=0;j<v[i].size();++j)
		{
			top=0;
			for(int tt=v[i][j];tt;tt=Fa[tt]) q[++top]=tt;
			while(top) pushdown(q[top]),--top;
			int res=a[v[i][j]];
			if(i&1) Ans[v[i][j]]=min(res+(t[v[i][j]]-R[i]),X);
			else Ans[v[i][j]]=max(0,res-(t[v[i][j]]-R[i]));
		}
	}
	for(int i=1;i<=m;++i) printf("%d\n",Ans[i]);
	return 0;
}



Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define endl '\n'
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,t,m,y,z=0;

    cin>>n>>x;
    for(int i=0;i<n;i++){
            cin>>y;
            z+=(y>=x);
        }
        cout<<z;
            

    return 0;
}

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

using i64 = int_fast64_t;
using f64 = double;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 k, a, b;
    cin >> k >> a >> b;
    string ans = "NG";
    for (i64 i = 0; i * k <= b; i++) {
        if (a <= i * k && i * k <= b) ans = "OK";
    }
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 3652
#include <iostream>
#include <math.h>
using namespace std;

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

	cin >> a >> b >> c;

	if (a < b && b < c) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
    return 0;
}


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

using usize = ::std::size_t;
using u64 = ::std::int_least64_t;
static constexpr u64 Inf = ::std::numeric_limits<u64>::max() / 2;

u64 N;

int main(int argc, char *argv[])
{
    
 
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> N;
    vector<u64> a(N), M;
    for (u64 i = 0; i < N; i++) {
        cin >> a[i];
    }
    M.push_back(a[0]);
    for (auto it = a.begin() + 1; it != a.end(); it++) {
        if (*it > M.back()) {
            M.push_back(*it);
        } else {
            auto location = lower_bound(M.begin(), M.end(), *it);
            *location = *it;
        }
    }
    
    cout << M.size() << endl;
    
    return 0;
}



Measured memory_bytes: 4472
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i=0; i<(n); ++i)
#define REP(i, d, n) for(long long i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
int main() {//言語変えろ言語変えろ言語変えろ言語変えろ言語変えろ

string s; cin>>s;
  rep(i,s.size()){
  if(s.at(i)=='?'){s.at(i)='D';}
  }
  
  cout<<s<<endl;
  
  
return 0; }


Measured memory_bytes: 3756
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
using namespace std;

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

    if (a == 3 || a == 5 || a == 7) {
        cout << "YES" << endl;
    }else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
from collections import Counter

def main():
    _ = int(input())
    a = [int(s) for s in input().split()]
    print(solve(a))

def solve(a):
    counter = Counter(a)
    s = 0
    for x, c in counter.most_common():
        if c > x:
            s += c - x
        elif c < x:
            s += c
    return s

main()


Measured memory_bytes: 21224
from bisect import bisect_left

s = input()
t = input()

oa = ord('a')

l = [[] for _ in range(26)]
for i,c in enumerate(s):
    l[ord(c) - oa].append(i)

x = -1
p = 0
for c in t:
    ll = l[ord(c)-oa]
    if len(ll)==0:
        print(-1)
        exit()

    y = bisect_left(ll, x)
    if y==len(ll):
        p += 1
        x = ll[0]+1
    else:
        x = ll[y]+1

print(p*len(s)+x)

Measured memory_bytes: 7540
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>
#include <bitset>
#include <stack>

using namespace std;
typedef long long ll;

int main(){
  string s;
  cin >> s;
  if (s[0] == s[s.length() -1]) {
    if(s.length() % 2 == 0) cout << "First";
    else  cout << "Second";
  } else {
    if(s.length() % 2 == 0) cout << "Second";
    else  cout << "First";
  }
  cout << endl;
  return 0;
}


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

using namespace std;

int main() {
  int N;
  cin >> N;
  priority_queue<double, vector<double>, greater<double>> q;
  for (int i = 0; i < N; ++i) {
    double vi;
    cin >> vi;
    q.push(vi);
  }
  while(q.size() > 1) {
    auto v1 = q.top();
    q.pop();
    auto v2 = q.top();
    q.pop();
    // cout << "v1 v2 "<< v1 << " " << v2 << endl;
    q.push((v1 + v2) / 2.);
  }
  cout << q.top() << endl;
}


Measured memory_bytes: 256
import numpy as np
#S = str(input())
S = str(input())
N = len(S) - 1

def honyaku(ini,n):
    ans = np.zeros(n)
    for i in range(n-1,-1,-1):
        ans[i] = ini % 2
        ini = ini // 2
    return ans

def sum_list(list_domain,list_S):
    tmp = list_S[0]
    ans = 0
    for i in range(len(list_domain)):
        if list_domain[i] == 0:
            tmp = tmp*10 + list_S[i+1]
        else:
            ans += tmp
            tmp = list_S[i+1]
    return tmp + ans

list_S = np.zeros(N+1)
for i in range(N+1):
    list_S[i] = int(S[i])
ans = 0    
for i in range(2**N):
    list_domain = honyaku(i,N)
    ans += sum_list(list_domain,list_S)
    
print(int(ans))
    

Measured memory_bytes: 12512
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	if(a<0LL)return 0;
	if(b<0LL)return 0;
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
// ここから編集しろ
char in[210000];
int main(){
	scanf("%s",in);
	int n=strlen(in);
	int ret=0;
	int la=2;
	for(int i=0;i<n;i++){
		if(la==2){
			la=1;
			ret++;
		}else{
			if(in[i-1]!=in[i]){
				ret++;
			}else{
				la=2;
				if(n-i>=2)ret++;
				i++;
			}
		}
	}
	printf("%d\n",ret);
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
using namespace std;

int main() {
	int a, b, c,d;
	cin >> a >> b >> c>>d ;
	a = min(a, b);
	c = min(c, d);
	cout << a + c;
}

Measured memory_bytes: 256
import sys
input=lambda: sys.stdin.readline().rstrip()
mod=10**9+7
n,m=map(int,input().split())
n_max=2*(10**5+1)
F,FI=[0]*(n_max+1),[0]*(n_max+1)
F[0],FI[0]=1,1
for i in range(n_max):
  F[i+1]=(F[i]*(i+1))%mod
FI[n_max-1]=pow(F[n_max-1],mod-2,mod)
for i in reversed(range(n_max-1)):
  FI[i]=(FI[i+1]*(i+1))%mod
def comb(x,y):
  return (F[x]*FI[x-y]*FI[y])%mod

pf={}
for i in range(2,int(m**0.5)+1):
  while m%i==0:
    pf[i]=pf.get(i,0)+1
    m//=i
if m>1:
  pf[m]=1

ans=1
for k in pf.keys():
  ans=(ans*comb(n-1+pf[k],pf[k]))%mod
print(ans)

Measured memory_bytes: 18932
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
using P = pair<ll,ll>;
ll inf = 1e18;
ll l=1, r=inf;
#define N 100005
vector<P> to[N];
P node[N];
void init(int n) {
    rep(i, n) {
        node[i].first = -1;
        node[i].second = 0;
    }
}
void rec(int v) {
    if(l==inf && r == -inf) return;
    for(P next : to[v]) {
        ll u = next.first;
        ll s = next.second;
        if(node[u].first == -1) {//未到達なら
            node[u].first = s - node[v].first;
            node[u].second = !node[v].second;
            //正・負
            if(!node[u].second) l = max(l, 1-node[u].first);
            else r = min(r, node[u].first-1);
            rec(u);
        } else {
           if(node[v].second != node[u].second) {//異符号
                if(node[v].first+node[u].first != s)
                    l = inf, r = -inf;
            } else {
                ll tmp = node[v].first + node[u].first - s;
                if(node[v].second==0 && node[u].second==0) tmp = -tmp;
                if(tmp <= 1) l = inf, r = -inf;
                else if(tmp/2 < l || r < tmp/2) l = inf, r = -inf;
                else l = max(l,tmp/2), r = min(r,tmp/2);
            }
        }
    }
}
int main(void) {
    int n, m; cin >> n >> m;
    init(n);
    rep(i, m) {
        int u, v, s; cin >> u >> v >> s;
        u--; v--;
        to[u].push_back(P{v,s});
        to[v].push_back(P{u,s});
    }
    node[0].first = 0;
    rec(0);
    ll ans = r - l + 1;
    if(ans < 0) ans = 0;
    //printf("%lld %lld ",l,r);
    cout << ans;
}


Measured memory_bytes: 14080
import sys
import math

big = 10 ** 9 + 7

N = int(input())
A = list(map(int, sys.stdin.readline().strip().split()))
sum_A = sum(A)

ans = 0
for i in range(1, len(A)):
    sum_A -= A[i - 1]
    ans += A[i - 1] * sum_A

print(ans % big)


Measured memory_bytes: 32948
#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int N, A, B;
  cin >> N >> A >> B;

  int a = 0, b = 0, c = 0;
  rep(i, N) {
    int p; cin >> p;
    if (p <= A)
      ++a;
    else if (p <= B)
      ++b;
    else
      ++c;
  }
  cout << min(a, min(b, c)) << "\n";

  return 0;
}


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

int main() {
	int K;
	string S;
	cin >> K >> S;
	if (S.size() <= K) {
		cout << S << endl;
	}
	else {
		for (int i = 0; i < K; i++) {
			cout <<S.at(i);
		}
		cout << "..." << endl;
	}
}

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

using namespace std;

unordered_map<string,bool> visited;

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

	long long int n;
	int res = 0;

	cin >> n;

	queue <string> que;
	que.push("357");
	que.push("375");
	que.push("537");
	que.push("573");
	que.push("735");
	que.push("753");
	visited["357"]=true;
	visited["375"]=true;
	visited["537"]=true;
	visited["573"]=true;
	visited["735"]=true;
	visited["753"]=true;

	while(!que.empty())
	{
		string now = que.front();
		que.pop();

		if(stoll(now)<=n)
		{
			res++;
		}

		for(int i=0;i<=now.length();i++)
		{
			for(int j=3;j<=7;j+=2)
			{
				string next = now.substr(0,i) + char(j+'0') + now.substr(i);
				//cout << next << '\n';
				if(visited[next]==false && stoll(next)<=n)
				{
					visited[next]=true;
					que.push(next);
				}
			}
		}	
	}

	cout << res << '\n';
	return 0;
}

Measured memory_bytes: 9636
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<iomanip>
#include<complex>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef stack<int> SI;
typedef queue<int> QI;
typedef list<int> LI;
typedef pair<int,int> PII;
typedef long long LL;

#define d(x)  cout<<#x<<" = "<<(x)<<endl;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define EMP empty()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).rbegin()) i=(c).rbegin(); i!=(c).rend(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c,n) sort(c,c+n)
#define VSORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define DFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define DREP(i,n) DFOR(i,n,0)
#define INF 1000000000
#define PI  acos(-1.0)
////////////////////////////////////////////////
#define N 4
#define N2 16
#define LIM 100

static const int dx[4]={0,-1,0,1};
static const int dy[4]={1,0,-1,0};
static const char dir[4]={'r','u','l','d'};
int MDT[N2][N2];

struct Puzzle{int f[N2],space,MD;};

Puzzle state;
int lim;
int path[LIM];

int getALLMD(Puzzle pz)
{
	int sum=0;
	REP(i,N2)
	{
		if(pz.f[i]==N2)continue;
		sum+=MDT[i][pz.f[i]-1];
	}
	return sum;
}

bool isSol()
{
	REP(i,N2)
	{
		if(state.f[i]!=i+1)
		{
			return false;
		}
	}
	return true;
}

bool dfs(int depth,int prev)
{
	if(state.MD==0)return true;
	if(depth+state.MD>lim)return false;
	
	int sx=state.space/N;
	int sy=state.space%N;
	Puzzle tmp;
	
	REP(r,4)
	{
		int tx=sx+dx[r];
		int ty=sy+dy[r];
		if(tx<0||ty<0||tx>=N||ty>=N)continue;
		if(max(prev,r)-min(prev,r)==2)continue;
		tmp=state;
		
		state.MD-=MDT[tx*N+ty][state.f[tx*N+ty]-1];
		state.MD+=MDT[sx*N+sy][state.f[tx*N+ty]-1];
		swap(state.f[tx*N+ty],state.f[sx*N+sy]);
		state.space=tx*N+ty;
		if(dfs(depth+1,r))
		{
			path[depth]=r;
			return true;
		}
		state=tmp;
	}
	return false;
}

string iterative_deepening(Puzzle in)
{
	in.MD=getALLMD(in);
	
	for(lim=in.MD;lim<=LIM;lim++)
	{
		state=in;
		if(dfs(0,-100))
		{
			string ans="";
			REP(i,lim)
			{
				ans+=dir[path[i]];
			}
			return ans;
		}
	}
	return "unsolvable";
}

int main()
{
	REP(i,N2)
	{
		REP(j,N2)
		{
			MDT[i][j]=abs(i/N-j/N)+abs(i%N-j%N);
		}
	}
	
	Puzzle in;
	
	REP(i,N2)
	{
		cin>>in.f[i];
		if(in.f[i]==0)
		{
			in.f[i]=N2;
			in.space=i;
		}
	}
	string ans=iterative_deepening(in);
	cout<<ans.size()<<endl;
	return 0;
}

Measured memory_bytes: 3160
import java.util.*;
import java.io.*;

public class Main{
	static PrintWriter out=new PrintWriter(System.out);
	public static void main (String[] args) throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		
		String[] input=br.readLine().trim().split(" ");
		
		
		String a=input[0];
		input=br.readLine().trim().split(" ");
		String b=input[0];
		
		out.println(isPossible(a,b));
		
		out.flush();
		out.close();
	}
	public static String isPossible(String a,String b)
	{
	   if(b.length()==a.length()+1){
	       for(int i=0;i<a.length();i++){
	           if(a.charAt(i)!=b.charAt(i)){
	               return "No";
	           }
	       }
	       return "Yes";
	   }
	   else{
	       return "No";
	   }
	}
}

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

int main(void){
    string s;
    cin >> s;
    int n = s.size();
    long long int ans = 0,tmp = 0;
    for(int i = 0;i < (1 << (n-1));i++){
        tmp = s[0] - '0';
        for(int j = 0;j < n-1;j++){
            if(i & (1 << j)){
                ans += tmp;
                tmp = 0;
            }
            tmp = tmp*10 + s[j+1] - '0';
        }
        ans += tmp;
    }
    cout << ans;
}

Measured memory_bytes: 256
N = int(raw_input())
lisday = []
lisp= []
last = []
for num in xrange(N):
  lisday.append( map(int,raw_input().split()) )
for num in xrange(N):
  lisp.append( map(int,raw_input().split()) ) 
for n in xrange(1,1024):
	n2 = format(n,"010b")
	lissum =[]
	for numb in xrange(N):
		check = map(int,list(str(n2)))
		count = 0
		for select in xrange(10):
			if check[select] == 1 and lisday[numb][select] == 1:
				count += 1
		lissum.append(lisp[numb][count])
	last.append(sum(lissum))
print max(last)


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

#define int long long int

const int M = 998244353;

int power(int x, int y) {
    if(y == 0)
        return 1ll;
    if(y % 2)
        return x * power(x, y - 1);
    int t = power(x, y / 2);
    return t * t;
}

signed main() {
    int n;
    cin >> n;
    map<string, int> mp;
    for(int i = 0; i < n; i++) {
        string s;
        cin >> s;
        mp[s]++;
    }
    cout << mp.size();
}


Measured memory_bytes: 19256
import java.util.*;

public class Main {
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       int n = Integer.parseInt(sc.next());
       int d = Integer.parseInt(sc.next());
       long x,y;
       int count = 0;
       List<String> list = new ArrayList<>();
       for(int i=0; i<n; i++) {
           x = Integer.parseInt(sc.next());
           y = Integer.parseInt(sc.next());
           String xy = String.valueOf(x)+String.valueOf(y);
           if(Math.sqrt(x*x+y*y) <= d) {
            count++;
           }
           
       }
       System.out.println(count);
    }
}


Measured memory_bytes: 60892
n, m = map(int, input().split())
switch = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))

ans = 0
for bits in range(1<<n):
    all_on = True
    for i in range(m):
        pow = 0
        for j in range(1, switch[i][0]+1):
            pow += (bits >> (switch[i][j]-1)) & 1
        if pow % 2 != p[i]:
            all_on = False
            break

    if all_on:
        # print(''.join([str((bits>>i)&1) for i in range(n)]))
        ans += 1

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s; cin >> s;
    int i,n = s.size();
    for(i=0;i<n;i++){
        if(s[i]!=s[n - 1 - i]){
            cout << "No" << endl;
            return 0;
        }
    }
    for(i=0;i<(n - 1)/2;i++){
        if(s[i]!=s[(n - 1)/2 - 1 - i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int a[200005],b[200005];
int main()
{
    int n;
    cin >> n;
    for(int i=0;i<n;i++)
        cin >> a[i] >> b[i];
    sort(a,a+n);
    sort(b,b+n);
    if(n%2){
        cout << (b[n/2]-a[n/2])+1 << endl;
    }
    else{
        cout << b[n/2]+b[n/2-1]-a[n/2]-a[n/2-1]+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 5148
import math
A, B, N = list(map(int, input().split()))
ans = 0
if B+1 < N:
    C = B+1
else:
    C = N
if B//A == 0:
    D = 1
else:
    D = B//A
#floor()の中のiをD分スキップしても、全てのfloor()値を表現できる。
for i in range(1, C+D, D):
    val = math.floor(A*i/B) - A*math.floor(i/B)
    #print("i", i, "val", val)
    ans = max(ans, val)

print(ans)

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

// THINK: INT vs LONG LONG?

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

	int x; cin >> x;
	cout << (x == 0 ? 1 : 0) << endl;
	return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {

    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    long long sum = 0;
    rep(i,N) {
        cin >> A[i];
        sum += A[i];
    }

    sort(A.begin(), A.end());
    
    vector<long long> divisor;
    for (long long i = 1; i * i <= sum; i++) {
        if (sum % i == 0) {
            divisor.push_back(i);
            if (i != sum / i) divisor.push_back(sum / i);
        }
    }
    
    sort(divisor.begin(), divisor.end(), greater<long long>());
    long long D = divisor.size();
    rep(i,D) {

        long long x = divisor[i];

        vector<long long> m(N);
        rep(i,N) m[i] = A[i] % x;

        sort(m.begin(), m.end());

        vector<long long> minus(N, 0), plus(N, 0);
        rep(i,N) minus[i] = m[i] + (i > 0 ? minus[i - 1] : 0);
        rep(i,N) plus[N - 1 - i] = (x - m[N - 1 - i]) + (i > 0 ? plus[N - i] : 0);
        long long count = min(plus[0], minus[N - 1]);
        rep(i,N-1) count = min(count, max(minus[i], plus[i + 1]));
        if (count <= K) {
            cout << x << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.conv;
import std.string;

int f(int n) {
	return n*(n+1)/2;
}

void main() {
	int n, l;
	scanf("%d %d", &n, &l);
	if (l <= 0 && l + n > 0) {
		write(f(l+n-1)-f(-l));
	}
	else if (l > 0) {
		write(f(l+n-1)-f(l));
	}
	else {
		write(-f(-l)+f(-l-n+1));
	}
}


Measured memory_bytes: 256
N = int(input())
X = list(map(int, input().split()))
X_sorted = sorted(X)
pre_med_index = (N // 2) - 1
pos_med_index = N // 2
import bisect

for i in range(N):
    if X[i] <= X_sorted[pre_med_index]:
        print(X_sorted[pos_med_index])
    else:
        print(X_sorted[pre_med_index])


Measured memory_bytes: 30756
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long int ll;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)

const int INF = 1000000000;
const ll LINF = 1001002003004005006ll;

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  if (c - a - b > 0 && 0 < ((a - b - c) * (a - b - c)) - (4 * b * c)) Yes;
  else No;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define INF 1000000001
#define MOD 1000000007

using namespace std;



class Dice {
	int num[6] = { 0,0,0,0,0,0 };
public:
	void setnum(int*);
	void roll(char);
	void ans();
};

void Dice::roll(char c) {
	switch(c) {
		int tmp;
	case'N':
		tmp = num[0];
		num[0] = num[1];
		num[1] = num[5];
		num[5] = num[4];
		num[4] = tmp;
		break;
	case'S':
		tmp = num[0];
		num[0] = num[4];
		num[4] = num[5];
		num[5] = num[1];
		num[1] = tmp;
		break;
	case'E':
		tmp = num[0];
		num[0] = num[3];
		num[3] = num[5];
		num[5] = num[2];
		num[2] = tmp;
		break;
	case'W':
		tmp = num[0];
		num[0] = num[2];
		num[2] = num[5];
		num[5] = num[3];
		num[3] = tmp;
		break;
	default:
		cout << "invalid char" << endl;
	}
}

void Dice::setnum(int* a) {
	REP(i, 6) {
		num[i] = a[i];
	}
}

void Dice::ans() {
	cout << num[0] << endl;
}

int main() {
	int a[6];
	REP(i, 6) {
		int b;
		cin >> b;
		a[i] = b;
	}
	Dice d;
	d.setnum(a);
	string s;
	cin >> s;
	REP(i, s.length()) {
		d.roll(s[i]);
	}
	d.ans();
	return 0;
}

Measured memory_bytes: 3160
def shortest_path
  cost = Array.new(@n-1, Float::INFINITY).unshift(0)
  node = Marshal.load(Marshal.dump(cost))

  @n.times do
    now = node.index(node.compact.min)
    @graph[now].each_with_index do |x, i|
      unless x == nil
        alt = cost[now] + x
        if cost[i] > alt
          cost[i] = alt
          node[i] = alt
        end
      end
    end
    node[now] = nil
  end
  
  return cost
end


@n = gets.to_i
@graph = Array.new(@n).map{Array.new(@n,nil)}

@n.times do |i|
  input = gets.split(" ").map{|x| x.to_i}
  u = input.shift
  k = input.shift
  k.times do
    @graph[u][input.shift] = input.shift
  end
end

shortest_path.each_with_index do |x, i|
  printf "%d %d\n",i ,x
end



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

namespace AtCoder.Abc
{
    class QuestionB
    {
        public struct Inp
        {
            public int A;
            public int B;
            public int C;
        }

        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数配列の入力
            var inputLongArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

            var inp = new Inp() { A = inputLongArray[0], B = inputLongArray[1], C = inputLongArray[2] };

            for(int i = 1; i <= inp.B; i++) {
                if((inp.A * i) % inp.B == inp.C) {
                    Console.WriteLine("YES");

                    Console.Out.Flush();
                    return;
                }
            }
            

            Console.WriteLine("NO");

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 13396
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;

int N;
int rev[123456];

int main() {
	cin >> N;
	for (int i = 0; i < N; ++i) {
		int tmp;
		cin >> tmp;
		--tmp;
		rev[tmp] = i;
	}
	multiset<int>S;
	S.insert(-1);
	S.insert(-1);
	S.insert(N);
	S.insert(N);
	LL ans = 0;
	for (int i = N - 1; i >= 0; --i) {
		auto r1 = S.lower_bound(rev[i]);
		auto r2 = next(r1);
		auto l1 = prev(r1);
		auto l2 = prev(l1);
		LL Ra = *r1 - rev[i];
		LL Rb = *r2 - *r1;
		LL La = rev[i] - *l1;
		LL Lb = *l1 - *l2;
		ans += (Ra * Lb + La * Rb) * (i + 1);
		S.insert(rev[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5376
N = int(input())

num_ac = 0
num_wa = 0
num_tle = 0
num_re = 0

for _ in range(N):
    s = input()
    if s == "AC":
        num_ac += 1
    elif s == "WA":
        num_wa += 1
    elif s == "TLE":
        num_tle += 1
    elif s == "RE":
        num_re += 1


print(f"AC x {num_ac}")
print(f"WA x {num_wa}")
print(f"TLE x {num_tle}")
print(f"RE x {num_re}")


        

Measured memory_bytes: 9160
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>

void yoko(std::vector<std::vector<int>>& a, size_t c) {
  size_t h = a.size();
  size_t w = a[0].size();

  std::vector<std::vector<int>> b(h);
  for (size_t i = 0; i < h; ++i) {
    std::vector<int> a0(c);
    for (size_t j = 0; j < c; ++j)
      a0[j] += a[i][j];

    std::reverse(a0.begin(), a0.end());

    std::vector<int> a1(w-c);
    for (size_t j = c; j < w; ++j)
      a1[j-c] += a[i][j];

    b[i].resize(std::max(c, w-c));
    for (size_t j = 0; j < c; ++j) b[i][j] += a0[j];
    for (size_t j = 0; j < w-c; ++j) b[i][j] += a1[j];
  }
  a = std::move(b);
}

void rotate(std::vector<std::vector<int>>& a) {
  size_t h = a.size();
  size_t w = a[0].size();
  std::vector<std::vector<int>> b(w, std::vector<int>(h));
  for (size_t i = 0; i < h; ++i)
    for (size_t j = 0; j < w; ++j)
      b[j][h-1-i] = a[i][j];

  a = std::move(b);
}

void tate(std::vector<std::vector<int>>& a, size_t c) {
  rotate(a);
  yoko(a, c);
  rotate(a);
  rotate(a);
  rotate(a);
}

int testcase_ends () {
  size_t n, m, t, p;
  scanf("%zu %zu %zu %zu", &n, &m, &t, &p);
  if (n == 0 && m == 0 && t == 0 && p == 0) return 1;

  std::vector<std::vector<int>> a(m, std::vector<int>(n, 1));
  for (size_t i = 0; i < t; ++i) {
    int d;
    size_t c;
    scanf("%d %zu", &d, &c);

    if (d == 1) {
      yoko(a, c);
    } else {
      tate(a, c);
    }
  }

  for (size_t i = 0; i < p; ++i) {
    size_t x, y;
    scanf("%zu %zu", &x, &y);
    printf("%d\n", a[a.size()-1-y][x]);
  }
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 2848
import java.math.BigDecimal;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
	  BigDecimal A = sc.nextBigDecimal();
	  BigDecimal B = sc.nextBigDecimal();
	  int c = A.compareTo(B);
	  if(c==0) {
		  System.out.print("EQUAL");
	  }
	  else if(c>0) {
		  System.out.print("GREATER");
	  }
	  else {
		  System.out.print("LESS");
	  }
	  sc.close();
    }
}

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

using namespace std ;

int main()
{   int a;
    cin>>a;
    int cnt=0;
    for(int i=0;i<3;i++){
    if(a % 10 == 1)cnt++;
    a = a / 10 ;;
    }
    cout << cnt ;
    return 0 ;
}


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

const int MOD = 1000000007;
int main() {
    int N;
    cin >> N;
    vector<long long> A(N);
    for(int i = 0; i < N;i++) cin >> A[i];
    
    long long res = 0;
    long long mul = 1;
    for(int i = 0; i < 60;i++){
        long long odd = 0;
        long long even = 0;
        for(int j = 0; j < N;j++){
            if( A[j] & (1LL << i) )even++;
            else odd++;
        }
        //cout << odd <<" "<<even << endl;
        long long add = ((odd*even)%MOD * mul %MOD);
        res = (res + add)%MOD;
        mul = (mul*2)%MOD;
    }
    cout << res << endl;
     
}


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

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

signed main(){
    int A,B,C,N;
    cin>>A>>B>>C>>N;

    int ans=(A*B+B*C+C*A)*2;

    set<tuple<int,int,int>>rem;
    rep(i,N){
        int x,y,z;
        cin>>x>>y>>z;
        rem.insert(make_tuple(x,y,z));
    }

    for(auto &latte:rem){
        int x,y,z;
        tie(x,y,z)=latte;
        rep(d,6){
            int nx=x+dx[d],ny=y+dy[d],nz=z+dz[d];
            if(nx<0||nx>=A||ny<0||ny>=B||nz<0||nz>=C)ans--;
            else{
                if(rem.find(make_tuple(nx,ny,nz))==rem.end())ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3104
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
  int n,a,mini,ans=-(1<<30);
  scanf("%d %d",&n,&mini);
  for(int i=0;i<n-1;i++){
    scanf("%d",&a);
    if(a-mini>ans)ans=a-mini;
    if(mini>a)mini=a;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3264
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    cin >> a >> b;
    if(a>b)
    cout<<"a > b"<<endl;
else if(a<b) cout<<"a < b"<<endl;
else cout<<"a == b"<<endl;
 
 
return 0;
 
}


Measured memory_bytes: 3080
def matrixChainMultiplication():
	INF = 100 * 100 * 100 + 1
	m = [[INF for _ in range(n + 1)] for _ in range(n + 1)]
	for i in range(1, n + 1):
		m[i][i] = 0
	for l in range(2, n + 1):
		for i in range(1, n - l + 2):
			j = i + l - 1
			for k in range(i, j):
				q = m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j]
				if q < m[i][j]:
					m[i][j] = q
	return m[1][n]

if __name__ == "__main__":
	n = int(input())
	p = list(map(int, input().split()))
	for i in range(1, n):
		p.append(list(map(int, input().split()))[1])
	print(matrixChainMultiplication())


Measured memory_bytes: 5752
import sys
import numpy as np
import math  # gcdもあるよ
from collections import deque
from collections import defaultdict
from copy import deepcopy
from itertools import accumulate #リストを与えると累積和を返す
def input(): return sys.stdin.readline().rstrip()
from functools import lru_cache #メモ化

def main():
    n = int(input())
    if n>=30:
        print("Yes")
    else:print('No')
    return 0

if __name__ == "__main__":
    main()

Measured memory_bytes: 27112
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
int main()
{
    string s;cin >> s;
    rep(i,s.size()-1){
        if(s[i]==s[i+1]){cout << i+1 << " " << i+2 << endl;return 0;}
    }
    rep(i,s.size()-2){
        if(s[i]==s[i+2]){
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }
    cout << -1 << " " << -1 << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define N 100005
#define M 505
using namespace std;
int n,m,a[N],b[N],c[N],d[N],deg[M],f[M],vis[M],fr[M];
void GG(){ printf("NO"); exit(0);}
int find(int x){ return f[x] ? f[x]=find(f[x]) : x;}
int main()
{
	int i,x,y;
	scanf("%d %d",&n,&m),m=2*m+1;
	for(i=1;i<=n;i++){
		scanf("%d %d %d %d",&a[i],&b[i],&c[i],&d[i]);
		if(c[i]!=0) x=2*c[i]+1; else x=2*a[i];
		if(d[i]!=0) y=2*d[i]; else y=2*b[i]+1;
		deg[x]++,deg[y]--,vis[x]=vis[y]=1;
		if(find(x)!=find(y)) f[find(x)]=find(y);
	  }
	for(i=1;i<=m;i++)
		if(deg[i]!=0){
			if(deg[i]>0&&(i&1)) GG();
			if(deg[i]<0&&(~i&1)) GG();
		  }
	for(i=1;i<=m;i++)
		if(vis[i]&&deg[i]>0) fr[find(i)]++;
	for(i=1;i<=m;i++)
		if(vis[i]&&find(i)==i&&!fr[i]) GG();
	printf("YES");
	return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
//bc|abbbc|baca|aacb->最短は絶対4つ、最初の区間にない英単語を選ぶ、次の区間では一個前の区間で選んだ英単語の後ろにない最小の英単語を選ぶ
//aaba
int b[200005]; // ある区間でi以降(i含め)で出てきた文字の集合
int c[200005]; // ある区間でi以降の最小の文字
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin>>s;
  for(int i=s.length()-1;i>=0;i--){
    b[i]=b[i+1]|(1<<(s[i]-'a'));
    c[i]=c[i+1];
    while(b[i]&(1<<c[i]))c[i]++;
    if(c[i]==26){
      b[i]=c[i]=0;
    }
  }
  for(int i=0;i<s.length();++i){
    char x=c[i]+'a';
    cout<<x;
    while(i<s.length()&&x!=s[i])i++;
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 2196
#include<stdio.h>

int main()
{
    int n,k,x,y;
    scanf("%d %d %d %d",&n,&k,&x,&y);
    int i=1,j,sum=0,s=0;
    while(i<=n){\
        if(i<=k)
            sum+=x;
        if(i>k)
            s+=y;
        i++;
    }
    printf("%d", sum+s);
    return 0;
}



Measured memory_bytes: 128
#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include <random>
#include<type_traits>
#include<stack>
#include <sstream> 
#include <limits>
#include <numeric>
#include<string.h>
#include<set>
using namespace std;
#define ll long long int
#define all(v) begin(v), end(v)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
//typedef vector<int> V;
//typedef vector<V> VV;
//typedef vector<VV> VVV;
using namespace std;


ll MOD = 1000000007;
ll C[3010][3010];

void make_C() {
	memset(C, 0, (ll)sizeof(C));
	for (int i = 0; i < 3010; i++) {
		C[i][0] = C[i][i] = 1;
		for (int j = 1; j < i; j++) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;
	}
}






ll fact[3000], invs[3000];

//MOD使ってる

ll pow(ll x, ll n, ll mod) { //x^n 計算量O(logn)
	ll ans = 1;
	while (n > 0) {
		if ((n & 1) == 1) {
			ans = ans * x%mod;
		}
		x = x * x%mod; //一周する度にx, x^2, x^4, x^8となる
		n >>= 1; //桁をずらす n = n >> 1
	}
	return ans % mod;
}

ll combination(ll n, ll r) {
	return ((fact[n] * invs[r] % MOD) * invs[n - r]) % MOD;
}
void make_c(ll n) {
	invs[0] = 1;
	fact[1] = 1, invs[1] = 1;
	for (int i = 2; i < n; i++) {
		fact[i] = fact[i - 1] * i%MOD;
		invs[i] = pow(fact[i], MOD - 2, MOD);
	}
}


int main(void) {
	ll n, k;
	cin >> n >> k;
	make_C();
	make_c(2030);
	for (ll i = 1; i <= k; i++) {
		if (i > n - k + 1) {
			cout << 0 << endl;
		}
		else {
			cout << ( combination(n-k+1,i)* C[k - 1][i - 1]) % MOD << endl;
		}
	}
}


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

using ll = long long;

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

    ll n;cin>>n;

    ll ans=0;

    for(int i=1;i<n;i++)
    {
        int o=n/i;
        if(n%i==0)o--;
        // cout<<o<<" "<<ans+o<<"\n";
        ans+=o;
    }

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 3656
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)



int main() {
	int h, w,hcnt,wcnt;
	cin >> h >> w;
	VI h_cnt(h),w_cnt(w);
	VS a(h);
	rep(i, h) cin >> a[i];

	rep(i, h) {
		hcnt = 0;
		rep(j, w) {
			if (a[i][j] == '.') hcnt++;
		}

		if (hcnt == w) {
			h_cnt[i]++;
		}
	}

	rep(i, w) {
		wcnt = 0;
		rep(j, h) {
			if (a[j][i] == '.') wcnt++;
		}
		if (wcnt == h) {
			w_cnt[i]++;
		}
	}

	rep(i, h) {
		if (h_cnt[i] > 0) continue;
		rep(j, w) {
			if (w_cnt[j] > 0) {
				continue;
			}
			cout << a[i][j];
		}
		cout << "\n";
	}
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  string S;
  cin >> S;
  int N = S.size();
  rep(i,N-8)
  {
    cout << S[i];
  }
  return 0;
}


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

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    int N;
    cin>>N;
    vector<int> D(N);
    vector<int> use(13,0);
    REP(i,N){
        cin>>D[i];
        use[D[i]]++;
    }
    ll ans=0;

    REP(bit,1<<13){
        vector<ll> t;
        t.push_back(0LL);
        REP(i,13){
            ll mask=1<<i;
            if(use[i]==0) continue;
            if(use[i]==1){
                if(bit&mask) t.push_back(i);
                else t.push_back((24LL-i)%24LL);
            }else if(use[i]==2){
                t.push_back(i);
                t.push_back((24LL-i)%24LL);
            }else{
                t.push_back(i);
                t.push_back(i);
            }
            
        }

        ll tmp=INF;
        REP(i,t.size()-1){
            REP2(j,i+1,t.size()){
                tmp=min(tmp,abs(t[i]-t[j]));
                tmp=min(tmp,abs(t[i]-t[j]+24LL));
            }
        }
        ans=max(tmp,ans);
    }
    cout<<ans<<endl;

       
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, M;
    cin >> N >> M;

    vector<ll> x(N);
    vector<ll> y(M);

    REP(i, N){
        cin >> x[i];
    }
    REP(i, M){
        cin >> y[i];
    }

    ll X=0;
    for(ll i=0; i<N; i++){
        X += x[N-1-i]*(N-1-2*i);
        X = X % MOD;
    }
    ll Y=0;
    for(ll i=0; i<M; i++){
        Y += y[M-1-i]*(M-1-2*i);
        Y = Y % MOD;
    }

    cout << (X*Y) % MOD << endl;
    return 0;
}

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

#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define pb push_back
#define int long long
#define ii pair<int, int>

const int N = 2e5 + 10;
const int oo = 1e14;

int n, k;
int val[N];
vector<int> vi[N];
priority_queue< pair<int, int> > pq;

signed main()
{
    //freopen("test.inp", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    cin >> n;
    FOR(i, 1, n) val[i] = oo;
    FOR(i, 1, n - 1) {
        int u, v; cin >> u >> v;
        vi[u].pb(v); vi[v].pb(u);
    }
    cin >> k;
    FOR(i, 1, k) {
        int u, x; cin >> u >> x;
        val[u] = x;
        pq.push(ii(x, u));
    }
    while(!pq.empty())  {
        int u = pq.top().second, du = pq.top().first;
        pq.pop();

        for(int v: vi[u])   {
            if(val[v] == oo) val[v] = du - 1, pq.push(ii(val[v], v));
            else if(abs(val[v] - du) != 1) {
                cout << "No"; return 0;
            }
        }
    }
    cout << "Yes\n";
    FOR(i, 1, n) cout << val[i] << '\n';
}


Measured memory_bytes: 12532