akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
using namespace std;
using namespace __gnu_pbds;

#define sp << " " <<
#define mod 1000000007
#define PI 3.14159265358979323
#define y second
#define x first
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define pqueue priority_queue< ll >
//#define pdqueue priority_queue< ll,vector<ll> ,greater< ll > >
#define codejamDebug(x) cout<<"Case #"<<x<<": ";
#define debug(x) cout<<"Case "<<x<<": "
#define rep(i,n) for(long long i=0;i<n;i++)
#define f(i,a,b) for(long long i = a; i < b; i++)
#define fd(i,a,b) for(long long i = a; i >=b; i--)
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int           ll;
typedef long double             ld;
typedef unsigned long long int ull;
typedef vector <int>            vi;
typedef vector <ll>            vll;
typedef pair <int, int>        pii;
typedef pair <ll, ll>          pll;
typedef vector < pii >        vpii;
typedef vector < pll >        vpll;
typedef vector <string>         vs;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//Handle:cyber_rajat

int main(int argc, char const *argv[])
{
	sync;
	/*#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif*/
	ll n,d;
	cin>>n>>d;
	ll q = n/(2*d + 1);
	ll rem = n%(2*d + 1);
	if(rem!=0)q++;
	cout<<q<<endl;
	return 0;
}


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

using namespace std;
int main(){

    int n,m,id,solved=0,penalty=0;
    string verdict;
    cin>>n>>m;
    int a[n+2]={0},vis[n+2]={0};
    while(m--){
        cin>>id>>verdict;
        if(verdict=="AC"&&vis[id]==0){
                solved++;
                vis[id]++;
                penalty+=a[id];
        }
       if(verdict=="WA") a[id]++;
    }
    cout<<solved<<" "<<penalty<<endl;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
vector<int> G[100100];
bool used[100100];
int V,E;
vector<int> topo;
void dfs(int v)
{
	used[v]=true;
	for(int i=0;i<G[v].size();i++)if(!used[G[v][i]])dfs(G[v][i]);
	topo.pb(v);
}
void construct_topo()
{
	memset(used,false,sizeof(used));
	for(int i=0;i<V;i++)if(!used[i])dfs(i);
	reverse(all(topo));
}
int main()
{
	scanf("%d %d",&V,&E);
	for(int i=0;i<E;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		G[a].pb(b);
	}
	construct_topo();
	for(int i=0;i<topo.size();i++)printf("%d\n",topo[i]);
	return 0;
}

Measured memory_bytes: 4156
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    string s;
    for (int i=0;i<=n;i++) {
        getline(cin,s);
        if (s!="") {
            for (int i=0;i<s.size();i++) {
                if (s[i]=='H') {
                    if (i+6<s.size()) {
                        if (s[i+1]=='o'&&s[i+2]=='s'&&s[i+3]=='h'&&s[i+4]=='i'&&s[i+5]=='n'&&s[i+6]=='o') {
                            cout<<"Hoshina";
                            i+=6;
                        } else {
                            cout<<s[i];
                        }
                    } else {
                        cout<<s[i];
                    }
                } else {
                    cout<<s[i];
                }
            }
            cout<<endl;
        }
    }
}


Measured memory_bytes: 3200
#include <cstdio>
const int maxn = 300010;

int a[maxn], g[maxn], f[maxn];
int s[maxn], t[maxn], p[maxn];

int main() {
  int n, k;
  scanf("%d", &n); k = n;
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  for (int i = 1; i <= n; ++i) g[a[i]]++;
  for (int i = 1; i <= n; ++i) f[g[i]]++;
  for (int i = 1; i <= n; ++i) s[i] = s[i - 1] + i * f[i];
  for (int i = n; i >= 1; --i) t[i] = t[i + 1] + f[i];
  for (int i = 1; i <= n; ++i) p[i] = (s[i] + i * t[i + 1]) / i;
  for (int i = 1; i <= n; ++i) {
    while (k && i > p[k]) --k;
    printf("%d\n", k);
  }
  return 0;
}

Measured memory_bytes: 7808
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<math.h>
using namespace std;

