akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define PI 3.141592653589793238
#define mod 1000000007
#define endl '\n'
#define fastio; ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;

int main()
{
    fastio;
    int n;
    cin>>n;
    vi h(n);
    for(int i=0;i<n;i++) cin>>h[i];
    vi neg(n),pos(n);
    map<int,vector<int> > MP;
    for(int i=0;i<n;i++)
    {
        neg[i]=i-h[i],pos[i]=i+h[i];
        MP[neg[i]].pb(i);
    }
    ll prs=0;
    for(int i=0;i<n-1;i++){
        if(MP[pos[i]].size()==0) continue;
        int k=MP[pos[i]].size();
        int idx=lower_bound(MP[pos[i]].begin(),MP[pos[i]].end(),pos[i])-MP[pos[i]].begin();
        prs+=(k-idx);
    }
    cout<<prs<<endl;

    return 0;
}


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

int main()
{
    int n;
    cin >> n;
    deque<int> deq;
    for (int i = n; i > 0; i--)
    {
        int tmp;
        cin >> tmp;
        if (i % 2) deq.push_front(tmp);
        else deq.push_back(tmp);
    }
    for (auto v : deq) cout << v << " ";
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl);
#define cop(a) for(auto x:(a)){cout << x << endl;}


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        // comment this out when you use scanf or printf
        // cin.tie(0); ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(15);
    };
}fastio;

int main(){

    string s, t;
    cin >> s >> t;
    cout << (s[0] == t[0]) + (s[1] == t[1]) + (s[2] == t[2]) << endl;
    return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
s=[]
for i in enumerate(l):
    s.append(i)
s=sorted(s,key=lambda x:(x[1][0],x[1][1]))
a=0
for i in range(m):
    if s[i][1][0]==0:
       a=1     
    elif s[i][1][0]==s[i-1][1][0]:
        a+=1
    elif s[i][1][0]!=s[i-1][1][0]:
        a=1
    s[i][1][1]=a
s = sorted(s,key=lambda x:x[0])
for i in s:
    print('%06d'%i[1][0]+'%06d'%i[1][1])


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

int main() {
	// your code goes here
	char b[5]; cin >> b;
	if(b[0]=='A') cout << "T" << endl;
	if(b[0]=='T') cout << "A" << endl;
	if(b[0]=='C') cout << "G" << endl;
	if(b[0]=='G') cout << "C" << endl;
	return 0;
}

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

namespace ABC087A
{
    class Program
    {
        static void Main(string[] args)
        {
            int x, a, b, c;

            x = int.Parse(Console.ReadLine());
            a = int.Parse(Console.ReadLine());
            b = int.Parse(Console.ReadLine());

            c = (x - a) % b;

            Console.WriteLine(c);

            Console.ReadKey();



        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i, a, n) for(int i=(int)(n-1);i>=a;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(nullptr); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int r, D, x2000;
    cin >> r >> D >> x2000;
    int ans = x2000;
    rep(i, 2001, 2011) {
        ans = ans * r - D;
        cout << ans << endl;
    }
    return (0^_^0);
}



Measured memory_bytes: 256
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		out=new PrintWriter (new BufferedOutputStream(System.out));
		FastReader s=new FastReader();
		int n=s.nextInt();
		int w=s.nextInt();
		long[] dp=new long[(int)1e6];
		Arrays.fill(dp, Long.MAX_VALUE);
		dp[0]=0;
		for(int i=0;i<n;i++) {
			long cw=s.nextLong();
			int cv=s.nextInt();
			for(int j=(int)1e6-cv;j>=0;j--) {
				if(dp[j]!=Long.MAX_VALUE) {
					dp[j+cv]=Long.min(dp[j+cv], dp[j]+cw);
				}
			}
		}
		long ans=0;
		for(int i=0;i<(int)1e6;i++) {
			if(dp[i]<=w) {
				ans=Long.max(i, ans);
			}
		}
		out.println(ans);
		out.close();
	}

	public static PrintWriter out;
	
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
		//it reads the data about the specified point and divide the data about it ,it is quite fast
		//than using direct 

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception e) {
				e.printStackTrace();
			}
			return str;
		}
	}
	
}


Measured memory_bytes: 32084
#include <algorithm>
#include <iostream>
using namespace std;
int main(void){
    for(;;){
    int a[2];
    cin >> a[0] >> a[1];
    if(a[0]==0&&a[1]==0){break;}
    sort(a,a +2);
    cout << a[0] << " " << a[1] << endl;}
}



Measured memory_bytes: 3156
from copy import deepcopy as dc

N, M = map(int, input().split())
edges = [list(map(lambda x:int(x) - 1, input().split())) for _ in range(M)]

edges_map = [[False for _ in range(N)] for _ in range(N)]
for edge in edges:
    edges_map[edge[0]][edge[1]] = True
    edges_map[edge[1]][edge[0]] = True
visited = [False for _ in range(N)]

def dfs(edge_now, edges_map, visited):
    visited[edge_now] = True
    for edge_to in range(N):
        if visited[edge_to]:
            continue
        if not edges_map[edge_now][edge_to]:
            continue
        dfs(edge_to, edges_map, visited)

def is_true(visited):
    if False in visited:
        return 1
    return 0

ans = 0
for edge in edges:
    visited_lc = dc(visited)
    edges_map_lc = dc(edges_map)
    edges_map_lc[edge[0]][edge[1]] = False
    edges_map_lc[edge[1]][edge[0]] = False
    dfs(0, edges_map_lc, visited_lc)
    ans += is_true(visited_lc)

print(ans)


