akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,x,y) for(ll i=x;i<=y;i++)
#define imin INT_MIN
#define imax INT_MAX
int mod =1e9+7;

int main(){
	cin.tie(NULL);
    ios_base::sync_with_stdio();
	ll x,k,d;

	cin>>x>>k>>d;
	ll ans;
	x=abs(x);

	ll req = (x/d);
		if(k>=req){
			k-=req;
			x-=d*req;
			if(k&1) {
				ans=abs(d-x);
			} else ans=x;
		} else {
			x-=d*k;
			ans=x;
		}

	cout<<ans;
	
	return 0;
}


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

if 400<=N and 599>=N:
  print(8)
if 600<=N and 799>=N:
  print(7)
if 800<=N and 999>=N:
  print(6)
if 1000<=N and 1199>=N:
  print(5)
if 1200<=N and 1399>=N:
  print(4)
if 1400<=N and 1599>=N:
  print(3)
if 1600<=N and 1799>=N:
  print(2)
if 1800<=N and 1999>=N:
  print(1)

Measured memory_bytes: 61696
#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;
const int INF = 1e9+7;

int main(){
    int x,y;
    cin >> x >> y;
    for(int i=0;i<=x;++i){
        int sum=0;
        sum += 2*i;
        sum += 4*(x-i);
        if(sum==y){
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
}

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

#define db(x) cout<<x<<'\n'
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define repi(i,n) for(int i=0;i<(n);++i)
//#define repA(i,a,n) for(int i=a;i<=(n);++i)
//#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define ll long long int
#define endl '\n'
#define lld long long double
#define vi vector<int> 
#define vl vector<ll> 
#define vb vector<bool> 
#define vvi vector<vector<int>  >
#define err(t) cout<<"Error : "<<t<<endl;
#define all(v) v.begin(),v.end()
#define mp make_pair
#define M 100000
#define MD 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= (b); i++)
#define pii pair<int,int>
#define pll pair<ll,ll> 
#define vec(a) vector<a >
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	// int n;cin>>n;
	// string s;cin>>s;
	
	//ll n;cin>>n; vl a(n); repi(i,n) cin>>a[i];
	set<string> s;string p;
	
	
	int q;cin>>q;while(q--){ 
		cin>>p;
		s.insert(p);
	 }
	 cout<<s.size()<<endl;
	 //*/
return 0;
}



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

using namespace std;

int n, m, x, nr, total, sol = INT_MAX;
int cost[15], val[15];
int add[15][15];

int main()
{

    cin.tie(0);
    ios_base::sync_with_stdio(0);

    cin >> n >> m >> x;
    for(int i = 1; i <= n; ++i){
        cin >> cost[i];
        for(int j = 1; j <= m; ++j)
            cin >> add[i][j];
    }

    for(; nr < (1 << n); ++nr){
        int cpy = nr;
        total = 0;

        for(int i = 1; i <= m; ++i) val[i] = 0;

        for(int i = 1; cpy > 0; ++i, cpy >>= 1){
            if(cpy & 1){
                for(int j = 1; j <= m; ++j) val[j] += add[i][j];

                total += cost[i];
            }
        }

        bool good = true;
        for(int i = 1; i <= m; ++i){
            if(val[i] < x){
                good = false;
                break;
            }
        }

        if(good) sol = min(sol, total);

    }

    cout << (sol != INT_MAX ? sol : -1);

    return 0;
}


Measured memory_bytes: 3640
#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 ll = long long;
using P = pair<int, int>;


int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    map<ll, ll> mp;
    rep(i, N) {
        cin >> A[i];
        mp[A[i]]++;
    }
    ll ans = 0;
    for (auto p: mp) {
        if (p.second <= 1) continue;
        ans += p.second*(p.second-1) / 2;
    }
    rep(i, N) {
        ll a = mp[A[i]];
        ll t_ans = ans;
        if (a > 2) {
            ll tmp = a*(a-1) / 2;
            tmp -= (a-1)*(a-2) / 2;
            t_ans -= tmp;
        } else if (a == 2) {
            t_ans -= 1;
        }
        cout << t_ans << endl;
    }
    return 0;
}

Measured memory_bytes: 11008
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var data = input.trim().split("\n");
while (true) {
   var str = data.shift();
   if(str=="#")break;
   str=str.replace(/\d/g,function(v){
      return "n".repeat(v-0);
   });
   var arr = str.split("/");
   arr = arr.map(v=> v.split(""));
   var [a,b,c,d] = data.shift().split(" ").map(Number);
   arr[a-1][b-1]="n";
   arr[c-1][d-1]="b";
   arr = arr.map(v=> v.join(""));
   str = arr.join("/");
   str=str.replace(/n+/g,function(v){
      return v.length;
   });
   console.log(str);
}


Measured memory_bytes: 16312
#include<stdio.h>
#include<cstdio>
#include<string>
#include<map>
using namespace std;

int main() {
  int N;
  scanf("%d", &N);
  char S[N][10];
  map<char, long long> m;
  m['M'] = 0;
  m['A'] = 0;
  m['R'] = 0;
  m['C'] = 0;
  m['H'] = 0;
  for (int i=0 ; i<N ; i++) {
    char S[10];
    scanf("%s", S);
    m[S[0]]++;
  }
  long long res = m['M']*m['A']*m['R'] + m['M']*m['A']*m['C'] + m['M']*m['A']*m['H'] + m['M']*m['R']*m['C'] + m['M']*m['R']*m['H'] + m['M']*m['C']*m['H']
    + m['A']*m['R']*m['C'] + m['A']*m['R']*m['H'] + m['A']*m['C']*m['H'] + m['R']*m['C']*m['H'];
  
  printf("%lld\n", res);
}

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

