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

using namespace std;

typedef long long  ll;

typedef int Weight;
const Weight INF = 1e8;

struct Edge {
    int src, dst;
    Weight weight;
    int rev;
    Edge(int f, int t, Weight c, int rev = 0) :
        src(f), dst(t), weight(c), rev(rev) {}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void AddEdge(Graph &g, int s, int dst, Weight cap){
    g[s].push_back(Edge(s, dst, cap, g[dst].size()));
    g[dst].push_back(Edge(dst, s, 0, g[s].size()-1));
}

void Bfs(const Graph &g, vector<int> &level, int s){
    level[s]=0;
    queue<int> que;
    que.push(s);
    while(!que.empty()){
        int v = que.front();
        que.pop();
        for (auto &e : g[v]) {
            if(e.weight > 0 && level[e.dst] < 0){
                level[e.dst] = level[v] + 1;
                que.push(e.dst);
            }
        }
    }
}
Weight Dfs(Graph &g, vector<int> &level, vector<int> &iter,
           int v, int t, Weight flow) {
    if(v == t)
        return flow;
    for (int &i = iter[v], N = g[v].size(); i < N; ++i) {
        Edge &e = g[v][i];

        if(e.weight > 0 && level[v] < level[e.dst]){
            Weight d = Dfs(g, level, iter, e.dst, t, min(flow, e.weight));
            if(d > 0){
                e.weight -= d;
                g[e.dst][e.rev].weight += d;
                return d;
            }
        }
    }
    return 0;
}

Weight Dinic(Graph &g, int s, int t){
    Weight flow = 0;

    while(true){
        vector<int> level(g.size(), -1);
        vector<int> iter(g.size(), 0);
        Bfs(g, level, s);

        if(level[t] < 0)
            break; // もう流せない
        Weight f = 0;
        while((f = Dfs(g, level, iter, s, t, INF)) > 0)
            flow += f;
    }
    return flow;
}

void WarshallFloyd(Matrix &dist) {
    int n = dist.size();
    for (int k = 0; k < n; ++k)
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < n; ++j)
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}

int main()
{
    int N, M, L, A, B, D, P, K;

    while (cin >> N >> M >> L) {
        Matrix dist(N, Array(N, INF));

        for (int i = 0; i < M; ++i) {
            cin >> A >> B >> D;
            dist[A - 1][B - 1] = dist[B - 1][A - 1] = D;
        }
        for (int i = 0; i < N; ++i)
            dist[i][i] = 0;

        WarshallFloyd(dist);

        Graph g(2 * N + 2);
        int s = 2 * N, t = 2 * N + 1;

        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < N; ++j) {
                if (i == j)
                    AddEdge(g, i, i + N, INF);
                else if (dist[i][j] < L)
                    AddEdge(g, i, j + N, INF);
            }
        }

        for (int i = 0; i < N; ++i) {
            cin >> P;
            AddEdge(g, s, i, P);
        }
        for (int i = 0; i < N; ++i) {
            cin >> K;
            AddEdge(g, i + N, t, K);
        }

        cout << Dinic(g, s, t) << endl;
    }

    return 0;
}

Measured memory_bytes: 1604
N, M = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort

min = a.first
bc = []

M.times do
  b, c = gets.split.map(&:to_i)
  bc << [b, c]
end
bc = bc.sort_by{|a| a[1]}.reverse
M.times do |i|
  b, c = bc[i]
  if c > min
    b.times do
      x = a.shift
      if x < c
        a << c
      else
        a = [x] + a
        min = x
        break
      end
    end
    min = a.first
  end
end
puts a.inject(&:+)

Measured memory_bytes: 20512
#include <stdio.h>
#include <cassert>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
#include <iomanip>
 
#ifdef LOCAL_CODE
	#define DEBUG(x) cerr << "[" << #x << '=' << x << "]" << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif
 
#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define PER(i, N) for(int i = (N)-1; i >= 0; i--)
#define REP(i, N) for(int i = 0; i < (int)(N); i++)
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.first >> p.second; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.first << ' ' << p.second; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

ll n,m,k;//A,B,C,D;
void solve(istream& cin, ostream& cout) {
	cin>>n>>m;
	cout <<n*m<<endl;
}


int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	solve(cin, cout);
	/*
	{
		istringstream instr("2\n2\n14");
		solve(instr, cout);
	}
 */
	return 0;
}


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

using namespace std;

using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  vector<ll> a(n);
  map<ll, ll> cnt;
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  ll conbi = 0;
  for (const auto& [ind, val] : cnt) {
    conbi += val * (val - 1) / 2;
  }
  for (ll i = 0; i < n; i++) {
    ll ori = cnt[a[i]] * (cnt[a[i]] - 1) / 2;
    ll mod = (cnt[a[i]] - 1) * (cnt[a[i]] - 2) / 2;
    ll dif = ori - mod;
    ll ans = conbi - dif;
    cout << ans << '\n';
  }
  return 0;
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<string> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  for (int i = 0; i < n; i++) sort(v[i].begin(), v[i].end());
  sort(v.begin(), v.end());
  ll ans = 0;
  bool same = false;
  ll c = 0;
  for (int i = 1; i < n; i++) {
    if (v[i] == v[i - 1]) {
      if (same) {
        c++;
      } else {
        c = 1;
        same = true;
      }
    } else {
      ans += c * (c + 1) / 2;
      c = 0;
    }
  }
  ans += c * (c + 1) / 2;
  cout << ans << endl;
  return 0;
}


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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll T;
	cin >> T;
	if(T>=30)
		cout <<"Yes\n"<<endl;
	else
		cout <<"No\n"<<endl;

}


