akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

struct edge_t {
  int from;
  int to;
};

using namespace std;

static int n, m;
static std::vector<edge_t> es{};
static std::vector<std::vector<int>> sources{};
static std::vector<std::vector<int>> dests{};
static std::forward_list<int> topologicals{};
static std::vector<bool> visited{};

void visit(int from) {
  if (visited[from]) {
    return;
  }
  visited[from] = true;
  for (auto const fromIdx : sources[from]) {
    auto& e = es[fromIdx];
    visit(e.to);
  }
  topologicals.push_front(from);
}

std::vector<int> solve(int root) {
  visit(root);
  std::vector<int> topologicalOrders(n);
  int i = 0;
  for (auto const idx : topologicals) {
    topologicalOrders[idx] = i++;
  }

  std::vector<int> ret(n);
  for (int i = 0; i < n; ++i) {
    int from = -1;
    int topologicalOrder = -1;
    for (auto const toIdx : dests[i]) {
      auto& e = es[toIdx];
      if (topologicalOrders[e.from] <= topologicalOrder) {
        continue;
      }
      topologicalOrder = topologicalOrders[e.from];
      from = e.from;
    }
    ret[i] = from + 1;
  }
  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  std::cin >> n >> m;
  es.resize(n - 1 + m);
  dests.resize(n, std::vector<int>(0));
  sources.resize(n, std::vector<int>(0));
  visited.resize(n, false);
  std::vector<bool> rootish(n, true);
  for (int i = 0; i < n - 1 + m; ++i) {
    auto& e = es[i];
    std::cin >> e.from;
    std::cin >> e.to;
    e.from--;
    e.to--;
    sources[e.from].push_back(i);
    dests[e.to].push_back(i);
    rootish[e.to] = false;
  }
  int root;
  for (root = 0; root < n; ++root) {
    if (rootish[root]) {
      break;
    }
  }
  auto ret = solve(root);
  for (auto node : ret) {
    std::cout << node << std::endl;
  }
  return 0;
}


Measured memory_bytes: 19192
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<iostream>
#include<algorithm>
#define N 200001
#define LL long long
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;	
}
using namespace std;
int n,a[N];
bool check(int m)/// ? <= x
{
	int x=N,y=N;
	for(int i=1;i<n+n-1;++i)
		if(a[i]<=m && a[i+1]<=m)
			x=min(x,min(abs(n-i),abs(n-i-1)));
		else if(a[i]>m && a[i+1]>m)
			y=min(y,min(abs(n-i),abs(n-i-1)));
	return x<y || (x==y && a[1]<=m);
}
int main()
{
	re(n);
	for(int i=1;i<n+n;++i)re(a[i]);
	int l=1,r=n+n-1;
	while(l < r)
	{
		int m=l+r>>1;
		if(check(m))r=m;
		else l=m+1;
	}
	printf("%d\n",l);
}

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

int main(){
  constexpr char a_sent= 'z'+ 1;
  constexpr int Nalp= 26;
  string S;
  int K0;
  cin >> S >> K0;

  string ans= S;
  int remK= K0;
  for(size_t i=0; i<S.size(); i++){
    if(S.at(i) != 'a' && remK >= a_sent- S.at(i)){
      remK-= a_sent- S.at(i);
      ans.at(i)= 'a';
    }

    if(remK==0){ break; }
  }
  if(remK > 0){// 操作回数が余ったら末尾を変える
    ans.back()+= remK % Nalp;
  }

  assert(islower(ans.back()));
  cout << ans << endl;
}

Measured memory_bytes: 3844
import java.io.*; 
import java.util.*; 
 
public class Main
{ 
    public static void main(String args[]) 
    { 
      
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int k = sc.nextInt();
		
		int sum;
	
		if(x == 0 && k == 0){
			
			System.out.print(x);
			
		} else {
		
		for(int i = 1; i < 1000; i++){
			
			sum = 0;
			sum = k - x + i; 
			System.out.print(sum + " ");
			if(sum == k+x-1){
				
				break;
				
				}
			
			}	
		
		}
    } 
} 

Measured memory_bytes: 21588
fun main(args : Array<String>) {
    while (true) {
        val (h, w) = readLine()!!.split(" ").map(String::toInt)
        if (w == 0 && h == 0) {break}

        for (i in 1..h) {
            for (k in 1..w) {
                if ((i + k) % 2 == 0) {
                    print("#")
                } else {
                    print(".")
                }
            }
            println()
        }
        println()
    }
}



Measured memory_bytes: 41260
#include<stdio.h>
#include<math.h>
int primality(int x);
int main(void){
    int n,i,cnt=0;
    int x;
    scanf("%d", &n);
    for(i=0;i<n;i++){
        scanf("%d", &x);
        if(primality(x)){
            cnt++;
        }
    }
    printf("%d\n",cnt);

    return 0;
}

int primality(int x){
    int i;
    if(x == 2){
        return 1;
    }
    if(x < 2 || x % 2 == 0){
        return 0;
    }
    i = 3;
    while(i <= sqrt(x)){
        if(x % i == 0){
            return 0;
        }
        i = i + 2;
    }

    return 1;
}