def main():
    N  = int(input())
    P = []
    for i in range(N):
        x, y, h = map(int, input().split())
        P.append([h, x, y])
    P.sort(reverse = True)

    for x in range(101):
        for y in range(101):
            distance =abs(x-P[0][1]) + abs(y-P[0][2]) + P[0][0]
            for p in P[1:]:
                if max(distance - abs(x-p[1]) - abs(y-p[2]), 0) !=  p[0]:
                    break
            else:
                print(x, y , distance)
                return

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define maxn 1500005
#define ll long long
#define ld double
#define mod 998244353
#define pb push_back
#define vi vector<int> 
using namespace std;
int fl[maxn];
int tr[maxn], cnt;
vi wk(int n)
{	//反向 
	vi x1;
	if(n == 0)
		x1.pb(0);
	else
	{
		vi x2 = wk(n - 1);
		for(int i = 0; i < x2.size(); i++)
			x1.pb(x2[i]);
		for(int i = x2.size() - 1; i >= 0; i--)
			x1.pb((1 << (n - 1)) + x2[i]);
	}
	return x1;
}
vector<int> wk1(int n)
{
	vector<int> x1;
	if(n == 1)
	{
		x1.pb(0), x1.pb(1);
		return x1;
	}
	vi n1 = wk(n - 1);
	vi n2 = wk1(n - 2);
	for(int i = 0; i < n1.size(); i++)
		x1.pb(n1[i]);
	for(int i = 0; i < n2.size(); i++)
	{
		int j = (i & 1);
		for(int s = 0; s < 2; s++)
		{
			int nr = n2[i] + (1 << (n - 1)) + (1 << (n - 2)) * (s ^ j ^ 1);
			x1.pb(nr);
		}
	}
	return x1;
}	
int n, a, b;
void otp(int c)
{
	int res = 0;
	for(int i = 0; i < n; i++)
		if(c & (1 << i))
			res ^= (1 << tr[i]);
	res ^= a;
	cout<<res<<" ";
}
int main()
{
//	vi x1 = wk1(17);
//	for(int i = 0; i < x1.size(); i++)
//		cout<<x1[i]<<" ";
//	cout<<endl;
	cin>>n>>a>>b;
	b ^= a;
	for(int i = 0; i < n; i++)
		if(b & (1 << i)) tr[cnt++] = i;
	int ns = cnt;
	for(int i = 0; i < n; i++)
		if(!(b & (1 << i))) tr[ns++] = i;
	if(!(cnt & 1)) cout<<"NO"<<endl;
	else
	{
		cout<<"YES"<<endl;
		vi t1 = wk1(cnt);
	//	cout<<"AF"<<endl;
		vi t2 = wk(n - cnt);
	//	cout<<"AF"<<endl;
		for(int i = 0; i < t1.size(); i++)
		{
			if(i & 1)
				for(int j = t2.size() - 1; j >= 0; j--)
					otp(t1[i] + (1 << cnt) * t2[j]);
			else
				for(int j = 0; j < t2.size(); j++)
					otp(t1[i] + (1 << cnt) * t2[j]);
		}
	}
	return 0;
} 
/*
5 7 24
*/

Measured memory_bytes: 1152
from bisect import bisect_left
from bisect import bisect_right
#input
N = int(input())
#print(N)

A = sorted(list(map(int, input().split()))) #この表記について...
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
#print(A,B,C)

#sort 昇順に並び替え
#A.sort()
#B.sort()
#C.sort()
ans = 0
for i in range(N):
    ab = bisect_left(A,B[i])
    bc = N-bisect_right(C,B[i])
    #print(ab, end='  ')
    #print(bc)
    ans += ab*bc
print(ans)

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

using namespace std;
long ans = 0;

long sum(string a) {
  long res = 0;
  string tmp;
  for (int i = 0; i < (int)a.size(); ++i) {
    if (a[i] == '+') {
      res += stol(tmp);
      tmp.clear();
    } else {
      tmp += a[i];
    }
  }
  res += stol(tmp);
  return res;
}

void dfs(int idx, string s) {
  if (idx == 0) {
    ans += sum(s);
    return;
  }
  dfs(idx - 1, s);
  s.insert(idx, "+");
  dfs(idx - 1, s);
}