Measured memory_bytes: 3688
from collections import deque
n,Q=map(int,input().split())
tr=[[] for _ in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    tr[a-1].append(b-1)
    tr[b-1].append(a-1)
counter=[0]*n
for _ in range(Q):
    p,x=map(int,input().split())
    counter[p-1]+=x
al=[0]*n
qi=deque([0])
while qi:
    x=qi.pop()
    al[x]=1
    for i in tr[x]:
        if al[i]==0:
            counter[i]+=counter[x]
            qi.append(i)
print(*counter)

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

int main() {

  int N, K;
  cin >> N >> K;

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

  sort(p.begin(), p.end());

  int ans = 0;

  for (int i = 0; i < K; i++) {
    ans += p[i];
  }
  
  cout << ans << endl;
  return 0;

}

Measured memory_bytes: 3496
/*input
10 4 8
*/

#include <bits/stdc++.h>
#define MOD 998244353
 
using namespace std;


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,x,y;
    cin >> n >> x >> y;
    // vector<int> dp(n+1,INT_MAX);
    // dp[1] = 1;
    // for(int i=2;i<=n;i++)
    //     dp[i] = dp[i-1]+1;
    // dp[y] = dp[x]+1;
    // for(int i=y+1;i<=n;i++)
    //     dp[i] = min(dp[i],dp[i-1]+1);
    map<int,int> mp;
    // for(int i=1;i<=n;i++)
    //     cout << dp[i] << " " << "\n";
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            mp[min(j-i,abs(i-x) + 1 + abs(j-y))]++;
            // if(i<=x && j<x){
            //     mp[j-i]++;    
            // }
            // else if(i<=x && j>=x && j<y){
            //     mp[j-i]++;
            // }
            // else if(i<=x && j>=y){
            //     mp[j-y+x-i+1]++;
            // }
            // else if(i>x && i<y && j>x && j=<y){
            //     int dist = j-i;
            //     dist = min(dist,i-x+1+y-j);
            //     mp[dist]++;
            // }
            // else if(i>=y){

            // }
            // mp[dp[j]-dp[i]]++;
        }
    }
    for(int i=1;i<n;i++)
        cout << mp[i] << "\n";
    // for(auto it: mp)
    //     cout << it.first << " " << it.second << "\n";

    return 0;
}


Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
 
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
   
using namespace std;
   
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
   
static const double EPS = 1e-8;
   
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

int cost[1010][1010];
int dp[1010][1010];

class State {
public:
  int x;
  int y;
  int cost;
  State(int x,int y,int cost) 
    : x(x), y(y), cost(cost) {}
  bool operator<(const State& s) const {
    return cost < s.cost;
  }
  bool operator>(const State& s) const {
    return cost > s.cost;
  }
};

int main(){
  int W, H;
  int num_of_staff;

  map<char,int> dict;
  dict['U'] = 0;
  dict['R'] = 1;
  dict['D'] = 2;
  dict['L'] = 3;

  while(~scanf("%d %d %d",&W,&H,&num_of_staff)){
    memset(cost,0,sizeof(cost));
    memset(dp,0x3f,sizeof(dp));

    int lan_start_x,lan_start_y;
    int lan_end_x,lan_end_y;
    scanf("%d %d %d %d",
          &lan_start_x,&lan_start_y,
          &lan_end_x,&lan_end_y);
    for(int staff_i = 0; staff_i < num_of_staff; staff_i++){
      int current_x,current_y;
      int repeat_time;
      string commands;
      cin >> current_x >> current_y >> repeat_time >> commands;
      current_x = 2 * current_x + 1;
      current_y = 2 * current_y + 1;

      for(int repeat_i = 0; repeat_i < repeat_time; repeat_i++){
        for(int command_i = 0; command_i < commands.size(); command_i++){
          int dir = dict[commands[command_i]];
          int dx = current_x + tx[dir] * 2;
          int dy = current_y + ty[dir] * 2;
          if(dx >= 2 * W || dx < 0 || dy >= 2 * H || dy < 0) continue;
          
          int mx = current_x + tx[dir];
          int my = current_y + ty[dir];
          
          cost[my][mx]++;
          current_x = dx;
          current_y = dy;
        }
      }
    }
    priority_queue<State,vector<State>,greater<State> > que;
    que.push(State(lan_start_x * 2, lan_start_y * 2, 0));
    dp[lan_start_y * 2][lan_start_x * 2] = 0;
    while(!que.empty()){
      State s = que.top();
      que.pop();
      for(int i = 0; i < 4; i++){
        int dx = s.x + tx[i] * 2;
        int dy = s.y + ty[i] * 2;
        if(dx >= 2 * W + 1 || dx < 0 || dy >= 2 * H + 1 || dy < 0) continue;

        int mx = s.x + tx[i];
        int my = s.y + ty[i];
        if(dp[dy][dx] <= s.cost + cost[my][mx]) continue;
        dp[dy][dx] = s.cost + cost[my][mx];
        que.push(State(dx, dy, s.cost + cost[my][mx]));
      }
    }

    printf("%d\n",dp[lan_end_y * 2][lan_end_x * 2]);
  }
}

