akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
//typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const int MAX_N=600;
int N,M;
vector<int> G[MAX_N];
double dp[MAX_N];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	scanf("%d %d",&N,&M);
	REP(i,M){
		int s,t;
		scanf("%d %d",&s,&t);
		s--;
		t--;
		G[s].push_back(t);
	}
	dp[N-1]=0;
	double ans=N;
	REP(k,N){
		for(int i=N-2;i>=0;i--){
			double mdp=0;
			dp[i]=0;
			for(auto e:G[i]){
				dp[i]+=dp[e];
				mdp=max(mdp,dp[e]);
			}
			if(i==k&&G[i].size()>=2){
				dp[i]-=mdp;
				dp[i]/=G[i].size()-1;
			}else{
				dp[i]/=G[i].size();
			}
			dp[i]++;
		}
		ans=min(ans,dp[0]);
	}
	printf("%.8f\n",ans);
}

Measured memory_bytes: 1408
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	static class Vertex{
		List<Integer> adj;
		public Vertex() {
			adj = new ArrayList<Integer>();
		}
	}
	static List<Integer> findCircuit(Vertex vs[] , int startPoint){
		Vertex v = vs[startPoint];
		if(v.adj.isEmpty()){
			return null;
		}
		Queue<Integer> q = new LinkedList<Integer>();
		q.add(startPoint);
		int N = vs.length;
		int prev[] = new int[N];
		Arrays.fill(prev, -1);
		while(!q.isEmpty()){
			int cur = q.poll();
			Vertex vcur = vs[cur];
			for(int n : vcur.adj){
				if(n == startPoint){ // find circuit
					List<Integer> ret = new ArrayList<Integer>();
					while(prev[cur] != startPoint){
						ret.add(cur);
						cur = prev[cur];
					}
					ret.add(cur);
					ret.add(startPoint);					
					return ret;
				}
				if(prev[n] == -1){
					prev[n] = cur;
					q.add(n);
				}
			}
		}
		return null;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		Vertex vs[] = new Vertex[N];
		for(int i = 0 ; i < vs.length ; ++i){
			vs[i] = new Vertex();
		}
		for(int i = 0 ; i < M ; ++i){
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			vs[a].adj.add(b);
		}
		List<Integer> minCircuit = null;
		for(int i = 0 ; i < N ; ++i){
			List<Integer> circuit = findCircuit(vs, i);
			if(circuit != null){
				if(minCircuit == null){
					minCircuit = circuit;
				}else if(circuit.size() < minCircuit.size()){
					minCircuit = circuit;
				}
			}
		}
		if(minCircuit == null){
			System.out.println(-1);			
		}else{
			System.out.println(minCircuit.size());
			for(int v : minCircuit){
				System.out.println(v + 1);
			}
		}
	}
}


Measured memory_bytes: 61888
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

ostream& operator << (ostream& os, const mint a) {
    os << a.x;

    return os;
}


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    ll N, K;
    cin >> N >> K;

    MOD = K;

    vll A(N);
    REP(i, N) {
        cin >> A[i];
    }

    vector<mint> S(N + 1);
    S[0] = 0;
    REP(i, N) S[i + 1] = S[i] + A[i];

    map<ll, int> m;
    ll ans = 0;
    REP(i, N + 1) {
        if (i - K >= 0) m[(S[i - K] - i + K).x]--;
        ans += m[(S[i] - i).x];
        m[(S[i] - i).x]++;
    }

    print(ans);
    
}


Measured memory_bytes: 18768
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;
lint p=998244353;

