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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

const ll mod=(1e+9)+7;
const ll inf=1e+16; 

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)

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

  ll n,k;
  cin >> n >> k;
  vll s(n+1,0),a(n);
  rep(i,0,n) cin >> a[i];
  rep(i,0,n) s[i+1]=s[i]+a[i];
  rep(i,0,n+1) {
    s[i]-=i;
    s[i]%=k;
  }
  map<ll,ll> mp;
  ll res=0;
  rep(i,0,n+1){
   ll c=mp[s[i]];
    res+=c;
    mp[s[i]]++;
    if(i+1-k>=0) mp[s[i+1-k]]--;
  } 
  cout << res << endl;
  
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
const int mod = (int)1e9 + 7;
const ll INF = (ll)1e18;
const int N = (int)1e5 + 100;
const int MAXA = (int)3e6;
int num[N];
bool have[N];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // ifstream cin("input.txt");
    // ofstream cout("output.txt");
    int n, m;
    cin >> n >> m;
    for(int i = 1;i <= n;i++)num[i] = 1;
    have[1] = 1;
    for(int i = 1;i <= m;++i){
        int u,v;
        cin >> u >> v;
        num[u]--;
        num[v]++;
        if(have[u])have[v] = 1;
        if(!num[u])have[u] = 0;
    }
    int ans = 0;
    for(int i = 1;i <= n;i++)ans += have[i];
    cout << ans;
    return 0;
}


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

using namespace std;

int n, cap;
int w[110], v[110];
long long dp[1000001][110];

int main(void){
    cin >> n >> cap;
    int w[n + 1], v[n + 1];
    long long dp[cap + 1][n + 1];
    w[0] = 0;
    v[0] = 0;
    for(int i = 1; i <= n; i++)
        cin >> w[i] >> v[i];
    
    memset(dp, -1, sizeof(dp));
    for(int i = 0; i <= cap; i++) dp[i][0] = 0;
    for(int j = 0; j <= n; j++) dp[0][j] = 0;

    for(long long i = 1; i <= cap; i++){
        for(int j = 1; j <= n; j++){
            if(w[j] > i) dp[i][j] = dp[i][j - 1];
            else dp[i][j] = max(v[j] + dp[i - w[j]][j - 1], dp[i][j - 1]);
        }
    }
    cout << dp[cap][n] << endl;

    return 0;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
#include <string.h>
#include <numeric>

using namespace std;

///////////////////////////////////////////
//const long long int INF = 1000000000000000000LL;
const long long int INF = 1000000;
using ll = long long int;
using vi = vector<int>;
using Vi = vector<long long int>;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
auto max(auto x,auto y){if(x>y){return x;}else{return y;}}
auto min(auto x,auto y){if(x>y){return y;}else{return x;}}
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(    v[0])>()) //降順でVをソート
///////////////////////////////////////////

ll n;
ll box[201]={0};
int cal(int x){
   ll ans = 0;
   rep(i,x){
       if(i==0){

       }else if(x%i==0){
           ans++;
       }else{
           //no action
       }
   }
   return box[x]=ans+1;
}

int main(){
   cin>>n;
   ll ans=0;
   for(int i=1;i<=n;i++){
       if(i%2==1 && cal(i)==8){
           ans++;
       }
   }
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

typedef struct{
    int x,y;
}Z;

void output(Z z[],int n){
    int i;
    for(i=0;i<n;i++){
        printf("%d %d\n",z[i].x,z[i].y);
    }
    return;
}

void makeHeap(Z z[],int cnt,int i){
    if(i==0||i==1)return;
    
    int parent,l,r,min;
    parent=i/2;
    if(i%2==0){
        l=i;
        r=i+1;
    }else{
        l=i-1;
        r=i;
    }
    min=parent;
    
    if(z[l-1].x<z[min-1].x)min=l;
    else if(z[l-1].x==z[min-1].x){
        if(z[l-1].y<z[min-1].y)min=l;
    }
    
    if(r<=cnt&&z[r-1].x<z[min-1].x)min=r;
    else if(r<=cnt&&z[r-1].x==z[min-1].x){
        if(z[r-1].y<z[min-1].y)min=r;
    }
    
    if(min!=parent){
        Z tmp;
        tmp=z[min-1];
        z[min-1]=z[parent-1];
        z[parent-1]=tmp;
        
        makeHeap(z,cnt,parent);
    }
    
    return;
}
void reHeap(Z z[],int cnt,int parent){
    if(parent>cnt)return;
    
    int l,r,min;
    l=parent*2;
    r=parent*2+1;
    min=parent;
    
    if(l<=cnt&&z[l-1].x<z[min-1].x)min=l;
    else if(l<=cnt&&z[l-1].x==z[min-1].x){
        if(z[l-1].y<z[min-1].y)min=l;
    }
    
    if(r<=cnt&&z[r-1].x<z[min-1].x)min=r;
    else if(r<=cnt&&z[r-1].x==z[min-1].x){
        if(z[r-1].y<z[min-1].y)min=r;
    }
    
    if(min!=parent){
        Z tmp;
        tmp=z[min-1];
        z[min-1]=z[parent-1];
        z[parent-1]=tmp;
        
        reHeap(z,cnt,min);
    }
    return;
}

int main(void){
    int i;
    
    int n;
    scanf("%d\n",&n);
    Z z[n];
    int cnt=0;
    for(i=0;i<n;i++){
        scanf("%d %d\n",&z[i].x,&z[i].y);
        cnt++;
        makeHeap(z,cnt,cnt);
    }
    
    for(i=0;i<n;i++){
        printf("%d %d\n",z[0].x,z[0].y);
        z[0]=z[--cnt];
        reHeap(z,cnt,1);
    }
    
    return 0;
}



Measured memory_bytes: 2636
#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;

int main()
{
    double xa, ya, ra, xb, yb, rb;
    int n;
    cin >> n;
    rep(i, n)
    {
        cin >> xa >> ya >> ra >> xb >> yb >> rb;
        double d = sqrt(pow((xa - xb), 2) + pow(ya - yb, 2));
        if (d > ra + rb)
            OP(0);
        else
        {
            if (d + rb < ra)
                OP(2);
            else if (d + ra < rb)
                OP(-2);
            else
                OP(1);
        }
    }

    return 0;
}


Measured memory_bytes: 3208
#include <iostream>
#include <vector>

template <int MOD>
struct ModInt {
    using lint = long long;
    int val;

    // constructor
    ModInt(lint v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };

    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }

    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(lint n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }

    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = lint(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }

    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }

    // I/O
    friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept { return is >> x.val; }
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

