akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 10005

struct Edge{
	Edge(int arg_to,int arg_weight){
		to = arg_to;
		weight = arg_weight;
	}

	int to,weight;
};

struct Info{
	Info(int arg_dist,int arg_node_id){
		dist = arg_dist;
		node_id = arg_node_id;
	}
	bool operator<(const struct Info &arg) const{

		return dist > arg.dist; //距離の降順
	}

	int dist,node_id;
};


int V;
int max_dist[SIZE];
vector<Edge> G[SIZE];
vector<Info> info[SIZE];


void dfs(int node_id,int pre){

	int tmp_max = 0;

	for(int i = 0; i < G[node_id].size(); i++){

		int child = G[node_id][i].to;
		if(child == pre)continue;

		dfs(child,node_id);

		info[node_id].push_back(Info(max_dist[child]+G[node_id][i].weight,child));
		tmp_max = max(tmp_max,max_dist[child]+G[node_id][i].weight);
	}
	max_dist[node_id] = tmp_max;
}

void dfs2(int node_id,int pre){

	for(int i = 0; i < G[node_id].size(); i++){

		if(G[node_id][i].to == pre){

			if(info[pre][0].node_id == node_id){ //親の最大距離方向が自分である場合

				if(info[pre].size() == 1){ //子が自分のみ

					info[node_id].push_back(Info(G[node_id][i].weight,pre));

				}else{

					info[node_id].push_back(Info(info[pre][1].dist+G[node_id][i].weight,pre));
				}

			}else{ //親の最大距離方向が自分ではない場合

				info[node_id].push_back(Info(info[pre][0].dist+G[node_id][i].weight,pre));
			}
			break;
		}
	}
	//親を先に処理
	sort(info[node_id].begin(),info[node_id].end());
	max_dist[node_id] = info[node_id][0].dist;

	for(int i = 0; i < G[node_id].size(); i++){

		int child = G[node_id][i].to;
		if(child == pre)continue;

		dfs2(child,node_id);
	}
}

int main(){

	scanf("%d",&V);

	if(V == 1){

		printf("0\n");
		return 0;
	}

	int from,to,weight;

	for(int i = 0; i < V-1; i++){

		scanf("%d %d %d",&from,&to,&weight);

		G[from].push_back(Edge(to,weight));
		G[to].push_back(Edge(from,weight));
	}

	dfs(0,-1);
	dfs2(0,-1);

	for(int i = 0; i < V; i++){

		printf("%d\n",max_dist[i]);
	}

	return 0;
}



Measured memory_bytes: 5464
N, K = map(int, input().split())
p = [list(map(int, input().split())) for _ in range(N)]
x = sorted(list(zip(*p))[0])
y = sorted(list(zip(*p))[1])
dic_x = {v: i + 1 for i, v in enumerate(x)}
dic_y = {v: i + 1 for i, v in enumerate(y)}
cum_sum = [[0] * (N + 1) for _ in range(N + 1)]
for i, j in p:
    cum_sum[dic_y[j]][dic_x[i]] = 1

for i in range(1, N + 1):
    for j in range(N):
        cum_sum[i][j + 1] += cum_sum[i][j]

for i in range(1, N + 1):
    for j in range(N):
        cum_sum[j + 1][i] += cum_sum[j][i]

ans = 10 ** 20
for l in range(N):
    for r in range(l + 1, N):
        for d in range(N):
            for u in range(d + 1, N):
                z = cum_sum[u + 1][r + 1] - cum_sum[d][r + 1] \
                     - cum_sum[u + 1][l] + cum_sum[d][l]
                if z >= K:
                    ans = min(ans, (x[r] - x[l]) * (y[u] - y[d]))
print(ans)


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