Measured memory_bytes: 3620
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
string a,b;
int main( )
{
    cin>>a>>b;
    if(a==b)
    {
    	cout<<"H"<<endl;
    	return 0;
	}
    else
    {
		cout<<"D"<<endl;
		return 0;	
	} 
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
alphabet = [chr(i) for i in range(97, 97+26)]
ans = ""
i = 0
while n - 26**i >= 0:
    n -= 26**i
    i += 1
# ここを抜けた時,iは桁数

for _ in range(i):
    q,r = divmod(n,26)
    n = q
    ans += alphabet[r]
print(ans[::-1])




Measured memory_bytes: 9080
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


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

    int ans = 0;
    REP(i,S.size()){
        ans+= S[i] - '0';
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <stack>
#include <cstdlib>

using namespace std;

int main() {
	char s[500];
	stack<double> S;
	while (scanf("%s", s) != EOF) {
		if ((s[0] < '0' || s[0] > '9') && (!s[1])) {
			double r = S.top(); S.pop();
			double l = S.top(); S.pop();
			switch (s[0]) {
				case '+': l += r; break;
				case '-': l -= r; break;
				case '*': l *= r; break;
				case '/': l /= r; break;
			}
			S.push(l);
		}
		else {
			S.push( (double)atoi(s) );
		}

		char c;
		if (scanf("%c", &c) == EOF || c != ' ') {
			printf("%.10f\n", S.top()); S.pop();
		}
	}
}

Measured memory_bytes: 1220
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
AB = list(map(list, (zip(*AB))))
A = sorted(AB[0])
B = sorted(AB[1])
if N % 2 == 0:
    m = N // 2
    left = (A[m] + A[m-1])
    right = (B[m] + B[m-1])
    print(right - left + 1)
else :
    m = N // 2
    print((B[m] - A[m]) + 1)


Measured memory_bytes: 125812
#include <iostream>
#include <string>
 
using namespace std;
 
int main() {
	int ans = 0;
	string s;
	cin >> s;
 
	for (int i = 0; i < s.size()-1; i++) {
		if (s[i] != s[i + 1]) {
			ans++;
		}
	}
	cout << ans<< endl; 
 
	return 0;
 }


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b; char ch; cin>>a>>ch>>b;
	cout<<(ch=='+'?(a+b):(a-b))<<endl;
	return 0;
}


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

int Q,L;

struct BIT{
  int d[400006];
  int n;
  void init(int _n){ 
    n = _n+2; 
    for(int i=0;i<=n;i++ )d[i] = 0;
  }
  int sum(int i){
    int s = 0;
    while( i > 0 ){
      s += d[i];
      i -= i & -i;
    }
    return s;
  }

  void add(int i,int x){
    while( i <= n ){
      d[i] += x;
      i += i & -i;
    }
  }  
};
BIT B;



int main(){
  while( ~scanf("%d%d",&Q,&L) ){
    if(!Q&&!L) break;
    int head = 1, tail = 0;
    B.init( Q );
    map<int,int> W;
    map<int,int> R;
    for(int i=0;i<Q;i++){
      int q,x; scanf("%d%d",&q,&x);
      //cout << q<< " "<< x <<  " tail = " << tail << endl;
      if( q == 0 ){
        W[x] = head;
        R[head] = x;
        B.add( head, 1 );
        head++;
      } else if( q == 1 || q == 2){
        int st = tail+1, ed = head;
        int t = ed;
        //cout << st << " " <<ed << " "<< t << endl;
        while( st <= ed ){
          int h = (st+ed)/2;
          //cout <<h << " " << B.sum( h )-B.sum(tail) << endl;
          if( B.sum( h ) - B.sum( tail ) >= x ) { t = h; ed = h-1; }
          else st = h+1;
        }
        if( q== 2 ) printf("%d\n",R[t] );
        else B.add( t, -1 );
      } else if( q == 3 ){
        B.add( W[x],-1 );
      }
      while( B.sum( head ) - B.sum( tail ) > L ) tail++;      
    }
    puts("end");
  }
}

Measured memory_bytes: 40260
using System;
using System.Collections.Generic;
using System.Linq;

class Solution
{
    static void Main()
    {
        var s = Console.ReadLine();
        var k = int.Parse(Console.ReadLine());
        int curK = 1;
        var current = s.Min(c => c).ToString();
        while (k != curK)
        {
            var nexts = new List<string>();
            for (int index = s.IndexOf(current, 0); index != -1; index = s.IndexOf(current, index + current.Length))
            {
                if (index + current.Length + 1 <= s.Length)
                {
                    var next = s.Substring(index, current.Length + 1);
                    nexts.Add(next);
                }
            }
            if (nexts.Count > 0)
            {
                current = nexts.OrderBy(x => x).First();
            }
            else
            {
                var next = s.Where(c => c > current[0]).Min().ToString();
                current = next;
            }

            curK++;
        }

        Console.WriteLine(current);
    }
}

Measured memory_bytes: 14176
import sys
input = sys.stdin.readline
N = int(input())
print(0)
sys.stdout.flush()
s = input()[: -1]
if s == "Vacant":
  exit(0)
zero = s

ok = 0
ng = N
while ng - ok > 1:
  m = (ok + ng) // 2
  print(m)
  sys.stdout.flush()
  s = input()[: -1]
  if s == "Vacant": exit(0)
  if ((m % 2) and (s != zero)) or ((m % 2 == 0) and (s == zero)): ok = m
  else: ng = m
print(ng)
sys.stdout.flush()
exit(0)

Measured memory_bytes: 38852
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

int f_dir[2][4] = {{-1, 0, 1, 0}, {0, 1, 0, -1}}; //↑→↓←
int e_dir[2][8] = {{-1, -1, -1, 0, 0, 1, 1, 1}, {-1, 0, 1, -1, 1, -1, 0, 1}};
bool is_in_field(int y, int x, int h, int w){
  return (y >= 0 && y < h && x >= 0 && x < w);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  int n; cin >> n;
  ll ans = 0;
  for(ll i = 1; i <= n; i++){
    if(i%3 && i%5) ans += i;
  }
  cout << ans << endl;

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 3608
#include <iostream>

using namespace std;

typedef long long int ll;

int main() {

    ll curpos = 0;
    ll X;

    cin >> X;

    int ans = 0;
    ll delta = 1;
    while (curpos < X) {
        curpos += delta;
        ++delta;
        ++ans;
    }

    cout << ans;

    return 0;
}

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

int main(){
  int A,B,C;
  scanf("%d%d%d",&A,&B,&C);
  if (A==B) printf("%d\n",C);
  if (A==C) printf("%d\n",B);
  if (C==B) printf("%d\n",A);
}


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

int main(){
  int n;
  bool prime[300005];
  for(int i=2;i<300000;i++)prime[i]=true;
  
  for(int i=2;i<300000;i++){
    for(int j=1;i*j<300000;j++){
      if(i!=i*j&&i*j<300000)prime[i*j]=false;
    }
  }
  
  while(1){
    cin>>n;
    if(n==0)break;
    int cnt=0;
    for(int i=n+1;i<=2*n;i++)if(prime[i])cnt++;
    cout<<cnt<<endl;
  }
  
  return 0;
}

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

int n;
vector<bool> s;

bool check(vector<bool> &ans) {
	for (int i = 1; i < n-2; i++) {
		if ((s[i] && !ans[i]) || (!s[i] && ans[i])) {
			ans[i+1] = ans[i-1];
		} else {
			ans[i+1] = !ans[i-1];
		}
	}
	if ((s[n-1] && !ans[n-1]) || (!s[n-1] && ans[n-1])) {
		if (ans[n-2] != ans[0]) {
			return false;
		}
	} else {
		if (ans[n-2] == ans[0]) {
			return false;
		}
	}
	if ((s[n-2] && !ans[n-2]) || (!s[n-2] && ans[n-2])) {
		if (ans[n-3] != ans[n-1]) {
			return false;
		}
	} else {
		if (ans[n-3] == ans[n-1]) {
			return false;
		}
	}
	return true;
}

void printvec(vector<bool> &ans) {
	for (int i = 0; i < n; i++) {
		cout << "SW"[ans[i]];
	}
}

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	string ch; cin >> n >> ch;
	for (int i = 0; i < n; i++) {
		if (ch[i] == 'o') s.push_back(true);
		else s.push_back(false);
	}
	for (int i = 0; i < 2; i++) {
		vector<bool> ans(n, false);
		ans[0] = bool(i);
		for (int j = 0; j < 2; j++) {
			if ((s[0] && !ans[0]) ||(!s[0] && ans[0])) {
				ans[1] = ans[n-1] = bool(j);
			} else {
				ans[1] = bool(j);
				ans[n-1] = !ans[1];
			}
			if (check(ans)) {
				printvec(ans);
				return 0;
			}
		}
	}
	cout << "-1" << endl;
	return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <iomanip>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define ls x<<1
#define rs x<<1|1
#define fi first
#define se second
#define ll long long
#define pb push_back
#define mp make_pair
#define fun function
#define vi vector<int>
#define lowbit(x) x&(-x)
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);

using namespace std;

const int INF = 0x3f3f3f3f;
const int p=1e9+7;


ll qpow(ll a,ll b) {
	ll ans=1;
	while(b) {
		if(b&1)ans=(ll)ans*a%p;
		a=(ll)a*a%p;
		b>>=1;
	}
	return ans%p;
}

ll Com(ll n,ll m) {
	ll x=1,y=1;
	for(ll i=1; i<=m; i++) {
		x=x*(n-i+1)%p;
		y=y*i%p;
	}

	return x*qpow(y,p-2)%p;
}


int main() {
	
#ifdef xiaofan
	freopen("1.in","r",stdin);
	freopen("1.out","w",stdout);
#endif

	ll n,x,y;
	cin>>n>>x>>y;
	ll ans=qpow(2,n);
	ll a=Com(n,x);
	ll b=Com(n,y);
	ans=(ans-a+p)%p;
	ans=(ans-b+p-1)%p;
	cout<<ans<<endl;



	return 0;
}


Measured memory_bytes: 256
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

n, m = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(n + m - 1)]