int main()
{
    long long n;
    cin>>n;
    if(n<1200)cout<<"ABC"<<endl;
    else if(n<2800)cout<<"ARC"<<endl;
    else cout<<"AGC"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>

#define PI 3.14159265358979323846

typedef double db;

int main(void)
{
	db a, b, h, m;

	scanf("%lf %lf %lf %lf", &a, &b, &h, &m);

	db min = m * 6.0;
	db hour = (h * 60.0 + m) * 0.5;

	db dis = min - hour;

	db tmp = (db)a * a + (db)b * b - (db)2 * a * b * cos(dis * PI / 180.0);

	printf("%.10lf", sqrt(tmp));
	return 0;
}

Measured memory_bytes: 2600
#include<bits/stdc++.h>
#define pb push_back
#define pp pop_back()
#define mp make_pair
#define fr first
#define sc second
#define sz size()
#define smin(x,y) ((x)=min((x),(y)))
#define smax(x,y) ((x)=max((x),(y)))
#define all(x) x.begin(),x.end()
#define CS ios_base::sync_with_stdio(false);
#define show(x) cerr << #x << " is " << x <<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi; 
int32_t main()
{
	ll x; cin>>x;
	ll ans = (x/11) * 2;
	x %= 11;
	if(x>0) ans++;
	if(x>6) ans++;
	return cout<<ans<<endl,0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

void solve(string s) {
  vector<int> cnt(26);
  for(char c:s) {
    ++cnt[c-'a'];
  }
  REP(i,26) {
    if (cnt[i] == 0) {
      cout << s + (char)(i + 'a') << endl;
      return;
    }
  }
  s += '$';
  if (next_permutation(ALL(s))) {
    REP(i,26) {
      if (s[i] == '$') {
        cout << s.substr(0, i) << endl;
        return;
      }
    }
    assert(false);
  } else {
    cout << -1 << endl;
  }
}

int main()
{
  string s;
  cin >> s;
  solve(s);
  return 0;
}


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

int main()
{
  double a, b, k;
  cin >> a >> b >> k;
  if ((a + b) / 2 > a + k - 1) {
    for (int i = a; i <= a + k - 1; i++) cout << i << endl;
    for (int i = b - k + 1; i <= b; i++) cout << i << endl;
  } else {
    for (int i = a; i <= b; i++) cout << i << endl;
  }
}

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

int main(){
  int n;
  cin >> n;
  int c = 0;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  for(int i=0;i<n-1;i++){
    int j=0;
    if(a.at(i) == a.at(i+1)){
      cout << "NO" << endl;
      c = 1;
      break;
    }
  }
  if(c == 0){
    cout << "YES" << endl;
  }
}

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

int main() {
  int n; cin>>n;
  int a[n]; for(int i=0; i<n; i++) cin>>a[i];
  long long x=1000;
  int i=0;
  while(1){
    while(i<n-1&&a[i]>=a[i+1]) i++;
    if(i==n-1) break;
    long long s=x/a[i];
    x=x%a[i];
    while(i<n-1&&a[i]<=a[i+1]) i++;
    x=x+s*a[i];
  }
  cout<<x<<endl;
}



Measured memory_bytes: 3540
function main(input) {
   input = input.trim();
  const a = input.split(" ").map(Number);
	console.log(a[0]==a[1]?a[0]*2
			   :a[0]>a[1]?a[0]+a[0]-1
				:a[1]+a[1]-1);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29456
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)


int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    rep(i,n)cin>>v[i];
    
    int m;
    cin>>m;
    vector<int> x(m);
    rep(i,m)cin>>x[i];
    
    map<int,int> a,b;
    rep(i,n)a[v[i]]++;
    rep(i,m)b[x[i]]++;
    
    
    for(auto e:b){
        int num = e.first;
        int sum = e.second;
        
        if( !(a.count(num)!=0 && a[num]>=sum) ){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
}

Measured memory_bytes: 20608
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long long INF = 1e18;
//const ll mod = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> A(N);
    ll factor = 0;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        factor ^= A[i];
    }
    for(int i = 0; i < N; i++) {
        cout << (A[i] ^ factor) << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 4716
def main():
    S = 'T' + input()
    odd = ['R','U','D']
    even = ['L','U','D']
    for i in range(1,len(S)):
        if i % 2 == 0:
            if S[i] not in even:
                print('No')
                exit()
        if i % 2 == 1:
            if S[i] not in odd:
                print('No')
                exit()

    print('Yes')


main()

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

int main() {
  int n = 0, c3 = 0, c2 = 0, c1 = 0, c0 = 0;
  cin >> n;

  c3 = n / 1000;
  c2 = (n % 1000) / 100;
  c1 = (n % 1000 % 100) / 10;
  c0 = (n % 1000 % 100 % 10);

  if ( (c3 == c2 && c2 == c1) || (c2 == c1 && c1 == c0) ) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=((ll)n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=((ll)a);i<((ll)n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vl x(n),y(n),h(n);
    rep(i,n)cin>>x[i]>>y[i]>>h[i];
    rep(ax,101)rep(ay,101){
        set<ll> st;
        rep(i,n){
            ll v=max(h[i]+abs(x[i]-ax)+abs(y[i]-ay), 0ll);
            if(v>0)st.insert(v);
        }
        for(auto&ah:st){
            bool ok=true;
            rep(i,n)ok&=max(ah-abs(x[i]-ax)-abs(y[i]-ay), 0ll) == h[i];
            if(ok){
                puta(ax,ay,ah);
                return 0;
            }
        }
    }
    return 0;
}

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

int main(void){
  int n;
  cin >> n;
  int a[n];
  for(int i = 0;i < n;i++){
    cin >> a[i];
  }
  int num = 0;
  for(int i = 0;i < n;i++){
    num += a[i];
  }
  int b = num*10;
  int nu = b/n;
  int average = nu/10;
  if(nu%10 <= 9 && nu%10 >= 5){
    average++;
  }
  int ans = 0;
  for(int i = 0;i < n;i++){
    ans += pow(a[i]-average,2);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>
#include<bitset>
using namespace std;

const int W_MAX = 1003;
const int H_MAX = 12;
string A[H_MAX];

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    for(int i = 0; i < h; i++){
        cin >> A[i];
    }
    int ans = h + w - 2;
    for(int S = 0; S < 1 << (h-1); S++){
        vector<int> cut;
        int num = 0;
        for(int i = 0; i < h-1; i++){
            if (S & (1 << i)){
                cut.push_back(i);
                num++;
            }
        }
        int bef[H_MAX];
        memset(bef, 0, sizeof(bef));
        int now[H_MAX];
        bool able = true;
        for(int i = 0; i < w; i++){
            int l = 0;
            memset(now, 0, sizeof(now));
            for(int j = 0; j < h; j++){
                if (l < cut.size() && cut[l] < j) l++;
                if (A[j][i] =='1')now[l]++;
                if (now[l] > k){
                    able = false;
                    break;
                }
            }
            if (!able) break;
            for(int t = 0; t < cut.size()+1; t++){
                if (now[t] + bef[t] > k){
                    num++;
                    memset(bef, 0, sizeof(bef));
                }
            }
            for(int t = 0; t < cut.size()+1; t++){
                bef[t] += now[t];
            }
        }
        if (able)ans = min(ans, num);
    }
    cout << ans << endl;
    return 0;
}

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


inline void solve(int T) {
    int a[10], cnt[10];
    rep(i, 1, 5) cnt[i] = 0;
    rep(i, 1, 5) cin >> a[i], cnt[a[i]] = 1;
    rep(i, 1, 5) if(cnt[i] == 0) {
        cout << i << endl;
        return;
    }

}   
int main()
{
//     ios_base::sync_with_stdio(0);
//     cin.tie(0);
//     cout.tie(0);
 
    // freopen("in.txt", "r", stdin);
    // freopen("out2.txt", "w", stdout);
 
    int T = 1;
    // cin >> T;
    rep(i, 1, T) solve(i);
}

Measured memory_bytes: 3632
def b():
    def solve(N, W, V, wv):
        dp = [10**10] * (V+1)
        dp[0] = 0

        for i in range(N):
            wi = wv[i][0]
            vi = wv[i][1]

            # 降順でやらないと複数回アイテムをカウントしちゃう（j1 + wi をやった後に j2 + wi をやると、 j1 + wi == j2 のときに2カウントになってしまう）
            for v in range(V - vi, -1, -1):
                if dp[v] == -1:
                    continue
                if dp[v+vi] > dp[v] + wi:
                    dp[v+vi] = dp[v] + wi

        light = [i for i, w in enumerate(dp) if w <= W]
        return light[-1]

    N, W = map(int, input().split())
    wv = []
    V = 0

    for i in range(N):
        w, v = map(int, input().split())
        wv.append([w, v])
        V += v

    print(solve(N, W, V, wv))

if __name__ == "__main__":
    b()


Measured memory_bytes: 7240
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int x, y;
  cin >> x >> y;
  cout << x + y / 2 << endl;
}


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

using namespace std;

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

inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

  int n;
  cin >> n;
  vector<int> a(n);
  int odd = 0, even = 0;
  rep(i, n) {
    cin >> a[i];
    if (a[i] % 2)
      odd++;
    else
      even++;
  }

  if (odd % 2) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }

  return 0;
}

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

int main() {
  string s;
  cin >> s;

  if (s[0] == s[1] && s[1] == s[2]) {
    cout << "Yes" << endl;
  }
  else if (s[1] == s[2] && s[2] == s[3]) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
     
int main(){
  int r,g;
  double x;
  /*
  (r+x)/2 = g
   r+x = 2g
   x = 2g - r
  */ 
  cin >> r >> g;
  cout << g * 2 - r << endl;
}

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

int main() {
  int A,B;
  cin >> A >> B;
  
  if (A%3 == 0 || B%3 == 0 || (A+B)%3 == 0) {
    cout << "Possible" << endl;
  }
  else {
    cout << "Impossible" << endl;
  }
  
  
  //int ans = 0;
  //cout << ans << endl;
}

Measured memory_bytes: 256
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let x: String = read();
    let y: String = read();
    println!(
        "{}",
        if x < y {
            '<'
        } else if x > y {
            '>'
        } else {
            '='
        }
    );
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}



Measured memory_bytes: 4352
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define ull unsigned long long
#define N 100005
#define mod 1000000007
//#define mod 1e18
#define boost ios_base::sync_with_stdio(false);cin.tie(0)
#define prec(n) fixed<<setprecision(n)

#define mii map<int,int>
#define mll map<ll,ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi  first

#define se second
#define pb push_back
#define mp make_pair
#define pp pop_back
#define vii vector<int>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define all(c) c.begin(),c.end()
#define tr(it,c) for(it = c.begin() ; it!=c.end() ; it++)
int inf = INT_MAX ;
ll modulo(ll num,ll MOD=mod){ return ((num%MOD)+MOD)%MOD;} // for negative integer
ll power(ll b,ll e,ll MOD=mod){ll ans=1; while(e){if(e%2) ans=(ans*b)%MOD; b=(b*b)%MOD; e/=2;} return ans;}
ll inv(ll num,ll MOD=mod){ return power(modulo(num),MOD-2,MOD); }
ll gcd(ll a,ll b){ return ((b==0) ? a:gcd(b,a%b));}
ll dp[10005][105][2];
ll k,n;
string str;

ll solve(int idx,int d,int t){
	if(idx>=k){
		if(d==0){
			return 1;
		}
		else{
			return 0;
		}
	}
	
	if(dp[idx][d][t]!=-1){
		return dp[idx][d][t];
	}
	
	ll ans = 0;
	if(t==1){
		for(int i = 0;i<=str[idx]-'0';i++){
			if(i==str[idx]-'0'){
				ans = (ans + solve(idx+1,(d-(i%n)+n)%n,1))%mod;
				continue;
			}
			ans = (ans + solve(idx+1,(d-(i%n)+n)%n,0))%mod;
		}
	}else{
		for(int i = 0;i<10;i++){
			ans = (ans + solve(idx+1,(d-(i%n)+n)%n,0))%mod;
		}
	}
	
	dp[idx][d][t] = ans;
	return ans;
}  

int main(){
	boost;
	cin>>str;
	cin>>n;
	k = str.size();
	
	for(int i = 0;i<10005;i++){
		for(int j = 0;j<105;j++){
			for(int m = 0;m<2;m++){
				dp[i][j][m] = -1;
			}
		}
	}
	
	
	ll ans = 0;
	ans = (ans + solve(0,0,1))%mod;
	ans = (ans - 1 + mod)%mod;
	cout<<ans;
	return 0;
}



Measured memory_bytes: 20868
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define Pr(a) (#a)<<"="<<(a)<<" "
#define pr1(a) cerr<<Pr(a)<<endl;
#define pr2(a,b) cerr<<Pr(a)<<Pr(b)<<endl;
#define pr3(a,b,c) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<endl;
#define pr4(a,b,c,d) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<endl;
#define pr5(a,b,c,d,e) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<Pr(e)<<endl;
#define pr6(a,b,c,d,e,f) cerr<<Pr(a)<<Pr(b)<<Pr(c)<<Pr(d)<<Pr(e)<<Pr(f)<<endl;
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


int color[2000][2000];
signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  
  int h,w,d;
  cin>>h>>w>>d;
  vector<string> ans(h,string(w,'.'));

  char RYGB[]={'R','Y','G','B'};

  
  for(int i=0;i<2000;i++)
    for(int j=0;j<2000;j++) {
      int a = (i / d)%2;
      int b = (j / d)%2;
      color[i][j] = RYGB[2*a+b];
    }

  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++){
      int u = i + j + 1000;
      int v = i - j + 1000;
      ans[i][j] = color[u][v];
    }

  for(int i=0;i<h;i++) cout<<ans[i]<<endl;


  
  return 0;
}


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

int main(){
  int64_t X;
  cin >> X;

  int64_t MA,MB;
  MA=X/500;
  MB=X-500*MA;
  MB/=5;

  int64_t res;
  res=1000*MA+5*MB;
  cout << res << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        char s = a.charAt(0);
        if(Character.isUpperCase(s)) {
            System.out.println("A");
        }else {
            System.out.println("a");
        }
    }
}


Measured memory_bytes: 35528
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  Int n;
  cin>>n;
  string s(n,'-');
  for(Int i=0;i<n;i++) cin>>s[i];
  static Int dp[222][222];
  memset(dp,0,sizeof(dp));
  dp[0][0]=1;
  const Int MOD=1000000007;
  for(Int i=0;i<n;i++){
    for(Int j=0;j<=n;j++){
      if(s[i]=='-'){
	dp[i+1][j]+=dp[i][j];
	dp[i+1][j]%=MOD;
      }
      if(s[i]=='D'){
	if(j){
	  dp[i+1][j-1]+=(dp[i][j]*j%MOD)*j%MOD;
	  dp[i+1][j-1]%=MOD;
	}
	dp[i+1][j]+=dp[i][j]*j%MOD;
	dp[i+1][j]%=MOD;
      }
      if(s[i]=='U'){
	dp[i+1][j]+=dp[i][j]*j%MOD;
	dp[i+1][j]%=MOD;
	  
	dp[i+1][j+1]+=dp[i][j];
	dp[i+1][j+1]%=MOD;
      }
    }
  }
  cout<<dp[n][0]<<endl;
  return 0;
}