int main() {
  string s;
  cin >> s;
  dfs(s.size() - 1, s);
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<set>
using namespace std;
int main(){
	set<char> s;
	char str[100] = {0};
	int len1, len2, i;
	cin >> str;
	for(i = 0; i < strlen(str); i++){
		s.insert(s.end(),str[i]);
	}
	if(s.size()==strlen(str)){
		cout << "yes" << endl;
	}else{
		cout << "no" << endl;
	}
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
struct nodel{
    int x,id;
    nodel(){}
    nodel(int a,int b){x=a;id=b;}
    bool operator < (const nodel a)const {
        return a.x > x;
    }
};
struct noder{
    int x,id;
    noder(){}noder(int a,int b){x=a;id=b;}
    bool operator < (const noder a)const {
        return a.x < x;
    }
};
priority_queue<nodel> ql,ql2;
priority_queue<noder> qr,qr2;
int n,out[100000+100];
ll ans1,ans2;
int main() {
    scanf("%d",&n);
    for(int i=1;i<=n;++i) {int l,r;
        scanf("%d%d",&l,&r);
        ql.push(nodel(l,i));
        ql2.push(nodel(l,i));
        qr.push(noder(r,i));
        qr2.push(noder(r,i));
    }
    // l r
    int now=0;
    for(int ti=1;ti<=n;++ti) {
        while(!ql.empty()&&out[ql.top().id])ql.pop();
        while(!qr.empty()&&out[qr.top().id])qr.pop();
        if(ti%2&&now < ql.top().x)ans1+=abs(now-ql.top().x),now=ql.top().x,out[ql.top().id]=1,ql.pop();
        else if(now > qr.top().x) ans1+=abs(now-qr.top().x),now=qr.top().x,out[qr.top().id]=1,qr.pop();
        //cout << now <<' ';
    }//cout << endl;
    ans1 += abs(now);
    //cout << ans1 <<'\n';
    memset(out,0,sizeof(out));
    now=0;
    for(int ti=1;ti<=n;++ti) {
        while(!ql2.empty()&&out[ql2.top().id])ql2.pop();
        while(!qr2.empty()&&out[qr2.top().id])qr2.pop();
        if(ti%2==0&&now < ql2.top().x)ans2+=abs(now-ql2.top().x),now=ql2.top().x,out[ql2.top().id]=1,ql2.pop();
        else if(now > qr2.top().x) ans2+=abs(now-qr2.top().x),now=qr2.top().x,out[qr2.top().id]=1,qr2.pop();
        //cout << now <<' ';
    }//cout << endl;
    ans2 += abs(now);
    cout << max(ans1,ans2) <<'\n';
    return 0;
}


Measured memory_bytes: 3924
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
const long long inf=5e17;
long long k;
int n,a[maxn];
int nxt[maxn],f[maxn],last[maxn];
long long up[60][maxn];
bool vis[maxn];
/**

*/

int main(){
    scanf("%d%lld",&n,&k);
    memset(f,-1,sizeof(f));
    memset(nxt,-1,sizeof(nxt));
    memset(last,-1,sizeof(last));
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(f[a[i]]==-1){
            f[a[i]]=i;
        }
    }
    for(int i=n-1;i>=0;i--){
        if(last[a[i]]==-1){
            nxt[i]=f[a[i]]+(n-i)+1;
            last[a[i]]=i;
        }
        else{
            nxt[i]=last[a[i]]-i+1;
            last[a[i]]=i;
        }
    }

    ///i+nxt[a[i]]] will send to
    long long t=k*n;
    for(int i=0;i<n;++i){
        up[0][i]=nxt[i];
    }
    for(int j=1;j<=58;j++){
        for(int i=0;i<n;i++){
            int cur=((up[j-1][i]+i)%n);
            up[j][i]=up[j-1][i]+up[j-1][cur];
            if(up[j][i]>inf)up[j][i]=inf;
        }
    }
    long long sum=0;
    int cur=0;
    for(int j=58;j>=0;j--){
        if(sum+up[j][cur]<t){
            sum+=up[j][cur];
            cur=(cur+(up[j][cur]%n))%n;
        }
    }
  ///  cerr<<sum<<'\n';
    sum%=n;
  ///  cerr<<sum<<'\n';
    vector<int> st;
    for(int i=sum;i<n;i++){
        if(!vis[a[i]]){
            st.push_back(a[i]);
            vis[a[i]]=true;
            continue;
        }
        while(!st.empty()&&st.back()!=a[i]){
            vis[st.back()]=false;
            st.pop_back();
        }
        vis[a[i]]=false;
        st.pop_back();
    }
    for(int i:st){
        printf("%d ",i);
    }
}


Measured memory_bytes: 99444
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str[];
        StringBuilder sb = new StringBuilder();
        int result;
        while(true){
            str = br.readLine().split("");
            if(str[0].equals("0")) break;
            result = 0;
            for(String str1 : str){
                result += Integer.parseInt(str1);
            }
            sb.append(result).append("\n");
        }
        System.out.print(sb);
    }
}

Measured memory_bytes: 25272
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format, std.datetime;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long X = lread();
    long ans;
    ans += (X / 500) * 1000;
    ans += ((X % 500) / 5) * 5;
    writeln(ans);
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] a = new int[M+1];
		long[] fib = new long[N+2];
		fib[0] = 1;
		fib[1] = 1;
		fib[2] = 1;
		for(int i = 3; i <= N+1; i++) {
			fib[i] = fib[i-1] + fib[i-2];
			fib[i] %= 1000000007;
		}
		for(int i = 1; i <= M; i++)
			a[i] = sc.nextInt();
		for(int i = 2; i <= M; i++)
			if(a[i] - a[i-1] == 1) {
				System.out.println(0);
				return;
			} 
		List<Long> F = new ArrayList<>();
		for(int i = 2; i <= M; i++)
			F.add(fib[a[i]-a[i-1]-1]);
		if(M != 0) {
			F.add(fib[a[1]]);
			F.add(fib[N-a[M]]);
		}
		else
			F.add(fib[N+1]);
		long ans = 1;
		for(int i = 0; i < F.size(); i++) {
			ans *= F.get(i);
			ans %= 1000000007;
		}
		System.out.println(ans);

	}

}

Measured memory_bytes: 48764
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

class segtree{
public:
	static const int N=1<<20;
	int dp[1<<21];
	int lazy[1<<21];
	segtree(){
		memset(dp,0,sizeof(dp));
		memset(lazy,0,sizeof(lazy));
	}
	void lazy_update(int k){
		dp[k]=max(dp[k*2+1],dp[k*2+2]);
	}

	void lazy_eval(int k){
		dp[k]=max(lazy[k],dp[k]);
		if(k<N-1){
			lazy[k*2+1]=max(lazy[k],lazy[k*2+1]);
			lazy[k*2+2]=max(lazy[k],lazy[k*2+2]);
		}
		lazy[k]=0;
	}

	void update(int a,int b,int v,int k=0,int l=0,int r=N){
		lazy_eval(k);
		if(b<=l || r<=a)return;
		if(a<=l && r<=b){
			lazy[k]=max(v,lazy[k]);
			lazy_eval(k);
			return;
		}
		int mid=(l+r)/2;
		update(a,b,v,k*2+1,l,mid);
		update(a,b,v,k*2+2,mid,r);
		lazy_update(k);
		return;
	}

	int query(int a,int b,int k=0,int l=0,int r=N){
		lazy_eval(k);
		if(b<=l || r<=a)return 0;
		if(a<=l && r<=b)return dp[k];
		int mid=(l+r)/2;
		int vl=query(a,b,k*2+1,l,mid);
		int vr=query(a,b,k*2+2,mid,r);
		lazy_update(k);
		return max(vl,vr);
	}
};

segtree seg;

int n;
int a[200005];
P p[200005];
int id=0;
vector<int> G[200005];
int ans[200005];
int l[200005],r[200005];