T = [[] for i in range(n+1)]
RT = [[] for i in range(n+1)]
IN = [0] * (n+1)

for a, b in A:
    T[a].append(b)
    RT[b].append(a)
    IN[b] += 1

D = [0] * (n+1)
P = [0] * (n+1)
used = [0] * (n+1)

def dfs(p, i, depth):
    if used[i]:
        return None
    D[i] = depth
    P[i] = p
    used[i] = True
    for t in tuple(T[i]):
        IN[t] -= 1
    for t in tuple(T[i]):
        if IN[t] == 0:
            dfs(i, t, depth+1)

def root(i):
    if not RT[i]:
        return i
    return root(RT[i][0])

dfs(0, root(1), 1)
for p in P[1:]:
    print(p)

Measured memory_bytes: 146652
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vvll vector<vll>
#define all(v) v.begin(),v.end()
#define itr(r,v) for(auto r=v.begin();r!=v.end();r++)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define ffo(i,a,b) for(ll i=a;i<=b;i++)
#define rfr(i,a,b) for(ll i=a;i>=b;i--)
#define space cout<<"\n\n";
#define endl "\n"
#define pqmx priority_queue<ll>
#define pqmn priority_queue<ll,vll,greater<ll>>
#define fps(x,y) fixed<<setprecision(y)<<x
#define merg(a,b,c) set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.begin()))
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define ctime auto sttart = high_resolution_clock::now()
#define etime auto sttop = high_resolution_clock::now()
#define go_t ll testcases; cin>>testcases; for(ll caseno= 1 ;caseno <= testcases; caseno++)
#define ptime auto z1z = duration_cast<microseconds>(sttop-sttart); cout<<"\nTime taken : "<<z1z.count()<<" microseconds\n"
#define dbg1(x)             cout <<#x<<": "<<x<<'\n';
#define dbg2(x, y)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<'\n';
#define dbg3(x, y, z)       cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<'\n';
#define dbg4(a, b, c, d)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<'\n';
#define dbg5(a, b, c, d, e) cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<'\n';