Measured memory_bytes: 3544
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <stack>
#include <map>
#include <string> 
#include <set>
#include <iomanip>
#define eps 1e-5
#define N 100005 
#define pi acos(-1)
#define e 2.71828182845904523536
using namespace std;

map<string,int> a;
int main()
{
	int n;
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		string s;
		cin>>s;
		a[s]++;
	}
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		string s;
		cin>>s;
		a[s]--;
	}
	int maxx=0;
	for (map<string, int>::iterator i=a.begin();i!=a.end();i++)
	{
		if (i->second>maxx) maxx=i->second;
	}
	printf("%d\n",maxx);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long MOD = 1000000007;
const long long INF = (1LL << 60);
using namespace std;
typedef long long ll;
map<int, int> mp;
using Graph = vector<vector<int>>; 
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

int h[100010];
int dp[100100];
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k; cin >> n >> k;
	rep(i, n)cin >> h[i];
	for (int i = 0; i < 100100; i++) {
		dp[i] = INF;
	}
	dp[0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 1; j <= k; j++) {
			chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
		}
	}
	cout << dp[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string s[4] = {"dream","dreamer","erase","eraser"};

int main() {
  string t;
  cin >> t;
  int now = t.size();
  while (1) {
    bool f = 0;
    for (int i = 0; i < 4; i++) {
      int bf = now - s[i].size();
      if (bf < 0) continue;
      if (s[i] == t.substr(bf,s[i].size())) {
        // cout << s[i] << " " << t.substr(bf,s[i].size()) << endl;
        now -= s[i].size();
        f = 1;
        break;
      }
    }
    if (!f) break;
  }
  // cout << now << endl;
  if (now != 0) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }
}