constexpr int MOD = 998244353;
using mint = ModInt<MOD>;

void solve() {
    int n, s;
    std::cin >> n >> s;

    mint ans = 0;
    std::vector<mint> dp(s + 1, 0);
    dp[0] = 1;
    for (int i = 1; i <= n; ++i) {
        int x;
        std::cin >> x;

        for (int j = s; j >= 0; --j) {
            if (j - x > 0) {
                dp[j] += dp[j - x];
            } else if (j - x == 0) {
                dp[j] += dp[j - x] * i;
            }
        }
        ans += dp[s];
    }

    std::cout << ans << std::endl;
}

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

    solve();

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    int n;
    cin>>n;
    ll ans = 0;
    map<ll,ll>m;
    for(int i=1;i<=n;i++) {
        ll x;
        cin>>x;
        m[i+x]++;
        ans+=m[i-x];
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 26236
#include <iostream>
#include <vector>
#include <algorithm>
int main() {
	int n;
	std::cin >> n;
	std::vector<double> gpas(n);
	for (auto &gpa : gpas) std::cin >> gpa;
	std::vector<double> copy = gpas;
	std::sort(gpas.begin(), gpas.end());
	for (const auto gpa : copy) {
		std::cout << (std::lower_bound(gpas.begin(), gpas.end(), gpa) - gpas.begin()) * 2 + (std::upper_bound(gpas.begin(), gpas.end(), gpa) - gpas.begin() - 1) << std::endl;
	}
}


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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    vector<int> a(m);
    vector<int> b(m);
    rep(i, m) {
        cin >> a[i];
        --a[i];
        cin >> b[i];
        --b[i];
    }
    vector<int> ma(n, 0);
    rep(i, m) {
        ma[a[i]] = max(ma[a[i]], h[b[i]]);
        ma[b[i]] = max(ma[b[i]], h[a[i]]);
    }

    int ans = 0;
    rep(i, n) {
        if(h[i] > ma[i]) ++ans;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4820
#include<stdio.h>
 
typedef struct{
  int p,l,r;
} Node;
 
Node T[100000];
 
int n;
 
int depth(int a);
int print(int a);
 
int main(){
 
  int i,j,x,d,c,l;
 
  scanf("%d",&n);
  for(i=0;i<=n-1;i++) T[i].p = T[i].l = T[i].r = -1;
 
  for(i=0;i<n;i++){
    scanf("%d %d",&x,&d);
    for(j=0;j<d;j++){
      scanf("%d",&c);
      if(j==0){
	T[x].l=c;
      }

      else{
	T[l].r =c;
      }

      l=c;
      T[c].p=x;
    }
  }
 
  for ( i=0; i<n; i++ ) print(i);
  return 0;
}
 
int print(int a){
  int i, c;
  printf("node %d: parent = %d, depth = %d, ", a, T[a].p,depth(a));
 
  if(T[a].p==-1) printf("root, ");
  else if(T[a].l!=-1) printf("internal node, ");
  else printf("leaf, ");
 
  printf("["); 
 
  for(i=0, c=T[a].l; c!=-1; i++, c=T[c].r){
    if(i==0) printf("%d", c);
    else printf(", %d", c);
  }
  printf("]\n");
 
  return 0;
}
 
int depth(int a){
  int num=0,s=T[a].p;
  while(s!=-1){
    num++;
    s=T[s].p;
  }
  return num;
}

Measured memory_bytes: 1788
S=input()
 
ans=[1]*len(S)
for i in range(1,len(S)):
  if S[i-1]==S[i]=='R': # RRが続いている時、1つ目のRにはもう戻ってこない,2つ目のRより右に行き着く
    ans[i+1]+=ans[i-1]
    ans[i-1]=0
for i in range(len(S)-2,0,-1): # LLが続いている時、2つ目のLにはもう戻ってこない,1つ目のLより左に行き着く
  if S[i+1]==S[i]=='L':
    ans[i-1]+=ans[i+1]
    ans[i+1]=0
print(*ans)

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i=0;i<n;i++)
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    rep(i, 3){
        char a;
        cin >> a;
        if(a == '1'){
            cout << 9;
        }else{
            cout << 1;
        }
    }
    cout << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<complex>
#include<utility>
#include<vector>

using namespace std;

typedef complex<double> P;

int x_1[100],y_1[100],x_2[100],y_2[100];
double eps=1e-6;

double cross(P a,P b){
  return a.real()*b.imag()-a.imag()*b.real();
}

bool on(P a,pair<P,P> l){
  return fabs(cross(a-l.first,l.second-l.first))<sqrt(eps);
}

P cp(pair<P,P> e,pair<P,P> f){
  P a=e.second-e.first;
  P b=f.second-f.first;
  double acb=cross(a,b);
  if(fabs(acb)<eps)throw 0;
  return e.first+a*cross(f.first-e.first,b)/acb;
}  

vector<pair<P,P> > elines(int x1,int x2){
  P a1=P(x_1[x1],y_1[x1]),a2=P(x_2[x1],y_2[x1]);
  P b1=P(x_1[x2],y_1[x2]),b2=P(x_2[x2],y_2[x2]);
  vector<pair<P,P> > v;
  try{
    auto cpab=cp(make_pair(a1,a2),make_pair(b1,b2));
    P ac=a1-a2,bc=b1-b2;
    P d=ac/abs(ac)+bc/abs(bc);
    v.emplace_back(cpab,cpab+d);
    v.emplace_back(cpab,cpab+d*P(0,1));
  }catch(...){
    //P m=(a1+b1)/2.l;
    P m=(a1+b1)/2.;
    v.emplace_back(m,m+a2-a1);
  }
  return v;
}
    
int main(){
  for(int n;cin>>n,n;){
    vector<pair<P,P> > lines;
    vector<P> points;
    for(int i=0;i<n;i++){
      cin>>x_1[i]>>y_1[i]>>x_2[i]>>y_2[i];
      for(int j=0;j<i;j++){
	if(i==1){
	  lines=elines(i,j);
	}else{
	  vector<pair<P,P> > nl;
	  vector<P> np;
	  for(auto e:elines(i,j)){
	    for(auto f:lines){
	      try{
		auto cpef=cp(e,f);
		np.push_back(cpef);
	      }catch(...){
		if(on(f.first,e)&&on(f.second,e)){
		  nl.push_back(f);
		}
	      }
	    }
	    for(auto f:points){
	      if(on(f,e)){
		np.push_back(f);
	      }
	    }
	  }
	  lines=nl;
	  points.clear();
	  for(int i=0;i<np.size();i++){
	    bool has=false;
	    for(auto e:points){
	      has|=abs(e-np[i])<eps;
	    }
	    if(!has){
	      points.push_back(np[i]);
	    }
	  }
	}
      }
    }
    if(n==1||!lines.empty()||points.size()>1){
      cout<<"Many"<<endl;
    }else if(points.empty()){
      cout<<"None"<<endl;
    }else{
      cout<<fixed<<points[0].real()<<' '<<points[0].imag()<<endl;
    }
  }
}

Measured memory_bytes: 1352
#include <algorithm> //min, max, sort, unique, fill
#include <iostream>
#include <numeric>
#include <string>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
#include <utility> //pair, swap,
#include <vector>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using VI = vector<ll>;
using VB = vector<bool>;
using VP = vector<P>;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) for (ll i = 0; i < (n); i++)