Measured memory_bytes: 2040
#include<algorithm>
#include<stack>
#include<ctime>
#include<cstring>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<queue>
using namespace std;
typedef int _int;
#define int long long
#define dl double 
const int maxn=200005;
const int BIG=1e9;
struct point{
	int two,five;
}p[maxn];
bool cmp(point a,point b){
	return a.two<b.two;
}
const int maxp=105;
const int Move=15;
int tr[maxp];
int n,MAX;
int lowbit(int x){return x&(-x);}
void ins(int x,int d){
	for(int i=x;i<=MAX;i+=lowbit(i))
		tr[i]+=d;
}
int query(int x){
	int ans=0;
	for(int i=x;i>0;i-=lowbit(i))ans+=tr[i];
	return ans;
}
_int main(){
	scanf("%lld",&n);MAX=1;
	for(int i=1,x;i<=n;++i){
		dl d;
		scanf("%lf",&d);x=d*BIG+0.5;
		p[i].two=p[i].five=-9;
		while(!(x%2)){x/=2;++p[i].two;}
		while(!(x%5)){x/=5;++p[i].five;}
		//cout<<p[i].two<<' '<<p[i].five<<endl;
		MAX=max(MAX,p[i].five+Move);
	}
	sort(p+1,p+n+1,cmp);
	int ans=0,R=n,tot=0;
	//puts("------------------------");
	for(int i=1;i<=n;++i){
		//cout<<p[i].two<<' '<<p[i].five<<':'<<endl;
		while(R&&p[R].two+p[i].two>=0){ins(p[R].five+Move,1);--R;++tot;}
		//cout<<-p[i].five-1<<endl;
		if(R<i){
			ins(p[i].five+Move,-1);--tot;
			ans+=tot-query(Move-p[i].five-1);
			/*puts(":");
			cout<<query(Move-p[i].five-1)<<endl;
			cout<<tot-query(Move-p[i].five-1)<<endl;*/
			ins(p[i].five+Move,1);++tot;
		}else {
			ans+=tot-query(Move-p[i].five-1);
			/*puts(":");
			cout<<query(Move-p[i].five-1)<<endl;
			cout<<tot-query(Move-p[i].five-1)<<endl;*/
		}
	}
	printf("%lld\n",ans/2);
	return 0;
}


Measured memory_bytes: 6724
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

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

    vector<int> pow2(21);
    pow2[0] = 1;
    for(int i=1;i<=20;i++){
        pow2[i] = pow2[i - 1] * 2;
    }

    int N = 20;
    vector<tuple<int, int, int>> edges;
    for(int i=2;i<N;i++){
        edges.emplace_back(i, i + 1, 0);
        edges.emplace_back(i, i + 1, pow2[19 - i]);
    }

    int used = 0;
    for(int i=20;i>=2;i--){
        if((L >> (20 - i))&1){
            edges.emplace_back(1, i, used);
            used += pow2[20 - i];
        }
    }
    assert((L - used) % pow2[18] == 0);
    while(L - used > 0){
        edges.emplace_back(1, 2, used);
        used += pow2[18];
    }

    cout << N << " " << edges.size() << endl;
    for(auto& t : edges){
        cout << get<0>(t) << " " << get<1>(t) << " " << get<2>(t) << endl;
    }


    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG //エラーを出すためのおまじない
#include <bits/stdc++.h>
#include <algorithm>
//#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
#include <math.h>
using namespace std;
#define coYES cout << "YES" << endl
#define coNO cout << "NO" << endl
#define coYes cout << "Yes" << endl
#define coNo cout << "No" << endl
#define coyes cout << "yes" << endl
#define cono cout << "no" << endl
//#define cocount cout << count << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define Cinint(n) int n;\
cin >> n;
#define Cinvecint(a, n) vector<int> a(n);\
for (int i = 0; i < (int)(n); i++) {\
  int num;\
  cin >> num;\
  a.at(i) = num;\
}
#define Cinstring(s) string s;\
cin >>s;

  

int main() {
  string s;
  cin >> s;
  if (s.at(1) == s.at(2)) {
    if (s.at(1) == s.at(0)) {
      coYes;
    }
    else if (s.at(2) == s.at(3)) {
      coYes;
    }
    else {
      coNo;
    }
  }
  else {
    coNo;
  }
}                       


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

using namespace std;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define all(x) begin(x),end(x)

#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair <T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

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

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

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

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld EPS = 1e-9;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    vi ns;

    for (;;) {
        string s; getline(cin,s);
        if (s == ".") break;

        bool valid = 1;
        stack<char> stk;
        for (char c : s) {
            if (c == '(' or c == '[') stk.push(c);
            else if (c == ')') {
                if (stk.empty() or stk.top() != '(') {
                    valid = false;
                    break;
                }
                stk.pop();
            }
            else if (c == ']') {
                if (stk.empty() or stk.top() != '[') {
                    valid = false;
                    break;
                }
                stk.pop();
            }
        }

        cout << (valid and stk.size() == 0 ? "yes" : "no") << endl;
    }

    return 0;
}



Measured memory_bytes: 3160
N, M = map(int, input().split(" "))
drinks = []
for i in range(N) :
    drinks.append(list(map(int, input().split(" "))))
    
drinks_s = sorted(drinks, key=lambda x: x[0])

cur = 0
cost = 0
for i in drinks_s :
    if cur + i[1] <= M :
        cur += i[1]
        cost += i[0] * i[1]
    else :
        cost += (M - cur) * i[0]
        break
        
print(cost)
        

Measured memory_bytes: 29788
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