int main() {
  string N;
  cin >> N;
  int f = 0;
  for (int i = 0; i < N.size(); i++) {
    f += N[i] - '0';
  }
  istringstream ss1;
  int intN;
  ss1 = istringstream(N);
  ss1 >> intN;
  if (intN % f == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

/**
 * @title Fenwick tree
 * @docs fenwick_tree.md
 */
template <typename AbelianGroup>
class FenwickTree{
  using value_type = typename AbelianGroup::value_type;
  AbelianGroup G;
  
  int size;
  std::vector<value_type> data;
  
public:
  FenwickTree(){}
  FenwickTree(int size):
    size(size), data(size + 1, G.id())
  {}
  
  void update(int i, const value_type &val){
    i += 1; // 1-index
    
    while(i <= size){
      data[i] = G.op(data[i], val);
      i += i & (-i);
    }
  }
  
  value_type get(int i) const { // [0, i)
    value_type ret = G.id();
    i += 1; // 1-index

    while(i > 0){
      ret = G.op(ret, data[i]);
      i -= i & (-i);
    }

    return ret;
  }

  value_type get(int l, int r) const { // [l, r)
    return G.op(get(r-1), G.inv(get(l-1)));
  }
  
  value_type at(int x) const {
    return get(x, x+1);
  }
};

/**
 * @docs sum.md
 */
template <typename T>
struct SumGroup{
  using value_type = T;

  value_type id() const {return 0;}
  value_type op(const value_type &a, const value_type &b) const {return a + b;}
  value_type inv(const value_type &a) const {return -a;}
};


template <typename T>
struct RangeCountQuery{
  std::vector<int> a;
  std::vector<std::pair<int, int>> qs;
  std::map<std::pair<int, int>, std::vector<int>> index;
  int N;

  RangeCountQuery(std::vector<T> a_): N(a_.size()){
    auto temp = a_;
    std::sort(temp.begin(), temp.end());
    temp.erase(std::unique(temp.begin(), temp.end()), temp.end());

    for(auto x : a_){
      int i = std::lower_bound(temp.begin(), temp.end(), x) - temp.begin(); 
      a.push_back(i);
    }
  }

  void add(int l, int r){ // [l, r)
    index[{l, r}].push_back(qs.size());
    qs.emplace_back(r, l);
  }

  auto solve(){
    std::sort(qs.begin(), qs.end());

    FenwickTree<SumGroup<int>> b(N);

    const int Q = qs.size();
    std::vector<int> last_index(N, -1);
    std::vector<int> ret(Q);
  
    int cur = 0;
    for(auto [r, l] : qs){
      while(cur < r){
        if(last_index[a[cur]] != -1){
          b.update(last_index[a[cur]], -1);
        }

        last_index[a[cur]] = cur;
        b.update(last_index[a[cur]], 1);

        ++cur;
      }

      for(auto i : index[{l, r}]){
        ret[i] = b.get(l, r);
      }
    }
    
    return ret;
  }
};


int main(){
  int N, Q; std::cin >> N >> Q;
  std::vector<int> c(N);
  for(int i = 0; i < N; ++i) std::cin >> c[i];

  RangeCountQuery<int> rcq(c);

  for(int i = 0; i < Q; ++i){
    int l, r; std::cin >> l >> r;
    rcq.add(l - 1, r);
  }

  auto ans = rcq.solve();

  for(auto x : ans) std::cout << x << "\n";

  return 0;
}


Measured memory_bytes: 72180
import math
N, K = map(int, input().split())
ans = 0
for i in range(1, N+1):
	deff = (K-1)/i
	if deff < 1:
		ans += 1/N
	else:
		ans += (1 / N) * (1 / 2) **  ((math.log2((K-1)/i))//1+ 1)
print(ans)

Measured memory_bytes: 3188
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		long ans = (long)Math.pow(2, m) * (1900 * m + 100 *(n-m));
		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 35728
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  if (s=="SUN") cout << 7;
  if (s=="MON") cout << 6;
  if (s=="TUE") cout << 5;
  if (s=="WED") cout << 4;
  if (s=="THU") cout << 3;
  if (s=="FRI") cout << 2;
  if (s=="SAT") cout << 1;
}









Measured memory_bytes: 3608
/*#include<bits/atdc++.h>
using namespace std;
int main(){
	int a,b,c,d,e;
	cin>>a>>b>>c;
	d=__gcd(a,b);
	cout<<(a/d)*(b/d)*c<<endl;
	
}*/
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<stack>
#include<queue>
#include<vector>
typedef long long int ll;
#define BIG_NUM 2000000000
using namespace std;

int calc(int x,int y){
	if(y==0){
		return x;
	}else{
		return calc(y,x%y);
	}
}

int main(){
	int W,H,C,common;
	cin>>W>>H>>C;
	if(W>=H)common=calc(W,H);
	else{
		common=calc(H,W);
	}
	cout<<W*H*C/(common*common)<<endl;
	return 0;
}



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

bool isprime(int X){
  if(X==1){
    return false;
  }
  for(int i=2;i*i<=X;i++){
    if(X%i==0){
      return false;
    }
  }
  return true;
}

int main(){
  int X;
  cin >> X;
  while(true){
    if(isprime(X)){
      cout << X << endl;
      return 0;
    }
    X++;
  }
}

Measured memory_bytes: 3588
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a % b);
}

int main()
{
    ll a, b;
    cin>>a>>b;
    ll g = gcd(a, b);
    ll ans = 1;
    for(ll i = 2; i*i <= g; ++i)
    {
        if(g % i == 0)
            ++ans;
        while(g % i == 0)
            g /= i;
    }
    if(g > 1)
        ++ans;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define REP(i, n) for (ll i = 0; i < (int)(n); i++)
#define RREP(i, n) for (ll i = (int)(n)-1; i > -1 ; i--)
#define IN(T, x) T x;cin >> x;
#define AIN(T, a, n) vector<T> a(n);REP(i, n){cin >> a[i];}
#define A2IN(T1, a, T2, b, n) vector<T1> a(n);vector<T2> b(n);REP(i, n){cin >> a[i] >> b[i];}
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) SORT(a);reverse(ALL(a))
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
#define OUT(x) cout << x << endl
#define BOUT(b) if(b){OUT("Yes");}else{OUT("No");}
const ll INF = 100000007;
#define REP10(i, j, M) for(ll i = j; i <= M; i++)

void repeat(ll I, ll M, ll N, ll count, ll &ans, vector<vector<ll>> &p, vector<ll> &num){
  if(count == N){
    ll sum = 0;
    REP(i,p.size()){
      if(num.at(p.at(i).at(1)-1) - num.at(p.at(i).at(0)-1) == p.at(i).at(2))
        sum += p.at(i).at(3);
    }
    chmax(ans, sum);
  }else{
    REP10(i,I,M){
      num.at(count) = i;
      repeat(i, M, N, count+1,ans,p,num);
    }
  }
}

int main() {
  IN(ll, N);
  IN(ll, M);
  IN(ll, Q);
  vector<ll> num(N,0);
  vector<vector<ll>> p(Q, vector<ll>(4));
  REP(i, Q){
    REP(j, 4){
      cin >> p.at(i).at(j);
    }
  }
  ll count = 0;
  ll ans = 0;
  repeat(1,M,N,count,ans,p,num);
  OUT(ans);
                  
}





Measured memory_bytes: 3640
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	vector<string> vecStr;
	vector<int> vecInt;
	int N, M;

	cin >> N;
	for (int i = 0; i < N;++i)
	{
		string str;
		cin >> str;
		bool isFound = false;
		for (int j = 0; j < vecStr.size(); ++j) 
		{
			if (vecStr[j] == str) {
				vecInt[j]++;
				isFound = true;
				break;
			}
		}
		if (!isFound) {
			vecStr.push_back(str);
			vecInt.push_back(1);
		}
	}

	cin >> M;
	for (int i = 0; i < M; ++i)
	{
		string str;
		cin >> str;
		bool isFound = false;
		for (int j = 0; j < vecStr.size(); ++j)
		{
			if (vecStr[j] == str) {
				vecInt[j]--;
				break;
			}
		}
	}