int main(){
  int N;
  cin>>N;
  int D[N];
  REP(i,N)cin>>D[i];
  map<lint,lint> m;
  REP(i,N)m[D[i]]++;
  lint ans=1;
  int counter=1;
  if(D[0]!=0){
      cout<<0<<endl;
      return 0;
  }
  FOR(i,1,N){
    if(m[i]==0 and counter<N){
      cout<<0<<endl;
      return 0;
    }
    REP(j,m[i]){
      ans*=m[i-1];
      ans%=p;
      counter++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 6912
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 20;
const int MAXD = 20;

struct node{
	int cor[MAXD];
	node(){memset(cor, 0, sizeof(cor));}
};

int n, d, ans;
node pt[MAXN];

inline bool dis(const node &x, const node &y);

int main(){
	scanf("%d %d", &n, &d);
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= d; j++)
			scanf("%d", &pt[i].cor[j]);
	ans = 0;
	for(int i = 1; i <= n; i++)
		for(int j = i + 1; j <= n; j++)
			if(dis(pt[i], pt[j])) ans++;
	printf("%d\n", ans);
	return 0;
}

inline bool dis(const node &x, const node &y){
	double res = 0;
	for(int i = 1; i <= d; i++)
		res += (x.cor[i] - y.cor[i]) * (x.cor[i] - y.cor[i]);
	int tmps = sqrt(res);
	if(tmps * tmps == res) return true;
	else return false;
}

Measured memory_bytes: 256
#include <cstdio>
typedef long long lld;
const int MAXN = 305;
lld graph[MAXN][MAXN]{ };
bool skip[MAXN][MAXN]{ };
lld M, ret=0;
int N;

int main()
{
	scanf("%d", &N);
	for(int i = 1; i <= N; ++i)
	for(int j = 1; j <= N; ++j)
		scanf("%d", &graph[i][j]);
	for(int k = 1; k <= N; ++k)
	for(int i = 1; i <= N; ++i) if(k != i)
	for(int j = 1; j <= N; ++j) if(k != j && i != j)
		if(graph[i][k] + graph[k][j] < graph[i][j])
			return puts("-1"), 0;
		else if(graph[i][k] + graph[k][j] == graph[i][j])
			skip[i][j] = skip[j][i] = true;
	for(int i = 1; i < N; ++i)
	for(int j = i+1; j <= N; ++j)
		if(!skip[i][j]) ret += graph[i][j];
	printf("%lld\n", ret);
	return 0;
}

Measured memory_bytes: 1152
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        //var n = int.Parse(Console.ReadLine());
        int[] nmk = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nmk[0];
        var m = nmk[1];
        var k = nmk[2];
        var ans = "No";

        for (int i = 0; i <= m; i++)
        {
            for (int j = 0; j <= n; j++)
            {
                var x = n - j;
                if (x < 0) x = 0;
                var y = m - i;
                if (y < 0) y = 0;

                var tmp = i * x + j * y;
                if (tmp == k) ans = "Yes";
            }
        }

        // 出力
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 28248
#include<bits/stdc++.h>
using namespace std;
#define pi pair<int, int>
vector<int> color;
vector<vector<pi>> adj;
int k;
void dfs(int node, int parEdge){
  int c = 0;
  for(int i = 0; i < adj[node].size(); i++){
    if(adj[node][i].second != parEdge){
      c++;
      if(parEdge != -1 && c == color[parEdge]) c++;
      color[adj[node][i].second] = c;
      dfs(adj[node][i].first, adj[node][i].second);
    }
  }
}
int main(){
  int N; cin >> N;
  int root = 0;
  adj = vector<vector<pi>>(N);
  for(int i = 0; i < N-1; i++){
    int a, b; cin >> a >> b; a--; b--;
    adj[a].push_back({b, i});
    adj[b].push_back({a, i});
  }
  k = 0;
  for(int i = 0; i < N; i++) k = max(k, (int)adj[i].size());
  cout << k << endl;
  color = vector<int>(N-1);
  dfs(root, -1);
  for(int i = 0; i < N-1; i++) cout << color[i] << endl;
}


Measured memory_bytes: 6912
#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<set>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)
#define pb push_back

int t,n;
int stx,sty;

typedef pair<int,int> pii;
set<pii> block;


bool input(){
	cin>>t>>n;
	if(t==0 && n==0)return false;
	
	block.clear();
	rep(i,n){
		int a,b;
		cin>>a>>b;
		block.insert(pii(a,b));
	}
	
	cin>>stx>>sty;
	return true;
}

class P{
	public:
	int x,y,t;
	P(int x,int y,int t):x(x),y(y),t(t){}
};

void solve(){
	set<pii> visit;
	queue<P> que;
	
	que.push(P(stx,sty,0));
	
	while(!que.empty()){
		
		P u = que.front();
		que.pop();
		
		if(block.find(pii(u.x,u.y)) != block.end())continue;
		
		if(visit.find(pii(u.x,u.y)) != visit.end())continue;
		
		visit.insert(pii(u.x,u.y));
		
		if(u.t==t)continue;
		
		
		int dx[]={1,1,0,-1,-1,0};
		int dy[]={0,1,1,0,-1,-1};
		
		rep(i,6){
			que.push(P(u.x+dx[i], u.y+dy[i], u.t+1));
		}
	}
	
	cout<<visit.size()<<endl;
}

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

Measured memory_bytes: 1372
N = int(input())
a = [0 for i in range(N)]
st = input().split()
for i in range(N):
  a[i] = int(st[i])
m = min(a); M = max(a)
b = [0 for i in range(M - m + 1)]
for i in range(N):
  b[a[i]-m] += 1
c = [0 for i in range(M - m + 1)]
if len(b) >= 2:
	c[0] = b[0] + b[1]
	c[M - m] = b[M - m] + b[M - m - 1]
	for i in range(1, M - m):
	  c[i] = b[i-1] + b[i] + b[i+1]
	print(max(c))
else:
  print(max(b))


Measured memory_bytes: 15408
for i in range(1, int(input()) + 1):
    x = i
    if not x % 3:
        print(f' {i}', end='')
        continue
    
    while x:
        if x % 10 == 3:
            print(f' {i}', end='')
            break
        x //= 10
print()
    



Measured memory_bytes: 5884
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s, t;
    cin >> s>> t;
    bool toggle = false;
    if(s.size() != t.size() - 1){
        cout<<"No\n";
        return 0;
    }
    for(int i= 0;i < s.size(); i++){
        if(s[i] != t[i]){
            toggle = true;
            break;
        }
    }
    if(toggle){
        cout<<"No\n";
    }
    else{
        cout<<"Yes\n";
    }
    return 0;
}

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

    using namespace std;

    typedef long long int ll;
    #define MOD (ll)(1e9+7)
    #define endl "\n"
    #define pb push_back
    #define TEST_CASES  ll t;cin>>t;while(t--)
    #define forn(i,a,n) for (int i = a; i < n; ++i)
    #define f first
    #define s second
    #define all(x) x.begin(), x.end()

    void __print(int x) {cerr << x;}
    void __print(long x) {cerr << x;}
    void __print(long long x) {cerr << x;}
    void __print(unsigned x) {cerr << x;}
    void __print(unsigned long x) {cerr << x;}
    void __print(unsigned long long x) {cerr << x;}
    void __print(float x) {cerr << x;}
    void __print(double x) {cerr << x;}
    void __print(long double x) {cerr << x;}
    void __print(char x) {cerr << '\'' << x << '\'';}
    void __print(const char *x) {cerr << '\"' << x << '\"';}
    void __print(const string &x) {cerr << '\"' << x << '\"';}
    void __print(bool x) {cerr << (x ? "true" : "false");}

    template<typename T, typename V>
    void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
    template<typename T>
    void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
    void _print() {cerr << "]\n";}
    template <typename T, typename... V>
    void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
    #ifndef ONLINE_JUDGE
    #define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
    #else
    #define debug(x...)
    #endif
    ll powD(ll x,ll y){
      ll res = 1;
      while(y > 0){
        if(y & 1)
          res = (res*x)%MOD;
        x = (x*x)%MOD;
        y = y>>1;
      }
      return res;
    }

  
    int dfs(int v,vector<bool>& visited,vector<set<int>>& adj){
      visited[v] = 1;
      int sum = 1;
      for(auto i : adj[v]){
        if(!visited[i]){
          sum += dfs(i,visited,adj);
        }
      }
      return sum;
    }

    /*CHECK FOR CORNER CASES FOR GOD'S SAKE*/
    int main()
    {
      //freopen("input.txt", "r", stdin);
      //freopen("output.txt", "w", stdout);
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      int n,m;
      cin>>n>>m;
      vector<set<int>> adj(n);
      forn(i,0,m){
        int u,v;
        cin>>u>>v;
        u--;v--;
        adj[u].insert(v);
        adj[v].insert(u);
      }
      int maxm = 0;
      vector<bool> visited(n,0);
      forn(i,0,n){
        if(!visited[i]){
          maxm = max(maxm,dfs(i,visited,adj));
        }
      }
      cout<<maxm<<endl;
      

  } 


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

int main() {
  string s;
  cin >>s;
  if(s[0] != s[1] && s[1] != s[2] && s[0] != s[2])
    cout << "Yes" << endl;
  else 
    cout <<"No" <<endl;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include <random>
#include <list>
#include <numeric>
#include <chrono>


#define rep(i,p,q) for(ll i = p;i < q;i++)
#define ll long long

using namespace std;

vector<vector<ll>> graph;
vector<ll> query;
vector<ll> ans;
vector<ll> visited;


//140 C
int main(void) {
	ll n;
	cin >> n;
	vector<ll> b = vector<ll>(n-1);
	rep(i, 0, n - 1) cin >> b[i];
	ll aB = b[1];
	ll ans = b[0];
	rep(i, 1, n-1) {
		ans += min(b[i], b[i - 1]);
	}
	ans += b[n - 2];
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
#include<complex>
#include<algorithm>
#include<vector>
#include<math.h>
#include<set>
#include<map>

int main()
{
	int x, t;
	scanf("%d%d", &x, &t);
	if (x > t)
		printf("%d\n", x - t);
	else
		printf("0\n");
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
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; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin >> n;
    ll ans=n*(n*n+3*n+2)/6;
    REP(i,n-1){
        ll u,v;cin >> u >> v;
        if(u>v){
            swap(u,v);
        }
        ans-=(n-v+1)*u;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3648
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;



struct aa {
	int id;
	int li;
	int cost;

	const bool operator<(const aa&r)const {
		return this->cost>r.cost;
	}
};
int main() {
	int W,H,N;cin>>W>>H>>N;

	vector<pair<int,int>>lights(N+1);

	lights[0]=make_pair(0,0);
	for (int i = 0; i < N; ++i) {
		int x,y;cin>>x>>y;
		lights[i+1]=make_pair(x-1,y-1);
	}
	lights.emplace_back(W-1,H-1);


	priority_queue<aa>que;
	vector<vector<int>>dp(N+2,vector<int>(1010,1e8));

	que.push(aa{ 0,0,0 });;
	dp[0][0]=0;

	while (!que.empty()) {
		aa atop(que.top());
		que.pop();

		const int now_id(atop.id);
		const int now_li(atop.li);
		const int now_cost=atop.cost;

		for (int next_id = 1; next_id < N + 2; ++next_id) {
			if(now_id==next_id)continue;
			if(now_id==0&&next_id==N+1)continue;

			int dis=abs(lights[now_id].first-lights[next_id].first)+abs(lights[now_id].second-lights[next_id].second);

			if (next_id != N + 1) {
				int next_li=max(1,dis-now_li+1);
				int next_cost=now_cost+(next_li-1);

				if (dp[next_id][next_li] > next_cost) {
					dp[next_id][next_li]=next_cost;
					que.push(aa{ next_id,next_li,next_cost });
				}
			}
			else {
				if (dis <= now_li-1) {
					dp[N+1][0]=min(dp[N+1][0],now_cost);

				}
				else {
					dp[N+1][0]=min(dp[N+1][0],now_cost+(dis-(now_li-1)));
				}
			}
		}
	}
	int ans=dp[N+1][0];
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 4252
#include<iostream>
using namespace std;
int main()
{
  int a,b,d,x,y;
  int i;
  while(cin>>a>>b>>d,a|b|d){
    x=y=(1<<30)-1;
    for(i=0;i<100000;i++){
      if(d>=a*i && (d-a*i)%b==0){
	if(x+y>i+(d-a*i)/b || (x+y==i+(d-a*i)/b && a*x+b*y>a*i+b*(d-a*i)/b)){
	  x=i;
	  y=(d-a*i)/b;
	}
      }
      if(a*i>=d && (a*i-d)%b==0){
	if(x+y>i+(a*i-d)/b || (x+y==i+(a*i-d)/b && a*x+b*y>a*i+b*(a*i-d)/b)){
	  x=i;
	  y=(a*i-d)/b;
	}
      }
      if((a*i+d)%b==0){
	if(x+y>i+(a*i+d)/b || (x+y==i+(a*i+d)/b && a*x+b*y>a*i+b*(a*i+d)/b)){
	  x=i;
	  y=(a*i+d)/b;
	}
      }
    }
    cout<<x<<" "<<y<<endl;
  }
}

Measured memory_bytes: 868
#include <iostream>
#include <cstring>

using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const int SIZE = 300;
const int N = 1000002;
int p[SIZE+1];
int dp1[N], dp2[N];

void make_pollock (void )
{
	memset (p, 0, sizeof (p ) );

	for (int i = 0; i <= SIZE; i++ ){
		ll ans = (ll)i*(i+1LL)*(i+2LL)/6LL;
		p[i] = (int)ans;
	} // end for
}

void make_dp (void )
{
	fill (dp1, dp1+N, INF );
	fill (dp2, dp2+N, INF );

	dp1[0] = 0;
	for (int i = 1; i <= SIZE; i++ ){
		int m = p[i];
		for (int j = m; j <= N; j++ )
			dp1[j] = min (dp1[j], dp1[j-m]+1 );
	} // end for

	dp2[0] = 0;
	for (int i = 1; i <= SIZE; i++ ){
		if (p[i] % 2 == 0 ) continue;
		int m = p[i];
		for (int j = m; j <= N; j++ )
			dp2[j] = min (dp2[j], dp2[j-m]+1 );
	} // end for	
}
	
int main()
{
	make_pollock();
	make_dp ();

	int n;
	while (cin >> n, n )
		cout << dp1[n] << ' ' << dp2[n] << endl;
	
	return 0;
}

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

inline long long read(){
    long long s = 0, w = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9'){
        if (ch == '-') w = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9'){
        s = s * 10 + ch - '0';
        ch = getchar();
    }
    return s * w;
}
long long n, r, g, b;
unsigned long long ans;
char s[4040];
int main(){
    n = read();
    for (int i = 1; i <= n; i++){
        s[i] = getchar();
        if (s[i] == 'R') r++;
        if (s[i] == 'G') g++;
        if (s[i] == 'B') b++;
    }
    ans = r * g * b;
    int _n = (n - 3) >> 1;
    for (int i = 0; i <= _n; i++){
        for (int j = 1; j + 2 * i + 2 <= n; j++){
            if (s[j] != s[j+i+1] && s[j] != s[j+i*2+2] && s[j+i+1] != s[j+i*2+2]){
                ans--;
            }
        }
    }
    cout << ans << endl;
    /*
    for (int i = 1; i <= n-2; i++){
        for (int j = i + 1; j <= n-1; j++){
            if (s[i] != s[j]){
                for (int k = j + 1; k <= n; k++){
                    if (j - i == k - j) continue;
                    if (s[i] != s[k] && s[j] != s[k]){
                        ans++;
                    }
                }
            }
        }
    }
    cout << ans << endl;
    */
    return 0;
}

Measured memory_bytes: 3628
def lcs():
    x, y = raw_input(), raw_input()
    x1 = [0 for k in range(len(y)+1)]
    for i in xrange(len(x)):
        e = x[i]
        x2 = x1 + []
        for j in xrange(len(y)):
            if e == y[j]:
                x1[j+1] = x2[j] + 1
            elif x1[j+1] < x1[j]:
                x1[j+1] = x1[j]
    print max(x1)
 
n = input()
for i in xrange(n):
    lcs()

Measured memory_bytes: 6500
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

n = int(readline())
a = list(map(int,readline().split()))
b = list(map(int,readline().split()))

c = [0]*(n+1)
d = [0]*(n+1)

for ai in a:
    c[ai] += 1

for bi in b:
    d[bi] += 1

for i in range(n+1):
    if (c[i]+d[i] > n):
        print("No")
        exit()
print("Yes")

for i in range(n):
    c[i+1] += c[i]
    d[i+1] += d[i]

divi = 0

for i in range(1,n+1):
    divi = max(divi, c[i]-d[i-1])

divi = n-divi

ans = b[divi:] + b[:divi]

print(" ".join(map(str, ans)))


Measured memory_bytes: 123608
A,B,K = map(int,input().split())

if K < A:
    A = A - K
    print(A,B)
else:
    K = K - A
    A = 0
#     print(K)
    if K < B:
        B -= K
        print(A,B)
    else:
        B = 0
        print(A,B)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline ll read(){
	ll ans=0;
	char ch=getchar();
	while(!isdigit(ch))ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
	return ans;
}
int n;
ll ans1=1,ans2=1;
inline ll gcd(ll a,ll b){while(b){ll t=a;a=b,b=t%a;}return a;}
int main(){
	n=read();
	for(int i=1;i<=n;++i){
		ll x=read(),y=read(),g=gcd(x,y);
		x/=g,y/=g;
		ll tmp1=ans1/x,tmp2=ans2/y,tmp;
		if(x*tmp1!=ans1)++tmp1;
		if(y*tmp2!=ans2)++tmp2;
		tmp=max(tmp1,tmp2);
		ans1=x*tmp,ans2=y*tmp;
	}
	cout<<ans1+ans2;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MAX = 1010;
const int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
//小さいほうから取り出すpriority queue
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
typedef pair<int, int>P;

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


long long nCr(long long n, long long r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	long long i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}	
signed main() {
	int R, G, B, N;
	int ans = 0;
	cin >> R >> G >> B >> N;
	REP(i, N / R+1) {
		REP(j, (N - i * R) / G+1) {
			if ((N - i * R - j * G) % B == 0)ans++;
		}
	}
	print(ans);
}


Measured memory_bytes: 256
divisors = [[] for i in range(101)]

for i in range(4, 101):
	for j in range(2, 10):
		if i % j == 0 and (i//j)//10 == 0 and i//j >= 2:
			divisors[i].append([j, i//j])

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

count = 0
for i in range(4, M+1):
	for divisor in divisors[i]:
		if divisor[0]*10 + divisor[1] <= D:
			count += 1

print(count)

Measured memory_bytes: 38492
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		long n = sc.nextInt();
		long k = sc.nextLong();
		List<Number> list = new ArrayList<Number>();
		for(int i = 0; i < n; i++) {
			list.add(new Number(sc.nextLong(), sc.nextLong()));
		}
		Collections.sort(list);
		
		long sum = 0, ans = 0;
		for(int i = 0; i < n; i++) {
			long num = list.get(i).number;
			sum += num;
			if (sum >= k) {
				ans = list.get(i).value;
				break;
			}
		}		
		out.println(ans);
		
		out.close();
	}
	static class Number implements Comparable<Number>{
		Long value;
		Long number;
		
		Number(long v, long n){
			this.value = v;
			this.number = n;
		}

		@Override
		public int compareTo(Number o) {
			
			return this.value.compareTo(o.value);
		}
		
	}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}


Measured memory_bytes: 31820
#include<bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace std;
int a,b,x,y;
signed main(){
//	freopen(".inp","r",stdin);
//	freopen(".out","w",stdout);
//	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>a>>b;
	y=b/2-a;
	x=a-y;
	if(x>=0&&y>=0&&x*2+y*4==b) cout<<"Yes";
	else cout<<"No";
}


Measured memory_bytes: 3628
/*input
20 11
33883322005544116655
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

ll modular_expo(ll base, ll index, ll mod)
{
    ll ret = 1;
    while(index > 0)
    {
        if(index & 1) ret = (ret * base) % mod;
        base = (base * base) % mod;
        index >>= 1;
    }
    return ret;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, p; cin >> n >> p;
    ll ans = 0;
    string s; cin >> s;
    if(p == 2)
    {
    	for(int i = 0; i < n; i++) if(!((s[i] - '0') & 1)) ans += i + 1;
    	cout << ans;
    	return 0;
    }
    if(p == 5)
    {
    	for(int i = 0; i < n; i++) if(s[i] == '5' || s[i] == '0') ans += i + 1;
    	cout << ans;
    	return 0;
    }
    vector<int> r(n + 1, 0);
    for(int i = 1; i < n + 1; i++) r[i] = (r[i - 1] + (modular_expo(10, i - 1, p)) * (s[n - i] - '0')) % p;
	map<int, ll> mapp;
	for(int i = 0; i < n + 1; i++) mapp[r[i]]++;
	for(auto it = mapp.begin(); it != mapp.end(); it++) ans += (it->second * (it->second - 1))/2;
	cout << ans;

    return 0;
}

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


bool isMonth(int n){
	return 1 <= n && n <= 12;
}

int main(){
	
	string s;
	cin >> s;
	vector<int> a(4);
	rep(i,4){
		a[i] = s[i] - '0';
	}
	
	int n1 = 10 * a[0] + a[1];
	int n2 = 10 * a[2] + a[3];
	
	
	if(!isMonth(n1) && !isMonth(n2)){
		puts("NA"); return 0;
	}
	else if(isMonth(n1) && isMonth(n2)){
		puts("AMBIGUOUS"); return 0;
	}
	else if(isMonth(n1)){
		puts("MMYY"); return 0;
	}
	else{
		puts("YYMM");
	}
	return 0;
}

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

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

   int cnt=0;
   while(n>0){
      n/=k;
      cnt++;
   }

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


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string S,M;
    cin >> S >> M;
    int count=0;
    for(int i=0; i<3; i++)
    {
        if(S.at(i)==M.at(i))
        {
            count++;
        }
    }
    cout << count <<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;

const int MAX_N = 16, INF = 0x3f3f3f3f;

int N, M, val[MAX_N][1 << 15];
int f[1 << 15][MAX_N];

vector<int> G[MAX_N];

inline void chmin(int &x, int y) {
  if (x > y) x = y;
}

int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1, a, b, c; i <= M; ++i) {
    scanf("%d%d%d", &a, &b, &c);
    G[a].push_back(b), G[b].push_back(a);
    val[a][1 << b - 1] = c, val[b][1 << a - 1] = c;
  }
  
  for (int i = 1; i <= N; ++i) {
    for (int mask = 1; mask < 1 << N; ++mask) {
      int lowbit = mask & -mask;
      val[i][mask] = val[i][mask ^ lowbit] + val[i][lowbit];
    }
  }

  memset(f, 0x3f, sizeof f);
  f[1][1] = 0;
  
  int S = (1 << N) - 1;
  
  for (int mask = 1; mask <= S; ++mask) {
    static int sum[1 << 15];
    int rev = S ^ mask;

    for (int u = 1; u <= N; ++u)
      if ((mask >> u - 1) & 1)
	for (int T = rev; T; T = (T - 1) & rev) 
	  sum[T] += val[u][T];
    
    for (int t = 1; t <= N; ++t)
      if (f[mask][t] != INF) {
	for (int v : G[t]) {
	  if ((mask >> v - 1) & 1) continue;
	  chmin(f[mask | (1 << v - 1)][v], f[mask][t] + val[v][mask ^ (1 << t - 1)]);
	}

	for (int T = rev; T; T = (T - 1) & rev)
	  chmin(f[mask | T][t], f[mask][t] + sum[T] - val[t][T]);
      }
    
    for (int u = 1; u <= N; ++u)
      if ((mask >> u - 1) & 1)
	for (int T = rev; T; T = (T - 1) & rev) 
	  sum[T] -= val[u][T];
  }

  printf("%d\n", f[S][N]);
  return 0;
}


Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

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

    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];
    sort(ALL(A));
    set<int> cand;
    int ans = 0;
    REP(j, N) {
        int a = A[j];
        if (j < N - 1 && A[j+1] == A[j]) {
            cand.insert(A[j]);
            continue;
        }
        int i = 1;
        bool ok = true;
        while (i * i <= a) {
            if (a % i == 0) {
                if (cand.count(i) > 0 || cand.count(a / i) > 0) {
                    ok = false;
                    break;
                }
            }
            i++;
        }
        if (ok) {
            ans++;
        }
        cand.insert(a);
    }
    cout << ans << endl;

}

Measured memory_bytes: 13456
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
const int INF = 100100100;
using namespace std;

int main()
{
  int X;
  bool res=false;
  cin >> X;

  if(X==7||X==5||X==3) res=true;

  if(res) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;

const int N = (int) 2e5 + 10;

int a[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll ans = 0;
  for (int i = 1; i < n; i++) {
    if (a[i] < a[i - 1]) {
      ans += a[i - 1] - a[i];
      a[i] = a[i - 1];
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 4360
#include<bits/stdc++.h>
using namespace std;
#define debug 1

const long long mod=1000000007;
// 1 0 0 0 0 0 0 0 0 
int a[2010],prefix[2010];
int b[2010];
int r[2010];
long long ans_in_one=0;

int main(int argc,char **argv) {
	memset(a,0,sizeof(a));
	int n,k;
	cin>>n>>k;
	int a_now;
	for(int i=0;i<n;i++) {
		scanf("%d",&a_now);
		a[a_now]++;
		b[i]=a_now;
	}
	prefix[0]=0;
	for(int i=1;i<2010;i++)
		prefix[i]=prefix[i-1]+a[i];
	
	long long ans=0;
	
	for(int i=0;i<n;i++)
		for(int j=i+1;j<n;j++)
			if(b[i]>b[j]) ans_in_one++;
	
	ans+=ans_in_one * (long long)k;
	ans%=mod;
	
	long long times=(long long) k * (k-1) /2;
	times%=mod;
	long long ans_others=0;
	for(int i=1;i<2010;i++) {
		ans_others+=prefix[i-1] * a[i];
		ans_others%=mod;
	}
	
	ans+=ans_others * times;
	ans%=mod;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#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 ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int a,b,c;
    cin >> a >> b >>c;
    map<int,int>m;
    m[a]++;
    m[b]++;
    m[c]++;
    cout << m.size() << endl;
    return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int64_t> stairs(N + 1);
  stairs.at(0) = 1;
  int64_t MOD = 1000000000 + 7;
  set<int> broken;
  for(int i = 0; i < M; i++) {
    int a;
    cin >> a;
    broken.insert(a);
  }
  for(int i = 1; i <= N; i++) {
    if(i == 1) {
      if(broken.count(1)) {
        stairs.at(1) = 0;
      }
      else {
        stairs.at(1) = 1;
      }
    }
    else {
      if(broken.count(i)) {
        stairs.at(i) = 0;
      }
      else {
        stairs.at(i) = stairs.at(i - 1) + stairs.at(i - 2);
        stairs.at(i) %= MOD;
      }
    }
  }
  cout << stairs.at(N) << endl;  
}


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

namespace ConsoleApplication1
{

    class Program
    {

        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            int c = int.Parse(Console.ReadLine());
            int x = int.Parse(Console.ReadLine());

            int ans = 0;
            int k = 0;
            int kk = 0;

            for(int i = 0; i <= a; i++)
            {
                k = x - 500 * i;
                if(k < 0)
                {
                    continue;
                }
                for(int j = 0; j <= b; j++)
                {
                    kk = k - 100 * j;
                    if(kk < 0)
                    {
                        continue;
                    }
                    
                    if(kk % 50 == 0 && (kk / 50) <= c)
                    {                      
                        ans++;
                    }

                }
            }

            Console.WriteLine(ans);

        }

    }

}
    


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,k,a[N];
int main()
{
    scanf("%d%d",&n,&k);k--;
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    printf("%d\n",(n-1)/k+((n-1)%k?1:0));
}


Measured memory_bytes: 640
import Control.Monad (replicateM)
import Data.List (group)

main = do
    n <- readLn
    if n == 0 then return () else do
        seq <- replicateM n readLn
        print (solve n seq)
        main


solve :: Int -> [Int] -> Int
solve n seq = n - maxChainLength
    where
    seq' = map (\s -> (head s, length s)) $ group seq

    maxChainLength = maximum chainLengths

    chainLengths = chainLengths' [head seq'] (tail seq')
        where
        chainLengths' _ [] = []
        chainLengths' seq1@((t1,c1):_) seq2@((t2,c2):seq2')
            = l1 : l2 : chainLengths' ((t2,c2):seq1) seq2'
            where
            l1 = chainLength (change t2 seq1) seq2
            l2 = chainLength seq1 (change t1 seq2)

chainLength :: [(Int,Int)] -> [(Int,Int)] -> Int
chainLength seq1 seq2 = chainLength' seq1 seq2 0
    where
    chainLength' [] _ acc = acc
    chainLength' _ [] acc = acc
    chainLength' ((t1,c1):seq1) ((t2,c2):seq2) acc
        | t1 == t2 && c1 + c2 >= 4 = chainLength' seq1 seq2 (acc+c1+c2)
        | otherwise = acc

change :: Int -> [(Int,Int)] -> [(Int,Int)]
change _ [] = []
change t ((t1,1):[]) = [(t,1)]
change t ((t1,1):(t2,c2):seq)
    | t == t2 = (t,c2+1):seq
    | otherwise = (t,1):(t2,c2):seq
change t ((t1,c1):seq) = (t,1):(t1,c1-1):seq

Measured memory_bytes: 7876
#include <stdio.h>

int main()
{
	int a, b;
	
	scanf( "%d %d", &a, &b );
	
	if ( a == b )
	{
		printf("Draw\n");
	}
	else
	if ( 1 == a )
	{
		printf("Alice\n");
	}
	else
	if ( 1 == b )
	{
		printf("Bob\n");
	}
	else
	if ( a < b )
	{
		printf("Bob\n");
	}
	else
	if ( a > b )
	{
		printf("Alice\n");
	}
	else
	{
		/* NOT REACHED */
	}
	
	return 0;
}



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

int main() {

    int N,M;
    cin >> N>>M;
   /* vector<int>A(N);
    for (int i = 0; i < N; i++) { cin >> A.at(i); }
    */
  if(N==M)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
    

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

int main(){
  double r, s, c;
  double pi= 3.141592653589;

  cin >> r;

  s = pi*(r*r);
  c = 2*pi*r;

  printf("%lf %lf\n", s,c);
  
  return 0;
}


Measured memory_bytes: 3296
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

const int N=101000;
int n,dp[N];
ll a,b,s[N],sdp[N];
int main() {
	scanf("%d%lld%lld",&n,&a,&b);
	if (a>b) swap(a,b);
	rep(i,1,n+1) scanf("%lld",s+i);
	s[n+1]=s[n]+b;
	s[0]=-b;
	dp[0]=1; dp[1]=1;
	sdp[0]=1; sdp[1]=2;
	int l=0,r=0;
	rep(i,2,n+2) {
		if (s[i]-s[i-1]>=b) dp[i]=(dp[i]+dp[i-1])%mod;
		while (r<=i-2&&s[i]-s[r]>=b) ++r; --r;
		if (l<=r) dp[i]=(dp[i]+sdp[r]-(l==0?0:sdp[l-1]))%mod;
		if (dp[i]<0) dp[i]+=mod;
		if (s[i]-s[i-1]<a) l=i-1;
		if (s[i+1]-s[i-1]>=a) sdp[i]=(sdp[i-1]+dp[i])%mod; else sdp[i]=sdp[i-1];
	}
	printf("%d\n",dp[n+1]);
}


Measured memory_bytes: 2304
MOD = 1000000007

N,K = map(int,input().split())
A = list(map(int,input().split()))

dp = [[0 for j in range(K+1)] for i in range(N+1)]
dp[0][0] = 1

for i in range(1,N+1):
    cum = [0 for j in range(K+2)]
    cum[0] = 0
    for j in range(1,K+2):
        cum[j] = cum[j-1]+dp[i-1][j-1]
        cum[j] %= MOD
    for j in range(K+1):
        dp[i][j] = cum[j+1]-cum[max(0,j-A[i-1])]
        dp[i][j] %= MOD

print(dp[N][K])

Measured memory_bytes: 181000
#include <cstdio>
#include <algorithm>
#include <stack>
using namespace std;
const int M = 1500;

struct Rectangle {int hei, pos;};
int a[M][M];
int t[M][M];

int GetMax(int w, int buffer[])
{
	stack<Rectangle> s;
	buffer[w] = 0;
	int maxs = 0;	
	
	for (int i = 0; i <= w; ++i)
	{
		Rectangle cur;
		cur.hei = buffer[i];
		cur.pos = i;
		
		if (s.empty()) s.push(cur);
		else
		{
			if (s.top().hei < cur.hei) s.push(cur);
			else if (s.top().hei > cur.hei)
			{
				int tmp = cur.pos;
				while (!s.empty() && s.top().hei >= cur.hei)
				{
					Rectangle pre = s.top(); s.pop();
					int area = pre.hei * (i - pre.pos);
					maxs = max(maxs, area);
					tmp = pre.pos;
				}
				cur.pos = tmp;
				s.push(cur);				
			}
		}
	}
	
	return maxs;
}

int GetMaxRectangle(int h, int w)
{
	for (int j = 0; j < w; ++j)
		for (int i = 0; i < h; ++i)
			if (a[i][j])	t[i][j] = 0;
			else t[i][j] = i ? t[i-1][j]+1 : 1;
		
	int maxs = 0;
	for (int i = 0; i < h; ++i)
		maxs = max(maxs, GetMax(w, t[i]));	
	
	return maxs;
}


int main()
{
	int h, w;
	scanf("%d %d", &h, &w);
	for (int i = 0; i < h; ++i)
		for (int j = 0; j < w; ++j)
			scanf("%d", &a[i][j]);
	
	printf("%d\n", GetMaxRectangle(h, w));
	return 0;
}


Measured memory_bytes: 19100
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

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

int n, ans, finalAns, cost[42], lim[42];
ll used, near[42];
vector<P> v;
vector<int> t[42];
map<string,int> name;

int nameToInt(string s){
  if(name.find(s) != name.end()){
    return name[s];
  }
  int size = name.size();
  name[s] = size;
  return name[s];
}

void dfs(int id, ll &bit){
  if(bit & (1LL << (ll)id)) return;
  bit |= (1LL << (ll)id);

  for(int i = 0; i < t[id].size(); i++){
    int to = t[id][i];
    dfs(to, bit);
  }
}

void solve(int idx, int sum, ll bit, ll okBit){
  if(idx == n){
    ans = max(ans, sum);
    return;
  }

  int id = v[idx].second;

  if((okBit & (1LL << (ll)id)) &&
     (bit & near[id]) == 0 &&
     ans < sum + lim[idx]){
    solve(idx + 1, sum + cost[id], bit | (1LL << (ll)id), okBit);
  }

  if(ans < sum + lim[idx + 1]){
    solve(idx + 1, sum, bit, okBit);
  }
}

void show(ll bit){
  for(int i = 0; bit != 0; i++){
    if(bit & 1LL){
      cout<<i<<", ";
    }
    bit /= 2LL;
  }
  cout<<endl;
}

int main(){
  while(cin >> n, n){
    name.clear();
    memset(near, 0, sizeof(near));

    for(int i = 0; i < 42; i++){
      t[i].clear();
    }

    v.clear();

    for(int i = 0; i < n; i++){
      int from, m;
      string s;
      cin >> s;

      from = nameToInt(s);
      cin >> cost[from] >> m;
      v.push_back(P(m, from));
      near[from] |= (1LL << (ll)from);

      for(int j = 0; j < m; j++){
        cin >> s;
        int to = nameToInt(s);
        t[from].push_back(to);
        near[from] |= (1LL << (ll)to);
      }
    }

    sort(v.begin(), v.end(), greater<P>());
    finalAns = cost[0];
    used = 1;

    for(int i = 0; i < n; i++){
      int id = v[i].second;
      if(used & (1LL << (ll)id)) continue;

      ll bit = 0;
      dfs(id, bit);

      memset(lim, 0, sizeof(lim));

      for(int j = n - 1; j >= 0; j--){
        int tid = v[j].second;
        if(bit & (1LL << tid)){
          lim[j] = cost[tid];
        }
        lim[j] += lim[j + 1];
      }

      ans = 0;

      if(bit & 1LL){
        solve(i, 0, 1, bit);
      }
      else{
        solve(i, 0, 0, bit);
      }

      finalAns += ans;
      used |= bit;
    }

    cout << finalAns << endl;
  }
}

Measured memory_bytes: 948
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	string S;
	int K;
	cin>>S>>K;
	int N = S.size();
	vector<string> vs;
	for (int i = 0; i < N; ++i){
		for (int j = 0; i+j <= N&& j <=K; ++j){
			vs.push_back(S.substr(i,j));
		}
	}

	set<string> ss(all(vs));
	vector<string> vs2(all(ss));
	sort(all(vs2));
	cout<<vs2[K]<<endl;
}

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

using namespace std;


#define MAXN 3001
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, a[MAXN];
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    ans += a[i]-1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define fi first
#define se second
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;
constexpr int mod = 1e9 + 7;
int n, a[N], cnt[N];
ll f(int x) { return 1ll*x*(x-1)/2; }
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n;
	for(int i=1; i<=n; i++) 
	{
		cin >> a[i];
		cnt[a[i]]++;
	}
	ll ans = 0;
	for(int i=1; i<=n; i++) ans += f(cnt[i]);
	for(int i=1; i<=n; i++)
	{
		ll tmp = ans;
		tmp -= f(cnt[a[i]]);
		cnt[a[i]]--;
		tmp += f(cnt[a[i]]);
		cnt[a[i]]++;
		cout << tmp << '\n';
	}
	return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

const int c = 1e5 + 1;

vector<pii> v[c];
bool visited[c];
int x[c];
bool flag = 0;

void dfs(int i, int p)
{
    visited[i] = true;
    x[i] = p;

    rep(j, v[i].size())
    {
        int u = v[i][j].first, cost = v[i][j].second;
        if (!visited[u])
            dfs(u, p + cost);
        else
        {
            if (x[u] != x[i] + cost)
                flag = 1;
        }
    }
}

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

    rep(i, m)
    {
        int l, r, d;
        cin >> l >> r >> d;
        v[l].push_back(pii(r, d));
        v[r].push_back(pii(l, -d));
    }

    rep(i, c)
    {
        if (!visited[i])
            dfs(i, 0);
    }

    flag == 1 ? OP("No") : OP("Yes");

    return 0;
}

Measured memory_bytes: 12032
import java.util.Scanner;

public class Main {

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

		String S = sc.next();
		String T = sc.next();

		int A = sc.nextInt();
		int B = sc.nextInt();

		String U = sc.next();

		if (S.equals(U)) {
			A = A - 1;
		} else if (T.equals(U)) {
			B = B - 1;
		}
		System.out.print(A+" "+B);
	}
}

Measured memory_bytes: 22740