/*　【提出前に確認すること】
・コンパイルできるか
・テストケース試したか
・オーバーフローあるか
*/

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    string s[3] = {"Sunny", "Cloudy", "Rainy"};
    string t;
    cin >> t;

    rep(i,3){
        if(t == s[i]){
            cout << s[(i+1)%3] << endl;
        }
    }
    
    return 0;
}
 
 


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int A = c - a;
    int B = d - b;
    cout << c - B << " " << d + A << " " << a - B << " " << b + A;
}


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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);i++)
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(ll)(n);i>0;i--)
#define REP(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(v) v.begin(),v.end()
#define UNIQUE(v) v.erase(unique(all(v)), 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 (a>b) { a = b; return 1; } return 0; }
const ll inf = 1000000001;
const ll INF = 2e18;
//const ll MOD = 1000000007;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
#define mp make_pair

const int N = 100010;
vector<vector<vector<pll > > > G(2, vector<vector<pll > > (N));
vll d(2, vl(N, INF));

void dijkstra(int s, int i) {
	priority_queue<pll, vector<pll>, greater<pll> > pq;
	d[i][s] = 0;
	pll now = pll(0, s);
	pq.push(now);
	while (!pq.empty()) {
		pll now = pq.top();
		pq.pop();
		ll u = now.second, c = now.first;
		if (d[i][u] < c) {
			continue;
		}
		rep(j, G[i][u].size()) {
			pll nex = G[i][u][j];
			ll v = nex.first, cost = nex.second;
			if (d[i][v] <= c + cost) {
				continue;
			}
			d[i][v] = c + cost;
			pq.push(pll(c + cost, v));
		}

	}
}