/*	for (int i = 0; i < vecStr.size(); ++i) {
		cout << vecStr[i] << " " << vecInt[i] << endl;
	}*/

	int max = 0;
	for (int i = 0; i < vecStr.size(); ++i) {
		if (vecInt[i] > max) {
			max = vecInt[i];
		}
	}

	if (max < 0) {
		max = 0;
	}
	cout << max;

	system("pause");
	return 0;
}

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

#define ll long long
const int inf = 1e9+7;
const ll INF = 1e18+7;

using namespace std;

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

  int n , d;
  cin >>d>>n;
  if(n == 100) ++n;
  while(d--){
    n *= 100;
  }
  cout<<n<<"\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int dp[MAXN];
char S[MAXN];

int main()
{
    int n,m,k,a,b,x,y;
    ll sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;

    scanf("%s",&S);

    n = strlen(S);

    int re = 0;//numbers of 'A'

    for(int i=0;i<n;i++){
        if(S[i]=='A')re++;
        else if(S[i]=='B'&&S[i+1]=='C'){
            sum+=(ll)re; i++;
        }
        else re = 0;
    }

    cout<<sum;

    return 0;
}


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

typedef long long int ll;
typedef vector<int> vi;			typedef vector<ll> vl;
typedef vector<vi> vvi; 		typedef vector<vl> vvl;
typedef pair<int, int> 	pii;	typedef pair<ll, ll> pll;
typedef vector<pii> vii; 		typedef vector<pll> vll;
typedef map<int,int> mii;
typedef vector<char> vc;
typedef vector<bool> vb;
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define rforne(i,n) for(int i=n;i>=1;i--)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define in insert
#define mp(a, b) make_pair(a, b)
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define INF INT_MAX
#ifdef KARAN
	#include "../../trace.h"
#else
    #define trace(args...)
#endif

ll modpow(ll a, ll b, ll m = MOD){a %= m; ll res = 1; 
	while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}
void graph(vvi &adj, int m) {int x, y; forn(i, m){cin>>x>>y; adj[--x].pb(--y); adj[y].pb(x);}}

void solve(){
	ll x, y, a, b, c;
	cin>>x>>y>>a>>b>>c;
	vl p(a), q(b), r(c);
	forn(i, a) cin>>p[i];
	forn(i, b) cin>>q[i];
	forn(i, c) cin>>r[i];

	sort(all(p), greater<ll>());
	sort(all(q), greater<ll>());
	sort(all(r), greater<ll>());
	
	vl app;
	forn(i, x) app.pb(p[i]);
	forn(i, y) app.pb(q[i]);
	sort(all(app), greater<ll>());
	
	vl pref(x+y+1, 0);
	forne(i, x+y) pref[i] = pref[i-1] + app[i-1];
	
	vl prefc(c+1, 0);
	forne(i, c) prefc[i] = prefc[i-1] + r[i-1];
	trace(app, pref, prefc);
	ll answer = 0;
	forn(i, min(c+1, x+y+1))
		answer = max(answer, pref[x+y-i] + prefc[i]);
	cout<<answer<<endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifdef KARAN
		freopen("inp.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
    	freopen("err.txt", "w", stderr);
	#endif
	int t=1;
	while(t--)
		solve();
}

Measured memory_bytes: 6256
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<vector>

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
    int N;
    string S, T;
    cin >> N;
    cin >> S >> T;
    rep(i, N) cout << S[i] << T[i];
    cout << endl;


	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using ll=unsigned long long;
unsigned long long euclidean_gcd(unsigned long long  a, unsigned long long  b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
    int N,M;
    vector<ll> v;
    cin >> N >> M;
    for(int i = 0;i < N;i++){
        ll a;
        cin >> a;
        v.push_back(a / 2);
    }
    ll lcm = v[0];
    for(int i = 0;i < N;i++){
        lcm = lcm / euclidean_gcd(lcm, v[i]) * v[i];
    }
    bool flg = false;
    for(int i = 0;i < N;i++){
        if((lcm / v[i]) % 2 == 0){
            flg = true;
            break;
        }
    }
    if(flg){
        cout << "0" << endl;
    }else{
        cout << ((M / lcm) + 1)/2 << endl;
    }
}



Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,arr[200],a,b,c,temp=0;
    cin>>n;
    int sum=0;
    for(int i=1; i<=n; i++)
    {
        cin>>arr[i];
    }
    cin>>a;
    for(int k=0; k<a; k++)
    {
        cin>>b>>c;
        temp=arr[b];
        arr[b]=c;
        sum=0;
        for(int j=1; j<=n; j++)
        {
            sum=sum+arr[j];
        }
        cout<<sum<<endl;
        arr[b]=temp;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
    cin>>n;
    int a[3001];
    long long int dp[3001][3001];
    long long int s=0;
   for(int i=0;i<n;i++){cin>>a[i];s=s+a[i];
       for(int j=0;j<n;j++)dp[i][j]=0;
   }
   for (int gap = 0; gap < n; ++gap) { 
        for (int i = 0, j = gap; j < n; ++i, ++j) { 
            long long int x = ((i + 2) <= j) ? dp[i + 2][j] : 0; 
            long long int y = ((i + 1) <= (j - 1)) ? dp[i + 1][j - 1] : 0; 
            long long int z = (i <= (j - 2)) ? dp[i][j - 2] : 0; 
  
            dp[i][j] = max(a[i] + min(x, y), a[j] + min(y, z)); 
        } 
    } 
  // lol(0,n-1);
   long long int ans=dp[0][n-1];
   cout<<2*ans-s<<endl;
}

Measured memory_bytes: 70656
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a * n, b) << endl;
}


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