using namespace std;
using namespace std::chrono;

const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
const ll maxN = 1e5 + 5;
const ll MAX_SIZE = 2e6 + 6;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const double PI = 3.14159265359;

ll powerM(ll x, ll y, ll M = MOD) { // default argument
	ll v = 1; x = x % M; while (y > 0) {if (y & 1)v = (v * x) % M; y = y >> 1; x = (x * x) % M;} return v;
}

ll power(ll x, ll y) {
	ll v = 1; while (y > 0) {if (y & 1)v = v * x; y = y >> 1; x = x * x;} return v;
}

ll n, k;
ll a[105];
ll dp[105][maxN];

// here dp[i][j] will store the prefix sum of the diff no. of ways to distribute
// j candies among i children with the given upper bound constraints

ll solve(ll child, ll candy) {
	if (candy < 0) return 0;
	if (candy == 0) return 1;
	if (child == n + 1) return 1;
	//
	ll& dd = dp[child][candy];
	if (dd != -1) return dd;
	// max amt of candies that can be given to the child
	ll mini = min(candy, a[child]);
	dd = solve(child + 1, candy) - solve(child + 1, candy - mini - 1) + MOD;
	dd %= MOD;
	dd += solve(child, candy - 1);
	dd %= MOD;
	return dd;
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	FIO
	// Ashishgup you're great bro
	cin >> n >> k;
	memset(dp, -1, sizeof(dp));
	for (ll i = 1; i <= n; i++) cin >> a[i];
	ll ans = solve(1, k) - solve(1, k - 1) + MOD;
	ans %= MOD;
	cout << ans;
	return 0;
}


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

#define debug(n) cerr << #n << ':' << n << endl;
#define rep(i,n) for(int i = 0; i < (n); ++i)
using ll = long long;

// int main(){
//   const int mod = 7 + (1e+9);
//   string s; cin >> s;
//   reverse(s.begin(), s.end());
//   const int n = static_cast<int>(s.size());
//   ll dp[n + 1][13] = {1};
//   rep(i,n){
//     if(isdigit(s[i])){
//       int x = s[i] - '0';
//       rep(j,13)dp[i+1][(j*10+x)%13] +=dp[i][j];
//     } else {
//       rep(j,13)rep(k,10)dp[i+1][(j*10+k)%13] += dp[i][j];
//     }
//     rep(j,13)dp[i+1][j] %= mod;
//   }
//   cout << dp[n][5] << endl;
//   return 0;
// }

int main(){
  const ll mod = 7 + (1e+9);
  auto modadd = [&](ll&a, ll&b){a = ((a+b)%mod);};
  string s; cin >> s;
  reverse(s.begin(), s.end());
  const int n = static_cast<int>(s.size());
  ll dp[13] = {1};
  ll c = 1;
  rep(i,n){
    ll next_dp[13]={};    
    if(s[i] == '?'){
      rep(j,13)rep(k,10)modadd(next_dp[(k*c+j)%13], dp[j]);
    } else {
      int x = s[i] - '0';
      rep(j,13)modadd(next_dp[(x*c+j)%13], dp[j]);
    }
    c = (c*10)%13;
    rep(j,13)dp[j] = next_dp[j];
  }
  cout << dp[5] << endl;
}








Measured memory_bytes: 512
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
    sc.Scan()
    return sc.Text()
}

func main() {
     sc.Split(bufio.ScanWords)

     s := nextLine()
     buf := strings.Split(s,"")

     if (buf[2]==buf[3]) && (buf[4]==buf[5]) {
     	fmt.Println("Yes")
     } else {
        fmt.Println("No")
     }	
}

Measured memory_bytes: 640
S = input()
l = len(S)
A = list(S)
flg = 0
if 'C' in A:
    C = A.index('C')
else:
    print('WA')
    flg = 1

if S[0] == 'A' \
and S[2:l-1].count('C') == 1 \
and S[1:C].islower() \
and S[C+1:].islower():
    print('AC')
else:
    if flg == 0:
        print('WA')

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


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	if (n == 7 || n == 5 || n == 3) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
from math import gcd
from functools import reduce
k=10**6+1
def judge(n,a):
  c=[0]*k
  for x in a:
    c[x]+=1
  t=any(sum(c[i::i])>1 for i in range(2,k))
  t+=reduce(gcd,a)>1
  return ['pairwise','setwise','not'][t]+' coprime'
n=int(input())
a=list(map(int,input().split()))
print(judge(n,a))


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

