akhauriyash/Code-Regression huggingface dataset:
use List::Util qw(max min sum);

my ($n) = split(/\s+/, <>);

my @a = qw/0 1 1 1 1 1 1 1 1 1/;
my $sum = 0;
my $target = 0;

for my $k (1..10) {
    $target = $k;
    last if ($sum +sum(@a)> $n);
    $sum += sum(@a);
    #print "$k=$sum ", join(" ", @a), "\n";

    my @b = qw/0 0 0 0 0 0 0 0 0 0/;
    for my $i (0..9) {
	$b[$i-1] += $a[$i] if $i-1>=0;
	$b[$i] += $a[$i];
	$b[$i+1] += $a[$i] if $i+1<10;
    }
    @a = @b;
}

#print "target=$target, sum=$sum\n";

for (1..9) {
    f(0,$_);
}

sub f {
    my ($depth, @a) = @_;
    if ($depth+1==$target) {
	$sum++;
	if ($sum == $n) {
	    print join("", @a), "\n";
	    exit;
	}
	return;
    }
    f($depth+1, @a, $a[$depth]-1) if $a[$depth]-1>=0;
    f($depth+1, @a, $a[$depth]);
    f($depth+1, @a, $a[$depth]+1) if $a[$depth]+1<=9;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
#define spln(i,n) (i==n?'\n':' ')
using namespace std;
long long n,m,i,j,a[100005],l,r,mid,ans;
bool check(long long x)
{
	long long sz=a[x],i;
	fd1(i,n)if(i!=x){
		if(sz*2>=a[i]) sz+=a[i]; else return 0;
	}
	return 1;
}
int main()
{
	scanf("%lld",&n);
	fz1(i,n){
		scanf("%lld",&a[i]); 
	}
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	l=1;r=n+1;
	while(l<r){
		mid=(l+r)/2;
		if(check(mid)){
			l=mid+1;
			ans=mid;
		}
		else r=mid;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    int n, dis_x, dis_y, dis_t;
    cin>>n;

    vector<int> t(n+1), x(n+1), y(n+1);
    t[0], x[0], y[0] = 0, 0, 0;
    for(int i=1; i<n+1; i++){
        cin>>t[i]>>x[i]>>y[i];
    }

    for(int i=0; i<n; i++){
        bool odd = false;

        dis_t = t[i+1]-t[i];
        dis_x = abs(x[i+1]-x[i]);
        dis_y = abs(y[i+1]-y[i]);
        
        if((dis_t - (dis_x + dis_y))%2==0){
            odd=true;
        }

        if((dis_x + dis_y) > dis_t){
            cout<<"No"<<endl;
            return 0;
        }else if((dis_x + dis_y) != dis_t){
            if(!odd){
                cout<<"No"<<endl;
                return 0;
            }
        }

    }

    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 4512
S = input()
S = list(map(int, S))

r = 0
t = 1
d = [0] * 2019
d[0] = 1
for i in range(1, len(S) + 1):
    r = (r + t * S[-i]) % 2019
    d[r] += 1
    t = t * 10 % 2019

ans = 0
for m in d:
    if m >= 2:
        ans += m * (m - 1) // 2

print(ans)


Measured memory_bytes: 75620
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
#include <limits>
using namespace std;

//static const int MAX = 1000;
void trace(int A[], int N){
    cout << A[0];
    for (int i=1;i<N;i++) cout << " " << A[i];
    cout << endl;
}
void insert(int A[], int N){
    for (int i=1;i<N;i++){
        int v = A[i];
        int j = i - 1;
        while (j >= 0 && A[j] > v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        trace(A, N);
    }
}

int main(){
    int N;
    cin >> N;
    int A[100];
    for (int i=0;i<N;i++) cin >> A[i];
    trace(A, N);
    insert(A, N);
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define  rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long int li;
typedef unsigned long long ull;

int main(int argc,char* argv[])
{
    int a,b,h;
    cin>>a>>b>>h;
    cout<<h*(a+b)/2<<endl;
    return 0;
}   

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define lPair pair<ll,ll>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int F[101][6][2];
int P[101][11];
int main(){
    string S; cin >> S;
    int n = S.size();
    ll ans = 0;
    for(int bit = 0; bit < (1 << n-1); bit++){
        ll sum = 0;
        ll a = S[0]-'0';
        for(int j = 0; j < n-1; j++){
            if(bit & (1 << j)){
                //j番目にフラグがあるとそこまでの数を足す  
                sum += a;
                a = 0; //a = 0にして再度計算
            }
            a = 10*a + (S[j+1]-'0'); //桁上げ   
        }
        sum += a;//last;
        ans += sum;
    }
    cout << ans << endl;
    return 0;
}



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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n; cin>>n;
	vi l(n);
	rep(i, n) cin>>l[i];
	sort(all(l));

	ll ans=1;
	rep(i, 3) ans*=n-i;
	ans /= 6;

	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			int p = l[i]+l[j];
			auto itr = lower_bound(l.begin(), l.end(), p);
			ans -= distance(itr, l.end());
		}
	}
	cout << ans << "\n";

	return 0;
}

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

int main(){
    int n, k; cin >> n >> k;
    ll ans = k;
    rep(i,n-1) ans *= (k-1);
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
    	Scanner sc = new Scanner(System.in);
    	String s = sc.nextLine();
    	int K = sc.nextInt();
    	char[] arr = s.toCharArray();
    	int i = 0;
    	while (i < arr.length && K > 0) {
    		if (arr[i] != 'a') {
    			int k = 26 - (arr[i] - 'a');
    			if (k <= K) {
    				arr[i] = getNextKLetters(arr[i], k);
    				K -= k;
    			}
    		}
    		i++;
    	}
    	if (K > 0) {
    		arr[arr.length - 1] = getNextKLetters(arr[arr.length - 1], K);
    	}
    	System.out.println(new String(arr));

    }
    public static char getNextKLetters(char ch, int k) {
    	int index = (ch - 'a' + k) % 26;
    	return (char)('a' + index);
    }

}

Measured memory_bytes: 14400
#include <vector>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())

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

  int n;
  ll y;
  cin >> n;
  cin >> y;

  int fuku = -1;
  int higu = -1;
  int nogu = -1;

  bool foundAns = false;
  int maxFuku = y/10000;
  REP(i, maxFuku+1) {
    int maxHigu = (y - (i*10000))/5000;
    REP(j, maxHigu+1) {
      if((y - (i * 10000 + j * 5000)) / 1000 == n-i-j) {
        foundAns = true;
        fuku = i;
        higu = j;
        nogu = (y - (i * 10000 + j * 5000)) / 1000;
        break;
      }
    }
    if(foundAns) {
      break;
    }
  }

  cout << fuku << " " << higu << " " << nogu << endl;
  return 0;
}


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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll h, n;
    cin >> h >> n;
    vector<ll> v(n);
    ll sum = 0;
    for(int i = 0; i < n; i++){
        cin >> v[i];
        sum += v[i];
    }
    if(sum >= h){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    //cout << sum << endl;



    return 0;
}