Measured memory_bytes: 13444
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/



signed main() {
	int a, b, c; cin >> a >> b >> c;
	rep(i, c) {
		int aa, bb;
		if (i % 2 == 0) {
			aa = a / 2, bb = a / 2 + b;
		}
		else {
			aa = a + b / 2, bb = b / 2;
		}
		a = aa, b = bb;
	}
	cout << a << " " << b << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;

int main() {
	fastIO;
#ifdef LOCAL
//	freopen("input.in", "rt", stdin);
#endif
	int a, b;
	cin >> a >> b;
	if(a > b) {
		cout << "safe";
	} else {
		cout << "unsafe";
	}
	return 0;
}


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

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

ll const mod = 1e9+7;
ll ans=0;
int N,M,Q,a,b,c,d;
vector<vector<vector<int>>> ab;
void dfs(int n, int di, string S,ll p, vector<vector<vector<int>>> &abc){
  if (di+1<=N)  rep2(i,n,M) {
    string tmp = to_string(i);
    ll delta=0;
    for (auto k:abc[di]) {
      // cout << S << "      " << S[k[0]] << endl;
      if ((S[k[0]])+k[1]==tmp[0]) delta+=k[2];
    }
    dfs(i,di+1,S+tmp,p+delta,abc);
  }
  else {
    // cout << S << endl;
    chmax(ans,p);}
}


int main() {
  cin >> N >> M >> Q;
  ab.resize(N);
  rep(i,Q) {
    cin >> a >> b >> c >> d;
    a--;b--;
    ab[b].push_back({a,c,d});
  }
  dfs(0,1,"0",0,ab);
  // vector<vector<int>> dp(N+1,vector<int> (M+1,0));
  // rep2(i,2,N+1) {//ix
  //   rep2(j,1,M+1) {//value
  //   dp[i][j]+=dp[i-1][j];
  //     for (auto t:abc) {
  //       if (t[1]==i && t[0]>0 && j-t[2]>0) {
  //         chmax(dp[i][j],dp[t[0]][j-t[2]]+t[3]);
  //       }
  //     }
  //   cout << dp[i][j] << ' ';
  //   }
  //   cout << endl;
  // }
  // cout << dp[N][M] << endl;
  cout << ans << endl;
}

Measured memory_bytes: 3696
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
8 5
-9 -7 -4 -3 1 2 3 4
)");
#define cin input
#endif

int main()
{
	int n, k;
	cin >> n >> k;

	vector<int> x(n);
	for (auto& i : x)
		cin >> i;
	
	int r = 1 << 30;
	REP (i, n - k + 1)
	{
		int t = x[i + k - 1] - x[i] + min(abs(x[i + k - 1]), abs(x[i]));
		if (t < r)
			r = t;
	}

	cout << r << endl;

	return 0;
}


Measured memory_bytes: 888
from itertools import tee


def pairwise(iterable):
    a, b = tee(iterable)
    next(b, None)
    return zip(a, b)


N, T = map(int, input().split())
ts = list(map(int, input().split()))
s = 0

for p, n in pairwise(ts + [ts[-1] + T]):
    if n - p >= T:
        s += T
    else:
        s += n - p
print(s)


Measured memory_bytes: 25204
#include <stdio.h>

int main()
{
  int i, j, S[10000], T[500], c=0, n, q, a=0;

  scanf("%d", &n);  
  for(i=0;i<n;i++){
    scanf("%d", &S[i]);
  }

  scanf("%d", &q);  
  for(j=0;j<q;j++){
    scanf("%d", &T[j]);
  }

  
  for(j=0;j<q;j++){
    for(i=0;i<n;i++){

      if(S[i] == T[j]){
	a = 1;
	break;
      }
    }
    if(a == 1){
      c++;
      a = 0;
    }
  }

  printf("%d\n", c);

  return 0;
}



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

int main() {
	int H,W;
	while(1){
	cin >>H>>W;
	if (H==0 && W==0) break;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if((i+j)%2==0){
				cout << "#";
			}
			else {
			cout <<".";
			}
		}
		cout << endl;
	
	}
	cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
n = int(input())
arr = [int(s) for s in input().split()]
freq = {}
count=0
for i in range(len(arr)):
    if i-arr[i] in freq:
        count+=freq[i-arr[i]]
    if arr[i]+i in freq:
        freq[arr[i]+i] = freq[arr[i]+i] + 1
    else:
        freq[arr[i]+i] = 1
print(count)

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

// clang-format off
#define rep(i, n) for(int i=0; i< (n); i++)
#define reps(i, a, n) for(int i=a; i < (n); i++)

const int INF{1001001001};
const int MOD{(int)1e9 + 7};
const double EPS{1e-9};
const double PI{acos(-1)};
const int dx[]{0, 1, 0, -1, 1, -1, 1, -1}, dy[]{1, 0, -1, 0, 1, -1, -1, 1};

const int MAX_N = 10000;
int main(){
    int N, ans = 0;
    long long a[MAX_N];
    int b[MAX_N];
    
    cin >> N;
    rep(i, N){
        cin >> a[i];
    }
    
    rep(i, N){
        long long x = a[i];
        
        while(true){
            if(x % 2 == 1)break;
            x /= 2;
            b[i]++;
        }
    }
    rep(i, N)ans += b[i];
    
        cout << ans;
        return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int first = 0;
		int second = 0;
		int third = 0;
		for(int i=1; i<=10; i++) {
			int height = s.nextInt();
			if(height > first) {
				third = second;
				second = first;
				first = height;
			} else if(height > second) {
				third = second;
				second = height;
			} else if(height > third) {
				third = height;
			}
		}
		System.out.println(first);
		System.out.println(second);
		System.out.println(third);
		s.close();
	}

}

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

