akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using namespace std;

int main(){
	int A, B;
	cin >> A >> B;
	int ans = 0;
	for (int i = A; i <= B; i++) {
		string S = to_string(i);
		if (S[0]==S[4] && S[1]==S[3]) ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3764
#include<cstdio>
#include<vector>
using std::vector;
int vis[200005], size[200005];
vector<int>g[200005];

void dfs(int u,int c){
    vis[u] = 1;
    size[c]++;
    for(int v: g[u]){
        if(vis[v]==0) dfs(v,c);
    }
}

int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i = 0; i < m; i++){
        int u,v;
        scanf("%d%d",&u,&v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    int cnt = 0; int ans = 0;
    for(int i = 1; i <= n; i++){
        if(!vis[i]){
            cnt++;
            dfs(i,cnt);
            if(ans<size[cnt]) ans = size[cnt];
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 24348
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>

#define FOR(i, a) for(int i=0;i<(int)a;++i)
typedef long long ll;
typedef long double ld;
using namespace std;

void solver() {
    int w, n;
    vector<int> a, b;
    vector<pair<int, int>> ans;
    cin >> w;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int ta, tb;
        scanf("%d,%d", &ta, &tb);
        a.push_back(ta);
        b.push_back(tb);
    }

    FOR(i, w) {
        auto p = i + 1;
        FOR(j, n) {
            if (p == a[j]) {
                p = b[j];
            } else if (p == b[j]) {
                p = a[j];
            }
        }
        ans.push_back({p, i + 1});
    }
    sort(ans.begin(), ans.end());

    FOR(i, w) cout << ans[i].second << endl;
}

int main() {
    solver();
    return 0;
}

Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repa(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define COUT(x) cout << (x) << endl
#define VIEW(x) do{cout << "--" << #x << "--" << endl; view(x);}while(0)
template<typename T> void view(T e){COUT(e);}
template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
#define _GLIBCXX_DEBUG

int main(){
  
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << min(a, b) + min(c, d) << endl;

}

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

int main(){
    bool YYMM=false,MMYY=false;
    string S;
    int s[10];
    cin>>S;
    for(int i=0;i<4;++i)
        s[i]=S[i]-'0';
    
    if(s[0]==0 && s[1]!=0) MMYY=true;
    if(s[0]==1 && (s[1]==0 || s[1]==1 || s[1]==2))MMYY=true;

    if(s[2]==0 && s[3]!=0) YYMM=true;
    if(s[2]==1 && (s[3]==0 || s[3]==1 || s[3]==2))YYMM=true;

    if(MMYY && YYMM)cout<<"AMBIGUOUS"<<endl;
    if(MMYY && !YYMM)cout<<"MMYY"<<endl;
    if(!MMYY && YYMM)cout<<"YYMM"<<endl;
    if(!MMYY && !YYMM)cout<<"NA"<<endl;

    return 0;   
}

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

lint n, m;
vector<lint> a;

int main() {
    cin >> n >> m;
    a.resize(n);
    lint sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    sort(a.begin(), a.end(), greater<lint>());
    for (int i = 0; i < m; i++) {
        if (a[i] * 4 * m < sum) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const ld eps = 1e-9;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
struct Elm {
  int d;
  vi v;
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n; cin >> n;
  vi a(n);
  for(int i=0;i<n;++i) {
    cin >> a[i];
    a[i]--;
  }
  queue<Elm> pq;
  map<vi, P> mp;
  map<vi, bool> upd1, upd2;
  pq.push({0, a});
  mp[a].first = 0;
  upd1[a] = true;
  while(!pq.empty()) {
    auto now = pq.front(); pq.pop();
    if(upd1[now.v] && mp[now.v].first < now.d) continue;
    for(int i=0;i<n;++i) {
      for(int j=i+1;j<n;++j) {
        for(int k=0;k<(j-i+1)/2;++k) {
          swap(now.v[i+k], now.v[j-k]);
        }
        if((!upd1[now.v] || mp[now.v].first > now.d + 1) && now.d < 4) {
          upd1[now.v] = true;
          mp[now.v].first = now.d + 1;
          if(now.d+1 < 4) pq.push({now.d + 1, now.v});
        }
        for(int k=0;k<(j-i+1)/2;++k) {
          swap(now.v[i+k], now.v[j-k]);
        }
      }
    }
  }
  vi init(n);
  for(int i=0;i<n;++i) {
    init[i] = i;
  }
  pq.push({0, init});
  mp[init].second = 0;
  upd2[init] = true;
  while(!pq.empty()) {
    auto now = pq.front(); pq.pop();
    if(upd2[now.v] && mp[now.v].second < now.d) continue;
    for(int i=0;i<n;++i) {
      for(int j=i+1;j<n;++j) {
        for(int k=0;k<(j-i+1)/2;++k) {
          swap(now.v[i+k], now.v[j-k]);
        }
        if((!upd2[now.v] || mp[now.v].second > now.d + 1) && now.d < 4) {
          upd2[now.v] = true;
          mp[now.v].second = now.d + 1;
          if(now.d+1 < 4) pq.push({now.d + 1, now.v});
        }
        for(int k=0;k<(j-i+1)/2;++k) {
          swap(now.v[i+k], now.v[j-k]);
        }
      }
    }
  }
  int ans = n-1;
  for(auto &e: mp) {
    if(upd1[e.first] && upd2[e.first]) ans = min(ans, e.second.first + e.second.second);
  }
  cout << ans << endl;
}



Measured memory_bytes: 194092
N,M = map(int,input().split())
A = list(map(int,input().split()))

import heapq
class Heapq:
    def __init__(self, arr, desc=False):
        if desc:
            arr = [-a for a in arr]
        self.sign = -1 if desc else 1
        self.hq = arr
        heapq.heapify(self.hq)

    def pop(self):
        return heapq.heappop(self.hq) * self.sign

    def push(self, a):
        heapq.heappush(self.hq, a * self.sign)

    def top(self):
        return self.hq[0] * self.sign

    def size(self):
        return len(self.hq)

q = Heapq(A, True)

for _ in range(M):
    a = q.pop()
    q.push(a//2)

print(-sum(q.hq))


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

using namespace std;

int INF=1e9;

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

    int n;
    cin>>n;

    vector<int> p(n);
    for(int i=0;i<n;i++){
        cin>>p[i];
        p[i]--;
    }

    int ans=0;

    if(p[0]==0){
        ans++;
        int w=p[0];
        p[0]=p[1];
        p[1]=w;
    }

    for(int i=1;i<n-1;i++){
        if(p[i]==i){
            ans++;
            int w=p[i];
            p[i]=p[i+1];
            p[i+1]=w;
        }
    }

    if(p[n-1]==n-1)ans++;

    cout<<ans<<endl;

}

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

int n, m, k;

inline void input (int &ret) {
	ret = 0; char ch = getchar ();
	while (!isdigit (ch)) ch = getchar ();
	while (isdigit (ch)) {
		ret = (ret << 1) + (ret << 3) + (ch ^ '0');
		ch = getchar ();
	}
	return;
}

char ch[7][7];
bool vis[7], visitttttttttt[7];
char change[7][7];
int ans;

inline void dfs (int nwwwwwww) {
	if (nwwwwwww == n + m + 1) {
		for (int i = 1; i <= n; ++ i) {
			for (int j = 1; j <= m; ++ j) change[i][j] = ch[i][j];
		}
		int cnt = 0;
		for (int i = 1; i <= n; ++ i) {
			for (int j = 1; j <= m; ++ j) {
				if (vis[i] || visitttttttttt[j]) change[i][j] = '.';
			}
		}
		for (int i = 1; i <= n; ++ i) {
			for (int j = 1; j <= m; ++ j) cnt += (change[i][j] == '#');
		}
		if (cnt == k) ++ ans;
		return;
	}
	if (nwwwwwww > n) {
		visitttttttttt[nwwwwwww - n] = true; dfs (nwwwwwww + 1);
		visitttttttttt[nwwwwwww - n] = false; dfs (nwwwwwww + 1);
		return;
	}
	if (nwwwwwww <= n) {
		vis[nwwwwwww] = true; dfs (nwwwwwww + 1);
		vis[nwwwwwww] = false; dfs (nwwwwwww + 1);
		return;
	}
	return;
}

int main () {
	cin >> n >> m >> k;
	for (int i = 1; i <= n; ++ i) {
		for (int j = 1; j <= m; ++ j) cin >> ch[i][j];
	}
	dfs (1);
	cout << ans << endl;
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> d(101);
  int m;
  rep(i,n) {cin >> m; d.at(m) = 1;}
  int ans = 0;
  rep(i,101) ans += d.at(i);
  cout << ans << endl;
}

Measured memory_bytes: 3544
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    string n;
    cin >> n;
    if ((n[0] == n[1] && n[1] == n[2]) || (n[1] == n[2] && n[2] == n[3]))
        cout << "Yes"
             << "\n";
    else
        cout << "No"
             << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
ll dp[55][3005];
// dp[i][j] means i length and sum j
int a[55];
int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
    int n,av;
    scanf("%d%d",&n,&av);
    int i;
    for(i=1;i<=n;i++)scanf("%d",&a[i]);
    dp[0][0] = 1;
    int j,k;
    for(i=1;i<=n;i++)
        {
        for(j=i-1;j>=0;j--)
            {
            for(k=0;k<=2500;k++)
                {
                int cur = k + a[i];
                dp[j+1][cur] += dp[j][k];
            }
        }
    }
    ll ans = 0;
   for(int len = 1; len<=n;len++)
       {
       ans += dp[len][av*len];
   }
    printf("%lld\n",ans);
    return 0;
}


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

int main(){
	ll r,d;cin>>r>>d;
	ll x;cin>>x;
	for(int i=1;i<=10;i++){
		x=r*x-d;
		cout<<x<<endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{
	static Scanner in;
	static long gcd(long p,long q)
	{
		if(p<q){long t=p;p=q;q=t;}
		if(q==0)return p;
		return gcd(q,p%q);
	}
	static long lcm(long p,long q)
	{
		return p*q/gcd(p,q);
	}
	public static void main(String[] args)
	{
		in=new Scanner(System.in);

		while(in.hasNext())
		{
		    long n,m;
			n=in.nextLong();m=in.nextLong();
		    System.out.println(gcd(n,m)+" "+lcm(n,m));
		}
	}
}

Measured memory_bytes: 17376
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.System.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    static void solve() throws Exception {
        String n = scanString();
        long nn = 0;
        for (int i = 0; i < n.length(); i++) {
            nn += Long.valueOf(n.charAt(i)-48);
        }
        out.print(nn % 9 == 0 ? "Yes" : "No");
    }

    static int scanInt() throws IOException {
        return parseInt(scanString());
    }

    static long scanLong() throws IOException {
        return parseLong(scanString());
    }

    static String scanString() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            solve();
            in.close();
            out.close();
        }
        catch (Throwable e) {
            e.printStackTrace();
            exit(1);
        }
    }
}

Measured memory_bytes: 36136
#include <iostream>
#include <cmath>
#include <vector>

typedef long long ll;

using namespace std;


int main() {
    int n, k;
    cin >> n >> k;
    int h[n + 1];
    int cost[n + 1];
    for (int i = 1; i < n + 1; ++i) {
        cin >> h[i];
        cost[i] = INT32_MAX;
    }
    cost[1] = 0;
    for (int i = 2; i <= n; ++i) {
        for (int j = i - 1; j >= max(1, i - k); j--) {
            cost[i] = min(cost[j] + abs(h[i] - h[j]), cost[i]);
        }
    }
    cout<<cost[n];
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>

int main()
{
    int A, B, T;
    std::cin >> A >> B >> T;
    int time = A;
    int ans = 0;
    while(time <= T)
    {
        ans += B;
        time += A;
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 256
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N = int(input())
    P = list(iim())
    m = P[0]
    i = 0
    for pi in P:
        if pi > m:
            continue
        m = pi
        i += 1
    print(i)

if __name__ == "__main__":
    resolve()


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
    int n, k; cin >> n >> k;
    int ans = 1;
    for(int i = 0; i < n; i++){
        if(ans * 2 - ans < k){
            ans *= 2;
        }else{
            ans += k;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int H; cin >> H;
    int N; cin >> N;
    vpi data(N);
    F0R(i, N) {
        int A, B; cin >> A >> B; data[i] = {A, B};
    }
    int dp[H+1]; dp[0] = 0; FOR(i, 1, H+1) dp[i] = 1000000000;

    FOR(h, 1, H+1) {
        F0R(i, N) {
            dp[h] = min(dp[h], dp[max(h-data[i].f, 0)] + data[i].s);
        }
    }

    cout << dp[H] << endl;

	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	int t,x;
	cin >> t >> x;
	cout << (double) t/x << endl;
	return 0;
}


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

arm = []
for i in range(N):
    X, L = map(int, input().split())
    arm.append((X - L, X + L))

arm = sorted(arm, key=lambda x: x[1])

count = 0
i = arm[0][0]
for start, end in arm:
    if start < i:
        continue
    i = end
    count += 1

print(count)


Measured memory_bytes: 19028
/** 
 *  Author : Parth Prajapati
 * 	Institute : Pandit Deendayal Petroleum University
**/
#include<bits/stdc++.h>

using namespace std; 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m;
    cin>>n>>m;
    int ans = (n*(n-1))/2 + (m*(m-1))/2;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

void kock(double,double,double,double,int);

double equ_tri_x(double,double);
double equ_tri_y(double,double);

int n;

int main(void){
	scanf("%d",&n);

	kock(0,0,100,0,0);

	return 0;
}


void kock(double x1,double y1,double x5,double y5,int cnt){
	double x2,y2;
	double x3,y3;
	double x4,y4;


	if(cnt==n){
		printf("%f %f\n",x1,y1);
	}
	else{
		x2=(x5-x1)/3.0+x1;
		y2=(y5-y1)/3.0+y1;
		x4=(x5-x1)/3.0*2.0+x1;
		y4=(y5-y1)/3.0*2.0+y1;

		x3=equ_tri_x(x4-x2,y4-y2)+x2;
		y3=equ_tri_y(x4-x2,y4-y2)+y2;

		kock(x1,y1,x2,y2,cnt+1);

		kock(x2,y2,x3,y3,cnt+1);
		
		kock(x3,y3,x4,y4,cnt+1);
		
		kock(x4,y4,x5,y5,cnt+1);
	}

	if(cnt==0) printf("%f %f\n",x5,y5);
}


double equ_tri_x(double dx,double dy){
	return (dx/2.0)-(sqrt(3.0)/2.0*dy);
}


double equ_tri_y(double dx,double dy){
 	return (sqrt(3.0)/2.0*dx)+(dy/2.0);
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <stdlib.h>
#include <iomanip>

using namespace std;

#define ll long long
#define vi vector<int>
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pi 3.14159265359


ll gcd(ll a, ll b)
{
	ll c;
	while (a != 0) {
		c = a; a = b % a;  b = c;
	}
	return b;
}

int main() {
	ll A, B, K;
	ll sum = 0;
	ll sums[100];
	cin >> A >> B >> K;
	FOR(i, 1, 101) {
		if (A % i == 0) {
			if (B % i == 0) {
				sums[sum] = i;
				sum++;
			}
		}
	}
	cout << sums[sum - K];

	return 0;
}

Measured memory_bytes: 256
S = input()
T = input()
M = len(S)
N = len(T)
for start in range(M-N,-1,-1):
    for i in range(N):
        if not (S[start+i] == '?' or S[start+i] == T[i]):
            break
    else:
        end = start + N
        pre = ''
        post = ''
        for i in range(start):
            if S[i] == '?':
                pre += 'a'
            else:
                pre += S[i]
        for i in range(end,M):
            if S[i] == '?':
                post += 'a'
            else:
                post += S[i]
        print(pre + T + post)
        exit()
else:
    print('UNRESTORABLE')


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
struct BiconectedGraph{
  typedef pair<int,int> P;
  int n;
  vector<vector<int> > G,C,T;
  vector<int> ord,low,belong;
  vector<P> B;
  BiconectedGraph(){}
  BiconectedGraph(int sz):n(sz),G(sz),C(sz),T(sz){}
  
  void add_edge(int u,int v){
    G[u].push_back(v);
    G[v].push_back(u);
  }

  void input(int m,int offset=0){
    int a,b;
    for(int i=0;i<m;i++){
      cin>>a>>b;
      add_edge(a+offset,b+offset);
    }
  }
  
  bool is_bridge(int u,int v){
    if(ord[u]>ord[v]) swap(u,v);
    return ord[u]<low[v];
  }
  
  void dfs(int v,int p,int &k){
    ord[v]=low[v]=k;
    ++k;
    for(int u:G[v]){
      if(u==p) continue;
      if(ord[u]>=0){
	low[v]=min(low[v],ord[u]);
      }else{
	dfs(u,v,k);
	low[v]=min(low[v],low[u]);
      }
      if(is_bridge(u,v)) B.push_back(P(u,v));
    }
  }
  
  void fill_component(int c,int v){
    C[c].push_back(v);
    belong[v]=c;
    for(int u:G[v]){
      if(belong[u]>=0||is_bridge(u,v)) continue;
      fill_component(c,u);
    }
  }
  
  void add_component(int v,int &k){
    if(belong[v]>=0) return;
    fill_component(k++,v);
  }
  
  int build(){
    int k=0;
    ord.resize(n);
    low.resize(n);
    belong.resize(n);
    fill(ord.begin(),ord.end(),-1);
    fill(belong.begin(),belong.end(),-1);
    for(int v=0;v<n;v++){
      if(ord[v]>=0) continue;
      dfs(v,-1,k);
    }
    k=0;
    for(int i=0;i<(int)B.size();i++){
      add_component(B[i].first,k);
      add_component(B[i].second,k);
    }
    for(int v=0;v<n;v++) add_component(v,k);
    for(int i=0;i<(int)B.size();i++){
      int u=belong[B[i].first],v=belong[B[i].second];
      T[u].push_back(v);
      T[v].push_back(u);
    }
    return k;
  }
};
//END CUT HERE

signed main(){
  int v,e;
  cin>>v>>e;
  BiconectedGraph bcc(v);
  bcc.input(e,0);
  bcc.build();
  typedef pair<int,int> P;
  vector<P> B=bcc.B;
  for(P &p:B) if(p.first>p.second) swap(p.first,p.second);
  sort(B.begin(),B.end());
  for(P p:B) cout<<p.first<<" "<<p.second<<endl;
  return 0;
}

/*
  verified on 2017/12/20
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_B&lang=jp
*/

Measured memory_bytes: 4808
#ifndef _LOCAL
#	define NDEBUG
#	define dprint(...)
#endif

#include <cmath>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <iostream>
#include <algorithm>
#include <assert.h>
using namespace std;
typedef long long ll;

bool check(map<int,int> m, int a, int b, int n)
{
	--m[a];
	--m[b];
	int x = a, y = b;
	for(int i=2; i<n; ++i)
	{
		int z = x ^ y;
		--m[z];
		if(m[z] < 0)
			return false;
		x = y;
		y = z;
	}
	return (x^y) == a;
}

int main()
{
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	map<int,int> m;
	for(int i=0; i<n; ++i)
	{
		int a;
		cin >> a;
		++m[a];
	}

	bool ans = check(m, m.begin()->first, m.rbegin()->first, n);
	
	cout << (ans ? "Yes" : "No") << "\n";

	return 0;
}
//a,b,ab,a,b


Measured memory_bytes: 7552
N = int(input())
A = list(map(int,input().split()))
sumA = 0
A.insert(0,0)
A.append(0)
for i in range(N+1):
    sumA += abs(A[i]-A[i+1])
for i in range(1,N+1):
    sumb = abs(A[i-1] - A[i+1]) - (abs(A[i-1] - A[i]) + abs(A[i] - A[i+1]))
    print(sumA + sumb)


Measured memory_bytes: 14044
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
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; }
using namespace std;

ll n, m ,q;
vector<tuple<ll, ll, ll, ll>> t;

ll score(const vi &v){
    ll ans = 0;
    rep(i, q) if((v[get<1>(t[i])]-v[get<0>(t[i])]) == get<2>(t[i])) ans += get<3>(t[i]);
    return ans;
}

ll dfs(vi &v){
    if((ll)v.size() == n) return score(v);
    ll ans = 0, back = (v.empty() ? 0 : v.back());
    for(ll i=back; i<m; i++){
        v.push_back(i);
        chmax(ans, dfs(v));
        v.pop_back();
    }
    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    cin >> n >> m >> q;
    rep(i, q){
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        t.push_back(make_tuple(a-1, b-1, c, d));
    }
    vi v;
    cout << dfs(v) << endl;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF = 2e9;
#define LINF = 1e18;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << = << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO")
#define Yes(n) cout << ((n) ? "Yes" : "No")

void input(vector<int> x, auto n){
   rep(i,n)cin >> x[i];
}

void PRec(){

    int h, w;
    cin >> h >> w;
    if(h == 0 && w == 0)return;
    rep(i, h){
        rep(i, w){
            putchar('#');
        }
        putchar('\n');
    }
    putchar('\n');
    return PRec();
}

int main(){
    PRec();
}


Measured memory_bytes: 3044
//#pragma comment(linker, "/STACK:102400000,102400000")
//#include <initializer_list>
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <cassert>
//#include <unordered_map>
//#include <unordered_set>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define eps 1e-8
#define LL_INF 0x3fffffffffffffff
#define INF 0x3f3f3f3f
#define mem(a, b) memset(a, b, sizeof(a))
#define pper(i,n,m) for(int i = n;i >= m; i--)
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))
#define slla(n) scanf("%lld", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define DE(val) cout<<#val<<": "<<val<<endl;
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); repp(i,1,___T)

const int dx44[5] = { 0,-1,-1,1,1 };
const int dy44[5] = { 0,-1,1,-1,1 };

const int dx4[5] = { 0,-1,0,1,0 };
const int dy4[5] = { 0,0,1,0,-1 };
const int dx8[9] = { 0,-1,0,1,0,1,1,-1,-1 };
const int dy8[9] = { 0,0,1,0,-1,1,-1,1,-1 };
const int maxn = 5e5 + 5;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
ll po(ll a, ll b, ll mod) { ll res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
ll gcd(ll a, ll b) { if (a == 0) { return b; } else { return gcd(b%a, a); } }
void YES() { puts("YES"); exit(0); }
void Yes() { puts("Yes");}// exit(0); }
void NO() { puts("NO"); exit(0); }
void No() { puts("No");}// exit(0); }
void one() { puts("-1"); exit(0); }

int m;
ll dist[maxn];

void solve()
{
 
    scanf("%d", &m);
    for (int i = 0; i < m; ++ i) {
        dist[i] = INF;
    }
    std::priority_queue< std::pair<int, int> > pq;
    dist[1]=0;
    pq.push(make_pair(0, 1));
 
    while (!pq.empty()) {
        auto top = pq.top();
        pq.pop();
        if (-top.first == dist[top.second]) {
            for (int d = 0; d < 10; ++ d) {
                int r = (top.second * 10 + d) % m;
                if (-top.first + d < dist[r]) {
                    dist[r] = -top.first + d;
                    pq.push(make_pair(-dist[r], r));
                }
            }
        }
    }
    //DE(dist[0])
    printf("%lld\n", dist[0] + 1);
}

int main()
{

    solve();
    // system("pause");
    return 0;
}

Measured memory_bytes: 3188
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int dp[100010], N, K;
vector<int> cand;

int solve(int rem) {
    int &val = dp[rem];
    if(val >= 0) return val;
    if(rem == 0) return false;
    
    bool ok = false;
    for(auto e : cand) {
        if(rem - e < 0) continue;
        ok |= (solve(rem - e) == 0);
    }

    // fprintf(stderr, "rem = %lld, val = %d\n", rem, ok);
    return val = ok;
}

signed main() {
    cin >> N >> K;
    for(int i=0; i<N; i++) {
        int val; cin >> val;
        cand.push_back(val);
    }

    fill(dp, dp + K + 1, -1);
    int ans = solve(K);
    if(ans == 1) cout << "First" << endl;
    else cout << "Second" << endl;
    return 0;
}


Measured memory_bytes: 7168
import numpy as np
n = int(input())
a = list(map(int, input().split()))

s = 0
ans1 = 0
ans2 = 0

for i in range(len(a)):
    s += a[i]
    if(i%2 == 0):
        if(np.sign(s) != 1):
            ans1 += abs(1 - s)
            s = 1
    else:
        if(np.sign(s) != -1):
            ans1 += abs(-1-s)
            s = -1
s = 0
for i in range(len(a)):
    s += a[i]
    if(i%2==0):
        if(np.sign(s) != -1):
            ans2 += abs(-1-s)
            s = -1
    else:
        if(np.sign(s) != 1):
            ans2 += abs(1-s)
            s = 1
print(min(ans1, ans2))

Measured memory_bytes: 38164
#include<iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int j,arr[n];
  for(j=0;j<n;j++)
      cin>>arr[j];
  int odd=0;
  for(j=0;j<n;j++)
  {
    if(arr[j]%2!=0)
        odd++;
  }
  if(odd%2==0)
      cout<<"YES"<<endl;
  else
     cout<<"NO"<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <fstream>
#include <queue>
#include <math.h>
#include <set>
#include <stdlib.h>
#include <time.h>
#include <list>

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

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
#define chk(a) rep(i, a.size()) cout << a[i] << " "
#define SORT(c) sort((c).begin(),(c).end())
#define ll long long
#define vi(m,a) vector<int> m(a)
#define vti(m,a,i) vector<vector<int>> m(a,vector<int>(i))
#define ALL(it,a) for(auto it = a.begin(); it!=a.end(); it++)
#define Fe(it,a) for(auto &it : a)
#define all(a) begin(a),end(a)


using namespace std;
typedef pair<int, int> pii;
#define WARU 1000000007;

int main(void) {
	int n, m; cin >> n >> m;
	vector<int> v(n);
	rep(i, n) {
		v[i] = 1;
	}
	vector<int> p(n);
	p[0] = 1;
	rep(i, m) {
		int x, y; cin >> x >> y;
		x--; y--;
		v[x]--; v[y]++;
		if (p[x] == 1) {
			p[y] = 1;
			if (v[x] == 0) {
				p[x] = 0;
			}
		}
	}
	int res = 0;
	rep(i, n) {
		if (p[i] == 1) {
			res++;
		}
	}
	cout << res << endl;


	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

long long power(int a, int b){
	long long ret = 1;
	for(int i=b;i>0;i--){
		ret *= a;
	}
	return ret;
}

int main(void){
	string a;
	cin >> a;
	a.at(5) = ' ';
	a.at(13) = ' ';
	cout << a << endl;
	return 0;
}

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

namespace AtCoder {

    class Program {
        static int gcd(int x, int y) {
            return y != 0 ? gcd(y, x % y) : x;
        }
        static void Main(string[] args) {

            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList();

            var Left = new List<int>(Enumerable.Repeat(0, N));
            var Right = new List<int>(Enumerable.Repeat(0, N));

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

                Left[i + 1] = gcd(Left[i], A[i]);
            }
            for (int i = N - 1 - 1; i >= 0; i--) {

                Right[i] = gcd(Right[i + 1], A[i + 1]);
            }
            var result = 0;
            for (int i = 0; i < N; i++) {

                result = Math.Max(result, gcd(Left[i], Right[i]));
            }

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 30044
using System;
using System.Collections.Generic;
using System.Linq;
using console = System.Console;

namespace AtCoderTemplate
{
    public class App
    {
        public static void Main(string[] args)
        {
            var p = long.Parse(console.ReadLine().Split()[1]);
          console.WriteLine(console.ReadLine().Split().Select(i=>long.Parse(i)).OrderBy(i=>i).Select(i=>{p-=i;return p;}).Count(i=>i>=0)-(p>0?1:0));
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int k, a, b, c, d;
unordered_map<int, int> cache;

int work(int n)
{
	if(n == 0)
		return 0;
	if(n == 1)
		return d;
	if(cache.count(n))
		return cache[n];
	int &ans = cache[n];
	ans = 4e18;
	if(n <= 4e9)
	    ans = min(ans, n * d);
	for(int i = -12; i <= 12; i++)
	{
		int nxtN = n + i;
		if(nxtN < 0)
			continue;
		if(nxtN % 2 == 0 && nxtN / 2 < n)
			ans = min(ans, d * abs(i) + a + work(nxtN / 2));
		if(nxtN % 3 == 0 && nxtN / 3 < n)
			ans = min(ans, d * abs(i) + b + work(nxtN / 3));
		if(nxtN % 5 == 0 && nxtN / 5 < n)
			ans = min(ans, d * abs(i) + c + work(nxtN / 5));
		if(nxtN % 6 == 0 && nxtN / 6 < n)
			ans = min(ans, d * abs(i) + a + b + work(nxtN / 6));
		if(nxtN % 15 == 0 && nxtN / 15 < n)
			ans = min(ans, d * abs(i) + b + c + work(nxtN / 15));
		if(nxtN % 10 == 0 && nxtN / 10 < n)
			ans = min(ans, d * abs(i) + a + c + work(nxtN / 10));
	}	
	return ans;
}

int32_t main()
{
	IOS;
	int t;
	cin >> t;
	while(t--)
	{
		cache.clear();
		cin >> k >> a >> b >> c >> d;
		int ans = work(k);
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 10072
N,K = map(int,input().split())
dp = [0 for _ in range(3*N)]
dp[0] = 1
S_left = []
S_right = []
for i in range(K):
    l,r = map(int,input().split())
    S_left.append(l)
    S_right.append(r)
plus = 0
for j in range(N):
    plus += dp[j]
    for k in range(K):
        dp[S_left[k]+j]+= plus
        dp[S_left[k]+j]%=998244353
        dp[S_right[k]+j+1]-= plus
        dp[S_right[k]+j+1]%=998244353
dp_cum = [1]
print(dp[N-1]%998244353)


Measured memory_bytes: 109164
def chess(H,W):
    for i in range(H):
        for j in range(W):
            if (i+j) % 2 == 0:
                print('#', end='')
            else:
                print('.', end='')
        print()

while True:
    n = input()
    H,W = map(int,n.split())
    if H == W == 0:
        break
    chess(H, W)
    print()
    

Measured memory_bytes: 9088
import java.util.Scanner;

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

    private
    void run()
    {
        Scanner in = new Scanner(System.in);

        int a = in.nextInt();

        if (a / 100 == a % 10)
        {
            System.out.println("Yes");
        }
        else
        {
            System.out.println("No");
        }
    }
}


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

#define mod 1000000007

using namespace std;
int main()
{
int n,m;
cin>>n>>m;
int arr[n][m];
long long dp[n][m];
memset(dp,0,sizeof(dp));
for(int i=0;i<n;i++)
{
    for(int j=0;j<m;j++)
    {
        char c;
        cin>>c;
        if(c=='.')
            arr[i][j]=1;
        else
            arr[i][j]=0;
            if(i==0&&j==0)
                dp[i][j]=1;
            else if(i==0)
            {
                if(arr[i][j]==0)
                    dp[i][j]==0;
                else
                    dp[i][j]=dp[i][j-1]%mod;
            }
            else if(j==0)
            {
                if(arr[i][j]==0)
                    dp[i][j]==0;
                else
                    dp[i][j]=dp[i-1][j]%mod;
            }

}
}

for(int i=1;i<n;i++)
{
    for(int j=1;j<m;j++)
    {

            if(arr[i][j])
                dp[i][j]=dp[i-1][j]%mod+dp[i][j-1]%mod;
                dp[i][j]=dp[i][j]%mod;
    }
}
cout<<dp[n-1][m-1];









}


Measured memory_bytes: 11904
#include<cstdio>
int sosu[1000000]={};
bool f[1000000]={false};
int main(){
  sosu[2] = 1;
  for(int i=3;i<=999999;i+=2){
    if(!f[i]){
      sosu[i] = 1;
      if(i < 1000){
	for(int j=i*i;j<=999999;j+=i) f[j] = true;
      }
    }
    sosu[i] += sosu[i-1];
    sosu[i+1] += sosu[i];
  }
  int n;
  while(scanf("%d",&n)!=EOF) printf("%d\n",sosu[n]);
  return(0);
}



Measured memory_bytes: 7484
import java.util.*;

/**
 * Created by Seiya on 2016/10/16.
 */

public class Main {

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

        int N = scanner.nextInt();
        int M = scanner.nextInt();
        pair[] a = new pair[N];
        for (int i = 0; i < N; i++) {
            long tempa = scanner.nextLong();
            long tempb = scanner.nextLong();
            a[i] = new pair(tempa, tempb);
        }
        pair[] b = new pair[M];
        for (int i = 0; i < M; i++) {
            long tempa = scanner.nextLong();
            long tempb = scanner.nextLong();
            b[i] = new pair(tempa, tempb);
        }

        for (int i = 0; i < N; i++) {
            long min = 999999999;
            int minN = M - 1;
            for (int j = M - 1; j >= 0; j--) {
                long temp = Math.abs(a[i].a - b[j].a) + Math.abs(a[i].b - b[j].b);
                // System.out.println(j + "==" + temp);
                if(min >= temp){
                    min = temp;
                    minN = j + 1;
                }
            }
            System.out.println(minN);
        }


    } // mainMethod

    static class pair {
            public long a;
            public long b;

            pair(){
                this.a = 0;
                this.b = 0;
            }

            pair(long a, long b){
                this.a = a;
                this.b = b;
            }

            public void set(long a, long b) {
                this.a = a;
                this.b = b;
            }
        }



} // MainClass


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll K;
ll t;
ll ret = 0;

void input() {
  IN(N);
  IN(K);
}

void solve() {
  if (N > K) {
    N %= K;
  }
  ll _N = K - N;
  ret = min(N, _N);
  PRINT(ret);
}

int main(void){
  input();
  solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	int N,M,Time=0;
	vector<int>T;
	cin>>N;
	fore(i,0,N){
		int t;
		cin>>t;
		T.push_back(t);
	}
	cin>>M;
	fore(i,0,M){
		int a,b;
		cin>>a>>b;
		fore(j,0,N){
			if(j==a-1){
				Time=Time+b;
			}
			else{
				Time=Time+T[j];
			}
		}
		cout << Time << endl;
		Time=0;
	}
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int n,x,d;
    cin>>n>>d>>x;
    int a[n],dem=1,sum=0;
    for (int i = 0 ; i < n ; i++){
        cin>>a[i];
        if (a[i]==0)    continue;
        if (a[i]>=1) sum++;
        for (;dem*a[i]+1<=d;dem++)
            sum++;
        dem=1;
    }
    cout<<sum+x;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
    int N,D;
    cin>>N>>D;
    int A=2*D+1;
    int ans=N/A;
    if(N%A!=0){
        ans++;
    }
    cout<<ans<<endl;
}


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

namespace abc151_e
{
  class Program
  {
    static void Main(string[] args)
    {
      var N = CIn.ReadInt();
      var K = CIn.ReadInt();
      var A = CIn.ReadIntArray(N);

      Array.Sort(A);

      var mod = new Mod((int)1e9 + 7);
      var maxSum = 0L;
      var minSum = 0L;

      for (var i = 0; i < N; i++)
      {
        maxSum = mod.Add(maxSum, mod.Mul(A[i], mod.Com(i, K - 1)));
        minSum = mod.Add(minSum, mod.Mul(A[i], mod.Com(N - i - 1, K - 1)));
      }

      Console.WriteLine(mod.Sub(maxSum, minSum));
    }
  }

  class Mod
  {
    public int N { get; }
    private readonly List<long> fac = new List<long>() { 1, 1 };
    private readonly List<long> inv = new List<long>() { 0, 1 };
    private readonly List<long> facInv = new List<long>() { 1, 1 };

    public Mod(int n)
    {
      N = n;
    }

    public long EuclidMod(long a)
    {
      var result = a % N;
      if (result < 0) result += N;
      return result;
    }

    public long Add(long a, long b) => EuclidMod(a % N + b % N);
    public long Sub(long a, long b) => EuclidMod(a % N - b % N);
    public long Mul(long a, long b) => EuclidMod(a % N * b % N);


    public long Com(int n, int k)
    {
      if (n < k || n < 0 || k < 0) return 0;
      for (var i = fac.Count; i <= n; i++)
      {
        fac.Add(fac[i - 1] * i % N);
        inv.Add(N - inv[N % i] * (N / i) % N);
        facInv.Add(facInv[i - 1] * inv[i] % N);
      }
      return fac[n] * (facInv[k] * facInv[n - k] % N) % N;
    }
  }

  class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }
      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(long n)
    {
      var array = new string[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }
      return array;
    }

    public static int[] ReadIntArray(long n)
    {
      var array = new int[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadInt();
      }
      return array;
    }

    public static long[] ReadLongArray(long n)
    {
      var array = new long[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadLong();
      }
      return array;
    }

    public static double[] ReadDoubleArray(long n)
    {
      var array = new double[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadDouble();
      }
      return array;
    }
  }
}


Measured memory_bytes: 31068
n, k = gets.split.map{|x|x.to_i}
s = gets.chomp.each_char.map {|x| x == '0' ? 0 : 1}

# stand, reverse, stand...
a = []

tmp = 0
i = 0

tmp = 0
while i < n && s[i] == 1
  tmp += 1
  i += 1
end
a << tmp

while i < n
  tmp = 0
  while i < n && s[i] == 0
    tmp += 1
    i += 1
  end
  a << tmp

  tmp = 0
  while i < n && s[i] == 1
    tmp += 1
    i += 1
  end
  a << tmp
end

b = Array.new(a.size + 1)
b[0] = 0

a.size.times do |i|
  b[i+1] = b[i] + a[i]
end

maximum = 0

[k * 2 + 1, b.size - 1].min.step(b.size - 1, 2) do |i|
  tmp = b[i] - b[[i - (2 * k + 1), 0].max]

  maximum = tmp if tmp > maximum
end

p maximum


Measured memory_bytes: 4988
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
int main() {
  string s, t;
  cin >> s >> t;
  vector<int> a(26, -1);
  vector<int> b(26, -1);
  for(int i=0; i<s.size(); i++){
    int aa = s[i] - 'a';
    int bb = t[i] - 'a';
    if(a[aa]!=-1 || b[bb]!=-1){
      if(a[aa]!=bb || b[bb]!=aa){
        cout << "No" << endl;
        return 0;
      }
    }
    else{
      a[aa] = bb;
      b[bb] = aa;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 776
L, R= list(map(int,input().split()))

if R - L >= 2018:
    print(0)
    exit()

ans = 2019
for i in range(L, R+1):
    for j in range(i+1, R+1):
        t = i*j%2019
        if t < ans:
            ans = t

print(ans)



Measured memory_bytes: 2940
import sys
def isPrime(n):
  if n < 2:
    # 2未満は素数でない
    return False
  if n == 2:
    # 2は素数
    return True
  for p in range(2, n):
      if n % p == 0:
        # nまでの数で割り切れたら素数ではない
        return False
  # nまでの数で割り切れなかったら素数
  return True

X=int(input())

while True:
    if(isPrime(X)):
        print(X)
        sys.exit()

    X+=1

Measured memory_bytes: 2940
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""


input:
5 12
0 1 4
0 2 3
1 1 2
1 3 4
1 1 4
1 3 2
0 1 3
1 2 4
1 3 0
0 0 4
1 0 2
1 3 0

output:
0
0
1
1
1
0
1
1

"""

import sys


class UnionFind(object):
    __slots__ = ('size', 'rank', 'p_list')

    def __init__(self, size):
        self.size = int(size)
        self.rank = [0] * self.size
        self.p_list = [i for i in range(self.size)]

    def find_set(self, x):
        if x != self.p_list[x]:
            self.p_list[x] = self.find_set(self.p_list[x])
        return self.p_list[x]

    def same(self, x, y):
        return self.find_set(x) == self.find_set(y)

    def link(self, x, y):
        if self.rank[x] > self.rank[y]:
            self.p_list[y] = x
        else:
            self.p_list[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    def unite(self, x, y):
        self.link(self.find_set(x), self.find_set(y))


def action(cmd):
    for _, each in enumerate(cmd):
        cmd, ele_1, ele_2 = map(int, each)
        if cmd == 0:
            case.unite(ele_1, ele_2)
        elif cmd == 1:
            if case.same(ele_1, ele_2):
                print('1')
            else:
                print('0')
    return case


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    ele_num, cmd_num = map(int, _input[0].split())
    cmd_list = map(lambda x: x.split(), _input[1:])

    case = UnionFind(size=ele_num)

    ans = action(cmd_list)

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, W;
  cin >> n >> W;
  
  vector<int> w(n), v(n);
  for(int i = 0; i < n; i++) cin >> w.at(i) >> v.at(i);
  
  vector<vector<ll>> dp(n, vector<ll>(1e5 + 1, 1e15));
  dp.at(0).at(v.at(0)) = w.at(0);
  for(int i = 0; i < n; i++) dp.at(i).at(0) = 0;
  
  for(int i = 1; i < n; i++){
    for(int j = 0; j <= 1e5; j++){
      if(j >= v.at(i)) dp.at(i).at(j) = min(dp.at(i - 1).at(j - v.at(i)) + w.at(i), dp.at(i - 1).at(j));
      else dp.at(i).at(j) = dp.at(i - 1).at(j);
    }
  }
  
  ll ans = 0;
  for(int i = 0; i <= 1e5; i++){
    if(dp.at(n - 1).at(i) <= W) ans = max<ll>(ans, i);
  }
  cout << ans << '\n';
}

Measured memory_bytes: 79488