int main() {
	int n, m, s, t;
	cin >> n >> m >> s >> t;
	s--; t--;
	rep(i, m) {
		int u, v;
		ll a, b;
		cin >> u >> v >> a >> b;
		u--; v--;
		G[0][u].push_back(pll(v, a)); G[0][v].push_back(pll(u, a));
		G[1][u].push_back(pll(v, b)); G[1][v].push_back(pll(u, b));
	}
	dijkstra(s, 0);
	dijkstra(t, 1);
	vector<pll> ans(n);
	rep(i, n) {
		ans[i].first = d[0][i] + d[1][i];
		ans[i].second = i + 1;
	}
	sort(all(ans));
	reverse(all(ans));
	rep(i, n) {
		while (ans.back().second <= i) {
			ans.pop_back();
		}
		cout << 1000000000000000 - ans.back().first << endl;
	}
}

Measured memory_bytes: 19800
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, maxint


def main():
    num = int(stdin.readline())

    M = []
    for _ in xrange(num):
        M.append([int(s) for s in stdin.readline().split()])

    g = set(xrange(1, num+1))
    index = g.pop()
    h = {index}
    weight = 0

    while g:
        minimum = maxint
        for j in h:
            mj = M[j-1]
            for i in g:
                if 0 <= mj[i-1] < minimum:
                    index = i
                    minimum = mj[i-1]
        h.add(index)
        g.remove(index)
        weight += minimum

    print(weight)


main()

Measured memory_bytes: 4520
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int T=in();
	int s=T%60;
	T/=60;
	int m=T%60;
	int h=T/60;
	cout<<h<<':'<<m<<':'<<s<<endl;
	
	return 0;
}



Measured memory_bytes: 3156
import sys
from math import sqrt
from collections import Counter

input = sys.stdin.readline


def I():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    n, k = MI()
    a_list = MI()

    c = Counter(a_list)
    sum = 0
    if len(c) <= k:
        print("0")
        exit()

    for l in c.most_common()[k:]:
        sum += l[1]
    print(sum)
    pass


if __name__ == "__main__":
    main()