vector<int> vc;
int gcd(int p, int q) {
    return q ? gcd(q, p%q) : p;
}

int main(void)
{
    int a,b,k,g;
    cin >> a >> b >> k;
    g = gcd(a, b);
    int i;
    for(i=1;i*i<g;i++){
        if(g%i==0){
            vc.push_back(i);
            vc.push_back(g/i);
        }
    }
    if(i*i==g) vc.push_back(i);
    sort(vc.begin(), vc.end());

    cout << vc[vc.size()-k];

}


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

//For recursion
long int gcd_Euclid(long int a, long int b){
	//assert(a>=b);
	if(b==0){return a;}
	else{gcd_Euclid(b,a%b);}
}


int main(){
	long int x,y;
	cin >> x >> y;
	if (x<y){swap(x,y);}
	cout << gcd_Euclid(x,y) << endl;
	return 0;
}



Measured memory_bytes: 3092
#include <stdio.h>

int main(void) {
    int ch;
    ch = getchar();

    if(ch >= 'a' && ch <= 'z') {
        putchar('a');
    }
    else if(ch >= 'A' && ch <= 'Z') {
        putchar('A');
    }
    printf("\n");
}

Measured memory_bytes: 1960
#include <bits/stdc++.h>
#define eb emplace_back
#define all(v) v.begin(),v.end()
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll INF=1LL<<60;
const ll MOD=998244353LL;
template<class T> void chmin(T &a,T b){a=min(a,b);}
template<class T> void chmax(T &a,T b){a=max(a,b);}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll n,t;cin>>n>>t;
	vector<ll> bs;
	vector<P> v;
	for(int i=0;i<n;i++){
		ll a,b;cin>>a>>b;
		if(a==0){
			bs.eb(b+1LL);
		}else{
			v.eb(a,b);
		}
	}
	sort(all(bs));
	vector<ll> sum(bs.size()+1);
	for(int i=0;i<bs.size();i++){
		sum[i+1]=sum[i]+bs[i];
	}
	sum.eb(INF);
	ll res=upper_bound(all(sum),t)-sum.begin();
	--res;
	n=v.size();
	sort(all(v),[](P &a,P &b){return (a.second+1LL)*b.first<a.first*(b.second+1LL);});
	vector<vector<ll>> dp(35,vector<ll>(n+1,INF));
	for(int i=0;i<n;i++){
		dp[1][i]=(v[i].first+1LL)+v[i].second;
		if(dp[1][i]<=t){
			ll s=upper_bound(all(sum),t-dp[1][i])-sum.begin();
			chmax(res,s);
		}
	}
	for(int i=2;i<=30;i++){
		ll mi=INF;
		for(int j=0;j<n;j++){
			if(mi<=t){
				dp[i][j]=(v[j].first+1LL)*mi+v[j].second;
				if(dp[i][j]<=t){
					ll s=upper_bound(all(sum),t-dp[i][j])-sum.begin();
					s+=i-1LL;
					chmax(res,s);
				}
			}
			chmin(mi,dp[i-1][j]+1LL);
		}
	}
	cout<<res<<endl;
}