static const ll kIntMax = numeric_limits<ll>::infinity();
static const double kFloatMax = numeric_limits<double>::infinity();

vector<ll> vi;

int main()
{

  bool ok = false;
  string s;
  cin >> s;
  
  for(int i = 2 ; i < s.size() -1;i++){
    
    if(ok && s[i] == 'C'){
      ok = false;break;
    }
    else if(s[i] == 'C'){
      ok = true;
    }else if(!('a' <= s[i] && s[i] <= 'z')){
      ok = false;
      break;

    } 
  }

  ok = ok && s[0] == 'A';
  ok = ok && 'a' <= s[1] && s[1] <= 'z';
  ok =ok &&  'a' <= s[s.size() - 1] && s[s.size() - 1] <= 'z';

  if (ok)
    cout << "AC" << endl;
  else
    cout << "WA" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;

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

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

  int H,W; cin >> H >> W;
  vector<string> G(H);
  rep(i, H) cin >> G[i];

  vector<vector<int>> D(H, vector<int>(W, 0));
  queue<pair<int,int>> Q;

  rep(h, H) {
    rep(w, W) {
      if(G[h][w] == '#') {
        Q.push({h,w});
      }
    }
  }

  while(!Q.empty()) {
    auto cur = Q.front(); Q.pop();
    rep(i, 4) {
      int nh = cur.first + dy[i];
      int nw = cur.second + dx[i];
      if(nh >= 0 && nh < H && nw >= 0 && nw < W && G[nh][nw] == '.') {
        if(G[nh][nw] == '#') continue;

        G[nh][nw] = '#';
        D[nh][nw] = D[cur.first][cur.second] + 1;
        Q.push({nh, nw});
      }
    }
  }

  int ans = 0;
  rep(h, H) {
    rep(w, W) {
      if(D[h][w] > 0) {
        chmax(ans, D[h][w]);
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 13456
h, w = map(int,input().split())
s = [list(input()) for i in range(h)]

#障害物がない直線経路を前計算しておく
L = [[0] * w for i in range(h)]
R = [[0] * w for i in range(h)]
U = [[0] * w for i in range(h)]
D = [[0] * w for i in range(h)]

for i in range(h):
    for j in range(w):
        temp_L = s[i][j]
        temp_R = s[i][-(j + 1)]
        temp_U = s[i][j]
        temp_D = s[-(i + 1)][j]

        if temp_L == '#':L[i][j] = 0
        else:
            if j == 0:L[i][j] = 1
            else:L[i][j] = L[i][j - 1] + 1

        if temp_R == '#':R[i][-(j + 1)] = 0
        else:
            if j == 0:R[i][-(j + 1)] = 1
            else:R[i][-(j + 1)] = R[i][-(j + 1) + 1] + 1

        if temp_U == '#':U[i][j] = 0
        else:
            if i == 0:U[i][j] = 1
            else:U[i][j] = U[i - 1][j] + 1

        if temp_D == '#':D[-(i + 1)][j] = 0
        else:
            if i == 0:D[-(i + 1)][j] = 1
            else:D[-(i + 1)][j] = D[-(i + 1) + 1][j] + 1

ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':continue
        temp = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3
        if ans < temp:ans = temp
print(ans)
#print(L,R,U,D,sep ='\n')

Measured memory_bytes: 311560
//Sameer's Code
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define MOD 1000000007
#define pb push_back
int minimumChar(string S1, string S2)
{
	int n = S1.size(), m = S2.size();

	int ans = INT_MAX;
	for (int i = 0; i < m - n + 1; i++) {
		int minRemovedChar = 0;
		for (int j = 0; j < n; j++) {
			if (S1[j] != S2[i + j]) {
				minRemovedChar++;
			}
		}		ans = min(minRemovedChar, ans);
	}

	// return answer
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r" , stdin);
	freopen("output.txt", "w", stdout);
#endif
	string s;
	string t;
	cin >> s >> t;
	cout << minimumChar(t, s);
	return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<cstring>

using namespace std;

int ans[10001];
int res[501];

bool linear_search(int arr[],int q,int key)
{
	int i=0;
	while(arr[i]!=key){
		i++;
		if(i==q)return false;
	}
	return true;
}

int main()
{
	memset(ans,0,sizeof(ans));
	memset(res,0,sizeof(res));
	int n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>ans[i];
	int q;
	cin>>q;
	for(int i=0;i<q;i++)cin>>res[i];
	int cnt=0;
	for(int i=0;i<q;i++){
		if(linear_search(ans,n,res[i]))cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 3140
n, m = map(int, input().split())
p = [list(map(int, input().split())) for i in range(n)]
s = []
for i in range(8):
  s.append([])
  for j in range(n):
    x, y, z = p[j]
    sx = i // 4 % 2 * 2 - 1
    sy = i // 2 % 2 * 2 - 1
    sz = i % 2 * 2 - 1
    s[i].append(sx * x + sy * y + sz * z)
  s[i] = sorted(s[i], reverse=True)
ans = 0
for i in range(8):
  ans = max(ans, sum(s[i][:m]))
print(ans)


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

int main(){
  int n,i,j,x[15][20];
  
  
  for ( i = 0 ; i < 15 ; i++){
    
    for (j = 0 ; j < 10 ; j++){
      if ( i == 3 || i == 7 || i == 11){
	continue;
      }
      else{
	x[i][j] = 0;
      }
    }
  }
  
  cin >> n;
  int b,f,r,v;
  for ( i = 0 ; i < n ; i++){
    cin >> b >> f >> r >> v;
    switch (b){
    case 1: x[f-1][r-1] =x[f-1][r-1]+ v;continue;
    case 2: x[f+3][r-1] =x[f+3][r-1]+  v;continue;
    case 3: x[f+7][r-1] =x[f+7][r-1]+  v;continue;
    case 4: x[f+11][r-1] =x[f+11][r-1]+  v;continue;
    }
  }
    
  for ( i = 0 ; i < 15 ; i++){
    for (j = 0 ; j < 10 ; j++){
      if ( i == 3 || i == 7 || i == 11){
	cout <<"##";
      }
      else{
	cout <<" " << x[i][j];
      }
    }
    cout <<endl;
  }
      
  return 0;
}
    

Measured memory_bytes: 1160
/* C++14 (Clang 3.8.0) for AtCoder */

#include <iostream>
#include <vector>
#include <string>
// #include <cmath>
// #include <algorithm>
// #include "./Debug.h"

namespace AtCoder {
	using Input = std::vector<std::string>;
	using Num = std::vector<int>;

	Input input(void) {
		Input result;
		{
			std::string buf = "", row = "";
			std::getline(std::cin, buf);
			for (unsigned int i = 0; i < buf.size(); i++) {
				if (' ' == buf[i]) {
					result.push_back(row);
					row = "";
				} else {
					row += buf[i];
				}
			}
			result.push_back(row);
		}
		return result;
	}

	Num replaceToInteger(Input original = { "" }) {
		Num result;
		for (unsigned int i = 0; i < original.size(); i++) {
			result.push_back(atoi(original[i].c_str()));
		}
		return result;
	}
}

int main(void) {

	AtCoder::Num s = AtCoder::replaceToInteger(AtCoder::input());

	int n = s[0];

	printf("%d\n", (180 * (n - 2)));

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int n1,n2,n3;
        n1 = n/100;
        n2 = (n-n1*100)/10;
        n3 = (n-n1*100-n2*10);
        if(n1==7||n2==7||n3==7){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
        }
        }


Measured memory_bytes: 35668
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int main()
{
	int r=0,b=0,n;
	string s;
	cin >> n >> s;
	rep(i,s.size()){
		if(s[i]=='R') r++;
		else b++;
	}
	if(r>b) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int n,m,K,S,T;
pair<int,int> s[1000005];
char a[1005][1005];
int d[1005][1005];
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
bool pan(int x,int y){
	if(x<1||y<1||x>n||y>m) return 0;
	return 1;
}
void bfs(int x,int y){
	if(x==1||y==1||x==n||y==m){
		puts("0");return;
	}
	memset(d,-1,sizeof(d));
	d[x][y]=0;
	s[0]=make_pair(x,y);
	int tou=0,wei=1,ans=1e9;
	while(tou<wei){
		x=s[tou].first;y=s[tou++].second;
		if(d[x][y]>K) break;
		ans=min(ans,min(min(x-1,y-1),min(n-x,m-y)));
		for(int i=0;i<4;i++) if(pan(x+dx[i],y+dy[i])&&d[x+dx[i]][y+dy[i]]==-1&&a[x+dx[i]][y+dy[i]]=='.'){
			d[x+dx[i]][y+dy[i]]=d[x][y]+1;
			s[wei++]=make_pair(x+dx[i],y+dy[i]);
		}
	}
	ans=ans==0?0:(ans-1)/K+1;
	printf("%d",ans+1);
}
int main(){
	scanf("%d%d%d",&n,&m,&K);
	for(int i=1;i<=n;i++) scanf("%s",a[i]+1);
	for(int i=1;i<=n;i++){
		for(int p=1;p<=m;p++) if(a[i][p]=='S') S=i,T=p;
	}
	bfs(S,T);
	return 0;
}

Measured memory_bytes: 10496
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<vector<vector<int>>> v3int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef vector<vector<vector<ll>>> v3ll;
typedef list<int> liint;
typedef pair<int, int> pint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, int>> vpll_int;
typedef vector<pair<int, ll>> vpint_ll;
typedef set<pair<int, int>> spint;
typedef set<pair<ll, int>> spll;
typedef unordered_map<int, unordered_set<int>> Graph;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#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++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    vint A(N);
    rep(i, N) cin >> A[i];
    ll ans = 0;
    rep(i, N) {
        if (((i + 1) % 2 == 1) && (A[i] % 2 == 1)) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
#define mkp make_pair
typedef long long ll;
using namespace std;

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

  int ans=0;
  for(int i=1;i<=N;i++){
    int cnt=0;
    int a=i;
    while(a>0){
      cnt++;
      a/=10;
    }
    if(cnt%2) ans++;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int H,W,K,ans=1000000000;
int cnt[10][1005];
int main(void){
    cin>>H>>W>>K;
    string S[H];
    rep(i,H)cin>>S[i];

    rep(div,1<<(H-1)){
        int g=0;
        vector<int>id(H);
        rep(i,H){
            id[i]=g;
            if(div>>i&1)++g;
        }
        ++g;
        rep(i,g)rep(j,W)cnt[i][j]=0;
        rep(i,H)rep(j,W)cnt[id[i]][j]+=(S[i][j]-'0');

        int num=g-1;
        vector<int>now(g);
        auto add=[&](int j){
            rep(i,g)now[i]+=cnt[i][j];
            rep(i,g)if(now[i]>K)return false;
            return true;            
        };
        rep(j,W){
            if(!add(j)){
                num++;
                now=vector<int>(g);
                if(!add(j)){
                    num=1001001001;
                    break;
                }
            }
        }
        ans=min(ans,num);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n; cin >> n;
  vi p(n); rep(i,n) cin >> p[i];
  sort(all(p));
  int ans = 0;
  rep(i,n) ans += p[i];
  ans -= p.back()/2;
  cout << ans;
  cout << endl;
  return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
using namespace std;

int h, w, c1, c2, d1, d2;
vector<string> mp;
unordered_map<int, int> color;
unordered_map<int, int> coord;
vector<unordered_set<int>> g(1000020, unordered_set<int>());
unordered_set<int> vis;

int encode(int i, int j) {
    return i * w + j;
}

void decode(int idx, int &i, int j) {
    i = idx / w;
    j = idx % w;
}

void build() {
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            for (int di = -2; di <= 2; ++di) {
                for (int dj = -2; dj <= 2; ++dj) {
                    int ni = i + di, nj = j + dj;
                    if (ni < 0 || ni >= h || nj < 0 || nj >= w || mp[ni][nj] == '#') continue;
                    int c1 = color[encode(i, j)];
                    int c2 = color[encode(ni, nj)];
                    g[c1].insert(c2);
                }
            }
        }
    }
}


void coloring(int i, int j, int c) {
    if (i < 0 || i >= h || j < 0 || j >= w || mp[i][j] == '#') return;
    int idx = encode(i, j);
    if (color.find(idx) == color.end()) {
        color[idx] = c;
        coloring(i+1, j, c);
        coloring(i-1, j, c);
        coloring(i, j+1, c);
        coloring(i, j-1, c);
    }
}

struct S {
    int idx, step;
};

int bfs(int start, int end) {
    if (start == end) return 0;
    queue<S> qu;
    qu.push(S{start, 0});
    vis.insert(start);
    while (!qu.empty()) {
        S cur = qu.front(); qu.pop();
        for (int nc : g[cur.idx]) {
            if (vis.find(nc) != vis.end()) {
                continue;
            }
            if (nc == end) {
                return cur.step + 1;
            }
            vis.insert(nc);
            qu.push(S{nc, cur.step+1});
        }
    }
    return -1;
}

int main() {
    ios::sync_with_stdio(false);
    cin >> h >> w >> c1 >> c2 >> d1 >> d2;
    for (int i = 0; i < h; i++) {
        string s; cin >> s;
        mp.push_back(s);
    }
    c1--;c2--;d1--;d2--;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            coloring(i, j, encode(i, j)+1);
        }
    }
    build();
    int ans = bfs(color[encode(c1,c2)], color[encode(d1,d2)]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 124136
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n); i++)
#define sz(x) int(x.size())
using namespace std;

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

    rep(i, sz(s)){
        char u = s.at(i) + n;
        // cout << (int)u << endl;
        if(u > 'A' && u > 'Z') u -= 26;
        s.at(i) = u;
    }

    cout << s << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <climits>

using namespace std;

/*******  All Required define Pre-Processors and typedef Constants *******/
#define in1(n) cin>>n;
#define in2(n, k) cin>>n>>k;
#define in3(n, k, s) cin>>n>>k>>s;
#define scn(t) scanf("%d", &t)
#define scnld(t) scanf("%ld", &t)
#define scnlld(t) scanf("%lld", &t)
#define scnc(t) scanf("%c", &t)
#define scns(t) scanf("%s", t)
#define scnf(t) scanf("%f", &t)
#define scnlf(t) scanf("%lf", &t)
#define mem(a, b) memset(a, (b), sizeof(a))
#define nloop(i, j, k, in) for (int i = j; i < k; i += in)
#define rloop(i, j, k, in) for (int i = j; i >= k; i -= in)
#define rep(i, j) nloop(i, 0, j, 1)
#define rrep(i, j) rloop(i, j, 0, 1)
#define inar(n, a) \
    rep(i, n)\
        cin>>a[i];
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert(B <= A && A <= C)
#define MP make_pair
#define PB push_back
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b)\
{\
return (a.second < b.second);\
}
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define fast  \
    ios_base::sync_with_stdio(false);\
    cin.tie(NULL);
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
const double pi = acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int, int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int uint64;

int main()
{
    fast
    double n, x, t;
    in3(n, x, t)
    cout<<int(ceil(1.0*n/x)*t)<<endl;
    return 0;
}

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


int main() {
    int n;
    cin >> n;
    if(n%2 == 0)cout << n;
    else cout << n*2 << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
import random
import math
N = list(map(int, input().split()))
A=N[0]
B=N[1]
C=N[2]
x=(int)(C/(A*7+B))
sum=x*7

if abs(x*(A*7+B)-C)>= 0.0000001:
    for i in range (1,8):
        sum=sum+1
        if i== 7 and C<=x*(A*7+B)+i*A+B:
            break
        if C<=x*(A*7+B)+i*A:
            break
print(sum)



Measured memory_bytes: 8176
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define endl "\n"
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define all(x) (x).begin(), (x).end()

ll dp[110][100010] = {0};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, W;
    cin >> n >> W;
    vector<ll> w(n), v(n);
    rep(i, 0, n) cin >> w[i] >> v[i];

    rep(i, 0, n) {
        rep(j, 0, W + 1) {
            if (j >= w[i]) {
                dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
            } else {
                dp[i + 1][j] = dp[i][j];
            }
        }
    }

    cout << dp[n][W] << endl;
    return 0;
}


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

int main()
{
	int h, w;
	cin >> h >> w;
	char word[h][w];
	for(int i = 0; i < h; ++i)
		for(int j = 0; j < w; ++j)
			cin >> word[i][j];
	
	for(int i = 0; i < w+2; ++i)
		cout << '#';
	cout << endl;

	for(int i = 0; i < h; ++i){
		for(int j = 0; j < w+2; ++j){
			if((j == 0) || (j == w+1)){
				cout << '#';
			} else {
				cout << word[i][j-1];
			}
		}
		cout << endl;
	}


	for(int i = 0; i < w+2; ++i)
		cout << '#';
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

    ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
    ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
const ll INF = 1e16;

int main(){
    int n,m;
    cin >> n >> m;
    vector<int>x(m);
    rep(i,m){
        cin >> x[i];
    }
    sort(x.begin(),x.end());
    vector<ll>y(m-1);
    rep(i,m-1){
        y[i]=x[i+1]-x[i];
    }
    sort(y.begin(),y.end());
    ll ans = 0;
    rep(i,m-n){
        ans += y[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
using namespace std;
const int MAXN=1e5+7;
int n,k;
int h[MAXN],f[MAXN];
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>h[i];
	h[0]=0x3f3f3f3f;
	for(int i=2;i<=n;i++)
	{
		int minx=0x3f3f3f3f;
		for(int j=1;j<=k;j++)
			if(i-j>0) minx=min(minx,abs(h[i]-h[i-j])+f[i-j]);
		f[i]=minx;
	}
	cout<<f[n]<<endl;
	return 0;
}

Measured memory_bytes: 4296
#include<iostream>
#include  <stdio.h>
using namespace std;

void QSort(int x[ ],int v[], int left, int right);
void Swap(int x[ ], int i, int j);

void QSort(int x[ ],int v[], int left, int right)
{
    int i, j;
    int pivot;

    i = left;                      /* ソートする配列の一番小さい要素の添字 */
    j = right;                     /* ソートする配列の一番大きい要素の添字 */

    pivot = v[ x[(left + right) / 2] ]; /* 基準値を配列の中央付近にとる */

    while (1) {                    /* 無限ループ */

        while (v[x[i]] < pivot)       /* pivot より大きい値が */
            i++;                   /* 出るまで i を増加させる */

        while (pivot < v[x[j]])       /* pivot より小さい値が */
            j--;                   /*  出るまで j を減少させる */
        if (i >= j)                /* i >= j なら */
            break;                 /* 無限ループから抜ける */

        Swap(x, i, j);             /* x[i] と x[j]を交換 */
        i++;                       /* 次のデータ */
        j--;
    }
    //ShowData(x, 10);               /* 途中経過を表示 */

    if (left < i - 1)              /* 基準値の左に 2 以上要素があれば */
        QSort(x, v, left, i - 1);     /* 左の配列を Q ソートする */
    if (j + 1 <  right)            /* 基準値の右に 2 以上要素があれば */
        QSort(x, v, j + 1, right);    /* 右の配列を Q ソートする */
}

  /* 配列の要素を交換する */
void Swap(int x[ ], int i, int j)
{
    int temp;

    temp = x[i];
    x[i] = x[j];
    x[j] = temp;
}

  /* n 個のデータを表示する */
void ShowData(int x[ ], int n)
{
    int i;

    for (i = 0; i < n ; i++)
        printf("%d  ", x[i]);
    printf("\n");
}

int main(){
    int N;
    int M;
    int i_start;
    int i_end;


    cin >> N;
    cin >> M;

    int Pi[M];
    int Y[M];
    int index[M];
    int count_i[M];
    int count_Pi[N];
    int i;
    int x_Pi;

    for( int n = 0 ; n < M ; n++ ){
        cin >> Pi[n];
        cin >> Y[n];
        index[n] = n;
    }

    for( int n = 0 ; n < N ; n++ ){
        count_Pi[n] = 0;
    }


    i_start = 0;
    i_end   = M - 1;
    QSort(index,Y,i_start, i_end);

    for( int n = 0 ; n < M ; n++ ){
        i    = index[n];
        x_Pi = Pi[i] - 1;
        count_Pi[x_Pi]++;
        count_i[i] = count_Pi[x_Pi];
    }

    for( int n = 0 ; n < M ; n++ ){
        printf("%06d",Pi[n]);
        printf("%06d",count_i[n]);
        printf("\n");
    }


    return 0;
}   

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define show(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<62;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

const ll mod=1e9+7;
ll inv[2001];

ll extgcd(ll a,ll b,ll &x,ll &y){
	ll d=a;
	if(b!=0){
		d=extgcd(b,a%b,y,x);
		y-=(a/b)*x;
	} else {
		x=1; y=0;
	}
	return d;
}

void solve(const ll n,const ll d,const ll x){
    static ll dp[2001][2001];
    fill_n((ll*)dp,2001*2001,0);
    rep(i,1,x) dp[1][i]=1;
    rep(i,2,n+1) rep(j,1,n+1){
        dp[i][j]=dp[i][j-1];
        if(j-x>=0) dp[i][j]=(dp[i][j]-dp[i-1][j-x]+mod)%mod;
        dp[i][j]=(dp[i][j]+dp[i-1][j-1]+mod)%mod;
    }

    ll ans=0;
    rep(i,1,min(d,n)+1){
        ll tmp=dp[i][n];
        rep(j,0,i){
            tmp=(d-j)%mod*tmp%mod;
            tmp=tmp*inv[i-j]%mod;
        }
        ans=(ans+tmp)%mod;
    }
    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);

    inv[1]=1;
    rep(i,2,2001){
        ll k;
        extgcd(i,mod,inv[i],k);
        inv[i]=(inv[i]+mod)%mod;
    }
    while(true){
        ll n,d,x;
        cin >> n >> d >> x;
        if(n==0 and d==0 and x==0) break;
        solve(n,d,x);
    }
    return 0;
}

Measured memory_bytes: 34444
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<array>

int main() {
    std::string s;
    std::cin >> s;
    int c = 0;
    for (int i = 0; i < 3; ++i) if (s[i] == '1') ++c;
    std::cout << c << std::endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<string>
#include<iomanip>
using namespace std;
typedef long long LL;
int main(){
	int a[3],ans = 0;
	cin >> a[0] >> a[1] >> a[2];
	for(int i = 0;i < 3;i++){
		for(int j = i+1;j < 3;j++){
			if(a[j] == a[i])
				a[j] = 0;
		}
	}
	for(int i = 0;i < 3;i++)
		if(a[i] != 0)
			ans+=1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;  
long INF=1000000000000000;
int main() {
    string S;
    cin>>S;
    
    vector<vector<long>> dp(S.size(),vector<long>(2,0));
    
    
    dp.at(0).at(0)=1;
    
    for(int i=1;i<S.size();i++){
        if(S.at(i-1)=='R' && S.at(i)=='R'){
            dp.at(i).at(0)=1+dp.at(i-1).at(1);
            dp.at(i).at(1)=dp.at(i-1).at(0);
            
            dp.at(i-1).at(0)=0;
            dp.at(i-1).at(1)=0;
        }else if(S.at(i)=='R') dp.at(i).at(0)=1;
    }
    
    dp.at(S.size()-1).at(0)=1;
    for(int i=S.size()-2;i>=0;i--){
        if(S.at(i+1)=='L' && S.at(i)=='L'){
            dp.at(i).at(0)=1+dp.at(i+1).at(1);
            dp.at(i).at(1)=dp.at(i+1).at(0);
            
            dp.at(i+1).at(0)=0;
            dp.at(i+1).at(1)=0;
        }else if(S.at(i)=='L') dp.at(i).at(0)=1;
    }
    /*for(int i=0;i<S.size();i++){
        cout<<dp.at(i).at(0)<<" "<<dp.at(i).at(1)<<endl;
    }*/
    for(int i=0;i<S.size();i++){
        long ans=0;
        
        if(S.at(i)=='R' && S.at(i+1)=='L') ans+=dp.at(i).at(0)+dp.at(i+1).at(1);
        if(S.at(i)=='L' && S.at(i-1)=='R') ans+=dp.at(i).at(0)+dp.at(i-1).at(1);
        
        cout<<ans<<" ";
    }
    
    cout<<endl;
}

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

using namespace std;

int main() {
        ios::sync_with_stdio(false);
        cin.tie(0);
        int n;
        string s;
        cin >> n >> s;
        set<int> occ[30];
        for (int i = 0; i < n; i++)
                occ[s[i] -= 'a'].insert(i);
        int q;
        cin >> q;
        while (q--) {
                int type;
                cin >> type;
                if (type == 1) {
                        int idx;
                        char c;
                        cin >> idx >> c;
                        occ[s[--idx]].erase(idx);
                        occ[s[idx] = c - 'a'].insert(idx);
                } else {
                        int l, r;
                        cin >> l >> r;
                        int ans = 0;
                        for (int i = 0; i < 30; i++)
                                ans += occ[i].lower_bound(l - 1) != occ[i].upper_bound(r - 1);
                        cout << ans << '\n';
                }
        }

        return 0;
}

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

const ll INF = pow(10, 9) + 7;

int main() {
	int N,K;
	cin >> N>> K;
	vector<int> p(N),pk(N-K+1);

	rep(i, N) cin >> p[i];

	rep(i, K) pk[0] += p[i];

	rep(i, N - K) {
		int aa;
		aa = pk[i] - p[i] + p[K + i];
		pk[i + 1] = aa;
	}
	sort(pk.rbegin(),pk.rend());
	double ans = 0;
	ans = (double)(pk[0] + K) / 2;

	printf("%lf",ans);
}



// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 1792
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<limits>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1000000000 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main() {
	string s;
	cin >> s;
	string ans = "No";
	map<char, int> cnt{};
	int size = s.size();

	for (int i = 0; i < size; i++) {
		cnt[s[i]]++;
	}

	if (cnt['N'] && cnt['S']) {
		if (cnt['W'] && cnt['E']) {
			ans = "Yes";
		}
		else if (cnt['W'] == 0 && cnt['E'] == 0) {
			ans = "Yes";
		}
	}else if (cnt['W'] && cnt['E']) {
		if (cnt['N'] && cnt['S']) {
			ans = "Yes";
		}
		else if (cnt['N'] == 0 && cnt['S'] == 0) {
			ans = "Yes";
		}
	}

	/*for (auto i = cnt.begin(); i != cnt.end(); i++) {
		cout << i->first << " " << i->second << endl;
	}*/

	cout << ans << endl;


	return 0;
}

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

#define PrintLn(X) cout << X << endl
#define Rep(i, n) for(int i = 0; i < (int)(n); ++i)

int main(void)
{
	int N;
	cin >> N;
	int x = 800 * N;
	int y = 200 * (N / 15);
	PrintLn(x - y);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

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

    int n;
    cin >> n;
    int cnt[100010] = {3}, ans = 1;
    rep(i, n)
    {
        int a;
        cin >> a;
        (ans *= cnt[a]) %= mod;
        cnt[a]--;
        cnt[a + 1]++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1152
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <queue>
#include <algorithm>

using namespace std;


// Highway Express Bus
// input 
// c n m s d : ????????? ????????° ???????????° ????????°??? ????????°???
// a b f : a??????b?????§f???

#define INF 1e+9
typedef pair<int, int> P;
struct edge{
	int to, cost; 
};

int c, n, m, s, d;
vector<edge> G[101];
int dp[11][101];	//????????????i???????????????j??°????????§???????°??????????


void dijkstra(int s,int a){		//????????????????????????????????°???a???????????????????????????
    priority_queue<P, vector<P>, greater<P> >Q;	//greater: ????´?????°????????????§??????????????¨????????????
    for(int i=0 ;i<n; i++) dp[a][i] = INF;
    dp[a][s] = 0;
    Q.push(P(0,s));	//??????????????°???
    
    while(!Q.empty()){
        P p=Q.top();  //p<cost, vertex>
        Q.pop();
        int v = p.second;
        
        if(dp[a][v] < p.first)continue;
        for(int i=0; i<G[v].size(); i++){
            edge e = G[v][i];	//v?????????????????´????????????{??°???????????????}
            int dm;
            if(a==0) dm = dp[a][v] + e.cost;	//???????????????????????¨???
            else dm = min(dp[a][v] + e.cost, dp[a-1][v] + e.cost/2);	//v?????????????????´?????§??????????????????
            															//??????????????§???????°????

            if(dp[a][e.to] > dm){
                dp[a][e.to] = dm;	//dm????????????????????????????????´??°
                Q.push(P(dp[a][e.to],e.to));	//?????\??????(?????????,?¬???°???)??§??\??????
            }
        }
    }
}


int main(){

	while(1){
		cin >> c >> n >> m >> s >> d;
		s--;
		d--;
		if(c==0) break;

		for(int i=0 ; i<m ; i++){
			int a, b, f;
			cin >> a >> b >> f;

			a--;
			b--;

			G[a].push_back((edge){b,f});	//??£??\?????????:a??????b?????§????????????
			G[b].push_back((edge){a,f});
		}

		int ans = INF;
	    for(int i=0;i<=c;i++){
    		dijkstra(s,i);
		}
        
	    cout << dp[c][d] << endl;
	     
	    for(int i=0;i<100;i++)G[i].clear();
	}

	return 0;
}

Measured memory_bytes: 1240
#include <iostream>
#include <string>
using namespace std;
int main(){
    string n;
    int a;
    cin >> n;
    if(n[0]=='1'){
        n[0]='9';
    }else if(n[0]=='9'){
        n[0]='1';
    }if(n[1]=='1'){
        n[1]='9';
    }else if(n[1]=='9'){
        n[1]='1';
    }if(n[2]=='1'){
        n[2]='9';
    }else if(n[2]=='9'){
        n[2]='1';
    }cout << n << endl;
}

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

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

	string s; cin >> s;
	long long k; cin >> k;
	for(int i = 0; i < s.size() && i < k; i++) {
		if(s[i] != '1'){
			cout << s[i] << endl;
			return 0;
		}
	}
	cout << 1 << endl;
	return 0;
}	


Measured memory_bytes: 256