Measured memory_bytes: 102736
#include<bits/stdc++.h>
using namespace std;
const int N=200007;
map<int,int>mp;int a[N];
int main()
{
    long long ans=0;
    int n;cin>>n;
    for(int i=1;i<=n;++i) cin>>a[i];
    for(int i=n;i;--i)
    {
	ans+=mp[i+a[i]];
	++mp[i-a[i]];
    }
    cout<<ans;
}



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


void solve(long long K, long long T, std::vector<long long> a){
    ll ma = *max_element(a.begin(), a.end());
    cout << max(0LL, ma - 1 - (K - ma)) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long K;
    scanf("%lld",&K);
    long long T;
    scanf("%lld",&T);
    std::vector<long long> a(T);
    for(int i = 0 ; i < T ; i++){
        scanf("%lld",&a[i]);
    }
    solve(K, T, std::move(a));
    return 0;
}


Measured memory_bytes: 256
#coding: utf-8
#from collections import defaultdict, deque

H, W = (int(x) for x in input().split())

paint = []
for i in range(H):
    paint.append(list(input()))

def has_adjacent(i, j):
    for next_i, next_j in ((i-1, j), (i+1, j), (i, j-1), (i, j+1)):
        if next_i < 0 or next_i >= H or next_j < 0 or next_j >= W:
            continue
        if paint[next_i][next_j] == '#':
            return True
    return False

for i in range(H):
    for j in range(W):
        if paint[i][j] == '#':
            if not has_adjacent(i, j):
                print("No")
                exit(0)

print("Yes")



Measured memory_bytes: 9204
#include<bits/stdc++.h>
using namespace std;
int b[1000000],d[1000000];
int main(){
  
  int c[181];
  fill(b,b+1000000,1000000);
  fill(d,d+1000000,1000000);
  for(int i=1;i<=180;i++){
    c[i] = i*(i+1)*(i+2)/6;
    b[ c[i] ] = 1;
    if(c[i]%2 == 1) d[ c[i] ] = 1;
  }
  
  for(int i=1;i<=180;i++){
    for(int j=1;j<1000000-c[i];j++){
      b[j+c[i]] = min(b[j+c[i]],b[j]+1);
      if(c[i]%2 == 1) d[j+c[i]] = min(d[j+c[i]],d[j]+1);
    }
  }
  
  
  
  int n;
  while(cin>>n,n!=0)
    cout << b[n] << ' ' << d[n] << endl;
  
  return (0);
}

Measured memory_bytes: 10872
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>



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

using namespace std;
int a,b;

int main(){
  cin >> a >> b;
  cout << a-b+1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,a=1,b=1,c=1,d=1,count;
  cin>>N;
  char e;
  for(int i=0;i<N;i++){
    cin>>e;
    if(a==1 &&e=='Y'){
      count++;
      a=0;
    }
        if(b==1 &&e=='W'){
      count++;
      b=0;
    }
        if(c==1 &&e=='P'){
      count++;
      c=0;
    }
        if(d==1 &&e=='G'){
      count++;
      d=0;
    }
  }
  if(count==3){
    cout<<"Three";
  }
  else{
    cout<<"Four";
  }
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	int a;
	int b;
	int c;
	cin >> a;
	cin >> b;
	cin >> c;
	if (c <= b&&c >= a)
		cout << "Yes" << endl;
	else 
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static int n, m, N;
	static int[][] data;
	static int[] memo;
	static boolean[] use;

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

		for (;;) {
			n = sc.nextInt();
			if (n == 0) {
				return;
			}
			data = new int[201][2];
			for (int i = 0; i < n; i++) {
				data[i][0] = sc.nextInt();
				data[i][1] = sc.nextInt();
			}
			m = sc.nextInt();
			N = n + m;
			memo = new int[N];
			use = new boolean[N];
			for (int i = n; i < N; i++) {
				data[i][0] = sc.nextInt();
				data[i][1] = sc.nextInt();
			}
			
			int ans = 0;
			for (int i = 0; i < N; i++) {
				ans = Math.max(ans, dfs(i));
			}
			System.out.println(ans);
		}
	}

	static int dfs(int nowIndex) {
		if (memo[nowIndex] > 0) {
			return memo[nowIndex];
		}
		int res = 1;
		use[nowIndex] = true;
		for (int i = 0; i < N; i++) {
			if (!use[i]) {
				if (data[nowIndex][0] > data[i][0]
						&& data[nowIndex][1] > data[i][1]) {
					res = Math.max(res, dfs(i) + 1);
				}
			}
		}
		use[nowIndex] = false;
		return memo[nowIndex] = res;
	}
}

Measured memory_bytes: 23424
import math as m

qt = int(input())
sl = [input() for i in range(qt)]
d = {}
count = 0

for s in sl:
    s = "".join(sorted(s))
    if s in d:
        d[s] += 1
    else:
        d[s] = 1

for e in d.values():
    if e > 1:
        count += m.factorial(e) // (m.factorial(e - 2) * 2)

print(count)



Measured memory_bytes: 24968
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

ll N, M, S;
ll A[100][100], B[100][100], C[100], D[100];
ll ans[100][5001];