Measured memory_bytes: 60268
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,k = LI()
    f = [-1]*(k+1)
    p = 2
    while p <= k:
        x = 2*p
        while x <= k:
            f[x] -= f[p]
            x += p
        p += 1
    ans = 0
    p = [1]
    for i in range(1,k+1):
        p.append(pow(k//i,n,mod))
    for i in range(1,k+1):
        res = p[i]
        x = 2*i
        j = 2
        while x <= k:
            res += p[x]*f[j]
            x += i
            j += 1
        ans += i*res
        ans %= mod
    print(ans%mod)
    return

#Solve
if __name__ == "__main__":
    solve()


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

#define stirng string
#define vvi vector<vector<int>>
#define vi vector<int>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const int inf = 1e9 + 7;

int main() {
  int x, a, b;
  cin >> x >> a >> b;
  int c = x - a;
  while (c > 0) {
    c -= b;
  }
  if (c == 0) {
    cout << c << endl;
  } else {
    cout << c + b << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
int main(){
  int a,b;
  cin>>a>>b;
  int af=a;
  int bf=b;
  for(int i=1; i<b; i++){
    a =a*10 +af;
  }
  for(int i=1; i<af; i++){
    b =b*10 +bf;
  }
  string as=to_string(a);
  string bs=to_string(b);
  if(as>bs) cout<<b<<endl;
  else cout<<a<<endl;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
w = [int(input()) for _ in range(n)]

def check(P):
    s, cnt = 0, 1
    for i in range(n):
        if w[i] > P:
            return False
        if s + w[i] <= P:
            s += w[i]
        else:
            s = w[i]
            cnt += 1
    return cnt <= k

l, r = 0, 10000 * n
while r - l > 1:
    m = (l + r) // 2
    if check(m):
        r = m
    else:
        l = m

print(r)

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

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

	string str;cin >> str;
	REP(i, str.size() - 1){
		if(str[i] == str[i+1]){
			cout << "Bad" << endl;
			return 0;
		}
	}

	cout << "Good" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define INF (1 << 27)
using namespace std;

typedef struct {
    int a, b, c;
} Item;

Item itm[50];
int n, ma, mb;
int dp[45][405][405];

int dfs(int i, int a, int b);

int main()
{
    for (int i = 0; i <= 40; i++) {
        for (int j = 0; j <= 400; j++) {
            for (int k = 0; k <= 400; k++) {
                dp[i][j][k] = -1;
            }
        }
    }
    
    cin >> n >> ma >> mb;
    for (int i = 0; i < n; i++) {
        cin >> itm[i].a >> itm[i].b >> itm[i].c;
    }

    int ans = dfs(0, 0, 0);

    if (ans == INF) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }

    return 0;
}

int dfs(int i, int a, int b)
{
    if (dp[i][a][b] != -1) {
        return dp[i][a][b];
    }
  
    if (i == n) {
        if (a * mb == b * ma && (a != 0 && b != 0)) {
            return 0;
        } else {
            return INF;
        }
    }
    
    return dp[i][a][b] = min(dfs(i + 1, a, b),
                             dfs(i + 1, a + itm[i].a, b + itm[i].b) + itm[i].c);
}


Measured memory_bytes: 26880
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
bool cf(pair<int,int> a,pair<int,int> b){
    if(a.first==b.first)return a.second<b.second;
    else return a.first<b.first;
}
signed main(){
    int n;cin>>n;
    int res=0;bool ok=true;
    vector<int> a(n);
    vector<pair<int,int>> b(n);
    vector<pair<int,int>> s(n);
    rep(i,n){
        cin>>a[i];
        b[i].first=a[i];
        b[i].second=i;
        s[i].first=i-a[i];
        s[i].second=i;
    }
    sort(b.begin(),b.end(),cf);
    sort(s.begin(),s.end(),cf);
    reverse(s.begin(),s.end());
    res+=s[0].second-s[0].first;
    rep1(i,n-1){
        if(s[i].first<0)ok=false;
        if(s[i-1].first!=s[i].first){
            res+=s[i].second-s[i].first;
        }
        //cout<<s[i].first<<" "<<s[i].second<<endl;
    }
    if(a[0]!=0)ok=false;
    rep1(i,n-1){
        if(a[i]<=a[i-1]||a[i]==a[i-1]+1)continue;
        ok=false;
    }
    if(ok)cout<<res;
    else cout<<"-1";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 8064
#include <iostream>
using namespace std;
 
int main() 
{
  int number[3];
  cin >> number[0] >> number[1] >> number[2];
  int min = 0;
  int i;
  for(i = 1;i < 3;i++){
    if(number[min] >number[i]){
      min = i;
    }
  }
  int max = 0;
  for(i = 1;i < 3;i++){
    if(number[max] < number[i]){
      max = i;
    }
  }
  int center = number[0] + number[1] + number[2] - number[min] - number[max];
  cout << number[min] << " " << center << " " << number[max] << endl;
  return 0;
}


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

template <typename T>
T gcd(T x, T y)
{
    if (y == 0)
        return x;
    return gcd(y, x % y);
}

template <typename T>
T lcm(T x, T y)
{
    if (x == 0 || y == 0)
        return 0;
    return x / gcd(x, y) * y;
}

int main()
{
    int X, Y, Z;
    cin >> X >> Y >> Z;
    X -= Z;
    cout << X / (Y + Z) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
map<ll,char>MP;
int N,M;
string S,T;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>N>>M>>S>>T;
    ll gc=__gcd(N,M);
    for(int i=0;i<N;i++)
        MP[M/gc*i]=S[i];
    for(int i=0;i<M;i++)
        if(MP.find(N/gc*i)!=MP.end()&& MP[N/gc*i]!=T[i])
        {
            cout<<-1;
            return 0;
        }
    cout<<(N/gc*M);
}


Measured memory_bytes: 6144
import java.io.*;

public class Main{
	public static void main(String[] args){
		String s;
		int d,n,number,x;
		int sum=0;
		BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
		try{
			while((s=r.readLine()) !=null){
				x=0;
				d=Integer.parseInt(s);
				number=600/d;
				for(int i=0;i<number;i++){
					sum +=d*x*x;
					x +=d;
				}
				System.out.println(sum);
				sum=0;
				continue;
			}
		}catch(IOException e){
			System.out.println(e);
		}
	}
}

Measured memory_bytes: 16860
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;
using ll = long long;
using P = pair<ll, ll>;


ll N;
vector<ll> A;

void input() {
    cin >> N;
    A.resize(N);
    for (auto &v : A)
        cin >> v;
}

int solve() {
    auto sum = 0;
    for (auto v : A)
        sum += v;
    auto ave = float(sum) / N;
    auto copyA = A;
    sort(copyA.begin(), copyA.end(), [ave](auto l, auto r) {
        return abs(l - ave) < abs(r - ave);
    });
    auto sumbN = copyA.front();
    for (int i = 0; i < N; i++) {
        if (A[i] == sumbN) {
            return i;
        }
    }
    return 0;
}


int main() {
    input();
    cout << solve() << endl;
    
    return 0;
}



Measured memory_bytes: 888
/* https://codeforces.com/contest/1360/problem/H */
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using vs = vector<string>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<ll, ll>>;
using ld = double;

#define f first
#define s second 
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define pb push_back
#define	lb lower_bound
#define	ub upper_bound
#define	sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define ins insert

const int MAX = INT_MAX;

int main() {
	
	int N, D;
	cin>>N>>D;
	ll x, y;
	int cnt = 0;
	for (int i = 0;i < N;++i) {
		cin>>x>>y;
		double d = sqrt(x*x + y*y);
		if (d <= D) {
			++cnt;
		}

	}

	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 3676
a, b, k = map(int, input().split())
ans = []

for i in range(a, min(b+1, a+k)):
    ans.append(i)

for i in range(b, max(a+k-1, b-k), -1):
    ans.append(i)

ans.sort()
for num in ans:
    print(num)

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

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define f(i,a,b) for(int i=a;i<b;i++)
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}
ll gcd_ll(ll x, ll y){
  long long a= max(x,y), b=min(x,y), c=a%b;
  while( c!=0){
    a =b;
    b =c;
    c = a%b;
  }
  return b;
}

int abs(int x, int y){
  if(x>=y){
    return x-y;
  }
  else if(y>x){
    return y-x;
  }
}
ll fiv(ll n){
  if(n==0){
    return 1;
  }
  else if(n==1){
    return 1;
  }
  return fiv(n-1)+fiv(n-2);
}
ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

int main(){
    string s;
    cin>>s;
    rep(i,s.size()){
      cout << 'x';
    }
    cout<<' '<<endl;
    

}





Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int V, E; cin >> V >> E;
	vector<vector<int>>G(V, vector<int>(V, INF));
	rep(i, 0, E) {
		int s, t, d; cin >> s >> t >> d;
		G[s][t] = d;
	}
	int ans(INF);
	vector<vector<int>>dp((1 << V), vector<int>(V, INF));
	rep(k, 0, 1) {
		dp[(1 << V) - 1][k] = 0;


		for (int bits = (1 << V) - 1 - 1; bits >= 0; bits--) {
			rep(i, 0, V) {
				// current point
				rep(j, 0, V) {
					if (!(bits&(1 << j))) {// not yet
						chmin(dp[bits][i], dp[bits | (1 << j)][j] + G[i][j]);
					}
				}


			}
		}
		chmin(ans, dp[0][k]);
	}
	cout << (ans==INF?-1:ans) << endl;
	return 0;
}

Measured memory_bytes: 6328
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int A[100010];
    rep(i, n) cin >> A[i];
    sort(A, A + n);
    int ans = 0;
    
    vector<int> v;
    
    deque<int> deq1, deq2;
    int sum = 0;
    int l = 0, r = n - 1;
    deq1.push_back(A[l++]);
    while(l <= r) {
        if(l <= r)
            deq1.push_back(A[r--]);
        if(l <= r)
            deq1.push_front(A[r--]);
        if(l <= r)
            deq1.push_back(A[l++]);
        if(l <= r)
            deq1.push_front(A[l++]);
    }
    rep(i, n - 1) sum += abs(deq1[i] - deq1[i + 1]);
    // rep(i, n) cout << deq1[i] << " ";
    // cout << endl;
    ans = sum;
    sum = 0;
    l = 0, r = n - 1;
    deq2.push_back(A[r--]);
    while(l <= r) {
        if(l <= r)
            deq2.push_back(A[l++]);
        if(l <= r)
            deq2.push_front(A[l++]);
        if(l <= r)
            deq2.push_back(A[r--]);
        if(l <= r)
            deq2.push_front(A[r--]);

    }
    // rep(i, n) cout << deq2[i] << " ";
    // cout << endl;
    rep(i, n - 1) sum += abs(deq2[i] - deq2[i + 1]);
    ans = max(ans, sum);
    cout << ans << endl;
   
    return 0;
}

// 1 7 3 5
// 7 1 5 3

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

string a;
int s;
int main() {
	int i, j;
	cin >> a;
	for(i=0, j=a.size()-1; i<j; i++, j--) s += a[i]!=a[j];
	cout << s;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
typedef pair<int, bool> sP;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-5;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;

void solve() {
	int a, b; cin >> a >> b;
	if (a <= 9 && b <= 9) {
		cout << a * b << endl;
	}
	else {
		cout << -1 << endl;
	}
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(7);
	//init();
	solve();
	//stop
	return 0;
}



Measured memory_bytes: 256
main = do
  li <- getLine
  let n = read li
  let ans = compute n
  putStrLn $ unlines ans

compute :: Int -> [String]
compute n = permlim n 'a'
  where
    xs = take n ['a'..]
-- 長さnで、xsの辞書順リスト。ただし新たな要素を使うなら必ずk
-- kを使った場合、それ以降はk+1まで使ってよい。
-- DPしないと吹っ飛ぶ？
    permlim 0 _ = [ [] ]
    permlim n k =
      [ x:ys
      | x <- takeWhile (k >=) xs
      , ys <- permlim (pred n) (if x == k then succ k else k) ]

Measured memory_bytes: 3580
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(){
    string s;
    vector<string> t(2);
    t[0] = "apple";
    t[1] = "peach";
    int cnt = 0;
    while(cin >> s){
        string ans = "";
        int n = s.size();
        for(int i = 0; i < n; i++){
            //cout << s.substr(i,5) << endl;
            if(s.substr(i,5) == t[0]){
                ans += t[1];
                i += 4;
            }else if(s.substr(i,5) == t[1]){
                ans += t[0];
                i += 4;
            }else{
                ans += s[i];
            }
        }
        if(cnt)cout << " ";
        cout << ans;
        cnt++;
    }
    cout << endl;
}



Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  
  if (S == "abc" || S == "acb" || S == "bac" || S == "bca" || S == "cab" || S == "cba"){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3588
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 19 22:51:44 2018

@author: maezawa
"""

class node():
    def __init__(self, key, parent=None, right=None, left=None):
        self.key = key
        self.parent = parent
        self.right = right
        self.left = left
        
def insert(z):
    global root
    y = None
    x = root
    while x != None:
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right
    z.parent = y
    
    if y == None:
        root = z
    elif z.key < y.key:
        y.left = z
    else:
        y.right = z  
    #inorder(root)
    
def find(x, k):
    while x != None and k != x.key:
        if k < x.key:
            x = x.left
        else:
            x = x.right
    return x

def delete_node(z):
    global root
    #x = node(None)
    if z.left == None or z.right == None:
        y = z
    else:
        y = get_successor(z)
        
    if y.left != None:
        x = y.left
    else:
        x = y.right
    if x != None:
        x.parent = y.parent

    if y.parent == None:
        root = x
        #print('deleteing {}, settting the root for {}'.format(y.key,x))
    elif y == y.parent.left:
        y.parent.left = x
    else:
        y.parent.right = x
    if y != z:
        z.key = y.key
        
def get_successor(x):
    if x.right != None:
        return get_min(x.right)
    y = x.parent
    while y != None and x == y.right:
        x = y
        y = y.parent
    return y

def get_min(x):
    while x.left != None:
        x = x.left
    return x
        
def inorder(u):
    if u == None:
        return
    inorder(u.left)
    print(' {}'.format(u.key), end = '')
    inorder(u.right)
    
def preorder(u):
    if u == None:
        return
    print(' {}'.format(u.key), end = '')
    preorder(u.left)
    preorder(u.right)
    
root = None

n = int(input())
for i in range(n):
    q = list(input().split())
    if q[0] == 'insert':
        z = node(int(q[1]))
        insert(z)
    elif q[0] == 'find':
        if find(root, int(q[1])):
            print('yes')
        else:
            print('no')
    elif q[0] == 'delete':
            z = find(root, int(q[1]))
            delete_node(z)
    elif q[0] == 'print':
        inorder(root)
        print()
        preorder(root)
        print()
    #print('root:{}'.format(root.key))
        
        


Measured memory_bytes: 85280
fun main(args: Array<String>) {
    val (x, y) = readLine()!!.split(" ").map { it.toInt() }
    val l = readLine()!!.split(" ").map { Math.abs(it.toInt() - y) }.reduce{a,b -> gcd(a, b)}
    println(l)
}

fun gcd(a: Int, b: Int): Int {
    if (b == 0) return a
    return if (a < b)gcd(b, a) else gcd(b, a % b)
}


Measured memory_bytes: 51680
main = getLine >> interact (f 0 0 0 . map ((`mod` 4) . read) . words)
 
f x y z []
  | y + 2 > x + t = "Yes"
  | otherwise = "No"
    where t = if z > 0 then 1 else 0
f x y z (0:as) = f x (succ y) z as
f x y z (2:as) = f x y (succ z) as
f x y z (_:as) = f (succ x) y z as

Measured memory_bytes: 2428
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e6 + 10; 
const double pi = acos(-1.0);

inline ll read()
{
    ll kk=0,f=1;
    char cc=getchar();
    while(cc<'0'||cc>'9'){if(cc=='-')f=-1;cc=getchar();}
    while(cc>='0'&&cc<='9'){kk=(kk<<1)+(kk<<3)+cc-'0';cc=getchar();}
    return kk*f;
}

int a[maxn]={0};
int main(void)
{
	int k,n;
	k = read();
	n = read();
	
//	int mi=0,ma=k;
	int d=0,md=0;
	a[0]=read();
	for(int i = 1;i<n;i++)
	{
		a[i]=read();
		d = a[i]-a[i-1];
		if(d>md)md=d;
	}
	
	int ans;
	ans = min(a[n-1]-a[0], k - md );
	printf("%d",ans);

	return 0;
}

Measured memory_bytes: 1024
a,b,i,c,k[3100];
main()
{
 
    scanf("%d%d",&a,&b);
    for(;;puts(""))
    {
      c=0;
      for(i=a;i<=b;i++)
	if(i%400==0||(i%100!=0&&i%4==0))
	  k[c++]=i;
      if(!c)
	puts("NA");
      else
	{
	  for(i=0;i<c;)
	    printf("%d\n",k[i++]);
	}
      scanf("%d%d",&a,&b);
      if(!a)
	exit(0);
    }
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

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

  int x[5];
  rep(i, 3) cin >> x[i];
  sort(x, x + 3, greater<int>());
  cout << x[0] * 10 + x[1] + x[2] << "\n";

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()


using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;

struct edge{
    int to;
    int dist;
};

vector<bool> seen(100000, false);
vector<int> pnt(100000, INF);
vector<vector<edge>> G(100000);
int n, m;
bool f = true;


void dfs(int v, int dist){
    seen[v] = true;
    if(pnt[v] == INF)pnt[v] = dist;
    else {
        if(pnt[v] != dist)f = false;
        return;
    }

    for(int i = 0; i < (int)(G[v].size()); i++){
        edge e = G[v][i];
        if(pnt[e.to] != INF && pnt[e.to] != pnt[v] + e.dist){
            f = false;
            return;
        }
        if(seen[e.to])continue;
        dfs(e.to, e.dist + pnt[v]);
    }
}

int main(){
    cin >> n >> m;
    int s;
    rep(i, m){
        int a, b, c;
        cin >> a >> b >> c;
        a--;b--;
        s = a;
        edge e1 = {b, c};
        edge e2 = {a, -c};
        G[a].push_back(e1);
        G[b].push_back(e2);
    }
    
    rep(i, n){
        if(G[i].size() == 0)continue;
        if(seen[i])continue;
        dfs(i, 0);
    }
    cout << (f ? "Yes" : "No") << endl;

}


Measured memory_bytes: 12032
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
int main(){
  int a, b, ans;
    cin >> a >> b;
    if(b%a==0){
      ans = a+b;
    }else
      ans = b-a;
    cout << ans <<endl;


}


Measured memory_bytes: 256
#include <cstdio>
typedef long long ll;

ll n, m;

int main(){

    scanf("%lld %lld" ,&n, &m);

    if(n==1 && m==1) printf("1");
    else if(n==1 || m==1){
        if(n==1) printf("%lld" ,m-2);
        else printf("%lld" ,n-2);
    }
    else printf("%lld" ,(n-2)*(m-2));
    return 0;
}

Measured memory_bytes: 128
package main
 
import (
  "fmt"
)
 
func main() {
 
  var n,k int
  fmt.Scan(&n)
  fmt.Scan(&k) 
  
  sum := 0
  mul := 0
  ans := 1
  
  for i := 0; i < n; i++ {
    sum = ans + k
    mul = ans * 2
    if (sum < mul) {
      ans = sum
    } else {
      ans = mul
    }
  }
    fmt.Println(ans)
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
/*bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
} */
int main()
{
     ll t;
     map<string,ll>mp;
     cin>>t;
     t--;
     string str;
     cin>>str;
     char ch=str[str.size()-1];
     mp[str]++;
     ll cnt=0;
     while(t--)
     {
         cin>>str;
         if(str[0]!=ch || mp[str]>0)
            cnt=10;
         ch=str[str.size()-1];
         mp[str]++;
     }
     if(cnt==10)
        cout<<"No"<<endl;
     else
        cout<<"Yes"<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
#define endl '\n'
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

int match[9]={2,5,5,4,5,6,3,7,6};
int dp[10001];

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

    int n,m; cin>>n>>m;
        vector<P> a(m);
    rep(i,m){
        cin>>a.at(i).F;
        a.at(i).S=match[a.at(i).F-1];
    }

    sort(all(a),greater<P>());
    fill(dp+1,dp+10001,-INF);
    rep(i,n){
        rep(j,m){
            if(i+1-a.at(j).S>=0)chmax(dp[i+1],dp[i+1-a.at(j).S]+1);
        }
    }

    while(n>0){
        rep(j,m){
            if(n-a.at(j).S>=0){
                if(dp[n]==dp[n-a.at(j).S]+1){
                    cout<<a.at(j).F;
                    n-=a.at(j).S;
                    break;
                }
            }
        }
    }
    cout<<endl;

}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=1234567;
const ll INF=1000000010;
const ll LINF=1000000000000000010LL;
const int MAX=10000010;
const double EPS=1e-3;
int dx[4]={0,1,0,1};
int dy[4]={0,0,1,1};
int prime[MAX];		
void erast(){
	prime[0]=0;prime[1]=0;
	for(int i=2;i<MAX;i++){
   		prime[i]=1;
	}
	for(int i=2;i<=MAX/2;i++){
    	if(prime[i]==1){
        	for(int j=i+i;j<=MAX;j+=i){
            	prime[j]=0;
        	}
    	}
	}
}
int main(){
	int n;
	erast();
	while(cin>>n){
		int ans=0;
		for(int i=1;i<=n;i++){
			if(prime[i]){
				ans++;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}



Measured memory_bytes: 42040
#include<iostream>
#define SIZE 200000
using namespace std;

struct Queue{
  int table[SIZE];
  int tail,head;

  void init(){
    head=tail=0;
  }

  bool empty(){
    return head==tail;
  }
  
  void inqueue(int x){
    table[tail]=x;
    tail++;
    tail%=SIZE;
  }

  int dequeue(){
    if(empty())return 0;
    int res=table[head];
    head++;
    head%=SIZE;
    return res;
  }
};

int main(){
  Queue queue,queue2;
  int n,q,num;
  string table[SIZE];
  cin>>n>>q;
  queue.init();
  queue2.init();
  for(int i=0;i<n;i++){
    cin>>table[i]>>num;
    queue.inqueue(num);
    queue2.inqueue(i);
  }
  
  int now=0,A,B;
  while(!queue.empty()){
    A=queue.dequeue();
    B=queue2.dequeue();
    if(A<=q){
      now+=A;
      cout<<table[B]<<' '<<now<<endl;
    }else{
      now+=q;
      A-=q;
      queue.inqueue(A);
      queue2.inqueue(B);
    }
  }
  
  return 0;
}

Measured memory_bytes: 6596