bool comp(const PII &l , const PII &r){
  if( l.first * r.second == r.first * l.second) return r.second > l.second;
  return (double) l.first/(double) l.second > (double) r.first / (double) r.second;
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int H;cin >> H;
  int N;cin >> N;
  vector<PII> v(N);
  rep(i,N)cin >> v[i].first >> v[i].second;
  vector<vector<int> > dp(2,vector<int> (H+1,1e9));
  vector<int>& pre = dp[0];
  vector<int>& nxt = dp[1];
  pre[0] = 0;
  rep(i,N){
    rep(j,H+1) nxt[j] = pre[j];
    rep(j,H+1){
      nxt[min(H,j+v[i].first)] = min(nxt[min(H,j+v[i].first)], nxt[j] + v[i].second);
    }
    swap(pre,nxt);
  }
  swap(pre,nxt);
  cout << nxt[H] << endl;
  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main(){
	int n;
	int siro=0,kuro=0,ans,i;
	char s[200002]="";
	if(scanf("%d ",&n)!=1)return 1;
	if(scanf("%s",s)!=1)return 1;
	for(i=0;i<n;i++){
		if(s[i]=='.'){
			siro++;
		}
	}
	ans=n;
	for(i=0;i<n;i++){
		if(s[i]=='.'){
			siro--;
		}
		
		if(kuro+siro<ans)ans=kuro+siro;
		if(s[i]=='#'){
			kuro++;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {

    static final int MOD=1000000007;


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double a = sc.nextInt();
        double b = sc.nextInt();
        for(int i=1;i<=10000;i++){
            double eight = i*0.08;
            double ten = i*0.1;
            eight=Math.floor(eight);
            ten = Math.floor(ten);
            if(eight==a&&ten==b) {
                System.out.println(i);
                return;
            }
        }
        System.out.println(-1);


    }
}




Measured memory_bytes: 23380
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define inf 10000000000000007
#define vsort(vec) sort(vec.begin(),vec.end())
#define vreverse(vec) reverse(vec.begin(),vec.end())
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int n, q;
int l, r;
string s;
char t[200010], d[200010];

signed main() {
	cin >> n >> q >> s;
	rep(i, q)cin >> t[i] >> d[i];
	for (int i = q - 1; i >= 0; i--) {
		if (t[i] == s[l] && d[i] == 'L') {
			l++;
		}
		if (l) {
			if (t[i] == s[l - 1] && d[i] == 'R') {
				l--;
			}
		}
		if (t[i] == s[n - r - 1] && d[i] == 'R') {
			r++;
		}
		if (r) {
			if (t[i] == s[n - r] && d[i] == 'L') {
				r--;
			}
		}
	}
	cout << n - (l + r) << endl;
	ggr
}

Measured memory_bytes: 1028
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int a = stdIn.nextInt();
		int b = stdIn.nextInt();
		int c = stdIn.nextInt();
		int d = stdIn.nextInt();
		
		int e = a * b;
		int f = c * d;
		
		if (e <= f) {
			System.out.println(f);
		} else {
			System.out.println(e);
		}
	}
}

Measured memory_bytes: 21844
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bitset>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef long long LL;

typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
//vector <vector<int>> x(20, vector<int> (20)), y(20,vector<int> (20));
/*int counter_1 (int x) {
    if(x == 0) return 0;
    return counter_1(x >> 1) + (x & 1);
}*/

//int Counter(int x)
int main(){
   int k,x;
   cin >> k >> x;
   if(k*500>=x) cout << "Yes" << endl;
   else cout << "No" << endl; 
}

    



Measured memory_bytes: 256
#pragma comment(linker,"/stack:16777216")
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<functional>
#include<utility>
#include<algorithm>
#include<sstream>
#include<cstring>
#include<cmath>
#include<cctype>
#include<exception>
#include<climits>
#include<cfloat>
#include<iomanip>
#include<bitset>
#include<streambuf>
#include<cstdlib>
#include<ctime>
//#include"functions.h"
//#include"highprecision.h"
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define np next_permutation
#define fi first
#define sc second
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> >
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pff pair<float,float>
#define pdd pair<double,double>
#define psi pair<string,int>
#define pis pair<int,string>
#define ppi pair<pii,int>
#define pdi pair<pii,pii>
#define LN 84757
#define INF 1e9
#define LLINF 1e18
#define MAXINT 0x7fffffff
#define MAXLL 0x7fffffffffffffff
#define EPS 1e-5
#define DEPS 1e-9
#define LDEPS 1e-13
#define MOD 1000000007
#define E 2.7182818284
#define PI 3.1415926535
#define rep(a,b) for(int a=0;a<b;a++)
#define rep(a,b) for(int a=0;a<b;a++)
#define forn(a,n) for(int a=1;a<=n;a++)
#define forr(a,n) for(int a=n;a>=1;a--)
#define repn(a,n,p) for(int a=0;a<n;a+=p)
#define repr(a,n) for(int a=n-1;a>=0;a--)
#define foreach(a,b) for(__typeof(b.begin())a=b.begin();a!=b.end();a++)
#define fillemp(a) memset(a,0,sizeof(a))
#define fillinf(a) memset(a,0x3f,sizeof(a))
#define frestream freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define stdf(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
#define inputf(a) freopen(a,"r",stdin);
#define outputf(a) freopen(a,"w",stdout);
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
using namespace std;

int a[100]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main(int argc,char** argv){
	int n;
	cin>>n;n--;
	cout<<a[n];
	return 0;
}


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

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+1; i++) cout << "D";
  for(int i = 0; i < tx-sx+1; i++) cout << "R";
  for(int i = 0; i < ty-sy+1; i++) cout << "U";
  cout << "L" << "U";
  for(int i = 0; i < tx-sx+1; i++) cout << "L";
  for(int i = 0; i < ty-sy+1; i++) cout << "D";
  cout << "R" << endl;
}