using namespace std;

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> n;
    vector<ll> a(n);
    for(i = 0; i < n; i++) {
        cin >> a[i];
    }
    if(a[0] != 0) {
        cout << -1 << endl;
        return 0;
    } else {
        vector<pair<ll, ll>> vp;
        ll now = 0;
        for(i = 1; i < n; i++) {
            if(a[i] > i) {
                cout << -1 << endl;
                return 0;
            } else {
                if(a[i] == now + 1)
                    now++;
                else {
                    vp.emplace_back(i - 1, i - 1 - now);
                    now = a[i];
                }
            }
        }
        vp.emplace_back(n - 1, n - 1 - now);
        sort(vp.begin(), vp.end());
        ll lim = 0, cnt = 0;
        for(pair<ll, ll> x : vp) {
            if(x.second < lim) {
                cout << -1 << endl;
                return 0;
            } else {
                lim = max(lim, x.second);
                cnt += a[x.first];
            }
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 7664
#include<bits/stdc++.h>
#define mod 998244353
using namespace std;
inline long long read(){
	long long x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}
long long a,b,n,k,ans,jie[300005],ni[300005];
long long n_(long long x){
	long long res=1,m=mod-2;
	while(m){
		if(m&1) res=(res*x)%mod;
		m>>=1,x=(x*x)%mod;
	}
	return res;
}
long long C(int m,int x){
	return ((jie[m]*ni[x]%mod)*ni[m-x])%mod;
} 
int main(){
	scanf("%lld%lld%lld%lld",&n,&a,&b,&k); 
	long long i;jie[0]=1;
	for(i=1;i<=300001;i++) jie[i]=(jie[i-1]*i)%mod;
	ni[n]=n_(jie[n]);for(i=n-1;i>=0;i--) ni[i]=ni[i+1]*(i+1)%mod;
	for(i=0;i<=n;i++)if(k>=i*a&&(k-i*a)%b==0&&(k-i*a)/b<=n){
		ans=(ans+C(n,i)*C(n,(k-i*a)/b)+mod)%mod;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define EM 100000000
using namespace std;
using LL = long long;
using P = pair<LL, LL>;
LL LINF = 1e18;
int INF = 1e9;
using vint = vector<int>;
using vLL = vector<LL>;
using vvint = vector<vector<int>>;
using vvLL = vector<vector<LL>>;

int main(){
	int N;
	cin >> N;
	vint a(N);
	for(int i = 0;i < N;i++)	cin >> a[i];
	sort(a.begin(), a.end());
	vector<P>	ans;
	int id = N-1;
	for(int i = 0;i < N;i++){
		if(a[i] > 0){
			id = i;
			break;
		}
	}
	for(int i = id+!id;i < N-1;i++){
		ans.push_back(P(a[max(0, id-1)], a[i]));
		a[max(0, id-1)] -= a[i];
	}
	for(int i = 0;i < id+!id;i++){
		ans.push_back(P(a[N-1], a[i]));
		a[N-1] -= a[i];
	}
	cout << a[N-1] << endl;
	for(auto an : ans)	cout << an.first << " " << an.second << endl;
}

Measured memory_bytes: 3952
#include <iostream>

using namespace std;

int
next(int a, int i, int *c, int *s, int *f)
{
        int start = s[i];
        if (start < a) {
                for (; start < a; start += f[i]) {
                }
        }
        return start + c[i];
}

int
main()
{
        int n;
        cin >> n;
        int in = n - 1;
        int c[in], s[in], f[in];
        for (int i = 0; i < in; ++i) {
                cin >> c[i] >> s[i] >> f[i];
        }
        // 到着i: a
        // 出発i: si + fi * x > a
        // 到着i+1: i出発 + ci
        for (int i = 0; i < in; ++i) {
                int a = 0;
                for (int j = i; j < in; ++j) {
                        a = next(a, j, c, s, f);
                }
                cout << a << endl;
        }
        cout << 0 << endl;
        return 0;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main()
{
	int n,i,h[101],a[101],flg,j,k,sa;
	while(1){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		for(i=0;i<n+1;i++){
			scanf("%d",&h[i]);
		}
		for(i=0;i<n+1;i++){
			k=0;
			for(j=0;j<n+1;j++){
				if(i!=j){
					a[k]=h[j];
					k++;
				}
			}
			flg=0;
			sa=a[1]-a[0];
			for(j=1;j<n-1;j++){
				if(sa!=a[j+1]-a[j]){
					flg=1;
					break;
				}
			}
			if(flg==0){
				break;
			}
		}
		printf("%d\n",h[i]);
	}
	return 0;
}


Measured memory_bytes: 2764
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a=n%10;
    int b=(n%100)/10;
    int c=(n%1000)/100;
    int d=(n%10000)/1000;
    int e=(n%100000)/10000;
    int f=(n%1000000)/100000;
    if(n==10||n==100||n==1000||n==10000||n==100000){
        cout<<10<<endl;
    }
    else{
        cout<<a+b+c+d+e+f<<endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b&&a==c){ cout<<1; return 0;}
    if(a==b || a==c || b==c){ cout<<2; return 0;}
    cout<<3;
    return 0;
}

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

class Program {
    static void Main() {
        string str = Console.ReadLine();
        int q = int.Parse(Console.ReadLine());
        for(int i = 0; i < q; i++) {
            string[] cmd = Console.ReadLine().Split();
            int a = int.Parse(cmd[1]);
            int b = int.Parse(cmd[2]);
            if(cmd[0] == "print") Console.WriteLine(str.Substring(a, b - a + 1));
            else if(cmd[0] == "reverse") str = str.Substring(0, a) + string.Join("", str.Substring(a, b - a + 1).Reverse()) + str.Substring(b + 1);
            else str = str.Substring(0, a) + cmd[3] + str.Substring(b + 1);
        }
    }
}


Measured memory_bytes: 18348
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

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

	int stat = a % 2 + b % 2 + c % 2;

	int n = 0;
	if (stat == 2) {
		n++;
		if (a % 2 == 0) {a--;}
		if (b % 2 == 0) {b--;}
		if (c % 2 == 0) {c--;}
	} else if (stat == 1) {
		n++;
		if (a % 2 == 1) {a--;}
		if (b % 2 == 1) {b--;}
		if (c % 2 == 1) {c--;}
	}

	int maxi = max({a, b, c});
	n += (maxi - a) / 2;
	n += (maxi - b) / 2;
	n += (maxi - c) / 2;

	cout << n << endl;
	return 0;
}


Measured memory_bytes: 256
#! /usr/bin/env python3

n = int(input())

v = []

tmp_n = n
plus = 0

if tmp_n < 0:
    plus = 1
    tmp_n *= -1

while tmp_n > 0:
    v.append(tmp_n & 1)
    tmp_n = tmp_n >> 1

r = [0 for _ in range(len(v) + 10)]
for i in range(len(v)):
    if i % 2 == plus:
        r[i] += v[i]
    else:
        r[i] += v[i]
        r[i + 1] += v[i]

for i in range(len(r)):
    while (r[i] >= 2 and r[i + 1] >= 1):
        r[i] -= 2
        r[i + 1] -= 1
    while r[i] >= 2:
        r[i + 1] += 1
        r[i + 2] += 1
        r[i] -= 2

started = False
res = ""
for i in range(len(r)):
    idx = len(r) - 1 - i
    if r[idx] == 1:
        res = res + "1"
        started = True
    elif started == True:
        res = res + "0"

if res == "": res = "0"
print(res)


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        int m,f,r;
        Scanner s = new Scanner(System.in);
        while(true){
            m = s.nextInt();
            f = s.nextInt();
            r = s.nextInt();
            if(m==-1&&f==-1&&r==-1)break;
            if(m==-1||f==-1)System.out.println("F");
            else if(m+f>=80)System.out.println("A");
            else if(m+f>=65)System.out.println("B");
            else if(m+f>=50)System.out.println("C");
            else if(m+f>=30){
                if(r>=50)System.out.println("C");
                else System.out.println("D");
            }
            else System.out.println("F");


        }
    }
}


Measured memory_bytes: 26284
def main():
    # n = int(input())
    n, k = map(int, input().split())
    # h = list(map(int, input().split()))
    # s = input()

    ans = 0
    while True:
        if (n - 1) * ans + 1 >= k:
            print(ans)
            break
        ans += 1


if __name__ == '__main__':
    main()


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

int main(void) {
	char X, Y;
	scanf("%c %c", &X, &Y);
	if (X < Y) printf("<\n");
	else if (X > Y) printf(">\n");
	else printf("=\n");
	return 0;
}


Measured memory_bytes: 3744
#include<stdio.h>
int main()
{
	int A,B,C;
	scanf("%d %d %d",&A,&B,&C);
	if(A==5&&B==5&&C==7||A==5&&B==7&&C==5||A==7&&B==5&&C==5)
		printf("YES\n");
	else
	    printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
using namespace std;
typedef vector<int> vi;
#define rep(i,n) for(int i=0; i<n; i++)
#define repr(i,a,b) for(int i=a; i<b; i++)

int main() {
  int N;
  cin >> N;
  vi d(N);
  rep(i,N) {
    cin >> d[i];
  }

  // rep(i,N) {
  //   cout << d[i] << endl;
  // }

  int ans = 0;
  rep(i,N-1) {
    repr(j,i+1,N) {
      ans += d[i]*d[j];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    long int a,b,c,d;
    cin>>a;
    b=a/11;
    c=a%11;
    
    if(c==0){
        d=2*b;
        cout<<d<<endl;
    }
    else{
    if(c<=6){
        d=2*b+1;
        cout<<d<<endl;
    }
    else{
        d=2*b+2;
        cout<<d<<endl;
    }
    
    }
}

Measured memory_bytes: 256
import * as fs from 'fs';
const input = (fs.readFileSync('/dev/stdin', 'utf8') as string).split('\n');
const n = +input[0];
let previous = [0, 0, 0];
let current = [];
let result = true
for(let i = 0; i < n; i++){
  current = input[i+1].split(' ').map((x: string): number => +x);
  const [ti, xi, yi] = current
  const [tj, xj, yj] = previous
  const dt = ti - tj
  const dist = Math.abs(xi - xj) + Math.abs(yi - yj);
  if (dt < dist) {
    result = false;
    break;
  }
  if (dist % 2 != dt % 2) {
    result = false;
    break;
  }
  previous = current
}
console.log(result ? 'Yes' : 'No');

Measured memory_bytes: 29260
def post_pd(t):
    string_list = ''
    for i in t:
        if i == '?':
            string_list = string_list + 'D'
        else:
            string_list = string_list + i
    
    return string_list

if __name__ == '__main__':
    t = input()
    print(post_pd(t))

Measured memory_bytes: 9460
def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

N = list(get_input())
N.sort()

N1,N2 = N[0].split()
word = N1
pnum = []
pnum.append(int(N2))

for l in range(1, len(N)):
    N1,N2 = N[l].split()

    if word != N1:
        print(word)
        pnum.sort()
        print(pnum[0], end="")
        for i in range(1, len(pnum)):
            print(" ", end="")
            print(pnum[i], end="")
        print("")
        word = N1
        pnum.clear()
        pnum.append(int(N2))
    else:
        pnum.append(int(N2))

print(word)
pnum.sort()
print(pnum[0], end="")
for i in range(1, len(pnum)):
    print(" ", end="")
    print(pnum[i], end="")
print("")


Measured memory_bytes: 5620
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

class mint {
  private:
    ll x;

  public:
    constexpr mint(const ll x = 0) noexcept : x((x % MOD + MOD) % MOD) {}
    constexpr ll value() noexcept { return x; }
    constexpr mint operator += (const mint right) noexcept {
      if ((x += right.x) >= MOD) x -= MOD;
      return *this;
    }
    constexpr mint operator -= (const mint right) noexcept {
      if ((x += MOD - right.x) >= MOD) x -= MOD;
      return *this;
    }
    constexpr mint operator *= (const mint right) noexcept {
      x = x * right.x % MOD;
      return *this;
    }
    constexpr mint operator /= (const mint right) noexcept {
      return *this *= right.inv();
    }
    constexpr mint operator + (const mint right) const noexcept {
      return mint(*this) += right;
    }
    constexpr mint operator - (const mint right) const noexcept {
      return mint(*this) -= right;
    }
    constexpr mint operator / (const mint right) const noexcept {
      return mint(*this) /= right;
    }
    constexpr mint operator * (const mint right) const noexcept {
      return mint(*this) *= right;
    }
    constexpr mint inv() const {
      return pow(MOD-2);
    }
    constexpr mint pow(ll n) const {
      if (n == 0) return 1;
      mint a = pow(n>>1);
      a *= a;
      if (n & 1) a *= *this;
      return a;
    }
};

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

  COMinit();
  
  int n, k; cin >> n >> k;
  vll a(n);

  rep(i, n) cin >> a[i];
  sort(all(a));

  mint left(0), right(0);

  rep(i, n-k+1) left += a[i] * COM(n-i-1, k-1);
  rep3(i, n-1, k-1) right += a[i] * COM(i, k-1);

  cout << (right - left).value() << endl;
  
  return (0);
}

Measured memory_bytes: 15848
ans = Array.new(10**4+1, 0)
(1..100).each{|i|
  (1..100).each{|j|
    (1..100).each{|k|
      wk = i**2 + j**2 + k**2 + i*j + j*k + k*i
      ans[wk] += 1 if wk <= 10**4
    }
  }
}

puts ans[1, gets.to_i]*?\n


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

public class Hello
{
    public static void Main()
    {
        string[] str = Console.ReadLine().Split(' ');
        int N = int.Parse(str[0]);
        int Y = int.Parse(str[1])/1000;

        for(int i = 0; i <= N; i++)
        {
            for(int j = 0; j <= N - i; j++)
            {
                int k = N - i - j;
                if(i+j*5+k*10 == Y)
                {
                    Console.WriteLine("{0} {1} {2}",k,j,i);
                    return;
                }

            }
        }
        Console.WriteLine("-1 -1 -1");
        return;
    }
    
}

Measured memory_bytes: 13140
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    
    long long a,b,c,k,ans,max;
    max = pow( 10.0, 18.0);
    cin >> a >> b >> c >> k;
    
    if( (k % 2) == 0 ) ans = a-b;
    else ans = b-a;
    
    if(abs(ans) > max) cout << "Unfair" << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void){
	int i,j,l,f=1;
	char s[1001];
	scanf("%s",s);
	l=strlen(s);
	for(i=0;i<l;i++){
		if(f){
			if(s[i]=='N'){
				for(j=0;j<l;j++){
					if(s[j]=='S') break;
				}
				if(j==l) f=0;
			}
			if(s[i]=='W'){
				for(j=0;j<l;j++){
					if(s[j]=='E') break;
				}
				if(j==l) f=0;
			}
			if(s[i]=='S'){
				for(j=0;j<l;j++){
					if(s[j]=='N') break;
				}
				if(j==l) f=0;
			}
			if(s[i]=='E'){
				for(j=0;j<l;j++){
					if(s[j]=='W') break;
				}
				if(j==l) f=0;
			}
		}
		else break;
	}
	if(f) puts("Yes");
	else puts("No");
	return 0;
}

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

typedef long long ll;
typedef long double ld;

const int MOD = 1000000007;
ll pw2[200005];

map <pair <ll, ll>, ll> cnt;

ll gcdd(ll a, ll b){
    if(a < b) swap(a, b);
    if(b == 0) return a;
    return gcdd(b, a%b);
}

ll add(ll a, ll b){
    a %= MOD;
    b %= MOD;
    return (a+b)%MOD;
}

ll mul(ll a, ll b){
    a %= MOD;
    b %= MOD;
    return (1LL*a*b)%MOD;
}

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;
    pw2[0] = 1;
    for(int i=1; i<=n; i++) pw2[i] = mul(pw2[i-1], 2);
    ll res = 1, imaa = 0, imab = 0;
    ll dod = 0;
    for(int i=1; i<=n; i++){
        ll a, b;
        cin >> a >> b;
        if(a == 0 && b == 0){
            n--;
            i--;
            dod++;
            continue;
        }
        if(a == 0){
            imaa++;
            continue;
        }
        if(b == 0){
            imab++;
            continue;
        }
        ll nzd = gcdd(abs(a), abs(b));
        a /= nzd;
        b /= nzd;
        if(a < 0 && b < 0){
            a = -a;
            b = -b;
        }
        if(b < 0){
            a = -a;
            b = -b;
        }
        cnt[{a, b}]++;
    }
    for(auto c : cnt){
        if(c.second == 0) continue;
        ll a = c.first.first;
        ll b = c.first.second;
        ll a1, b1;
        if(a < 0){
            a1 = b;
            b1 = -a;
        }
        else{
            a1 = -b;
            b1 = a;
        }
        ll p = cnt[{a, b}];
        ll d = cnt[{a1, b1}];
        cnt[{a, b}] = cnt[{a1, b1}] = 0;
        res = mul(res, add(1, add(pw2[p]-1, pw2[d]-1)));
    }
    res = mul(res, add(1, add(pw2[imaa]-1, pw2[imab]-1)));
    cout << add(res, MOD-1+dod);
    return 0;
}


Measured memory_bytes: 30036
a,b=input(),input();
length = len(a)+len(b)
result = []
count1 = 0
count2 = 0
for i in range(length):
  if i % 2 == 0:
    try:
      result.append(a[count1])
      count1 += 1
    except:
      continue
  else:
    try:
      result.append(b[count2])
      count2 += 1
    except:
      continue
print(''.join(result))

Measured memory_bytes: 8984
import numpy as np
N, W = map(int, input().split())
ndp = np.zeros(W+1, dtype= np.int64)
for _ in range(N):
    w, v = map(int,input().split())
    np.maximum(ndp[:-w] + v, ndp[w:], out = ndp[w:])
print(ndp[-1])


Measured memory_bytes: 14572
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<fstream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

vector<ll> A;

bool tallest(ll index){
    ll h = A[index];
    FOR(i, 0, index){
        if(A[i]>h){
            return false;
        }
    }
    return true;
}

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

    // input
    ll N;
    cin >> N;
    A.resize(N);

    FOR(i, 0, N){
        cin >> A.at(i);
    }

    if(N==1){
        p(1);
        return 0;
    }

    ll count = 1;
    FOR(i, 1, N){
        if(tallest(i)){
            count++;
        }
    }

    p(count);
    
    return 0;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a, b = MAP()
print((b - a)*(b - a - 1) // 2 - a)

Measured memory_bytes: 5392
#include <iostream>

using namespace std;

int Atoi(char c) { return c - '0'; }

int Sig(bool flag, int x) { return flag ? -x : x; }

int main() {
  char buf[8] = {0};
  cin >> buf;
  const int A = Atoi(buf[0]);
  const int B = Atoi(buf[1]);
  const int C = Atoi(buf[2]);
  const int D = Atoi(buf[3]);

  for (int i = 0; i < 8; ++i) {
    int n = A + Sig(i & 0x1, B);
    n += Sig(i & 0x2, C);
    n += Sig(i & 0x4, D);

#define OP(cond) ((cond)) ? '-' : '+'
    if (n == 7) {
      printf("%d%c%d%c%d%c%d=7\n", A, OP(i & 0x1), B, OP(i & 0x2), C,
             OP(i & 0x4), D);
      break;
    }                                                                                                                                                                                
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T>
T gcd(const T a, const T b)
{
    return (b != 0) ? gcd(b, a % b) : a;
}

template <typename T>
T lcm(const T a, const T b)
{
    return (a / gcd(a, b)) * b;
}

int main()
{
    int N;
    cin >> N;
    ll ans = 1;
    for (int i = 0; i < N; i++) {
        ll a;
        cin >> a;
        ans = lcm(ans, a);
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3084
// E - Sequence Sum
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rp(i,s,e) for(int i=(int)(s);i<(int)(e);++i)

int main(){
	ll N; int X, M; cin>>N>>X>>M;

	int mn = min(N, (ll)M);
	set<ll> S;
	vector<ll> A;
	ll a = X;
	ll ans = 0;

	rp(_i, 0, mn){
		if(S.find(a) != S.end()) break;
		S.insert(a);
		A.push_back(a);
		ans += a;
		a = a*a % M;
		a = (a + M) % M;
		if(a == 0){
			cout<< ans <<endl;
			return 0;
		}
	}

	if((int)A.size() >= mn){
		cout<< ans <<endl;
		return 0;
	}

	int st_len = 0;
	while(st_len < (int)A.size() && a != A[st_len]) st_len += 1;
	ll st = 0; rp(i, 0, st_len) st += A[i];
	ll cyc_sum = 0; rp(i, st_len, A.size()) cyc_sum += A[i];
	int cyc_len = A.size() - st_len;
	int ed_len = (N - st_len) % cyc_len;
	ll cyc_num = (N - st_len) / cyc_len;
	ll ed = 0; rp(i, st_len, st_len + ed_len) ed += A[i];
	cout<< st + cyc_sum * cyc_num + ed <<endl;
}


Measured memory_bytes: 5836
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
using namespace std;
#define N 605
bool vis[N][N][2];
int n,cnt;
int main(){
	scanf("%d",&n);
	rep (op,0,1){
		int d,len=0;scanf("%d",&d);
		while (d%4==0) d/=4,len++;
		if (d%4==2){
			rep (i,0,2*n-1) rep (j,0,2*n-1)
				if (i>>len&1) vis[i][j][op]=1;
		} else{
			rep (i,0,2*n-1) rep (j,0,2*n-1)
				if ((i>>len)+(j>>len)&1) vis[i][j][op]=1;
		}
	}
	rep (i,0,2*n-1) rep (j,0,2*n-1)
		if (!vis[i][j][0]&&!vis[i][j][1]){
			printf("%d %d\n",i,j);
			if (++cnt==n*n) exit(0);
		}
	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define sd(a) scanf("%d", &a)
#define sd2(a,b) scanf("%d%d", &a, &b)
#define sd3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sld(a) scanf("%lld", &a)
#define sld2(a,b) scanf("%lld%lld", &a, &b)
#define sld3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define pd(a) printf("%d", a)
#define pld(a) printf("%lld", a)
#define sp printf(" ")
#define nl printf("\n")
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define clr(a, val) memset((a), (val), sizeof(a))
#define pb push_back
#define endl "\n"
#define mp(a, b) make_pair(a, b)
#define pii pair<int, int>
#define xx first
#define yy second
#define mx 51
vector<int> v[mx];
int vis[mx];
void dfs(int cur)
{
	vis[cur]=1;
	for(int i=0;i<v[cur].size();i++)
		if(!vis[v[cur][i]])
			dfs(v[cur][i]);
}
int main()
{
	clr(vis, 0);
	int n,m;sd2(n,m);
	while(m--)
	{
		int x,y;sd2(x,y);
		v[x].pb(y);
		v[y].pb(x);
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<v[i].size();j++)
		{
			vis[i]=1;
			for(int k=0;k<v[i].size();k++)
				if(k!=j)
					dfs(v[i][k]);
			if(vis[v[i][j]]==0)
				ans++;
			clr(vis,0);
		}
	}
	pd(ans/2);nl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int a,b,c;
    scanf("%d",&a);
    c=1;
    for(b=1;b<=9;b++)
    {
        if(a==b*c)
            {
                printf("Yes");
                exit(0);
            }
        else
        {
            for(c=1;c<=b;c++)
            {
                if(a==b*c)
                    {
                        printf("Yes");
                        exit(0);
                    }
            }
        }

    }printf("No");
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define pb emplace_back
#define rt(v) return cout<<v,0
#define sz(v) (int)(v.size())
#define all(a) a.begin(),a.end()
#define endl '\n'
#define space " "
typedef long long ll;
typedef unsigned long long ull;
const int N = 10 + 1e5;
const int mod = 1e9 + 7;
/*

███╗   ███╗███████╗███╗   ███╗███████╗    ██╗      ██████╗ ██████╗ ██████╗
████╗ ████║██╔════╝████╗ ████║██╔════╝    ██║     ██╔═══██╗██╔══██╗██╔══██╗
██╔████╔██║█████╗  ██╔████╔██║█████╗      ██║     ██║   ██║██████╔╝██║  ██║
██║╚██╔╝██║██╔══╝  ██║╚██╔╝██║██╔══╝      ██║     ██║   ██║██╔══██╗██║  ██║
██║ ╚═╝ ██║███████╗██║ ╚═╝ ██║███████╗    ███████╗╚██████╔╝██║  ██║██████╔╝
╚═╝     ╚═╝╚══════╝╚═╝     ╚═╝╚══════╝    ╚══════╝ ╚═════╝ ╚═╝  ╚═╝╚═════╝

*/

using namespace std;
void Ferrari() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int const n = 10 + 1e5;
int frq[n];
int main() {
	int s; cin >> s;
	vector<int>v(s);
	for (int i = 0; i < s; ++i)
	{
		cin >> v[i];
		frq[v[i]]++;
	}
	int ans = -1;
	for (int i = 0; i < s; ++i) {
		int c1 = frq[v[i]] + frq[v[i] + 1];
		if (v[i] - 1 >= 0) c1 += frq[v[i] - 1];
		int c2 = frq[v[i]] + frq[v[i] + 1] + frq[v[i] + 2];
		int c3 = frq[v[i]];
		if (v[i] - 1 >= 0) c3 += frq[v[i] - 1];
		if (v[i] - 2 >= 0) c3 += frq[v[i] - 2];
		ans = max({ ans,c1,c2,c3 });
	}
	cout << ans;
	return 0;
}
//1 2 3 4 5 -


//5 4 3 2 1
/* stuff you should look for
	* keepin sharp mind.
	* int overflow, array bounds.
	* special cases (n=1?), set tle , make sure you understand the problem correctly.
	* don`t stuck in a problem.
	* test the idea on samples.
	*/

Measured memory_bytes: 1024
def insertionSort(a, n, g, cnt):
    for i in range(g,n):
        v = a[i]
        j = i-g
        while j >= 0 and a[j] > v:
            a[j+g] = a[j]
            j -= g
            cnt += 1
        a[j+g] = v
    return cnt


def shellSort(a, n):
    g = []
    h = 1
    while True:
        if h > n:
            break
        g.append(h)
        h = 3*h + 1
    cnt = 0
    m = len(g)
    for i in range(m-1,-1,-1):
        cnt = insertionSort(a, n, g[i], cnt)
    print(m)
    print(' '.join(list(map(str, g[::-1]))))
    print(cnt)
    for k in a:
        print(k)



n = int(input())
aa = [0]*n
for i in range(n):
    aa[i] = int(input())
shellSort(aa, n)



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

using namespace std;

const int maxn = 1e5+10;

vector<int> grafo[maxn], chat[maxn];

int mark[maxn], c, sz[maxn], s;

void dfs(int u){
    mark[u] = c;

    s++;

    for(auto v : grafo[u]){
        if(!mark[v]){
            dfs(v);
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int n, m, k;

    cin >> n >> m >> k;

    for(int i=1; i<=m; i++){
        int u, v;

        cin >> u >> v;

        grafo[u].push_back(v);
        grafo[v].push_back(u);
    }

    for(int i=1; i<=k; i++){
        int u, v;

        cin >> u >> v;

        chat[u].push_back(v);
        chat[v].push_back(u);
    }

    for(int i=1; i<=n; i++){
        if(!mark[i]){
            c++;
            s = 0;
            dfs(i);
            sz[c] = s;
        }
    }

    for(int i=1; i<=n; i++){
        int ans = sz[mark[i]] - 1;

        set<int> a;

        for(auto v : chat[i]){
            if(mark[v] == mark[i] and a.find(v) == a.end()){
                ans--;
                a.insert(v);
            }
        }

        for(auto v : grafo[i]){
            if(a.find(v) == a.end()){
                ans--;
                a.insert(v);
            }
        }

        cout << ans << " ";
    }

    return 0;
}


Measured memory_bytes: 16888
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>

using namespace std;

typedef pair<int, int> P;
#define FOR(i, a, b) for(ll (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
#define Print(p) cout<<(p)<<endl
#define _1 first
#define _2 second
#define pb push_back
#define bigmod 1000000007
#define INF 1050000000

const int maxn = 1e5 + 10;
ll n, m, u, v;
ll dist[maxn];
vector<pair<ll, ll>> g[maxn];

void dfs(ll to, ll from, ll cost) {
	dist[to] = cost;
	for(auto i:g[to]) {
		if (i.first == from) continue;
		dfs(i.first, to, cost+i.second);
	}
}

int main() {
	C(n);
	rep(i, n-1) {
		ll a, b, c;
		cin >> a >> b >> c;
		g[a].pb(pair<ll,ll>(b, c));
		g[b].pb(pair<ll,ll>(a, c));
	}
	ll q, k;
	cin >> q >> k;
	ll x[maxn], y[maxn];
	rep(i, q) {
		cin >> x[i] >> y[i];
	}
	dfs(k,0,0);
	//rep(i, n+1)Print(dist[i]);
	rep(i, q) Print(dist[x[i]] + dist[y[i]]);
	return 0;
}

Measured memory_bytes: 15872