void dfs(int v,int p){
	l[v]=id++;
	for(int i=0;i<G[v].size();i++){
		int nv=G[v][i];
		if(nv==p)continue;
		dfs(nv,v);
	}
	r[v]=id++;
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		p[i]=P(a[i],i);
	}
	for(int i=0;i<n-1;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		a--;
		b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs(0,-1);
	sort(p,p+n);
	queue<int> que;
	int prev=-1;
	for(int i=0;i<n;i++){
		if(p[i].first!=prev){
			while(que.size()){
				int pt=que.front();
				que.pop();
				seg.update(l[pt],r[pt],ans[pt]);
			//	printf("pu %d %d %d %d\n",pt,ans[pt],l[pt],r[pt]);
			}
		}
		int v=p[i].second;
		ans[v]=seg.query(l[v],l[v]+1)+1;
		que.push(v);
		prev=p[i].first;
		//printf("%d %d %d %d %d\n",p[i].first,v,ans[v],l[v],r[v]);
	}
	while(que.size()){
		int pt=que.front();
		que.pop();
		seg.update(l[pt],r[pt],ans[pt]);
		//printf("pu %d %d %d %d\n",pt,ans[pt],l[pt],r[pt]);
	}
	for(int i=0;i<n;i++){
		printf("%d\n",seg.query(l[i],l[i]+1));
	}
	return 0;
}


Measured memory_bytes: 44280
#include <iostream>

int main() {
    int n;
    std::cin >> n;
    int a[n];
    for(int i = 0; i < n; i++) {
        std::cin >> a[i];
    }

    bool flag = true;
    for(int i = 0; i < n; i++) {
        if(a[i] % 2 == 0) {
            if((a[i] % 3 != 0) && (a[i] % 5 != 0)) {
                flag = false;
            }
        }
    }

    if(flag) {
        std::cout << "APPROVED" << std::endl;
    } else {
        std::cout << "DENIED" << std::endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	
	int a;
	scanf("%d", &a);
	
	if(a%2==0) {
		printf("%d",a/2);
	}
	else if(a%2 !=0) {
		printf("%d",(a/2)+1);
	}
	

	return 0;
}

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


using ll = long long;


int main()
{
    ll n, a, b;
    cin >> n >> a >> b;
    ll ab = a + b;
    ll q = n / ab;
    ll r = n % ab;
    ll ans = q * a + min(a, r);
    cout << ans << endl;
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    int tmp = a[0];
    int count = 0;
    int flag = 0;
    for(int i = 0; i < n; i++){
        flag = 0;
        for(int j = 0; j < i; j++){
            if(a[i] < a[j]){
                flag = 1;
                break;
            }
        }
        if(flag == 0){
            count++;
        }
    }

    cout << count << endl;
}

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

main(){
	string s,t; cin>>s>>t;
	
	int ans=s.length();
	for(int i=0; i<=s.length()-t.length(); i++){
		int k=i, cnt=0;
		for(int j=0; j<t.length(); j++,k++){
			if(t[j] != s[k]){
				cnt++;
			}
		}
		ans = min(ans,cnt);
	}
	cout<<ans;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    return Parent[a] = root(Parent[a]);
  }

  bool issame(int a, int b){
    return root(a) == root(b);
  }

  int size(int a){
    return -Parent[root(a)];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);

    if(a == b) return false;

    if(size(a) < size(b)) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }
};

void bfs(int s, vvi &G, vi &dist){
  fill(all(dist),-1);
  queue<int> q;

  q.push(s);
  dist[s] = 0;
  
  while(!q.empty()){
    int v = q.front();
    q.pop();

    for(auto nv : G[v]) {
      if(dist[nv] != -1) continue;
      dist[nv] = dist[v] + 1;
      q.push(nv);
    }
  }
}

int main(){
  int n, u, v; cin >> n >> u >> v;
  u--; v--;
  vvi G(n);
  rep(i,n-1) {
    int a,b; cin >> a >> b;
    a--; b--;
    G[a].pb(b); G[b].pb(a);
  }

  vi udist(n);
  bfs(u, G, udist);
  vi vdist(n);
  bfs(v, G, vdist);

  // <vからの距離、頂点番号>
  vector<pii> longest(n);
  rep(i,n) {
    longest[i] = mp(vdist[i],i);
  }
  sort(all(longest));
  reverse(all(longest));

  //rep(i,n) cout << longest[i].first << endl;
  rep(i,n) {
    int ndist = longest[i].first;
    int nu = longest[i].second;
    if(udist[nu] < vdist[nu]){
      cout << ndist-1 << endl;
      return 0;
    }
  }


}

Measured memory_bytes: 7424
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep2(i,st,ed) for(int i = st; i < ed; ++i)
#define mk(x,y) make_pair(x,y)
#define pb(x) push_back(x)
const ll mod = 1e9 + 7;
const ll N = 2e5 + 200;
const int INF = 0x3f3f3f3f;
const double eps = 1e-7;


int main() {
	ll n;
	cin>>n;
	queue<ll> q;
	for(int i = 1; i <= 9; i++){
		q.push(i);
	}
	ll rst = 0;
	ll cnt = 0;
	while(!q.empty()){
		ll tmp = q.front();
		q.pop();
		cnt++;
		if(cnt == n){
			rst = tmp;
			break;
		}
		ll nw = tmp%10;
		if(nw - 1 >= 0){
			q.push(tmp*10+(nw-1));
		}
		if(nw >= 0){
			q.push(tmp*10+nw);
		}
		if(nw + 1 <= 9){
			q.push(tmp*10 + nw+1);
		}
	}
	cout<<rst<<endl;


}


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

#define whole(f, x, ...)                                 \
  ([&](decltype((x)) whole) {                            \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__); \
  })(x)

using namespace std;
using ll = long long;

void solve() {
  int n;
  cin >> n;
  --n;
  vector<int> c(n);
  vector<int> s(n);
  vector<int> f(n);
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    c[i] = tmp;
    cin >> tmp;
    s[i] = tmp;
    cin >> tmp;
    f[i] = tmp;
  }

  for (int i = 0; i < n; i++) {
    int cnt = 0;
    for (int j = i; j < n; j++) {
      if (cnt > s[j]) {
        while (cnt % f[j]) ++cnt;
      } else {
        cnt = s[j];
      }
      cnt += c[j];
    }
    cout << cnt << "\n";
  }
  cout << 0 << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename key>