Measured memory_bytes: 256
#include <climits>
#include <cmath>
#include <algorithm>
#include <array>
#include <iostream>
#include <vector>
using namespace std;
int main(int, char**)
{
	int N, D;
	cin >> N >> D;
	vector<vector<int>> ps(N, vector<int>(D));
	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < D; ++j)
		{
			cin >> ps[i][j];
		}
	}
	int count = 0;
	for (int i = 0; i < N; ++i)
	{
		for (int j = i + 1; j < N; ++j)
		{
			double d = 0;
			for (int k = 0; k < D; ++k)
			{
				d += pow(ps[i][k] - ps[j][k], 2);
			}
			d = sqrt(d);
			if (static_cast<int>(d) == d)
			{
				++count;
			}
		}
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
#include<set>
#include<map>
#include<list>
#include<queue>
#include<cmath>
#include<vector>
#include<cstdio>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define qread(x) x=read()
#define mes(x,y) memset(x,y,sizeof(x))
#define mpy(x,y) memcpy(x,y,sizeof(x))
#define INF 2147483647
inline int read(){
	int f=1,x=0;char ch;
	while(!(ch>='0'&&ch<='9')){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
int n,x,a[100010],ans;
int gcd(int a,int b){
	if(a==0)return b;
	else return gcd(b%a,a);
}
bool bk;
int main(){ 
    qread(n),qread(x);
    bk=false;
    for(int i=1;i<=n;i++){
		qread(a[i]);
	}
	a[++n]=x;
	std::sort(a+1,a+n+1);
	ans=a[2]-a[1];
	for(int i=3;i<=n;i++){
		ans=gcd(ans,a[i]-a[i-1]);
	} 
    printf("%d\n",ans);
}

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

public class Seito
{
    public int kisu { get; set; }
    public int gusu { get; set; }
    public bool play { get; set; }
}
public class hello
{
    public static void Main()
    {
        var d = new Dictionary<int, Seito>();
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        DictSet(d, n);
        string[] line2 = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line2, int.Parse);
        PlayGame(d, a);
        string[] line3 = Console.ReadLine().Trim().Split(' ');
        var b = Array.ConvertAll(line3, int.Parse);
        foreach (var x in b)
            if (d[x].play) Console.WriteLine(1);
            else Console.WriteLine(0);
    }
    public static void PlayGame(Dictionary<int, Seito> d, int[] a)
    {
        var ze = 0;
        for (int i = 0; i < a.Length; i++)
        {
            if (a[i] % 2 == 0) ze = GetGusu(d, a[i], ze);
            else ze = GetKisu(d, a[i], ze);
            d[ze].play = false;
            var z1 = d[ze].gusu;
            var z2 = d[ze].kisu;
            d[z1].kisu = z2;
            d[z2].gusu = z1;
            ze = GetGusu(d, 1, ze);
        }
    }
    public static int GetGusu(Dictionary<int, Seito> d, int a, int ze)
    {
        var count = 0;
        while (true)
        {
            ze = d[ze].gusu;
             count++;
            if (count == a) return ze;
        }
    }
    public static int GetKisu(Dictionary<int, Seito> d, int a, int ze)
    {
        var count = 0;
        while (true)
        {
            ze = d[ze].kisu;
             count++;
            if (count == a) return ze;
        }
    }
    public static void DictSet(Dictionary<int, Seito> d, int n)
    {
        foreach (var x in Enumerable.Range(0, n))
        {
            int kisu; int gusu;
            if (x == n - 1) gusu = 0;
            else gusu = x + 1;
            if (x == 0) kisu = n - 1;
            else kisu = x - 1;
            d[x] = new Seito { kisu = kisu, gusu = gusu, play = true };
        }
    }
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N;i++) {
    cin >> A.at(i);
  }
  string a = "APPROVED";
  for (int i = 0; i < N; i++) {
    if(A.at(i) % 2 == 0) {
      if(A.at(i) % 3 != 0 && A.at(i) % 5 != 0) {
        a = "DENIED";
      }
    }
  }
  cout << a << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5,S = 1e6;
int n,a[N],ans;
bool vis[S+5];
int main() {
	ios::sync_with_stdio(0);
	cin >> n;
	for(int i = 1;i <= n;++i)
		cin >> a[i];
	sort(a+1,a+n+1);
	for(int i = 1;i <= n;++i) {
		if(a[i] == a[i-1]) {continue;}
		if(!vis[a[i]] && a[i] != a[i+1]) ++ans;
		for(int j = a[i];j <= S;j += a[i])
			vis[j] = 1;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5400
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;
int x[50100];
int main()
{
	int n,ans;
	int x[5];
	for (int i=1;i<=3;i++)
	{
		scanf("%d",&x[i]);
	}
	int m=1000000;
	if (max(x[2]-x[1],x[1]-x[2])+max(x[2]-x[3],x[3]-x[2])<m) m=max(x[2]-x[1],x[1]-x[2])+max(x[2]-x[3],x[3]-x[2]);
	if (max(x[3]-x[1],x[1]-x[3])+max(x[2]-x[3],x[3]-x[2])<m) m=max(x[3]-x[1],x[1]-x[3])+max(x[2]-x[3],x[3]-x[2]);

	if (max(x[2]-x[1],x[1]-x[2])+max(x[3]-x[1],x[1]-x[3])<m) m=max(x[2]-x[1],x[1]-x[2])+max(x[3]-x[1],x[1]-x[3]);
	if (max(x[3]-x[2],x[2]-x[3])+max(x[1]-x[3],x[3]-x[1])<m) m=max(x[3]-x[2],x[2]-x[3])+max(x[1]-x[3],x[3]-x[1]);
	
    if (max(x[1]-x[3],x[3]-x[1])+max(x[2]-x[1],x[1]-x[2])<m) m=max(x[1]-x[3],x[3]-x[1])+max(x[2]-x[1],x[1]-x[2]);
	if (max(x[3]-x[2],x[2]-x[3])+max(x[2]-x[1],x[1]-x[2])<m) m=max(x[3]-x[2],x[2]-x[3])+max(x[2]-x[1],x[1]-x[2]);
	printf("%d\n",m);

	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int W[110];
  for (int i = 0; i < N; i++) {
    cin >> W[i];
  }
  
  int all = 0;
  for (int i = 0; i < N; i++) {
    all += W[i];
  }
  
  int ans = 100000;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    sum += W[i];
    int sum_other = all - sum;
    ans =min(ans,(max(sum,sum_other) - min(sum,sum_other)));
  }
  cout << ans << endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;

int H,W,h,w;

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);
	
	cin>>H>>W>>h>>w;
	
	if (H%h==0 && W%w==0) {
		cout<<"No\n";
		return 0;
	}

	cout<<"Yes\n";
	rep(i,0,H) rep(j,0,W) {
		if ((i+1)%h==0 && (j+1)%w==0) cout<<-4000*(h*w-1)-1; else cout<<4000;
		cout<<" \n"[j+1==W];
	}
}


Measured memory_bytes: 1664
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.AbstractMap;
import java.util.StringTokenizer;

public class Main {

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

		solve(sc, out);

		out.flush();
	}
	
	public static void solve(FastScanner sc, PrintWriter out) {
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		int res = 0;
		
		for(int i = k; i <= n; i++) {
			res++;
		}
		out.println(res);
	}
	
	public static int gcd(int a, int b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(final K key, final V value) {
        super(key, value);
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

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

    public int nextInt() {
        return Integer.parseInt(next());
    }

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

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

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

#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define lg long long
#define db double
#define lb(x) ((x)&-(x))
#define ft first
#define sd second

#define HII cerr<<"HI"<<endl
#define LLLINE cerr<<"@@@@@@@@@@@@@@@@@@@@"<<endl

template <class _T_>
void read(_T_& d){
	d=0;int f=1;char c=getchar();
	for(;c<'0'||c>'9';c=getchar())if(c=='-')f*=-1;
	for(;c>='0'&&c<='9';c=getchar())d=d*10+c-'0';
	d*=f;
}

/************************************************/
#define Md 1000000007
#define MN 200005
int n,m;
char c[MN];
lg Pow(lg x,lg y){
	lg res=1;for(;y;y>>=1,x=x*x%Md)if(y&1)res=res*x%Md;return res;
}
int Fix(int x){
	if(x<0)return x+Md;
	if(x>=Md)return x-Md;
	return x;
}
int dp[MN],tmp[MN];
int miu[MN];
int main(){
	read(n);read(m);
	scanf("%s",c+1);
	miu[1]=1;
	for(int i=1;i<MN;++i){
		for(int j=i+i;j<MN;j+=i){
			miu[j]-=miu[i];
		}
	}
	char Hd=c[1];
	int cnt=0,mx;
	for(int i=1;i<=m;++i){
		if(c[i]==Hd)++cnt;
		else break;
	}
	if(cnt&1)mx=cnt;else mx=cnt+1;
	if((n&1)&&cnt!=m)return puts("0"),0;
	if(cnt==m){
		int res=0;
		tmp[0]=1;
		dp[0]=1;
		if(n>=2)res=n;
		for(int i=1;i<n-1;++i){
			dp[i]=(i>=2?tmp[i-2]:0);
			tmp[i]=Fix(tmp[i-1]+dp[i]);
			res=Fix(res+1ll*dp[i]*(n-i)%Md);
		}
		printf("%d",res+1);
		return 0;
	}
	int res=(cnt==m);
	cnt=0;
	for(int i=1;i<=m;++i){
		if(c[i]==Hd)++cnt;
		else{
			if(!cnt)continue;
			if(cnt&1)mx=min(mx,cnt);
			cnt=0;
		}
	}
	//for(int i=1;i<=5;++i)cerr<<miu[i]<<' ';cerr<<endl;
	tmp[0]=tmp[1]=1;
	dp[0]=1;
	mx+=2;
	if(n<mx)res+=n;
	for(int i=2;i<=n;i+=2){
		dp[i]=Fix(tmp[i-1]-(mx>i?0:tmp[i-mx]));
		tmp[i]=tmp[i+1]=Fix(tmp[i-1]+dp[i]);
		//cerr<<dp[i]<<' '<<i<<endl;
		if((n-i)%2==0&&n-i<mx)res=Fix(res+1ll*dp[i]*(n-i)%Md);
	}
	cout<<res;
	return 0;
}


Measured memory_bytes: 2816
var
 a:array[1..3] of longint;
 j,i,m:longint;
begin
 read(a[1],a[2],a[3]);
 for i:=1 to 3 do
  for j:=i to 3 do
   begin
    if a[i]>a[j] then begin m:=a[i];a[i]:=a[j]; a[j]:=m; end;
   end;
 write(a[1]+a[2]);
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,k,s; cin >> n >> k >> s;
  if(s!=1000000000){
    for(ll i=0; i<k; i++){
      cout << s << ' ';
    }
    for(ll i=0; i<(n-k); i++){
      cout << 1000000000 << ' ';
    }
    cout << endl;
  }else{
    for(ll i=0; i<k; i++){
      cout << s << ' ';
    }
    for(ll i=0; i<(n-k); i++){
      cout << 3 << ' ';
    }
    cout << endl;
  }
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  int n;
  cin >> n;
  int table[n][n];
  for(int i=0;i<n;i++){
    for(int j=0;j<n-1;j++){
      cin >> table[i][j];
      table[i][j]--;
    }
  }
  int o[n] = {};
  int cnt = 0;
  for(int i=0;i<(n-1)*n/2;i++){
    bool used[n] ={};
    for(int dst=0;dst<n;dst++){
      if(used[dst] || o[dst] == n-1){
        continue;
      }
      int tar = table[dst][o[dst]];
      if(table[tar][o[tar]] == dst && !used[tar]){
        o[dst]++;
        o[tar]++;
        used[dst] = true;
        used[tar] = true;
      }
    } 
    cnt++;

    bool f = true, all = true;
    for(int c=0;c<n;c++){
      if(used[c]) f = false;
      if(o[c] != n-1) all = false; 
    }
    if(all) break;
    if(f) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 4096
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		
		//long startTime = System.currentTimeMillis();
		
		Scanner sc=new Scanner(System.in);
		int a1=sc.nextInt();
		int a2=sc.nextInt();
		int a3=sc.nextInt();
		
		if(a1+a2+a3>=22){
			System.out.println("bust");
		}else{
			System.out.println("win");
		}
		
	}
}


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

const long long oo = 1e16;
long long a[500];
long long s[500];
long long f[500][500];
bool c[500][500];
int n;

void inp()
{
    cin >> n;
    for (int i = 1; i <= n; i ++)
    {
        cin >> a[i];
        s[i] = s[i-1] + a[i];
    }
}


long long tryyy(int l,int r)
{
    if (l == r) return 0;
    if (c[l][r]) return f[l][r];
    long long tmp = oo;
    c[l][r] = true;
    for (int m = l; m < r; m++)
    tmp = min(tmp, tryyy(l,m) + tryyy(m+1,r));
    tmp += s[r]- s[l-1];
    f[l][r] = tmp;
    return tmp;
}



int main()
{
    inp();
    cout << tryyy(1,n);
    return 0;
}


Measured memory_bytes: 2048
#include <stdio.h>

int main(void)
{
	int max=0,a,b,k,n,i,c;
	scanf("%d",&k);
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a);
		if(i==0){
			b=a;
			c=a;
		}
		else{
			if(a-c>max)max=a-c;
			c=a;
		}
	}
	if(k-a+b>max)max=k-a+b;
	printf("%d",k-max);
	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iomanip>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)
#define FOR(i,a,n) for(int i=a; i<n; i++)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;


int main()
{
	int m, f, b;
	cin >> m >> f >> b;

	if (m >= b)cout << 0 << endl;
	else if (b - m <= f)cout << b - m << endl;
	else cout << "NA" << endl;
	return 0;
}

Measured memory_bytes: 3112
#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;

char data[2000];
bool visited[2000];
int W, H;
string maxi;

bool isNum(char c) {
  return c >= '0' && c <= '9';
}

main() {
  while(1) {
    cin >> W >> H;
    if(W == 0 && H == 0) break;
    for(int i = 0; i < H; i++) {
      for(int j = 0; j < W; j++) {
	cin >> data[i*W+j];
      }
    }
    string dp[2000];
    fill_n(dp, W*H, "");
    fill_n(visited, W*H, false);
    maxi = "";
    for(int j = 0; j < W; j++) {
      for(int i = 0; i < H; i++) {
	string up, left;
	if(isNum(data[i*W+j])) {
	  if(i-1 >= 0) up = dp[(i-1)*W+j];
	  else         up = "";
	  if(j-1 >= 0) left = dp[i*W+j-1];
	  else         left = "";
	  if(     up.length() > left.length()) dp[i*W+j] = up;
	  else if(up.length() < left.length()) dp[i*W+j] = left;
	  else dp[i*W+j] = max(up, left);
	  dp[i*W+j] += data[i*W+j];

	  if(dp[i*W+j] == "0") dp[i*W+j] = "";
	} else {
	  dp[i*W+j] = "";
	}
	if(maxi.length() < dp[i*W+j].length()) maxi = dp[i*W+j];
	else if(maxi.length() == dp[i*W+j].length())
                                    maxi = max(maxi, dp[i*W+j]);
      }
    }
    if(maxi == "") maxi = "0";
    cout << maxi << endl;
  }
}

Measured memory_bytes: 1024
"""
now...今注目する値
used...使った数字の数
sum...それまでの合計

dp[now][used][sum]...nowまででused個の数字を使って合計sumの場合の数
dp[now][used][sum] = dp[now - 1][used - 1][sum - now] + dp[now - 1][used][sum] (used >= 1 and sum >= now)
                     dp[now - 1][used][sum]                                    (used == 0  or  sum < now)
"""
dp = [[[0 for _ in range(1001)] for _ in range(10)] for _ in range(101)]
dp[0][1][0] = 1
dp[0][0][0] = 1

for now in range(1, 101):
  for used in range(10):
    for s in range(1001):
      if used >= 1 and s >= now:
        dp[now][used][s] = dp[now - 1][used - 1][s - now] + dp[now - 1][used][s]
      else:
        dp[now][used][s] = dp[now - 1][used][s]

while True:
  n, s = map(int, input().split())
  if not n:
    break
  print(dp[100][n][s])


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

#define rep(i, j, n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define Puts(x) puts(x? "Yes":"No")
const int mod = 1e9 + 7;

int gcd(int n, int m) {return (m == 0? n : gcd(m, n % m));}
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
 
typedef pair<int, int> pi;
typedef long long i64;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

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

  string s;
  cin >> s;
  i64 ans = (i64)s.size() * (s.size() - 1) / 2;

  map<char, i64> mp;
  rep(i, 0, s.size()) mp[s[i]]++;
  for(auto it : mp) ans -= it.second * (it.second - 1) / 2;
  cout << ans + 1 << endl;
}