using item = pair<ll, pll>;

void dijkstra(){
    priority_queue<item, vector<item>, greater<pair<ll, pll>>> que;
    que.push(item(0, pll(0, S)));
    while(!que.empty()){
        ll d = que.top().first;
        ll i = que.top().second.first;
        ll s = que.top().second.second;
        que.pop();
        if(5000 < s || ans[i][s] <= d) continue;
        ans[i][s] = d;
        que.push(item(d + D[i], pll(i, s + C[i])));
        for(ll j = 0; j < N; j++){
            if(j == i || B[i][j] == 0 || s < A[i][j]) continue;
            que.push(item(d + B[i][j], pll(j, s - A[i][j])));
        }
    }
}

signed main(){
    cin >> N >> M >> S;
    int u, v, a, b, c, d;
    REP(i, M){
        cin >> u >> v >> a >> b;
        u--; v--;
        A[u][v] = A[v][u] = a;
        B[u][v] = B[v][u] = b;
    }
    REP(i, N){
        cin >> c >> d;
        C[i] = c;
        D[i] = d;
    }
    REP(i, N) REP(j, 5001) ans[i][j] = LONG_LONG_MAX;
    S = min(S, 5000LL);
    dijkstra();
    FOR(i, 1, N){
        ll m = LONG_LONG_MAX;
        REP(j, 5001) m = min(m, ans[i][j]);
        PRINT(m);
    }
    return 0;
}

Measured memory_bytes: 17576
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
BC = []
for i in range(Q):
    BC.append(list(map(int,input().split())))

num = [0]*(10**5+1)

S = []
 
#1 iterlation
S.append(sum(A))
for i in range(N):
    num[A[i]]+=1

    
for j in range(Q):
    if num[BC[j][0]] != 0:
        #Bに当たる交換するものがある時
        B = BC[j][0]
        C = BC[j][1]
        S.append(S[-1] + (C - B)*num[B] )
        #S[-1]で合計の一番最新のもの
        dammy = num[B]
        num[B] = 0
        num[C] += dammy
 
    else:
        B = BC[j][0]
        C = BC[j][1]
        S.append(S[-1])

        
for i in range(1,Q+1):
    print(S[i])

Measured memory_bytes: 98088
# include <bits/stdc++.h>
# define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
# pragma GCC optimize "-O3"
# define int long long
  
using namespace std;
  
const int N = 1e4 + 7;
const int mod = 1e9 + 7;

vector < int > a, b, c, d, vc;
int ans, n, m, q;

vector < int > adj[N];

void rec( int it, int v, int sum ) {
	vc[it] = v;
	int cnt = sum;
	for ( auto i: adj[ it ] ) {
		if ( v - vc[a[i]] == c[i] ) {
			cnt += d[i];
		}
	}
	if ( it == n ) {
		ans = max( ans, cnt );
		return;
	}	
	for ( int j = v; j <= m; j++ ) {
		rec( it + 1, j, cnt );
	}
}

void solve() {
	cin >> n >> m >> q;
	a.assign(q, 0);
	b.assign(q, 0);
	c.assign(q, 0);
	vc.assign(n + 1, 0);
	d.assign(q, 0);
	for ( int i = 0; i < q; i++ ) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		adj[ b[i] ].push_back(i);
	}
	for ( int i = 1; i <= m; i++ ) {
		rec( 1, i, 0 );
	}
	cout << ans;
}

int32_t main() {
	speed;
	int T = 1;
	// cin >> T;
	while ( T-- ) {
		solve();
	}
}

Measured memory_bytes: 3892
INF = 10 ** 9 + 7

S = input()
# dp[i][j]はうしろからi桁を13で割った余りがjであるものの個数
dp = [[0] * 13 for _ in range(len(S) + 1)]
dp[0][0] = 1
mul = 1

for i in range(len(S)):
    x = S[-(i + 1)]
    if x == "?":
        for k in range(10):
            for j in range(13):
                dp[i + 1][(mul * k + j) % 13] += dp[i][j]
                dp[i + 1][(mul * k + j) % 13] %= INF
    else:
        k = int(x)
        for j in range(13):
            dp[i + 1][(mul * k + j) % 13] += dp[i][j]
            dp[i + 1][(mul * k + j) % 13] %= INF
    mul = mul * 10 % 13  # 計算量削減のためここで13で割っている

print(dp[len(S)][5])


Measured memory_bytes: 62300
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define ii pair<int,int>
#define iii pair<ii,int>
#define vii vector<pair<int,int> >
#define vi vector<int>
#define vvi vector<vector<ll> >
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define nu 100000
#define mod 1000000007
#define inf pow(10,8)
#define h pow(10,-8)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

int main()
{
	fastio;
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	if (k%2 == 0)
	{
		cout << a-b;
	}
	else
	{
		cout << b-a;
	}
}	

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