using ordered_set = tree<key, null_type, less<key>, rb_tree_tag, tree_order_statistics_node_update>;
#define F first
#define S second
#define T second.first
//#define C second.second
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);
#define all(v) v.begin(),v.end()
#define OO 0x3f3f3f3fLL
#define INF 0x3f3f3f3f3f3f3f3fLL
#define sz(s) (int)(s.size())
#define RT(s) return cout<<s,0
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef pair<ll,pair<ll,ll>> piii;
const int N = 2e5+5, M= 20, mod = 1000000000;
const double EPS = 1e-10;


int main(){
    FIO
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int n;
    string s;
    cin>>n;
    map<string, int>mp;
    while(n--){
        cin>>s;
        mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<"\n";
    cout<<"WA x "<<mp["WA"]<<"\n";
    cout<<"TLE x "<<mp["TLE"]<<"\n";
    cout<<"RE x "<<mp["RE"]<<"\n";
}


Measured memory_bytes: 3624
def solve():
    n = int(input())
    if 0 < n <= 9:
        print(n)
    elif 9 < n <= 99:
        print(9)
    elif 99 < n <= 999:
        print(n-90)
    elif 999 < n <= 9999:
        print(999-90)
    elif 9999 < n <= 99999:
        print(n-9999+999-90)
    else:
        print(90909)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main(){
    string a,b;
    cin>>a>>b;
    
    if(a=="H"&&b=="H"){cout<<"H";}
    else if(a=="H"&&b=="D"){cout<<"D";}
    else if(a=="D"&&b=="H"){cout<<"D";}
    else if(a=="D"&&b=="D") {cout<<"H";}
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int K = Integer.parseInt(sc.next());
		sc.close();

		int ans = 0;
		for(int i = 0; i < Math.pow(10, 9); i++) {
			double check = Math.pow(K, i);
			int num = (int) check;
			if(N > num) {
				continue;
			}else if(N == num) {
				ans = i + 1;
				break;
			}else {
				ans = i;
				break;
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair <int, int>
#define iiii pair <int, pii >
#define mp make_pair
#define INF 1000000000
#define rep(i, x) for(int (i) = 0; (i) < (x); (i)++)
inline int getint() {
  int x = 0, p = 1; char c = getchar();
  while (c <= 32) c = getchar();
  if (c == 45) p = -p, c = getchar();
  while (c > 32) x = x * 10 + c - 48, c = getchar();
  return x * p;
}
using namespace std;
const int mod = 1e9 + 7;
inline void reduce(int &x) { x += x >> 31 & mod; }
inline int mul(int x, int y) { return 1ll * x * y % mod; }
//ruogu_alter
const int N = 2e5 + 5;
int n, m, len[N], vis[N], d[N];
vector<pii> v, g[N];
//
int main() {
  n = getint(); m = getint();
  rep(i, n) v.emplace_back(d[i] = getint(), i);
  sort(v.begin(), v.end());
  rep(i, m) {
    int x = getint() - 1, y = getint() - 1;
    g[x].emplace_back(y, i);
    g[y].emplace_back(x, i);
  }
  rep(i, m) len[i] = INF;
  for (auto &u : v) {
    int s = u.second, l = u.first;
    if (vis[s]) continue;
    bool fg = false;
    for (auto &to : g[s]) if (vis[to.first]) {
      fg = true;
      vis[s] = 3 - vis[to.first];
      len[to.second] = l;
      break;
    }
    if (fg) continue;
    for (auto &to : g[s]) if (d[to.first] == l) {
      fg = true;
      vis[s] = 1; vis[to.first] = 2;
      len[to.second] = l;
      break;
    }
    if (!fg) return !printf("%d\n", -1);
  }
  rep(i, n) putchar(vis[i] == 1 ? 'W' : 'B');
  putchar('\n');
  rep(i, m) printf("%d\n", len[i]);
  return 0;
}


Measured memory_bytes: 15916
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <array>
#include <vector>

using namespace std;

vector<int> *makePrimes( const int limit ) {
  vector<bool> isPrime( limit + 1 );
  fill( isPrime.begin(), isPrime.end(), true );
  isPrime[ 0 ] = isPrime[ 1 ] = false;
  for ( int i = 2; i * i <= limit; i++ ) {
	if ( isPrime[ i ] ) {
	  for ( int j = i * i; j <= limit; j+= i ) {
		isPrime[ j ] = false;
	  }
	}
  }
  const int size = count( isPrime.begin(), isPrime.end(), true );
  auto ans = new vector<int>( size );
  int index = 0;
  for ( int i = 0; i <= limit; i++ ) {
	if ( isPrime[ i ] ) {
	  (*ans)[ index++ ] = i;
	}
  }
  return ans;
}

int binary_search( vector<int> *vs, int val ) {
  int left = 0;
  int right = vs->size() - 1;
  while( left + 1 < right ) {
	const int middle = ( left + right ) / 2;
	if ( (*vs)[ middle ] <= val ) {
	  left = middle;
	} else {
	  right = middle;
	}
  }
  return left;
}

int main() {
  auto primes = makePrimes( 2000000 );
  while( true ) {
	int n;
	cin >> n;
	if ( n == 0 ) break;

	if ( binary_search( primes->begin(), primes->end(), n ) ) {
	  cout << 0 << endl;
	} else {
	  int li = binary_search( primes, n );
	  cout << (*primes)[ li + 1 ] - (*primes)[ li ] << endl;
	}
  }
  delete primes;
}

Measured memory_bytes: 1792
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    X,Y=pin()
    for i in range(10**7):
        if X>Y:print(i);return
        else:X*=2
#%%submit!
resolve()

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

int main()
{
    string s;
    cin >>s;

    int out;

    if(s == "SUN"){
            out=7;
    }else if(s=="MON"){
           out=6;
    }else if(s=="TUE"){
            out=5;
    }else if(s=="WED"){
            out=4;
    }else if(s=="THU"){
            out=3;
    }else if(s=="FRI"){
            out=2;
    }else if(s=="SAT"){
            out=1;
    }
    cout << out << endl;

    return 0;
}


Measured memory_bytes: 256
class _Node {
  constructor(key, left = null, right = null) {
    this.key = key;
    this.left = left;
    this.right = right;
  }
}

class BinaryTree {
  constructor() {
    this.root = null;
  }

  static get Node() { return _Node; }

  insert(key) {
    this.root = new BinaryTree.Node(key, null, null);
    this.insert = (key) => {
      let x = this.root, y;
      let newNode = new BinaryTree.Node(key, null, null);
      while (x !== null) {
        y = x;
        x = x[key < x.key ? 'left' : 'right'];
      }
      y[key < y.key ? 'left' : 'right'] = newNode;
    }
  }

  printByIneorder() {
    let str = '';
    const innerFunc = (n) => {
      if (n === null) return;
      innerFunc(n.left);
      str += ` ${n.key}`;
      innerFunc(n.right);
    }
    innerFunc(this.root);
    console.log(str);
  }

  printByPreorder() {
    let str = '';
    const innerFunc = (n) => {
      if (n === null) return;
      str += ` ${n.key}`;
      innerFunc(n.left);
      innerFunc(n.right);
    }
    innerFunc(this.root);
    console.log(str);
  }

  print() {
    this.printByIneorder();
    this.printByPreorder();
  }
}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());

  const tree = new BinaryTree();
  lines.forEach(function(cmd) {
    switch(cmd.charAt(0)) {
    case 'i':
      tree.insert(Number(cmd.split(' ')[1]));
      break;
    default:
      tree.print();
    }
  });
})();



Measured memory_bytes: 198064
#include<iostream>
using namespace std;
int main()
{
	int a;
	cin >> a;
	int f=0;
	for(int i=1;i<10;i++) 
		for(int j=1;j<10;j++) 
			if(i*j==a) f=1;
	if(f) cout <<"Yes" ;
	else cout <<"No" ;
	return 0;
} 

Measured memory_bytes: 256
use std::io::Read;
use std::i64;
use std::cmp;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };

    (iter = $i:expr, $($r:tt)*) => {
        input_inner!{$i, $($r)*}
    };

    ($($r:tt)*) => {
        let mut buf = String::new();
        std::io::stdin().read_to_string(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}



fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input_iter = buf.split_whitespace();

    input!{iter = input_iter, n: i64, m: i64}

    let mut dp: Vec<i64> = vec![i64::MAX; 1 << n];
    dp[0] = 0;
    for _ in 0 .. m {
        input!{
            iter = input_iter,
            a: i64,
            b: i64,
            c: [i64; b]
        }

        let mask = c.iter().fold(0, |acc, i| {acc | (1 << (i - 1))});
        for idx in 0 .. (1 << n) {
            if dp[idx] < i64::MAX {
                dp[idx | mask] = cmp::min(dp[idx | mask], dp[idx] + a);
            }
        }
    }

    println!("{}", if dp[(1 << n) - 1] < i64::MAX {dp[(1 << n) - 1]} else {-1})
}

Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<cmath>
using namespace std;