Measured memory_bytes: 768
#include<iostream>
#include<iomanip>
#include<string>
#include<set>
#include<vector>
#include<utility>
#include<algorithm>

using namespace std;

#define LL long long

int N;
int d[100002];

int main() {
	cin >> N;
	for (int i = 0; i < N; i++)cin >> d[i];
	sort(d, d + N);
	cout << d[N / 2] - d[(N / 2) - 1] << endl;
	return 0;
}

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

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

constexpr int W = 4;
constexpr int H = 5;
constexpr int N = W * H;

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

#define out(x, y) ((x) < 0 || (y) < 0 || (x) >= W || (y) >= H)
#define get_index(x, y) ((x) + (y) * W)

int ans;

void dfs(const vector<int> &cards) {
	ans = min<int>(ans, cards.size());

	rep(i, cards.size()) {
		const int x = i % W;
		const int y = i / W;

		rep(d, 4) {
			const int nx = x + dx[d];
			const int ny = y + dy[d];
			const int idx = get_index(nx, ny);

			if(out(nx, ny) || idx >= cards.size()) continue;

			if(cards[i] == cards[idx]) {
				vector<int> tmp(cards);
				const int a = min(i, idx);
				const int b = max(i, idx);
				tmp.erase(tmp.begin() + b);
				tmp.erase(tmp.begin() + a);
				dfs(tmp);
			}
		}
	}
}