Measured memory_bytes: 1024
N,M = map(int,input().split())
ans = 0

odd = [i for i in range(1, M*2+2, 2)]
even = [i for i in range(2, N*2+2, 2)]

for k in range(M):
  ans = ans + k

for g in range(N):
  ans = ans + g
print(ans)

Measured memory_bytes: 3064
using System;
using static System.Console;
using System.Linq;

namespace AC
{
   public class shiokara
   {
      static void Main(string[] args)
      {
         string S = ReadLine();
         string T = ReadLine();
         int ans = 0;
         for(int i = 0; i < S.Length; i++){
             if(S[i] != T[i]) ans++;
         }
         WriteLine(ans);
      }
   }
}

Measured memory_bytes: 27328
#include <iostream>

int main(){
    int D, G, p[11], c[11];
    std::cin >> D >> G;
    for(int i = 0; i < D; ++i){
        std::cin >> p[i] >> c[i];
    }
 
    int ans = 1e9;
    for(int mask = 0; mask < (1 << D); ++mask){
        int s = 0, num = 0, rest_max = -1;
        for(int i = 0; i < D; ++i){
            if(mask >> i & 1){
                s += 100 * (i+1) * p[i] + c[i];
                num += p[i];
            }else{
                rest_max = i;
            }
        }
        if(s < G){
            int s1 = 100 * (rest_max + 1);
            int need = (G - s + s1 - 1) / s1;
            if(need >= p[rest_max]){
                continue;
            }
            num += need;
        }
        ans = std::min(ans, num);
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 256
import heapq

def dijkstra(s,g,c):
    d=[float('inf')]*n
    d[s]=0
    heapq.heappush(pq,[0,s])
    while len(pq)!=0:
        t,u=heapq.heappop(pq)
        if d[u]<t:
            continue
        for v in g[u]:
            if d[u]+c[u][v]<d[v]:
                d[v]=d[u]+c[u][v]
                heapq.heappush(pq,[d[v],v])
    return d

n=int(raw_input())
g=[[] for _ in xrange(n)]
cost=[[10**9+5]*n for i in xrange(n)]

for i in xrange(n):
    en=map(int,raw_input().split())
    u=en[0];k=en[1];v=en[2:-1:2];c=en[3::2]
    for j in xrange(k):
        g[u].append(v[j])
        cost[u][v[j]]=c[j]

pq=[]
dist=dijkstra(0,g,cost)

for i in xrange(n):
    print i,dist[i]

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

char c[14][14];
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};

int ice[14][14];
int num[10000];
int gx,gy;

int ans = 0;
int ccc = 0;
void dfs(int x,int y,int C,int px,int py){
  if( c[y][x] == '#' || c[y][x] == '*') return;
  if( C + abs(x-gx) + abs(y-gy) >= ans ) return;
  if( c[y][x] == 'G'){ans = C; return; }

  for(int i = 0 ; i < 4 ; i++){
    int tx = x + dx[i];
    int ty = y + dy[i];
    if( px == tx && ty == py ) continue;
    if( c[ty][tx] == '*' ) return;
  }
  char cur = c[y][x];
  c[y][x] = '*';
  for(int i = 0 ; i < 4 ; i++){
    int tx = x + dx[i];
    int ty = y + dy[i];
    if( c[ty][tx] == 'X' ){
      int b = ice[ty][tx];
      if( num[b] > 0 ){
	num[b]--;
	dfs(tx,ty,C+1,x,y);
	num[b]++;
      }
    }else{
      dfs(tx,ty,C+1,x,y);
    }
  }
  c[y][x] = cur;
  return;
}
void grouping(int x,int y,int k){
  if( c[y][x] != 'X') return;
  if( ice[y][x] != -1 ) return;
  ice[y][x] = k;
  num[k]++;
  for(int i = 0 ; i < 4 ; i++)
    grouping(x+dx[i],y+dy[i],k);
}

int main(){
  ios_base::sync_with_stdio(false);
  int W,H;
  while(cin >> W >> H && W){
    rep(i,14)rep(j,14) ice[i][j] = -1;
    rep(i,14)rep(j,14) 
      c[i][j] = '#';
    int sx , sy;
    for(int i = 0 ; i < H ; i++){
      for(int j = 0 ; j < W ; j++){
	cin >> c[i+1][j+1];
	if(c[i+1][j+1] == 'S'){
	  c[i+1][j+1] = '.';
	  sx = j+1 , sy = i+1;
	}else if(c[i+1][j+1] == 'G' ){
	  gx = j+1 , gy = i+1;
	}
      }
    }
    int k = 0;
    for(int i = 1 ; i <= H ; i++){
      for(int j = 1 ; j <= W ; j++){
	if( c[i][j] == 'X' && ice[i][j] == -1){
	  num[k] = 0;
	  grouping(j,i,k);
	  num[k] /= 2;
	  k++;
	}
      }
    }
    ans = 1e7;
    dfs(sx,sy,0,-1,-1);
    cout << ans << endl;
    
  }
}

Measured memory_bytes: 1200
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <array>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
using ll = long long;

int main() {

	int a;
	int b;
	cin >> a >> b;

	if (a <= 9 && b <= 9) cout << a * b << endl;
	else cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;

// 入力
int N;
long long h[110000];

// DP テーブル
long long dp[110000];

int main() {
    int N, K; cin >> N >> K;
    for (int i = 0; i < N; ++i) cin >> h[i];

    // 初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 110000; ++i) dp[i] = INF;

    // 初期条件
    dp[0] = 0;

    // ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 1; j <= K; ++j) {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }

    // 答え
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 5212
#include <stdio.h>
int main(void)
{
    int S,h,m,s;
    scanf("%d %d %d %d",&S,&h,&m,&s);
    h=(S/3600);
    m=(S%3600)/60;
    s=S%60;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

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

class UnionFind {
private:
	int num;
	vector<int> p, n;

public:
	UnionFind(int Num) {
		num = Num;
		p.resize(num + 1);
		n.resize(num + 1);
		for (int i = 0; i < p.size(); i++) {
			p[i] = i;
			n[i] = 1;
		}
	}

	int Parent(int n) {
		if (p[n] == n)
			return n;
		return p[n] = Parent(p[n]);
	}

	void Union(int a, int b) {
		a = Parent(a);
		b = Parent(b);
		if (a != b) {
			p[a] = b;
			n[b] += n[a];
		}
		return;
	}

	int Same(int a, int b) {
		a = Parent(a);
		b = Parent(b);
		return a == b;
	}

	int Maxnum() {
		int i, ans = 0;
		rep(i, num) {
			chmax(ans, n[i]);
		}
		return ans;
	}
};

int main(void) {
	int num, m, i, a, b;
	cin >> num >> m;
	UnionFind d(num + 1);
	rep(i, m) {
		cin >> a >> b;
		d.Union(a, b);
	}
	cout << d.Maxnum() << "\n";
	return 0;
}

Measured memory_bytes: 4848
n, m = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
for i in range(n-m+1):
    for j in range(n-m+1):
        h = True
        for k in range(m):
            if a[i+k][j:j+m] != b[k]:
                h = False
        if h:
            print("Yes")
            exit()
print("No")


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

using namespace std;

typedef pair<int, int> P;

bool dp[1001][1001] = {0};
int main() {
	int N;
	while ( cin >> N, N ) {
		vector<P> v;
		for (int i = 0; i < N; ++i) {
			int r, w; cin >> r >> w;
			v.push_back( P(r, w) );
		}
		sort(v.begin(), v.end());
		if (N == 1) {
			cout << v[0].first + v[0].first + v[0].second << endl;
		}
		else {
			int S = 0;
			for (int i = 0; i < N-1; ++i) {
				S += v[i].first;
			}
			if (S >= v[N-1].first) {
				int ans = 0;
				for (int i = 0; i < N; ++i) {
					ans += v[i].first + v[i].second;
				}
				cout << ans << endl;
			}
			else {
				int W = v[N-1].first-S;
				fill(dp[0], dp[1001], false);
				dp[0][0] = true;
				for (int i = 0; i < N-1; ++i) {
					for (int j = 0; j <= W; ++j) {
						if (dp[i][j]) {
							dp[i+1][j] = true;
							int nj = j + v[i].second;
							if (nj <= W) {
								dp[i+1][nj] = true;
							}
						}
					}
				}
				int ans = 0;
				for (int i = 0; i <= W; ++i) {
					if (dp[N-1][i]) {
						ans = i;
					}
				}

				int SW = 0;
				for (int i = 0; i < N; ++i) {
					SW += v[i].second;
				}
				ans = v[N-1].first + v[N-1].first + SW - ans;
				cout << ans << endl;
			}
		}
	}
}

Measured memory_bytes: 2192
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
int main(){
    int n;
    cin>>n;
    vector<int64_t> a(n);
    vector<int64_t> s(n+1);
    s[0]=0;
    rep(i,n){
        cin>>a[i];
        s[i+1]=s[i]+a[i];
    }
    /*
    rep(i,n+1){
        cout<<s[i]<<" ";
    }
    cout<<endl;
    */
    int64_t min=1000000000000;
    for(int i=1;i<n;i++){
        int64_t x=s[i];
        int64_t y = s[n]-s[i];
        //cout<<x<<" "<<y<<endl;
        if(abs(x-y)<min){
            min = abs(x-y);
        }
    }
    cout<<min<<endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int,int> P;
int main() {
  int n;
  cin>>n;
  if (n==0) {
    cout<<0<<endl;
    return 0;
  }
  int d=-2;
  vector<int> a;
  while (n) {
    if (n>0) {
      a.push_back(n%d);
      n/=-2;
    }
    else {
      a.push_back(-n%2);
      n=-n/2+(-n%2==0? 0:1);
    }
  }
  int s=a.size();
  for (int i=0; i<s; i++) {
    cout<<a[s-1-i];
  }
  return 0;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container, std.typecons;
import std.numeric, std.math;
import core.bitop;

T RD(T = string)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T)(in string str, T fix) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool INSIDE(T)(T x, T b, T e) { return x >= b && x < e; }

long mod = pow(10, 9) + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

struct UnionFind
{
	void init(long n) { par = new long[](n); foreach (i; 0..n) par[i] = i; }
	long root(long i) { return par[i] == i ? i : (par[i] = root(par[i])); }
	bool same(long i, long j) { return root(i) == root(j); }
	void unite(long i, long j) { i = root(i); j = root(j); if (i == j) return; par[i] = j; }
	long[] par;
}

long[] dijkstra(long from, long to, long[][] edges)
{
	long[] path;
	auto cost = new long[](edges.length); fill(cost, long.max); cost[from] = 0;
	long[][] open = [[from]];
	while (!open.empty)
	{
		auto n = open.front; open.popFront;
		auto p = n[0];
		foreach (i; 0..edges.length)
		{
			if (edges[p][i] == -1) continue;
			auto c = cost[p] + edges[p][i];
			if (c < cost[to] && c < cost[i]) { cost[i] = c; if (i == to) path = i ~ n; else open ~= i ~ n; }
		}
	}
	return cost[to] ~ path;
}

void main()
{
	auto N = RD!long;
	auto p = RDR.ARR!long(-1);
	
	long ans;
	bool hasLast = false;
	foreach (i; 0..N)
	{
		if (p[i] == i)
		{
			if (hasLast)
			{
				hasLast = false;
			}
			else
			{
				++ans;
				hasLast = true;
			}
		}
		else
		{
			hasLast = false;
		}
	}

	writeln(ans);
	stdout.flush();
}

Measured memory_bytes: 4412
a,b,c = map(int,input().split(" "))
count = 0
if a == b and b == c:
    if a % 2 == 0:
        print(-1)
    else:
        print(0)
else:
    while True:
        if a % 2 == 1 or b % 2 == 1 or c % 2 == 1:
            print(count)
            break
        else:
            a,b,c = (b+c)//2,(a+c)//2,(a+b)//2
            count += 1

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

using pii = pair<int, int>;

int main() {
    int n; cin >> n;
    set<pii> ans;
    for(int i = 1; i <= n; ++i) {
        for(int j = i + 1; j <= n; ++j) {
            ans.emplace(i, j);
        }
    }
    if(n & 1) {
        for(int i = 1; i <= n / 2; ++i) {
            ans.erase(make_pair(i, n - i));
        }
    } else {
        for(int i = 1; i <= n / 2; ++i) {
            ans.erase(make_pair(i, n - i + 1));
        }
    }

    cout << ans.size() << endl;
    for(auto& x : ans) {
        cout << x.first << " " << x.second << endl;
    }
}

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

using namespace std;

int main(){
	int K, X;
	scanf("%d%d", &K, &X);
	
	for(int i = max(X-K+1, -1000000); i <= min(X+K-1, 1000000); i ++){
		printf("%d", i);
		if(i != min(X+K-1, 1000000)){
			printf(" ");
		}
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
 
using namespace std;
 
struct before_main{before_main(){cin.tie(0); ios::sync_with_stdio(false);}} before_main;
 
#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
 
typedef long long ll;
int const inf = 1<<29;
 
int H, W;
vector<string> F;
 
int dx[8] = {-1,0,1,0,-1,1,1,-1};
int dy[8] = {0,-1,0,1,-1,-1,1,1};
 
unordered_map<string, int> mp;
 
void go(int y, int x, int dir, int sy, int sx) {
  string s;
  while(1) {
    s += F[y][x];
    int ny = y + dy[dir];
    int nx = x + dx[dir];
    if(ny >= H) { ny = 0; }
    if(ny < 0) { ny = H-1; }
    if(nx >= W) { nx = 0; }
    if(nx < 0) { nx = W-1; }
    if(ny == sy && nx == sx) { break; }
    y = ny, x = nx;
    mp[s]++;
  }
  mp[s] ++;
}
 
int main() {
 
  for(; cin >> H >> W && (H | W);) {
 
    F.clear(); rep(i, H) F.resize(H);
    vector<string> v;
    rep(i, H) cin >> F[i];
    mp.clear();
    rep(i, H) rep(j, W) {
      rep(k, 8) {
        go(i, j, k, i, j);
      }
    }
 
    vector<string> u;
    for(auto && e: mp) {
      if(e.first.size() > 1 && e.second > 1) {
        u.push_back(e.first);
      }
    }
 
    if(u.empty()) {
      cout << 0 << endl;
    }
    else {
      sort(all(u), [&](string const& s, string const& t){ int n=s.size(),m=t.size(); return n != m ? n > m : s < t; });
      cout << u[0] << endl;
    }
  }
   
  return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 4e4 + 5;

struct line {
	ll a, b, c;
};

line lines[MAXN];

double val[MAXN];

int per[MAXN];

int n;

double ans[2];

// vals for the tree
ll vals[MAXN];

// 0-indexed Fenwick tree (for sum)
// Use: fill n, call init(MyArray)
// Call get_val(l, r) and upd_val(pos, add)
struct fenwick_tree{
	// Number of elements
	int n;
	
	// Items of the tree
	int ft[MAXN];
	
	// Get query [l ... r]
	int get_val(int l, int r){
		return get_val(r) - get_val(l - 1);
	}
	
	// Get query [0 ... r]
	int get_val(int r){
		int res = 0;
		for(; r >= 0; r = (r & (r + 1)) - 1){
			res += ft[r];
		}
		return res;
	}
	
	// Update query
	void upd_val(int pos, int add){
		for(; pos < n; pos = (pos | (pos + 1))){
			ft[pos] += add;
		}
	}
} ftree;

bool cmp1(const line &l1, const line &l2) {
	return -l1.a / (l1.b + 0.) > -l2.a / (l2.b + 0.);
}

bool cmp2(int ind1, int ind2) {
	return val[ind1] < val[ind2];
}

void solve(){
	scanf("%d", &n);
	REP(i, 0, n) {
		scanf("%lld%lld%lld", &lines[i].a, &lines[i].b, &lines[i].c);
	}
	REP(k, 0, 2) {
		sort(lines, lines + n, cmp1);
		
		/*REP(i, 0, n) {
			printf("%lld %lld\n", lines[i].a, lines[i].b);
		}*/
		
		double l = -1e9, r = 1e9;
		for(int it = 0; it < 100; it++) {
			double mid = (l + r) / 2.0;
			REP(i, 0, n) {
				val[i] = (lines[i].c - lines[i].a * mid) / lines[i].b;
				per[i] = i;
			}
			sort(per, per + n, cmp2);
			
			/*if (it <= 1) {
				REP(i, 0, n) {
					printf("%lld %lld %lf\n", lines[per[i]].a, lines[per[i]].b, val[per[i]]);
				}
			}*/
			
			ftree.n = n;
			REP(i, 0, n) {
				ftree.ft[i] = 0;
			}
			ll cur = 0ll;
			for(int i = n - 1; i >= 0; i--) {
				int pos = per[i];
				/*if (it <= 1) {
					printf("%d ", per[i]);
				}*/
				cur += ftree.get_val(0, pos);
				ftree.upd_val(pos, 1);
			}
			
			/*if (it <= 1) {
				printf(" => %lld\n", cur);
			}*/
			
			if (2 * cur < (ll)n * (ll)(n - 1) / 2) {
				l = mid;
			} else {
				r = mid;
			}
		}
		ans[k] = r;
		REP(i, 0, n) {
			swap(lines[i].a, lines[i].b);
		}
	}
	printf("%.12lf %.12lf\n", ans[0], ans[1]);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	String s = sc.next();
    	
    	int ans = 1;
    	char before = s.charAt(0);    	
    	for(int i = 1; i < n; i++) {
    		if(before != s.charAt(i)) {
    			ans++;
    			before = s.charAt(i);
    		}
    	}
    	
    	System.out.println(ans);

	}

}


Measured memory_bytes: 25616
import numpy as np 

listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        #または、quit(),os.exit()をして止める。

sum=listA[1][0]+listA[1][-1]
for i in range(len(listA[1])-1):
  if listA[1][i+1]>listA[1][i]:
    sum+=listA[1][i]
  else:
    sum+=listA[1][i+1]
print(sum)

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

using ll=long long;
const ll MOD=998244353;

ll powm(ll x,ll k){
    ll res=1;
    while(k){
        if(k&1) res=res*x%MOD;
        x=x*x%MOD;
        k>>=1;
    }
    return res;
}

ll inv(ll x){
    return powm(x,MOD-2);
}

int main(){

    int N; ll S;
    cin>>N>>S;


    vector<vector<ll>> C(N+2,vector<ll>(N+2,1));
    for(int i=2;i<=N+1;i++){
        for(int j=1;j<i;j++) C[i][j]=(C[i-1][j]+C[i-1][j-1])%MOD;
    }
    auto comb=[&](int n,int k){
        return C[n][k];
    };
    vector<ll> pow2(N+1,1),powS(N+1,1);
    for(int i=0;i<N;i++) pow2[i+1]=pow2[i]*2%MOD;
    for(int i=0;i<N;i++) powS[i+1]=powS[i]*(S+1)%MOD;

    ll Z=S/2+S%2;

    vector<ll> X(N+1);
    X[0]=Z;
    for(int m=1;m<=N;m++){
        X[m]=1;
        for(int i=0;i<=m;i++) X[m]=X[m]*(Z+1)%MOD;
        
        X[m]--;
        for(int k=0;k<m;k++){
            X[m]-=comb(m+1,k)*X[k];
            X[m]%=MOD;
        }
        X[m]*=inv(m+1);
        X[m]%=MOD;
    }

    
    auto mypow=[&](int x,int k){
        if(x==2){
            return pow2[k];
        }
        else if(x==S+1){
            return powS[k];
        }
        assert(false);
    };
    auto solve0=[&](){
        ll res=(MOD+1)/2*S%MOD*(S+1)%MOD;
        for(int i=0;i<N-2;i++) res=res*(S+1)%MOD;
        return res;
    };
    auto solve1=[&](){
        ll res=0;
        for(int i=0;i<N-1;i++){
            for(int j=0;j<=i;j++){
                ll v0=comb(N-1,i);
                ll v1=comb(i,j);
                ll v2=mypow(S+1,i-j)*mypow(2,j)%MOD;
                ll v3=X[j];
                ll sc=v0*v1%MOD*v2%MOD*v3%MOD;
                if(j%2==0) res+=sc;
                else res-=sc;
                res%=MOD;
            }
        }
        return res;
    };
    
    ll ret0=solve0();
    ll ret1=solve1();
    ll ans=ret0+ret1;
    cout<<(ans%MOD+MOD)%MOD<<endl;
    
    
    return 0;
}




Measured memory_bytes: 10740
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main() {
	int n, k, x, y; cin >> n >> k >> x >> y;
	if (n <= k)cout << x * n << endl;
	else cout << x * k + y * (n - k) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  int k, n;
  cin >> n >> k;
  vector<int> a(n);
  int answer = 0;
  
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  
  sort(a.begin(), a.end());
  
  for(int i = 0; i < k; i++){
    answer += a[i];
  }
   
  cout << answer << endl;
  
  return 0;
}

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

const int C = 100010;

int L[C];
int A[C];

int main() {
  int n, m;
  cin >> n >> m;
  L[0] = 0;
  for (int i=1; i<=n-1; i++) {
    cin >> L[i];
  }
  for (int i=0; i<m; i++) {
    cin >> A[i];
  }
  for (int i=1; i<=n-1; i++) {
    L[i] += L[i-1];
  }
  int ans = 0;
  int now = 0;
  for (int i=0; i<m; i++) {
    int next = now + A[i];
    ans += abs(L[next] - L[now]);
    now = next;
    ans %= 100000;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1940
from sys import stdin
import numpy as np


# noinspection PyShadowingBuiltinsInspection

def main():
    n, k = [int(x) for x in input().split()]
    hs = [int(x) for x in input().split()]
    cnt = 0
    for h in hs:
        if h >= k:
            cnt += 1
    print(cnt)
    return


if __name__ == "__main__":
    main()

Measured memory_bytes: 21624
import math

[a, b, h, m] = [int(s) for s in input().split()]
hd = h * 30 + m * 0.5
md = m * 6
d = abs(hd - md)
if d > 180:
    d = 360 - d

l = a**2 + b**2 - 2 * a * b * math.cos(math.radians(d))
print(math.sqrt(l))

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

int main() {
  long long num;
  cin >> num;
  vector<char> name;
  int cnt = 0;
  for (int i = 0; i < 12; i++) {
    int rest;
    rest = num % 26;
    if (rest == num) cnt++;
    if (cnt == 2 || num == 0) break;
    if (rest == 0) rest = 26;
    num = (num - rest) / 26;
    name.push_back((char)(rest+96));
  }
  reverse(name.begin(), name.end());
  for (int i = 0; i < name.size(); i++) {
    cout << name[i];
  }
  cout << endl;
}

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

int main() {
	int A, B;

	cin >> A >> B;

	if (A - 2 >= B) {
		cout << A + A - 1 << endl;
	}

	else if (B - 2 >= A) {
		cout << B + B - 1 << endl;
	}

	else if (A == B ||A-1==B||B-1==A) {
		cout << A + B << endl;
	}

}

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

int main(){
  string s;
  cin >> s;
  int n;
  n = s.size();
  string t;
  rep(i,n/2){
    if(s[i] != s[n-i-1]){
      puts("No");
      return 0;
    }
  }
  rep(i,n/2){
    t[i] = s[i];
  }
  int m = n/2;
    rep(i,m/2){
      if(t[i] != t[m-i-1]){
        puts("No");
        return 0;
      }
    }
  

  puts("Yes");
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

using namespace std;

#define MAX 100000
#define INF 1000000000

typedef struct _card {
	int number;
	char symbol;
} card_t;

card_t ary_a[MAX];
card_t ary_b[MAX];
card_t ary_bl[MAX/2];
card_t ary_br[MAX/2];

int partition( int p, int r ) {
	int i = p-1;
	int x = ary_a[r].number;
	card_t tmp;

	for ( int j = p ; j < r ; j++ ) {
		if ( ary_a[j].number <= x ) {
			i++;
			tmp = ary_a[j];
			ary_a[j] = ary_a[i];
			ary_a[i] = tmp;
		}
	}

	tmp = ary_a[r];
	ary_a[r] = ary_a[i+1];
	ary_a[i+1] = tmp;

	return i+1;
}

void quicksort( int p, int r ) {
	int q;
	if ( p < r ) {
		q = partition( p, r );
		quicksort( p, q-1 ); 
		quicksort( q, r );
	}
}

void merge( int left, int mid, int right ) {
	int n1 = mid - left;
	int n2 = right - mid;

	for ( int i = 0 ; i < n1 ; i++ ) {
		ary_bl[i] = ary_b[left+i];
	}

	for ( int i = 0 ; i < n2 ; i++ ) {
		ary_br[i] = ary_b[mid+i];
	}

	ary_bl[n1].number = INF;
	ary_br[n2].number = INF;

	int i = 0, j = 0;
	card_t tmp;
	for ( int k = left ; k < right ; k++ ) {
		if ( ary_bl[i].number <=  ary_br[j].number ) {
			ary_b[k] = ary_bl[i];
			i++;
		} else {
			ary_b[k] = ary_br[j];
			j++;
		}
	}
}

void mergesort( int left, int right ) {
	if ( left+1 < right ) {
		int mid = ( left + right ) / 2;
		mergesort( left, mid );
		mergesort( mid, right );
		merge( left, mid, right );
	}
}

int main() {
	int number;
	int stable = 1;
	scanf( "%d", &number );

	for ( int i = 0 ; i < number ; i++ ) {
		scanf( " %c %d", &ary_a[i].symbol, &ary_a[i].number );
		ary_b[i].symbol = ary_a[i].symbol;
		ary_b[i].number = ary_a[i].number;
	}

	quicksort( 0, number-1 );
	mergesort( 0, number );

	for ( int i = 0 ; i < number ; i++ ) {
		if ( ary_a[i].symbol != ary_b[i].symbol ) {
			stable = 0;
			break;
		}
	}
	if ( stable ) {
		fprintf( stdout, "Stable\n" );
	} else {
		fprintf( stdout, "Not stable\n" );
	}

	for ( int i = 0 ; i < number ; i++ ) {
		fprintf( stdout, "%c %d\n", ary_a[i].symbol, ary_a[i].number );
	}
	return 0;
}



Measured memory_bytes: 5072
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i=0;i<n;i++){
            h[i]=sc.nextInt();
        }
        int[] dp = new int[n+1];
        dp[1]=0;
        if(n>=2) {
            dp[2] = Math.abs(h[1] - h[0]);
        }
        if(n >= 3){
            for (int i = 3; i < n + 1; i++) {
                dp[i] = Math.min(dp[i - 1] + Math.abs(h[i - 1] - h[i - 2]), dp[i - 2] + Math.abs(h[i - 1] - h[i - 3]));

            }
        }
//        for(int i=1;i<n+1;i++){
//            System.out.println(dp[i]);
//        }
        System.out.println(dp[n]);
    }
}


Measured memory_bytes: 50376
import java.io.*;
import java.lang.*;
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;

public class Main {
	public static void main(String[] args){
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		String buf;
		try {
			while(br.ready()){
				buf = br.readLine();
				Scanner scanner = new Scanner(buf);
				int i, x, n = scanner.nextInt();

				for(i = 1; i <= n; i++){
					x = i;
					if(x % 3 == 0){
						System.out.print(" " + i);
					} else{
						for(;;){
							if(x % 10 == 3){
								System.out.print(" " + i);
								break;
							}
							x /= 10;
							if(x == 0){
								break;
							}
						}
					}
				}
				System.out.print("\n");
			}
		}
		catch(IOException e) {
			System.out.println("Read error.");
			return;
		}
	}
}

Measured memory_bytes: 28716
#include<iostream>
    using namespace std;
    int main(){
        int N, count=0;
        int A[200];
        cin >> N;
        for(int i=0;i<N;i++) cin >> A[i];
        bool exist_odd = false;
        for(int k=0;;k++){
            for(int i=0;i<N;i++){
                if(A[i]%2 != 0) exist_odd = true;
            }
            if(exist_odd) break;
            for(int i = 0;i<N;i++){
                A[i] /= 2;
            }

            ++count;
        }
        cout << count <<endl;
        
    }


Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;

const int MOD = 998244353;

struct Modint {
  ll val;
  
  Modint (ll _val = 0)
    : val(_val % MOD) {}

  Modint operator+ (Modint other) const {
    return Modint(val + other.val);
  }

  void operator+= (Modint other) {
    val += other.val;
    val %= MOD;
  }

  Modint operator- () const {
    return Modint(MOD - val);
  }

  Modint operator- (Modint other) const {
    return Modint(val + MOD - other.val);
  }

  void operator-= (Modint other) {
    val += MOD - other.val;
    val %= MOD;
  }

  Modint operator* (Modint other) const {
    return Modint(val * other.val);
  }

  void operator*= (Modint other) {
    val *= other.val;
    val %= MOD;
  }

  bool operator== (Modint other) const {
    return val == other.val;
  }

  bool operator!= (Modint other) const {
    return val != other.val;
  }
};

Modint exp (Modint a, int k) {
  if (k == 0) {
    return Modint(1);
  } else if (k % 2 == 0) {
    Modint half = exp(a, k / 2);
    return half * half;
  } else {
    return a * exp(a, k - 1);
  }
}

Modint inv (Modint a) {
  return exp(a, MOD - 2);
}

ostream& operator<< (ostream& out, Modint p) {
  out << p.val;
  return out;
}

const int MAX_N = 3e5 + 5;

Modint fact [MAX_N];
Modint invfact [MAX_N];

Modint choose (int n, int k) {
  if (k < 0 || n < k) return Modint(0);
  return fact[n] * invfact[k] * invfact[n - k];
}

int main () {
  fact[0] = Modint(1);
  for (int i = 1; i < MAX_N; i++) {
    fact[i] = Modint(i) * fact[i - 1];
  }

  invfact[0] = Modint(1);
  for (int i = 1; i < MAX_N; i++) {
    invfact[i] = inv(Modint(i)) * invfact[i - 1];
  }

  ll n, a, b, k;
  cin >> n >> a >> b >> k;

  Modint ans (0);
  for (ll u = 0; u <= n && u * a <= k; u++) {
    if ((k - u * a) % b == 0) {
      ll v = (k - u * a) / b;
      ans += choose(n, u) * choose(n, v);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 4992
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  while (cin >> n, n) {
    int w, h;
    cin >> w >> h;
    vvi v(h, vi(w));
    while (n--) {
      int x, y;
      cin >> x >> y;
      x--;
      y--;
      v[y][x] = 1;
    }
    int s, t;
    cin >> s >> t;
    int m = 0;
    rep(i, h - t + 1) rep(j, w - s + 1) {
      int c = 0;
      loop(k, i, i + t) loop(l, j, j + s) c += v[k][l];
      cmax(m, c);
    }
    cout << m << endl;
  }
}

Measured memory_bytes: 3108
from heapq import heappush, heappop


#  https://atcoder.jp/contests/abc137/submissions/6840855 を参考にした。
q = []
if __name__ == '__main__':
    n, m = map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(n)]
    ab = sorted(ab, reverse=True)

    q = []
    answer = 0
    for i in range(m-1, -1, -1):
        while ab and i + ab[-1][0] <= m:
            (a, b) = ab.pop()
            heappush(q, -b)

        if q:
            answer -= heappop(q)

    print(answer)


Measured memory_bytes: 28656
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABeginner solver = new ABeginner();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABeginner {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int r = in.nextInt();
            out.println(r + Math.max(10 - n, 0) * 100);
        }

    }
}



Measured memory_bytes: 35932
d, n = map(int, input().split())


def f(x):  # 何回割り切れるか
    if x % 100 != 0:
        return 0
    else:
        return f(x // 100) + 1


cnt = 0
i = 1

while 1:
    if f(i) == d:
        cnt += 1
        if cnt == n:
            ans = i
            break
    i += 1

print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define INT long long int
#define MOD (INT)(1e9)+7
using namespace std;

string s;
int cnt = 1, chk;
int main()
{
     cin>>s;
     for(int i = 1 ; i < 4 ; i++ )
     {
        if( s[i] == s[i-1] ) cnt++;
        else cnt = 1;
        if( cnt >= 3 ) chk = true;
     }
     if( chk ) cout<<"Yes\n";
     else cout<<"No\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <cassert>
#include <random>
#include <stack>
#include <ctime>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

int main() {
    long x, a, b;
    cin >> x >> a >> b;
    if (abs(x - a) < abs(x - b)) {
        cout << "A" << endl;
    } else {
        cout << "B" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
using ll=long long;
#ifdef ONLINE_JUDGE
#define D(...)
#else
#define D(...)cerr<<__LINE__<<":"<<"["<<#__VA_ARGS__<<"]->",P(__VA_ARGS__)
#endif
void P(){cerr<<endl;} 
template<typename H,typename...T>void P(H h,T...t){cerr<<h<<" ";P(t...);}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    set<int>st;
    int n;cin>>n;
    for(int i=1;i<=9;++i){
        for(int j=1;j<=9;++j){
            for(int k=1;k<=9;++k){
                if(i+j+k<=9){
                    string s1(i,'3');
                    string s2(j,'5');
                    string s3(k,'7');
                    s1+=s2;s1+=s3;
                    int val=stoi(s1);
                    if(val>int(1e9))continue;
                    do{
                        val=stoi(s1);
                        st.insert(val);
                    }
                    while(next_permutation(all(s1)));
                }
            }
        }
    }
    cout<<distance(st.begin(),st.upper_bound(n));
}

Measured memory_bytes: 4896
#include<cstdio>
#include<algorithm>
using namespace std;

int main()
{
        int i,t;
        scanf("%d",&t);
        for(i=0;i<t;i++)
        {
                int s, n,k;
                scanf("%d %d",&n,&k);
                int x[n];
                int cnt;
                for(cnt=1;cnt<=n;cnt++)
                {
                        scanf("%d",&x[cnt]);
                }
                //データの取得

                //X[m]=x(m+1)-x(m) (m=1,,,,n-1)を取得する
                int m,X[n];X[0]=0;
                for(m=1;m<=n-1;m++)
                {
                        X[m]=x[m+1]-x[m];
                }

                sort(X,X+n);
                //k台の発電機により、k-1のエリアと両端には電線を引かなくてよい
                //ゆえにもとめる電線の長さLは
                //L=(x(n)-x(1)) - (X(1)+X(2)+,,,X(k-1)) である。

                int l1,l2={0};
                l1=x[n]-x[1];
                for(s=1;s<=k-1;s++)
                {
                        l2=l2+X[n-s];
                }
                int L;
                L=l1-l2;
                if(n<=k)
                {printf("0\n");}
                else
                {
                printf("%d\n",L);
                }
         }
return 0;
}

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

s = input().split() 
s = list(s[0])
t = input().split() 
t = list(t[0])

dp = [[0]*(len(t)+1) for _ in range(len(s)+1)]

for i in range(1,len(s)+1):
    for j in range(1,len(t)+1):
        if s[i-1]==t[j-1]:
            dp[i][j] = max(dp[i-1][j-1]+1,dp[i-1][j],dp[i][j-1])
        else:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])
#print(dp[len(s)][len(t)])

ans = ""
i = len(s)
j = len(t)
while i>0 and j>0:
    if dp[i][j]==dp[i-1][j]:
        i-=1
    elif dp[i][j]==dp[i][j-1]:
        j-=1
    else:
        ans = s[i-1]+ans
        i-=1
        j-=1
print(ans)

Measured memory_bytes: 112860
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
using namespace std;
int main(){
    int N; cin >> N;
    set<string> W;
    string ans = "Yes";
    string tmp_a;
    cin >> tmp_a;
    W.insert(tmp_a);
    for (int i=1;i<N;i++){
        string tmp_b;
        cin >> tmp_b;
        if (tmp_a[tmp_a.size()-1]==tmp_b[0]&&!(W.count(tmp_b))){
            W.insert(tmp_b);
            tmp_a = tmp_b;
        }
        else ans = "No";
    } 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> t(n);
  int sum = 0;
  for(int i = 0;i < n;i++) {
    cin >> t.at(i);
    sum += t.at(i);
  }
  int m;
  cin >> m;
  int p,x;
  for(int i = 0;i < m;i++) {
    cin >> p >> x;
    cout << sum - (t.at(p - 1) - x) << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b,ans=2147483648,n;
int main()
{
    cin>>a;
    for(int s=0;s<a;s++)
    {
        cin>>b;
        n=0;
        while(b%2==0)
        {
            b=b/2;
            n++;
        }
        ans=min(ans,n);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
    int n,k=0;
    cin>>n;
    vector<int> a(n);
    rep(i,n)
    {
        cin>>a[i];
    }
    int now=1;
    int count=0;
    bool end=false;
    for (int i = 0 ; i < n; i++)
    {
        if(a[i]==now)
        {
            k+=count;
            count=0;
            now++;
        }
        else
        {
            count++;
        }
    }
    k+=count;
    if(now==1 && count==0)cout<<k<<endl;
    else if (now==1 && count!=0)cout<<-1<<endl;
    else cout<<k<<endl;

    return 0;
}


Measured memory_bytes: 1024