using namespace std;

int main(){
	int n;
	cin>>n;
	string s;
	map<string,long long> cnt;
	long long ans=0;
	for(int i=0;i<n;++i){
		cin>>s;
		sort(s.begin(),s.end());
		ans+=cnt[s];
		cnt[s]++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 11136
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

def Topo_sort(x,y):
    co = cl.Counter(n for m in x.values() for n in m)
    S = cl.deque([i for i in range(y) if co[i] == 0])
    while S:
        n = S.popleft()
        yield n
        for i in x[n]:
            co[i] -= 1
            if co[i] <= 0:
                S.append(i)
    
    """
    if sum(co.values()) != 0:
        print(1)
        exit()
    else:
        print(0)
        exit()
    """
    #閉路検出(1が存在,0が存在しない)
# g = cl.dafaultdict(set)に有向グラフを作成し(g[~] != ~ ,yはノード数) リストが帰ってくる
n = onem()

d = l()


po = cl.defaultdict(int)

for i in range(n):
    po[str(d[i])] += 1

M = onem()

t = l()

for i in range(M):
    if po[str(t[i])]:
        po[str(t[i])] -= 1
    else:
        print("NO")
        break
else:
    print("YES")



        



Measured memory_bytes: 124240
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <bits/stdc++.h>

using namespace std;

long long n, m;

int main () {
    cin >> n >> m;
    if ( m < n ) {
        cout <<"No";
    }
    else {
        cout <<"Yes";
    }
}


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

#define N 200000

int n, k, a[N+1];

int main(void){
    cin >> n >> k;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
    }
    
    for (int i = k+1; i <= n; i++){
        if (a[i-k]<a[i]){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 4424
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        String[] s = new String[n];
        int[] p = new int[n];
        Map<String, Map<Integer, Integer>> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            s[i] = scanner.next();
            p[i] = scanner.nextInt();
            Map<Integer, Integer> map2 = map.getOrDefault(s[i], new HashMap<>());
            map2.put(p[i], i+1);
            map.put(s[i], map2);
        }
        Arrays.sort(s);
        Set<String> done = new HashSet<>();
        for (String str : s) {
            if (done.contains(str)) {
                continue;
            }
            Map<Integer, Integer> m = map.get(str);
            List<Integer> scoreL = new ArrayList<>(m.keySet());
            scoreL.sort(Collections.reverseOrder());
            for (Integer score : scoreL) {
                System.out.println(m.get(score));
            }
            done.add(str);
        }
    }
}

Measured memory_bytes: 20560
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

class union_find {
public:
	union_find(int n)
	: par_(n, P(-1, 0))
	{}

	P root(int x) {
		if(par_[x].first < 0) return P(x, 0);
		P tmp = root(par_[x].first);
		par_[x].first = tmp.first;
		par_[x].second += tmp.second;
		return par_[x];
	}

	bool unite(int x, int y, int w) {
		ll px = root(x).first, py = root(y).first;
		if(px == py) {
			return false;
		} else {
			if(par_[px].first < par_[py].first) {
				par_[px].first += par_[py].first;
				par_[py].first = px;
				par_[py].second = (par_[x].second + w) - par_[y].second;
			} else {
				par_[py].first += par_[px].first;
				par_[px].first = py;
				par_[px].second = (par_[y].second - w) - par_[x].second;
			}
			return true;
		}
	}

	bool same(int x, int y) {
		return root(x).first == root(y).first;
	}

	bool compare(int x, int y, ll& result) {
		if(!same(x, y)) return false;
		result = root(y).second - root(x).second;
		return true;
	}
	std::vector<P> par_;
};
/* --------------------------------------- */

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll r, c;
	cin >> r >> c;
	ll n;
	cin >> n;
	vector<vector<P>> v(r);
	union_find uf(c);
	REP(i,n) {
		ll rr, cc, aa;
		cin >> rr >> cc >> aa;
		rr--; cc--;
		v[rr].pb(P(cc, aa));
	}
	REP(i,r) sort(ALL(v[i]));
	REP(i,r) {
		FOR(j,1,v[i].size()) {
			if(uf.same(v[i][j].first, v[i][j - 1].first)) {
				ll tmp = 0;
				uf.compare(v[i][j].first, v[i][j - 1].first, tmp);
				if(tmp != v[i][j].second - v[i][j - 1].second) {
					cout << "No" << endl;
					return 0;
				}
			} else {
				uf.unite(v[i][j].first, v[i][j - 1].first, v[i][j].second - v[i][j - 1].second);
			}
		}
	}
	vector<ll> maxi(c, -INF * INF);
	REP(i,c) maxi[(uf.root(i)).first] = max(maxi[(uf.root(i)).first], (uf.root(i)).second);
	REP(i,r) REP(j,v[i].size()) {
		if(v[i][j].second + (uf.root(v[i][j].first)).second - maxi[uf.root(v[i][j].first).first] < 0) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

/* --------------------------------------- */



Measured memory_bytes: 8064
def str_to_int(lista):
    for num, i in enumerate(lista):
        lista[num]=int(i)
        
def main():
    list_NK = input().split()
    str_to_int(list_NK)
    list_N = []
    list_K=[]
    for i in range(list_NK[1]):
        list_K.append(input())
        temp = input().split()
        str_to_int(temp)
        for j in temp:
            if j not in list_N:
                list_N.append(j)
    print(list_NK[0]-len(list_N))

main()

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


int main()
{
    int i, j;
    char p[101] = {'\0'}, s[101] = {'\0'};
    scanf("%s", p);
    scanf("%s", s);

    int lengthp = strlen(p);
    int lengths = strlen(s);
    for (i = 0; i < lengthp; i++)
    {
        for (j = 0; j < lengths && s[j] == p[(i + j) % lengthp]; j++);
        if (j == lengths)
        {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}

int main1()
{
    char p[101] = {'\0'}, s[101] = {'\0'};
    scanf("%s", p);
    scanf("%s", s);

    int length = strlen(s);

    int i = 0, flag = 1;
    while (p[i] != '\0' && flag ==1)
    {
        if (p[i] == s[0])
        {
            char *pt = &p[i + 1];
            //char *st = &s[1];
            if ('\0' == *pt)
            {
                pt = p;

            }
            int j;
            for (j = 1; j < length; )
            {
                if (s[j] == *pt)
                {
                    j++;
                    pt++;
                    if (*pt == '\0')
                    {
                        pt = p;
                        flag = 0;
                    }
                }
                else
                {
                    break;
                }
            }
            if (length == j)
            {
                printf("%s\n", "Yes");
                return 0;
            }
        } // if (p[i] == s[0])
        i++;
    }
    printf("%s\n", "No");
    return 0;
}

int main2(int argc, char *argv[])
{
    char p[101] = {'\0'}, s[101] = {'\0'};
    // char p[101], s[101];
    scanf("%s", p);
    scanf("%s", s);


    char *pt = p;
    int flag = 1;

    while (*pt != '\0' && flag == 1)
    {
        if (*pt == *s)
        {
            pt++;
            char *st = s;
            st++;
            if ('\0' == *st)
            {
                printf("%s\n", "Yes");
                return 0;
            }
            while (*pt++ == *st++)
            {
                if ('\0' == *pt)
                {
                    pt = p;
                    flag = 0;
                }
                if ('\0' == *st)
                {
                    printf("%s\n", "Yes");
                    return 0;
                }
            }
        } // if (*pt == *st)
        pt++;
    }

    return 0;
}



Measured memory_bytes: 3156
// Problem : D - Keep Distances
// Contest : AtCoder - ACL Contest 1
// URL : https://atcoder.jp/contests/acl1/tasks/acl1_d
// Memory Limit : 1024 MB
// Time Limit : 3000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#pragma GCC optimize("Ofast,-funroll-loops")
#include <bits/stdc++.h>
using namespace std;

constexpr int Maxn = 2e5 + 5;
constexpr int LOG = 20;

int n, K, q;
int a[Maxn];
int pre[Maxn][LOG];
int suf[Maxn][LOG];
int64_t pre_sum[Maxn][LOG];
int64_t suf_sum[Maxn][LOG];

int main() {

  scanf("%d %d", &n, &K);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
  }
  for (int i = 1; i <= n; ++i) {
    pre[i][0] = upper_bound(a + 1, a + n + 1, a[i] - K) - a - 1;
    suf[i][0] = lower_bound(a + 1, a + n + 1, a[i] + K) - a;
    pre_sum[i][0] = (pre[i][0] >= 1 ? pre[i][0] : 0);
    suf_sum[i][0] = (suf[i][0] <= n ? suf[i][0] : 0);
  }
  for (int j = 1; j < LOG; ++j) {
    for (int i = 1; i <= n; ++i) {
      pre_sum[i][j] = pre_sum[i][j - 1];
      suf_sum[i][j] = suf_sum[i][j - 1];
      if (pre[i][j - 1] >= 1) {
        pre[i][j] = pre[pre[i][j - 1]][j - 1];
        pre_sum[i][j] += pre_sum[pre[i][j - 1]][j - 1];
      }
      else {
        pre[i][j] = 0;
      }
      if (suf[i][j - 1] <= n) {
        suf[i][j] = suf[suf[i][j - 1]][j - 1];
        suf_sum[i][j] += suf_sum[suf[i][j - 1]][j - 1];
      }
      else {
        suf[i][j] = n + 1;
      }
    }
  }
  
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d %d", &l, &r);
    int64_t left_sum = 0;
    int64_t right_sum = 0;
    int len = 1;
    {
      int lg = LOG - 1, pos = r;
      while (lg >= 0) {
        if (pre[pos][lg] >= l) {
          left_sum += pre_sum[pos][lg];
          pos = pre[pos][lg];
          len += (1 << lg);
        }
        --lg;
      }
    }
    {
      int lg = LOG - 1, pos = l;
      while (lg >= 0) {
        if (suf[pos][lg] <= r) {
          right_sum += suf_sum[pos][lg];
          pos = suf[pos][lg];
        }
        --lg;
      }
    }
    printf("%lld\n", left_sum - right_sum + len + r - l);
  }
  
  return 0;
  
}


Measured memory_bytes: 98308
#include <stdio.h>

struct TOPPING{
	int ene;
	int f;
};
typedef struct TOPPING topping;

void sort01(topping data[],int n);
int maxindex00(topping data[], int from, int to);

int main()
{
	int n;		//トッピングの種類
	int A;		//生地の値段
	int B;		//トッピングの値段
	int C;		//生地のカロリー
	topping D[100];	//トッピングのカロリー。
	int i;		//インデックス用
	int nedan=0;
	int kosuu=0;
	int ene=0;
	scanf("%d", &n);
	scanf("%d %d", &A, &B);
	scanf("%d", &C);
	for(i=0; i<n; i++){
		scanf("%d", &D[i].ene);
		D[i].f=C+D[i].ene;
	}
	sort01(D, n);
	nedan+=A;
	ene+=C;
	for(i=0; i<n; i++){
		if(ene/nedan<=(ene+D[i].ene)/(nedan+B)){
			ene+=D[i].ene;
			nedan+=B;
		}
		else{
			break;
		}
	}
	printf("%d\n", ene/nedan);
	return 0;
}

void sort01(topping data[],int n)
{
	int i,maxindex;
	topping work;
	for(i=0;i<n;i++){
		maxindex=maxindex00(data,i,n);
		work=data[i];
		data[i]=data[maxindex];
		data[maxindex]=work;
	}
	return;
}

int maxindex00(topping data[], int from, int to)
{
	int i;
	int result=from;
	for(i=from;i<to;i++){
		if(data[result].f<data[i].f){
			result=i;
		}
	}
	return result;
}

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

int main(){
  int n, a, b;
  cin >> n >> a >> b;
  int ans = 0;
  for(int i = 1; i <= n; i++){
    int sum = 0;
    int x = i;
    for(int j = 0; j < 5; j++){
      sum += x % 10;
      x /= 10;
    }
    if(a <= sum && sum <= b){
      ans += i;
    }
  }
  cout << ans << endl;
  return 0;
}

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

ll g1(ll n, int p){
    //n!
    if(n==0) return 0;
    return n/p + g1(n/p, p);
}

ll g2(ll n, int p){
    //n!!
    if(n%2==1){
        return g1(n,p) - g2(n-1,p); 
    }
    ll res = g1(n/2, p);
    if(p==2) res += n/2;
    return res;
}

int main(){
    ll n; cin >> n;
    ll ans = min(g2(n,2),g2(n,5));
    cout << ans << endl;
    return 0;
}

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

#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

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

bool chkmax(int &x,int y){return x<y?x=y,true:false;}
bool chkmin(int &x,int y){return x>y?x=y,true:false;}

int readint(){
	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;
}

int n,m,cys;
ll d[3005][3005],fac[3005],inv[3005],pw1[3005],pw2[3005],cm[3005];

ll mod(ll x){return x>=cys?x-cys:x;}
ll C(ll x,ll y){return x<y?0:fac[x]*inv[y]%cys*inv[x-y]%cys;}

ll qpow(ll x,ll p,ll Mod){
	ll ret=1;
	for(;p;p>>=1,x=x*x%Mod) if(p&1) ret=ret*x%Mod;
	return ret;
}

int main(){
	n=readint(); cys=readint();
	fac[0]=inv[0]=pw1[0]=pw2[0]=1;
	for(int i=1;i<=n;i++) fac[i]=fac[i-1]*i%cys;
	for(int i=1;i<=n;i++) pw1[i]=pw1[i-1]*2%(cys-1);
	for(int i=1;i<=n;i++) pw2[i]=pw2[i-1]*2%cys;
	inv[n]=qpow(fac[n],cys-2,cys);
	for(int i=n-1;i>=1;i--) inv[i]=inv[i+1]*(i+1)%cys;
	d[0][0]=1;
	for(int i=0;i<=n;i++) cm[i]=C(n,i);
	for(int i=1;i<=n+1;i++) for(int j=1;j<=i;j++) d[i][j]=mod(d[i-1][j]*j%cys+d[i-1][j-1]);
	ll ans=0;
	for(int i=0;i<=n;i++){
		ll pt1=qpow(2,pw1[n-i],cys),pt2=1;
		for(int j=0;j<=i;j++){
			ll tmp=pt1*d[i+1][j+1]%cys*cm[i]%cys*pt2%cys;
			if(i&1) ans=mod(ans+cys-tmp);
			else ans=mod(ans+tmp);
			pt2=pt2*pw2[n-i]%cys;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 69248
/**
 * @brief ユーザ定義リテラル
 * @author えびちゃん
 */

#ifndef H_int_literals
#define H_int_literals
#include <cstddef>
#include <cstdint>

constexpr intmax_t  operator ""_jd(unsigned long long n) { return n; }
constexpr uintmax_t operator ""_ju(unsigned long long n) { return n; }
constexpr size_t    operator ""_zu(unsigned long long n) { return n; }
constexpr ptrdiff_t operator ""_td(unsigned long long n) { return n; }

#endif  /* !defined(H_int_literals) */

#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <numeric>

int main() {
  size_t n, k;
  scanf("%zu %zu", &n, &k);

  std::vector<int> h(n);
  for (auto& hi: h) scanf("%d", &hi);

  std::sort(h.begin(), h.end());
  for (size_t i = 0; i < k; ++i) {
    if (h.empty()) break;
    h.pop_back();
  }

  intmax_t res = std::accumulate(h.rbegin(), h.rend(), 0_jd);
  printf("%jd\n", res);
}


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

int main (){
  int x , y;
  
  cin >> x;
  
  if (x / 10 % 111 == 0 || x % 1000 % 111 == 0){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

int main(){
    long long A, B, C, D;
    cin >> A >> B >> C >> D;
    
    //Cの倍数
    long long CN = B/C - (A-1)/C;
    //Dの倍数
    long long DN = B/D - (A-1)/D;

    long long c = C;
    long long d = D;
    long long r;
    //C*Dの最小公倍数の数
    if (c < d){
        long long r = d % c;
        while(r != 0){
            d = c;
            c = r;
            r = d % c;
        }
    }
    else if (d < c) {
        long long tmp;
        tmp = d;
        d = c;
        c = tmp;
        while(r != 0){
            d = c;
            c = r;
            r = d % c;
    }
    }
    else {
        c = C;
    }
    long long E = C*D / c;
    long long CDN = B/E - (A-1)/E;

    long long ans = (B - A + 1) - CN - DN + CDN;
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.stream.Stream;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			int N = Integer.parseInt(reader.readLine());
			String[] s = reader.readLine().split(" ");
			int[] A = Stream.of(s).mapToInt(Integer::parseInt).toArray();

			String ans = "YES";
			Arrays.sort(A);
			for(int i=1; i<N; i++) {
				if(A[i] == A[i-1])
					ans = "NO";
			}

			System.out.println(ans);
		}catch(IOException e) {

		}
	}

}


Measured memory_bytes: 62732
import java.util.*;
/*
NOTES:
-more than 10 digits (10^10), use long
-prefix sum of 1's and -1's to control flow of highlighting a region
-log(a)/log(b) = log base b of a
-create a position array if trying to see if elements show up next to each other sequentially
 i.e. elements 1,2,3 are within 3 spots of each other in an array
      arr[scannedInt - 1] = i; (position of i at p[i] in original)
- use a freq array when counting instances of an element occurring
- increment the counter first before simulating anything turn-based (two player game)

 */

public class Main {
    static long mod = (long)(Math.pow(10, 9) + 7);
    public static String alpha = "zabcdefghijklmnopqrstuvwxy";
    public static void main(String[] args) {
        Scanner scan =new Scanner(System.in);
        int n = scan.nextInt();
        int k = scan.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i<n; i++){
            arr[i] = scan.nextInt();
        }
        Arrays.sort(arr);
        long sum = 0;
        for(int i= 0; i<k; i++) sum += arr[i];
        System.out.println(sum);


        scan.close();
    }





    static int GCD(int a, int b) {
        // Everything divides 0
        if (a == 0) return b;
        if (b == 0) return a;

        // base case
        if (a == b) return a;

        // a is greater
        if (a > b) return GCD(a-b, b);
        return GCD(a, b-a);
    }
    static int LCM(int a, int b){
        return (a*b)/(GCD(a,b));
    }
    static String rev(String s){
        char[] arr = s.toCharArray();
        for(int i = 0; i<(s.length()+1)/2; i++){
            char temp = arr[i];
            arr[i] = arr[s.length()-i-1];
            arr[s.length()-i-1] = temp;
        }
        String fin = new String(arr);
        return fin;
    }
    static long pow(long a, long N) {
        if (N == 0) return 1;
        else if (N == 1) return a;
        else {
            long R = pow(a,N/2);
            if (N % 2 == 0) {
                return R*R;
            }
            else {
                return R*R*a;
            }
        }
    }

    static long powMod(long a, long N) {
        if (N == 0) return 1;
        else if (N == 1) return a % mod;
        else {
            long R = powMod(a,N/2) % mod;
            R *= R;
            R %= mod;
            if (N % 2 == 1) {
                R *= a;
                R %= mod;
            }
            return R % mod;
        }
    }

}

Measured memory_bytes: 38992
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
#define INF 1e12
#define MOD 1e9+7
typedef long long ll;
using namespace std;

ll dp[305][305];
ll dp2[305][305];

int main()
{
	fill(dp[0], dp[304], INF);
	fill(dp2[0], dp2[304], INF);
	int n, m, l;
	cin >> n >> m >> l;
	rep1(i, n)dp[i][i] = 0;
	rep(i, m)
	{
		int a, b, c;
		cin >> a >> b >> c;
		dp[a][b] = c;
		dp[b][a] = c;
	}
	int q;
	cin >> q;
	vector<int> s(q), t(q);
	rep(i, q)cin >> s[i] >> t[i];
	//WF
	rep1(k, n)
	{
		rep1(i, n)
		{
			rep1(j, n)
			{
				if (dp[i][k] + dp[k][j] < dp[i][j])
					dp[i][j] = dp[i][k] + dp[k][j];
			}
		}
	}
	//fuel
	rep1(i, n)
	{
		rep1(j, n)
		{
			if (dp[i][j] <= l)
			{
				dp2[i][j] = 1;
			}
		}
	}
	//WF
	rep1(k, n)
	{
		rep1(i, n)
		{
			rep1(j, n)
			{
				if (dp2[i][k] + dp2[k][j] < dp2[i][j])
					dp2[i][j] = dp2[i][k] + dp2[k][j];
			}
		}
	}
	//query
	rep(i, q)
	{
		int ans;
		if (dp2[s[i]][t[i]] == INF)
		{
			ans = -1;
		}
		else
		{
			ans = dp2[s[i]][t[i]] - 1;
		}
		co(ans);
	}
	return 0;
}


Measured memory_bytes: 2688
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
#R = 10**9 + 7
R = 998244353

def ddprint(x):
  if DBG:
    print(x)

def modinv2(x,r):
  return pow(x,r-2,r)

def perm(n,a,R):
    return (fact[n]*modinv2(fact[n-a],R))

def comb(n,a,R):
    return (fact[n]*modinv2(fact[n-a]*fact[a],R))

def factinit(n,R):
    global fact
    fact = [1]*(n+1)
    for i in range(2,n+1):
        fact[i] = (fact[i-1]*i)%R

n,m,k = inm()
if n==m+1==k+2==-3:
    3/0
    print(0)
    exit()
if m==1:
    print(1 if k==n-1 else 0)
    exit()
factinit(n,R)
s = 0
x = (m*pow(m-1,n-1,R))%R
m1i = modinv2(m-1,R)
for j in range(k+1):
    s = (s + x*comb(n-1,j,R))%R
    x = (x*m1i)%R
    #ddprint(f"{j=} {s=} {x=}")
print(s)


Measured memory_bytes: 77500