void solve() {
	vector<int> cards(N);
	for(auto &e : cards) cin >> e;

	ans = N;
	dfs(cards);
	cout << ans << endl;
}

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

	int t;
	cin >> t;
	while(t--) solve();

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
const ll mod = 998244353;
const int N = 2e5+5;
const int M = 1e9+7;
int a[N];
int lst[N];
ll iv[N], f1[N], f2[N];
ll nck(int n, int k){
    if(k>n)return 0;
	return f1[n]*f2[k]%M*f2[n-k]%M;
}
void solve(){
    iv[1]=1;
	for(int i=2; i<N; ++i)
		iv[i]=M-M/i*iv[M%i]%M;
	f1[0]=f2[0]=1;
	for(int i=1; i<N; ++i) {
		f1[i]=f1[i-1]*i%M;
		f2[i]=f2[i-1]*iv[i]%M;
	}
    int n;
    cin>>n;
    int del = -1;
    for(int i=0;i<=n;i++){
        int x;
        cin>>x;
        a[x]++;
        if(a[x]==2){
            del = n-i+lst[x];
        }
        lst[x] = i;
    }
    assert(del>=0);
    for(int i=0;i<=n;i++){
        int trt = nck(n+1,i+1);
        trt = ((trt-nck(del,i))%M+M)%M;
        cout<<trt<<endl;
    }
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 7296
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
using namespace std;

long long n, a, b;
vector<long long> h;

bool good(long long m){
    long long d = m * b, cnt = 0;
    for(int i = 0; i < n; ++i){
        if(h[i] > d){
            cnt += (h[i] - d + a - 1 - b) / (a - b);
        }
    }
    return cnt <= m;
}

int main(){
    cin >> n >> a >> b;
    h.resize(n);
    for(int i = 0; i < n; ++i) cin >> h[i];
    long long l = 0, r = 1e10;
    while(r - l > 1){
        long long m = (r - l) / 2 + l;
        if(good(m)){
            r = m;
        }
        else l = m;
    }
    cout << r;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
#define REP(i,n) for (int i=0;i<(int)n; ++i)

int main() {
  map<string, map<string, bool> > winmp;
  string hoge[] = {"Rock", "Fire", "Scissors", "Snake", "Human", "Tree", "Wolf", "Sponge",
                   "Paper", "Air", "Water", "Dragon", "Devil", "Lightning", "Gun"};

  REP(i, 15) {
    REP(j,7) {
      winmp[hoge[i]][hoge[(i+j+1)%15]] = 1;
    }
  }
  int n;
  while(cin>>n, n) {
    set<string> ss;
    REP(i,n) {
      string s;
      cin >> s;
      ss.insert(s);
    }
    set<string> se;
    map<string,bool> win;
    for (set<string>::iterator it=ss.begin(); it!=ss.end(); ++it)
      win[*it] = 1;
    
    map<string,bool> ww;
    for (set<string>::iterator it=ss.begin(); it!=ss.end(); ++it) {
      for (set<string>::iterator jt=ss.begin(); jt!=ss.end(); ++jt) {
        
        if (winmp[*it][*jt]) {
          win[*jt] = 0;
          ww[*it] = 1;
        }
      }
    }
    for (set<string>::iterator it=ss.begin(); it!=ss.end(); ++it) {
      if (win[*it]&&ww[*it])
        se.insert(*it);
    }
    if(se.size()==1) {
      cout << *se.begin() << endl;
    }else {
      cout << "Draw" << endl;
    }
  }
    
}

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

using namespace std;

int main() {
    int64_t a, b;
    cin >> a >> b;
    int64_t i = 2;
    int64_t c = min(a, b);
    int64_t d = max(a, b);
    int64_t p = 1;
    if (a % 2 == 0 && b % 2 == 0) {
        p++;
    }
    while (c % 2 == 0) {
        c /= 2;
    }
    for (int64_t i = 3; i <= sqrt(c); i++) {
        bool f = false;
        while (c % i == 0) {
            c /= i;
            f = true;
        }
        if (f && d % i == 0) {
            p++;
        }
    }
    if (c > 2 && d % c == 0) {
        p++;
    }
    cout << p << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
const int mod = 1e9+7;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) v.begin(),v.end()
#define Pr(type) priority_queue<type>
#define gPr(type) priority_queue<type,vector<type>,greater<type>>
#define V(type) vector<type>
#define rep(i,n) for(int i=0; i<n; i++)
#define rer(i,st,en) for(int i=st; i<en; i++)
#define eb emplace_back
#define pri1(a) cout<<a<<'\n'
#define pri2(a,n) rep(i,n)cout<<a[i]<<'\n'
#define pri3(a,n) rep(i,n-1)cout<<a[i]<<' '; cout<<a[n-1]<<'\n'
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template< typename T >
struct WeightedUnionFind {
  vector< int > data;
  vector< T > ws;

  WeightedUnionFind() {}

  WeightedUnionFind(int sz) : data(sz, -1), ws(sz) {}

  int find(int k) {
    if(data[k] < 0) return k;
    auto par = find(data[k]);
    ws[k] += ws[data[k]];
    return data[k] = par;
  }

  T weight(int t) {
    find(t);
    return ws[t];
  }

  bool unite(int x, int y, T w) {
    w += weight(x);
    w -= weight(y);
    x = find(x), y = find(y);
    if(x == y) return false;
    if(data[x] > data[y]) {
      swap(x, y);
      w *= -1;
    }
    data[x] += data[y];
    data[y] = x;
    ws[y] = w;
    return true;
  }

  T diff(int x, int y) {
    return weight(y) - weight(x);
  }
};

int n,m,_,x,y,q,key;
string s,sb;
bool ok;

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

  cin>>n>>m; WeightedUnionFind<int> a(n);
  rep(i,m){
    cin>>x>>y>>q; x--; y--;
    if(a.find(x)==a.find(y)){
      if(a.diff(x,y)!=q){pri1("No"); return 0;}
    }else{
      a.unite(x,y,q);
    }
  }
  pri1("Yes");
}


Measured memory_bytes: 1024
from sys import stdin
input = stdin.readline

N,M = map(int,(input().split()))

ans = "IMPOSSIBLE"

seta,setb = set(),set()
af,bf = [False]*M,[False]*M

for m in range(M):
    a,b = map(int,(input().split()))
    if a-1 == 0:
        af[m] = True
        seta.add(b-1)
    if b-1 == N-1:
        bf[m] = True
        setb.add(a-1)
    if af[m] and bf[m]:
        ans = "POSSIBLE"
        break
    
for a in seta:
    if ans == "POSSIBLE":
        break
    if a in setb:
        ans = "POSSIBLE"
        break

print(ans)

Measured memory_bytes: 22140
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4,avx2,abm,fma")
#include <bits/stdc++.h>
using namespace std;
#define _USE_MATH_DEFINES

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;

const char nl = '\n';
const ll INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll MOD = 1e9+7;
const ld EPS = 1e-11;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());