int main() {
    char s[100001];
    scanf("%s",s);
    int ans=0,m='a';
    for(int i = 0;i<26;i++) {
        if (strchr(s, m) == NULL) {
            printf("%c",m);
            return 0;
        } else {
            m++;
        }
    }
    printf("None");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int sum = 0;
	int n,d,x;
	cin>>n>>d>>x;
	while(n--)
	{
		int ai;
		cin>>ai;
		for(int i=0;i<d;i++)
		{
			if(i*ai+1<=d)
			{
				sum++;
			}
			else
			{
				break;
			}
		}
	}
	sum+=x;
	cout<<sum<<endl;
	return 0;
}

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

int main(void){
  int n, m, ro[55][55];
  for(int i=0;i<55;++i) 
    for(int j=0;j<55;++j)
      ro[i][j] = 0;
  cin >> n >> m;
  for(int i=0;i<m;++i){
    int a, b;
    cin >> a >> b;
    ro[a-1][b-1] += 1;
    ro[b-1][a-1] += 1;
  }
  for(int i=0;i<n;++i){
    int sum=0;
    for(int j=0;j<n;++j){
      sum += ro[i][j];
    }
    cout << sum << endl;
  }
}

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

const ll mod = 1000000007;

ll modpow(ll x, ll n){
    if(n == 0) return (ll)1;
    if(n % 2 == 0) return modpow(x * x % mod, n / 2);
    else return x * modpow(x, n - 1) % mod;
}

int main() {
    ll n, k;
    cin >> n >> k;
    
    vector<ll> cnt(k, 0);
    for(int x = k; x > 0; x--){
        ll sum = modpow(k / x, n);
        for(int y = 2 * x; y <= k; y += x){
            sum = (sum - cnt[y-1] + mod) % mod;
        }
        cnt[x-1] = sum;
    }

    ll ans = 0;
    rep(i, k)ans = (ans + (cnt[i] * (i + 1)) % mod) % mod;
    cout << ans << endl;
}

Measured memory_bytes: 4000
N, M = map(int, input().split())
KA = [list(map(int, input().split())) for _ in range(N)]

# 各Kについて積集合をとる
ans = set([int(i) for i in range(1, M+1)])

for n in range(N):
    ans = ans & set(KA[n][1:])

print(len(ans))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
using namespace std;
int main(){
    string s;
    cin>>s;
    vector<long long> a(26,0);
    f(i,0,s.size()){
        a[s[i]-'a']++;
    }
    f(i,0,26) {
		if (a[i] == 0) {
		    
			cout << (char)(i + 'a') << endl;
			return 0;
		}
	}
	cout << "None" << endl;
    return 0;
}


Measured memory_bytes: 3756
#include <stdio.h>

int bar[30][9];

int check(int n, int m, int h, int d);

int main(void) {
	int n, m, h, d;
	char str[10];
	int i, j, k;
	int flag;
	
	while (1) {
		scanf("%d", &n);
		if (!n)
			break;
		scanf("%d", &m);
		scanf("%d", &h);
		scanf("%d", &d);
		for (i = 0; i < d; i++) {
			scanf("%s", str);
			for (j = 0; j < n-1; j++) {
				bar[i][j] = str[j] - '0';
			}
		}
		if (check(n, m, h, d))
			printf("0\n");
		else {
			for (i = 0; i < d; i++) {
				for (j = 0; j < n-1;j++) {
					if (j == 0 && !bar[i][j] && !bar[i][j+1])
						flag = 1;
					else if (j == n-2 && n-1 != 1 && !bar[i][j] && !bar[i][j-1])
						flag = 1;
					else if (j > 0 && j < n-2 && !bar[i][j-1] && !bar[i][j] && !bar[i][j+1])
						flag = 1;
					else
						flag = 0;
					if (flag) {
						bar[i][j] = 1;
						if (check(n, m, h, d)) {
							printf("%d %d\n", i+1, j+1);
							i = d;j = n;
						}
						else
							bar[i][j] = 0;
					}
				}
			}
			if (i == d && j == n-1)
				printf("1\n");
		}
	}
	return 0;
}

int check(int n, int m, int h, int d) {
	int i;
	for (i = 0; i < d; i++) {
		if (m == 1 && bar[i][m-1])
			m++;
		else if (m == n && bar[i][m-2])
			m--;
		else if (m != 1 && m != n) {
			if (bar[i][m-2])
				m--;
			else if (bar[i][m-1])
				m++;
		}
	}
	
	if (m == h)
		return 1;
	else
		return 0;
}

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

int main() {
  int s,s1,s2,s3,result = 0;
  cin >> s;
  s1 = s / 100;
  s2 = s / 10 % 10;
  s3 = s % 10;
  result = s1 + s2 + s3;
  cout << result << endl;
}

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

bool isPrime(int x){
  if(x==2){
    return true;
  }
  if(x<2 || x%2==0){
    return false;
  }

  int i=3;
  while(i<=sqrt(x)){
    if(x%i==0){
      return false;
    }
    i = i+2;
  }

  return true;
}

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

  int N[n];
  int c=0;
  for(int i=0;i<n;i++){
    cin >> N[i];
    if(isPrime(N[i])){
      c++;
    }
  }
  cout << c << endl;

  return 0;
}



Measured memory_bytes: 3068