int main(){
	int N;
	cin>>N;
	vector<long>a(N);
	for(int i=0;i<N;++i)cin>>a[i];
	long ans;
	long sum1,sum2;
	sum1=a[0];
	sum2=0;
	for(int i=1;i<N;++i){
		sum2+=a[i];
	}
	ans=abs(sum1-sum2);
	for(int i=1;i<N-1;++i){
		sum1+=a[i];
		sum2-=a[i];
		//cout<<abs(sum1-sum2)<<endl;
		if(abs(sum1-sum2)<ans)ans=abs(sum1-sum2);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include"bits/stdc++.h"
using namespace std;

#define ll long long int
#define f(i,x,n)  for(int i=x;i<n;i++)
#define FASTIO cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define sz(a) int((a).size())
#define mod 1000000007
#define inf LLONG_MAX
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
template <typename T>
inline T gcd(T a, T b)
{
    while (b != 0) swap(b, a %= b);
    return a;
}

template <typename T>
inline void seethis(vector<T>vect)
{
    for(T x : vect)
        cout << x << " ";
    cout << "\n";
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
//LCM
int lcm(int a, int b)
{
    return a * (b / gcd(a, b));
}

//For sort by second
bool cmp(const pair<int, int> &a)
{
    return a.first < a.second;
}

//Tree
/* const int MAXN = 1e5 + 5;
vector<ll> adj[MAXN];*/

//ModPower
ll modpower(ll a, ll b, ll c)
{
    ll res = 1;
    while(b)
    {
        if(b & 1LL)
            res = (res * a) % c;
        a = (a * a) % c;
        b >>= 1;
    }
    return res;
}
ll dp[22][1 << 22];
ll can[22][22];
ll solve(ll men, ll woman_subset, ll n)
{
    if(men == n)
    {
        if(woman_subset == 0)
            return 1;
        else
            return 0;
    }

    if(dp[men][woman_subset] != -1)
        return dp[men][woman_subset];


    ll res = 0;
    for(int i = 0; i < n; i++)
    {
        if(can[men][i] and ((woman_subset) & (1 << i)))
        {
            res = (res % mod + solve(men + 1, woman_subset ^ (1 << i), n) % mod) % mod;
        }
    }
    //cout<<"sabquwshfduiqw";

    return dp[men][woman_subset] = res;

}
int main()
{
    FASTIO;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    cin >> n;


    memset(dp, -1, sizeof dp);



    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            cin >> can[i][j];

    cout << solve(0, ((1 << n) - 1), n) << "\n";

    return 0;
}

Measured memory_bytes: 724532
S = input()

#print(type(S[:2]))
#print(type(int(S[:2])))

if (1 <= int(S[:2]) <= 12) & (1 <= int(S[2:]) <= 12):
    print('AMBIGUOUS')
elif (1 <= int(S[:2]) <= 12) & ((int(S[2:]) == 0) or (13 <= int(S[2:]))):
    print('MMYY')
elif (1 <= int(S[2:]) <= 12) & ((int(S[:2]) == 0) or (13 <= int(S[:2]))):
    print('YYMM')
else:
    print('NA')

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int N;
double T, A;
double tmp[1005];

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

	cin >> N >> T >> A;

	double MIN = 1e10;

	int ans;

	for (int i = 0;i < N;i++){
		double h;
		cin >> h;
		double t = T-h*0.006;
		double d = abs(A-t);
		if(MIN > d){
			MIN = d;
			ans = i+1;
		}
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int k = sc.nextInt();

		int[] a = new int[n];
		int[] b = new int[n];

		for (int i=0;i<n;i++) {
			a[i]=sc.nextInt();
			b[i]=sc.nextInt();
		}

		long ans = 0;

		for (int j=0;j<n;j++) {
			if((a[j] & ~k) == 0) {
				ans += b[j];
			}
		}
		
		for (int i=1;i<32;i++) {
			if((k>>i) %2 != 0) {
				long tmp = 0;
				int x = ((k>>i)<<i)-1;
				for (int j=0;j<n;j++) {
					if((a[j] & ~x) == 0) {
						tmp += b[j];
					}
				}
				ans = Math.max(ans, tmp);
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 82648
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<queue>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;

int main() {
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	for (int i = 0; i < tx-sx; i++)
		cout << "R";
	for (int i = 0; i < ty-sy; i++)
		cout << "U";
	for (int i = 0; i < tx-sx; i++)
		cout << "L";
	for (int i = 0; i < ty-sy; i++)
		cout << "D";
	cout << "L";
	for (int i = 0; i < ty-sy+1; i++)
		cout << "U";
	for (int i = 0; i < tx-sx+1; i++)
		cout << "R";
	cout << "D";
	cout << "R";
	for (int i = 0; i < ty-sy+1; i++)
		cout << "D";
	for (int i = 0; i < tx-sx+1; i++)
		cout << "L";
	cout << "U" << endl;
	return 0;
}


Measured memory_bytes: 384
package main

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

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func main() {
	s1 := readLine()
	s2 := readLine()
	s2col := strings.Split(s2, " ")
	nums, _ := strconv.Atoi(s1)
	trueTotal := 0
	min := 1000000
	for i := 0; i < nums; i++ {
		num, _ := strconv.Atoi(s2col[i])
		if min >= num {
			trueTotal++
			min = num
		}
	}
	fmt.Println(trueTotal)
}


Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod;
ll N;
ll Factorial[10000];
ll Inv[10000];
ll FactorialInv[10000];
ll dp[2005][2005];
ll beki2[5000000];
ll invbeki2[5000000];
ll beki(ll a, ll b) {
    a %= mod;
    if (a < 0) a += mod;
    if(b < 0) {
        ll inverse = beki(a, -b);
        return beki(inverse, mod - 2);
    }
    if(b == 0) return 1;
    ll ans = beki(a, b/2);
    ans = ans * ans % mod;
    if(b % 2 == 1) ans = ans * a % mod;
    return ans;
}

void init() {
    Inv[1] = 1;
    FactorialInv[1] = 1;
    Factorial[1] = 1;
    for(ll i = 2; i < 10000; i++) {
        Inv[i] = beki(i, mod - 2);
        Factorial[i] = Factorial[i-1] * i % mod;
        FactorialInv[i] = FactorialInv[i-1] * Inv[i] % mod;
    }
    beki2[0] = 1;
    invbeki2[0] = 1;
    for(int i = 1; i < 5000000; i++) {
        beki2[i] = beki2[i - 1] * 2 % mod;
        invbeki2[i] = invbeki2[i - 1] * Inv[2] % mod;
    }
    for(int y = 0; y <= 2000; y++) {
        ll Factor = (1 - invbeki2[y] + mod) % mod;
        dp[y][0] = 1;
        for(int z = 1; z <= 2000; z++) {
            dp[y][z] = dp[y][z-1] * Factor % mod;
        }
    }
}

ll combination(ll a, ll b) {
    if((a == b) || (b == 0)) return 1;
    ll ans = Factorial[a] * FactorialInv[b] % mod;
    ans = ans * FactorialInv[a-b] % mod;
    return ans;
}

int main() {
    cin >> N >> mod;
    //cerr << beki(2, -2) << endl;
    init();
    ll ans = 0;
    for(ll R = 0; R <= N; R++) {
        ll B = N - R;
        for(ll r = 0; r <= R; r++) {
           ll now = combination(R, r);
           now = now * beki2[N*(N-1)/2-r*B] % mod;
           //ll sub = 1 - invbeki2[R-r];
           //sub = (sub + mod) % mod;
           //sub = beki(sub, B);
           ll sub = dp[R-r][B];
           now = now * sub % mod;
           now = now * combination(N, R) % mod;
           if(r % 2 == 1) now = -now;
           //cout << R << " " << r << " " << now << endl;
           ans = (ans + now + mod) % mod;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 112804
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back

const long long MOD = 924844033;
const long long MAXN = 1e6 + 1;
using namespace std;

typedef long long ll;

long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}

int dp[2][MAXN];

int f[MAXN];
int ans[MAXN];

int main() {
	#ifdef IZI_KATKA
	freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int n = readInt(), k = readInt();
    vector <int> ord;
    for (int i = 1; i <= min(n, k + k); i++) {
    	for (int j = i; j <= n; j += k + k) {
    		ord.pb(j);
    	}
    }
    dp[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		int x = ord[i - 1];
		for (int j = n; j >= 0; j--) {
			if (x - k >= 1) {
				dp[0][j + 1] += dp[0][j];
				dp[0][j + 1] %= MOD;
			}
			if (x - k >= 1 && x - k - k < 1) {
				dp[0][j + 1] += dp[1][j];
				dp[0][j + 1] %= MOD;
			}
			if (x + k <= n) {
				dp[1][j + 1] += dp[1][j];
				dp[1][j + 1] %= MOD;
				dp[1][j + 1] += dp[0][j];
				dp[1][j + 1] %= MOD;
			}
			dp[0][j] += dp[1][j];
			dp[0][j] %= MOD;
			dp[1][j] = 0;
		}
	}
	f[0] = 1;
	for(int i = 1; i < MAXN; i++)
		f[i] = 1ll * f[i - 1] * i % MOD;
	for (int i = 0; i <= n; i++) {
		ans[i] = 1ll * (dp[0][i] + dp[1][i]) * f[n - i] % MOD;
	}
	int res = 0;
	for (int i = 0; i <= n; i++) {
		if (i % 2) {
			res += (MOD - ans[i]);
		} else {
			res += ans[i];
		}
		res %= MOD;
	}
	cout << res;
    return 0;
}

Measured memory_bytes: 8448
{-# LANGUAGE TupleSections #-}
import Control.Monad
import Data.List
import qualified Data.IntMap as MP
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)

readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

includingBoxes h w [a, b] = [w * x + y |
  x <- [a -2, a - 1, a], x >= 0, x <= h - 3,
  y <- [b -2, b - 1, b], y >= 0, y <= w - 3]

frequency :: [Int] -> [(Int, Int)]
frequency = MP.toList . MP.fromListWith (+) . map (, 1)

solve h w ls = find <$> [0..9]
  where
  boxFreqs = frequency $ includingBoxes h w =<< ls
  freqs    = frequency $ filter (<= 9) $ map snd $ boxFreqs
  zeros    = (h - 2) * (w - 2) - length boxFreqs
  find v   = MP.findWithDefault 0 v $ MP.fromList $ (0, zeros) : freqs

main = do
  [h, w, n] <- map read . words <$> getLine
  ls        <- replicateM n $ map pred <$> readInts
  mapM print $ solve h w ls


Measured memory_bytes: 212348
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  if (b % a == 0) cout << a + b << endl;
  else
    cout << b-a << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;

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

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

    if(N > K){
        N = N % K;
    }

    cout << min(N, abs(N - K)) << endl;

    return 0;
}


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

using namespace std;

int main(){

    int n,d;
    cin>>n>>d;
    int count=0;
    while (n--)
    {
        /* code */
        long long int x,y;
        cin>>x>>y;

        


        if(pow(x*x+y*y,0.5)<=d)
        {
            count++;
        }
    }

    cout<<count<<endl;
    
    return 0;
}

Measured memory_bytes: 4248
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

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

  int n;
  cin >> n;

  if (n % 2 == 0) cout << n << endl;
  else cout << n * 2 << endl;

  return 0;
}


Measured memory_bytes: 256
inf = 10**10
def dijkstra(s):
    d = [(inf, 1)] * N
    used = [False] * N
    d[s] = (0, -L)  
    for i in range(N):
        v = -1
        for i in range(N):
            if used[i]:
                continue
            if v==-1:
                v = i
            elif d[v]>d[i]:
                v = i
        if v == -1:
            break
        used[v] = True   
        m, r = d[v]
        r = -r
        for nv in range(N):
            c = cost[v][nv]
            if r>=c:
                d[nv] = min(d[nv],(m, -(r-c)))
            elif c<=L:
                d[nv] = min(d[nv], (m+1, -(L-c)))
    return d
N, M, L = map(int, input().split())
cost = [[inf]*N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    cost[a-1][b-1] = c
    cost[b-1][a-1] = c
ans = []
for i in range(N):
    ans.append(dijkstra(i))
Q = int(input())
for _ in range(Q):
    a, b = map(int, input().split())
    res = ans[a-1][b-1][0]
    print(res if res != inf else -1)

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

N = int(input())
A = list(map(int, input().split()))
MOD = 10**9+7
inv = lambda x: pow(x, MOD-2, MOD)
acc = [0]

for i in range(1, N+1):
    acc.append((acc[-1]+inv(i))%MOD)

ans = 0

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

for i in range(1, N+1):
    ans *= i
    ans %= MOD

print(ans)

Measured memory_bytes: 91024
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Tue Jan 29 11:30:46 2019
//
package main

import (
	"fmt"
	"sort"
)

type pair struct {
	x, y int
}

type blues []pair

func (ps blues) Len() int {
	return len(ps)
}

func (ps blues) Swap(i, j int) {
	ps[i], ps[j] = ps[j], ps[i]
}

func (ps blues) Less(i, j int) bool {
	return ps[i].x < ps[j].x
}

type reds []pair

func (ps reds) Len() int {
	return len(ps)
}

func (ps reds) Swap(i, j int) {
	ps[i], ps[j] = ps[j], ps[i]
}

func (ps reds) Less(i, j int) bool {
	return ps[i].y > ps[j].y
}

func main() {
	var N int
	fmt.Scan(&N)

	reds := make(reds, N)
	for i := range reds {
		fmt.Scan(&reds[i].x, &reds[i].y)
	}

	blues := make(blues, N)
	for i := range blues {
		fmt.Scan(&blues[i].x, &blues[i].y)
	}
	sort.Sort(reds)
	sort.Sort(blues)

	count := 0
	used := make([]bool, len(reds))
	for _, b := range blues {
		for i, r := range reds {
			if !used[i] && r.x < b.x && r.y < b.y {
				used[i] = true
				count++
				break
			}
		}
	}

	fmt.Println(count)
}


Measured memory_bytes: 512
#include <stdio.h>

int main(){

    char s[101];
	scanf("%s",s);

	int bool=0;
	int i=0;

	while(s[i]!='\0'){
        if(s[i]=='C' && bool==0){
            bool=1;
        }else if(s[i]=='F' && bool==1){
            bool=2;
        }
        i++;
	}
	if (bool==2){
        printf("Yes");
	}else{
        printf("No");
	}
    return 0;
}


Measured memory_bytes: 128