int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cout << fixed << setprecision(10);

	ll n, a, b;
	cin >> n >> a >> b;
	ll cnt = n / (a+b);
	ll m = cnt * (a+b);
	cout << cnt*a + min(a, n-m) << nl;

	return 0;
}


Measured memory_bytes: 256
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

//--------------------------------------------

int h,w;
int board[60][60];
string s;

signed main(){
    cin >> h >> w;
    REPS(i,h){
        cin >> s;
        REP(j,w){
            board[i][j+1] = (s[j] == '#');
        }
    }
    REPS(i,h) REPS(j,w){
        if(board[i][j]){
            cerr << i << " " << j << endl;
            if (!(board[i-1][j] || board[i+1][j] || board[i][j-1] || board[i][j+1])){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

using namespace std;

long long gcd(long long A, long long B){
  if(A < B) swap(A, B);
  if(B == 0) return A;
  return gcd(B, A % B);
}

int main(){
  long long A, B;
  cin >> A >> B;
  
  cout << A * B / gcd(A, B);
  
  return 0;
}

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

int main(void){
    string S; cin >> S;
    set<string> se;
    int k; cin >> k;

    for(int i=1; i<=k; i++){
        for(int j=0; j<S.size()-i+1; j++){
            se.insert(S.substr(j,i));
        }
    }

    auto itr=se.begin();
    for(int i=0; i<k-1; i++) itr++;
    cout << *itr << endl;
}

Measured memory_bytes: 1664