akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
    int H, W;
    char a[100][100];
    cin >> H >> W;
    REP(i, H) {
        REP(j, W) cin >> a[i][j];
    }

    for(int i = 0; i < H; i++) {
        bool is_rm = true;
        for(int j = 0; j < W; j++) {
            if(a[i][j] == '#'){
                is_rm = false;
                break;
            }
        }
        if(is_rm) {
            H--;
            for(int k = i; k < H; k++) {
                for(int l = 0; l < W; l++) {
                    a[k][l] = a[k+1][l];
                }
            }
            i--;
        }
    }

    for(int j = 0; j < W; j++) {
        bool is_rm = true;
        for(int i = 0; i < H; i++) {
            if(a[i][j] == '#'){
                is_rm = false;
                break;
            }
        }
        if(is_rm) {
            W--;
            for(int k = j; k < W; k++) {
                for(int l = 0; l < H; l++) {
                    a[l][k] = a[l][k + 1];
                }
            }
            j--;
        }
    }

    REP(i, H) {
        REP(j, W) cout << a[i][j];
        cout << endl;
    }

    return 0;
}


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

int main(void){

    int n,m;
    cin>>n;

    string a[100];
    string b[100];
    int re[100]={1};
    int max;
    for(int i=0;i<100;i++)re[i]=1;

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

    cin>>m;

    for(int i=0;i<m;i++){
        cin>>b[i];
    }

    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(a[i]==a[j]){
                re[i]++;
            }
        }
        for(int j=0;j<m;j++){
            if(a[i]==b[j]){
                re[i]--;
            }
        }
    }
   // for(int i=0;i<n;i++)cout<<re[i]<<" ";

    max=re[0];
    for(int i=0;i<n;i++){
        if(max < re[i]) max=re[i];
    }
    if(max<0)cout<<0<<endl;
    else cout<<max<<endl;


}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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;}
//int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int w,h;

int ver[35][35];int hor[35][35];

int maze[35][35];

int main(){
	while(1){
		cin>>w>>h;
		if(w==0&&h==0)break;
		for(int i=0;i<35;i++){
			for(int j=0;j<35;j++){
				maze[i][j]=-1;
			}
		}
		for(int i=0;i<2*h-1;i++){
			if(i%2==0){
				for(int j=0;j<w-1;j++){
					cin>>ver[i/2][j];
				}
			}else{
				for(int j=0;j<w;j++){
					cin>>hor[i/2][j];
				}
			}
		}
		
		maze[0][0]=0;
		queue<pair<int,int> > QQ;
		QQ.push(make_pair(0,0));
		while(QQ.size()){
			pair<int,int> q=QQ.front();QQ.pop();
			if(q.first<h-1&&maze[q.first+1][q.second]==-1&&hor[q.first][q.second]==0){
				maze[q.first+1][q.second]=maze[q.first][q.second]+1;
				QQ.push(make_pair(q.first+1,q.second));
			}
			if(q.first>0&&maze[q.first-1][q.second]==-1&&hor[q.first-1][q.second]==0){
				maze[q.first-1][q.second]=maze[q.first][q.second]+1;
				QQ.push(make_pair(q.first-1,q.second));
			}
			if(q.second<w-1&&maze[q.first][q.second+1]==-1&&ver[q.first][q.second]==0){
				maze[q.first][q.second+1]=maze[q.first][q.second]+1;
				QQ.push(make_pair(q.first,q.second+1));
			}
			if(q.second>0&&maze[q.first][q.second-1]==-1&&ver[q.first][q.second-1]==0){
				maze[q.first][q.second-1]=maze[q.first][q.second]+1;
				QQ.push(make_pair(q.first,q.second-1));
			}
		}
		
		/*REP(i,h){
			REP(j,w){
				printf("%4d",maze[i][j]);
			}
			printf("\n");
		}*/
		
		cout<<maze[h-1][w-1]+1<<endl;
		
	}
	return 0;
}


Measured memory_bytes: 3172
#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
#include<functional>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(int)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	int x = h - (h % a), y = w - (w % b);
	cout << h * w - x * y << endl;
}
/* --------------------------------------- */



Measured memory_bytes: 3232
#include<bits/stdc++.h>
using namespace std;
//define
typedef pair<int,int>pi;
#define int long long
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define Rep(x,y) for(int k=x;k<y;k++)
#define all(x) x.begin(),x.end()
#define pb() push_back()
#define mod 100000007
#define elif else if
#define str string

signed main(){
  int a,b,tmp,N,M,O,P,count=0,count2=0,Amax=0,imin=0,Amin=0;
  double d;
  char c;
  string S,T,R;
  cin>>a>>b;

  N=a*b;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  /* ユークリッドの互除法 */
  count = a % b;
  while(count!=0){
    a = b;
    b = count;
    count = a % b;
  }

  cout<<N/b<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(void){
  int n, m;
  scanf("%d", &n);
  int t[100];
  int ans = 0;
  
  for(int i = 0; i < n; i++){
    scanf("%d", &t[i]);
    ans += t[i];
  }
  
  scanf("%d", &m);
  for(int i = 0; i < m; i++){
    int p, x;
    scanf("%d%d", &p, &x);
    printf("%d\n", ans - t[p - 1] + x);
  }
  
  return 0;
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

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

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

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int tmp, ans = 0;
  tmp = read();
  while (tmp != 0) {
    ans += tmp % 10;
    tmp /= 10;
  }
  print(ans);
}


Measured memory_bytes: 256
// Implementation practice (Have seen the editorial)
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef map<int,int> mii;
typedef map<string,int> msi;
typedef set<int> si;
typedef priority_queue<int> pqi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define loop(i, a) for (int i = 0; i < (a); i++)
#define loop1(i, a) for (int i = 1; i <= (a); i++)
#define loopr(i, a, b) for (int i = (a); i <= (b); i++)
#define dloop(i, a) for (int i = (a) - 1; i >= 0; i--)
#define dloopr(i, b, a) for (int i = (b); i >= (a); i--)
#define show(a) cout << a << "\n"
#define showloop(a, len) for (int i = 0; i < len; i++) cout << a[i] << "\n"
#define itloop(a, len) for (int i = 0; i < len; i++) cout << a[i] << "\n"
#define debug(a) cout << #a << ": " << (a) << "\n"
#define mem(x, val) memset((x), (val), sizeof(x));
#define sz(x) ((int)x.size())
#define ran(a, b) ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a))
const int MOD = 1000000007;
const double PI = acos(-1);

const int N = 201, M = 400, R = 9;
int n, m, r;
int city[R];
ll path[N][N];

struct node {
	int at;
  	ll cost;
	node(int _at, ll _cost) {
		at = _at;
		cost = _cost;
	}
};
bool operator<(node A, node B) {
	return A.cost > B.cost;
};
struct edge {
	int v, cost;
	edge(int _v, int _cost) {
		v = _v;
		cost = _cost;
	}
};

vector<edge> road[N];
priority_queue<node> pq;
ll dist[N];
bool visited[N];

void dijkstra(int root) {
	loop1(i, N - 1) dist[i] = (ll)MOD;
	dist[root] = (ll)0;
	pq.push(node(root, 0));

	while(!pq.empty()) {
		node nearest = pq.top();
		pq.pop();

		if (nearest.cost != dist[nearest.at]) continue;
		for (edge e: road[nearest.at]) {
			if (dist[e.v] > nearest.cost + e.cost) {
				dist[e.v] = (ll)nearest.cost + e.cost;
				pq.push(node(e.v, dist[e.v]));
			}
		}
	}

	loop1(i, r) {
		if (city[i] == root) continue;
		path[root][city[i]] = (ll)dist[city[i]];
	}
}

int main() {
	//freopen("in", "r", stdin);
	//freopen("out", "w", stdout);
	ios::sync_with_stdio(false);cin.tie(NULL);

	cin >> n >> m >> r;
	loop1(i, r) cin >> city[i];
	loop1(i, m) {
		int a, b, c;
		cin >> a >> b >> c;
		road[a].pb(edge(b, c));
		road[b].pb(edge(a, c));
	}

	ll ans = MOD << 5;
	loop1(i, r) dijkstra(city[i]);
	int cities[r];
	loop(i, r) cities[i] = city[i + 1];
  	sort(cities, cities + r);
	do {
		ll curr = (ll)0;
		loop1(i, r - 1) curr += (ll)path[cities[i - 1]][cities[i]];
		ans = min(curr, ans);
	} while (next_permutation(cities, cities + r));
	show(ans);

	return 0;
}

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

using namespace std;

#define fRead(x)        freopen(x,"r",stdin)
#define fWrite(x)       freopen (x,"w",stdout)

#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())


#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);

int main()
{
    LL n,a,b;
    cin >> n >> a >> b;
    if(a>b){
        cout << 0 << "\n";
        return 0;
    }
    if(n==1)
    {
        if(a==b)cout << 1 << "\n";
        else cout << 0 << endl;
    }else{

        n-=2;
        LL dif = b - a;
        LL ans = n*dif + 1;
        cout << ans << "\n";
    }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const int MOD = 1000000007;

void solve() {
  int n, k;
  cin >> n >> k;
  vector<ll> x(n);
  rep(i,n) cin >> x[i];
  ll ans = pow(10,15);
  rep(i,n-k+1) {
    int l = i;
    int r = i + k - 1;
    ll temp = 0;
    if (x[l] <= 0 && x[r] <= 0) temp = abs(x[l]);
    else if (x[l] >= 0 && x[r] >= 0) temp = x[r];
    else {
      temp = 2 * min(abs(x[l]), abs(x[r])) + max(abs(x[l]), abs(x[r]));
    }
    ans = min(ans,temp);
  }
  cout << ans << endl;
}

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

Measured memory_bytes: 4036
/*
* @Author Silviase(@silviasetitech)
* For ProCon
*/

import java.util.*;
import java.lang.*;
import java.math.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        String w = sc.next();
        List l = new ArrayList<Integer>();
        for (int i = 0; i < w.length(); i++) {
            if (w.charAt(i) == 'B') {
                if (l.size() > 0){
                    l.remove(l.size()-1);
                }
            } else {
                l.add(w.charAt(i));
            }
        }
        for (int i = 0; i < l.size(); i++) {
            System.out.print(l.get(i));
        }
        System.out.println("");


        sc.close();
    }

}





Measured memory_bytes: 21844
#include<iostream>
using namespace std;
int main(){
	int a,b,n,ansa=0,ansb=0;

	for(;;){
		cin>>n;
		if(n==0)break;
		ansa=0;
		ansb=0;
		for(int i=0;i<n;i++){
			cin>>a>>b;
			if(a>b){
				ansa=ansa+a+b;
			}
			else if(a<b){
				ansb=ansb+a+b;
			}
			else if(a==b){
				ansa=ansa+a;
				ansb=ansb+b;
			}
		}
		cout<<ansa<<" "<<ansb<<endl;
	}


	return 0;
}


Measured memory_bytes: 3052
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
string alphabet = "abcdefghijklmnopqrstuvwxyz";
string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
  char a , b;
  cin >> a >> b;
  if(a == 'H')cout << b << endl;
  else{
    if(b == 'H')cout << 'D' << endl;
    else cout << 'H' << endl;
  }
}


Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using coord= pair<int, int>;
constexpr char block = '@';
constexpr char vacant= '.';
constexpr int TBC= INT_MAX;

int BFS(const vector<string> &board, coord s, coord g, int sz_step, vector<vector<int>> *dist){  
  const int H= board.size();
  const int W= board.at(0).size();

  const vector<coord> diff= {make_pair(0,-1), make_pair(-1,0), make_pair(1,0), make_pair(0,1) // 上下4方向
                               // make_pair(-1,-1), make_pair(1,-1), make_pair(-1,1), make_pair(1,1) // 斜め4方向
                            }; // 探索方向

  vector<vector<int>> checked(H, vector<int>(W, TBC));
  queue<coord> bfs;
  dist->at(s.first).at(s.second)= 0;
  bfs.push(s);

  while( !bfs.empty() ){
    coord p= bfs.front();
    auto [x, y]= p;
    bfs.pop();

    if(p==g){ break; }
    else{
      for(const auto& [dx_e, dy_e]:diff){
        for(int sz=1; sz <= sz_step; sz++){
          int dx= sz* dx_e;
          int dy= sz* dy_e;
          if(x+dx <= -1 || x+dx >= H || y+dy <= -1 || y+dy >= W) break;
          else if(board.at(x+dx).at(y+dy)==block){
            break;
          }
          else if(dist->at(x+dx).at(y+dy) > dist->at(x).at(y)+ 1){
            dist->at(x+dx).at(y+dy)= dist->at(x).at(y)+ 1;
            bfs.push(make_pair(x+dx, y+dy));
          }
          else if(dist->at(x+dx).at(y+dy) < dist->at(x).at(y)+ 1){
            break;
          }
        }
      }
    }
  }

  return dist->at(g.first).at(g.second);
}

int main() {
  int H,W,K;
  cin >> H >> W >> K;

  coord s,g;
  cin >> s.first >> s.second >> g.first >> g.second;
  s.first--; s.second--; g.first--; g.second--; // 1-indexed -> 0-indexed

   vector<string> board(H);
   for(int i=0; i<H; i++){
     cin >> board.at(i);
   }
  vector<vector<int>> dist(H, vector<int>(W, TBC));

  int dist_s2g= BFS(board, s, g, K, &dist);

  int ans= (dist_s2g != TBC) ? dist_s2g
                             : -1;
  cout << ans << endl;
}

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

typedef long long int ll;

#define endl '\n'

ll dp[100005];
ll n,m;
vector <ll> vec[100005];

ll solve(ll u)
{
    if(dp[u]==-1)
    {
        dp[u] = 0;
        for(ll i=0;i<vec[u].size();++i){
            ll v = vec[u][i];
            dp[u] = max(dp[u],1+solve(v));
        }


    }
    return dp[u];
}

int main()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    memset(dp,-1,sizeof(dp));
    cin>>n>>m;

    for(ll i=0;i<m;i++){
        ll x,y;cin>>x>>y;
        vec[x].push_back(y);
    }

    for(ll i=1;i<=n;i++){
        if(dp[i]==-1){
            solve(i);
        }
    }

    ll val = 0;

    for(ll i=1;i<=n;i++)
    val = max(val,dp[i]);

    cout<<val<<endl;



}


Measured memory_bytes: 8576
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
using namespace std;
typedef long long int ll;

ll cnt[26];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	string s; cin >> s;
	ll n=s.size();
	ll ans=n*(n-1)/2+1;
	for(int i=0;i<n;i++){
		cnt[s[i]-'a']++;
	}
	for(int i=0;i<26;i++){
		ans-=cnt[i]*(cnt[i]-1)/2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 720
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), k = sc.nextInt();
		long[] h = new long[n];
		long ans = 0;
		for (int i = 0; i < n; i++) h[i] = sc.nextLong();
		Arrays.parallelSort(h);
		for (int i = 0; i < n-k; i++) ans += h[i];
		System.out.println(ans);
	}
}

Measured memory_bytes: 89724
N = int(input())
d = {}
city = []
for i in range(N):
    s, p = input().split()
    d[i] = (s, p)
    if s not in city:
        city.append(s)

ans = []
city.sort()
for c in city:
    key = [k for k, v in d.items() if v[0] == c]
    num = [int(d[k][1]) for k in key]
    key_num = [(key[i], num[i]) for i in range(len(key))]
    key_num = sorted(key_num, key=lambda x:int(x[1]), reverse=True)
    key_num = [k[0] + 1 for k in key_num]
    ans += key_num

for a in ans:
    print(a)
    





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

signed main(void)
{
	int n;
	string s;
	cin >> s;
	n = s.size();
	vector<int> ans(n);
	rep(ri, 2)
	{
		int cnt = 0;
		rep(i, n)
		{
			if (s[i] == 'R') cnt++;
			else {
				ans[i] += cnt / 2;
				ans[i - 1] += (cnt + 1) / 2;
				cnt = 0;
			}
		}
		reverse(ans.begin(), ans.end());
		reverse(s.begin(), s.end());
		rep(i, n)
		{
			if (s[i] == 'L') s[i] = 'R';
			else s[i] = 'L';
		}
	}
	rep(i, n)
	{
		printf("%d\n", ans[i]);
	}
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<cstring>
using namespace std;
typedef long long ll;
const long long inf64 = 1e18;
// int func(ll arr, int n, int m){

// }

int main()
{
  // freopen("input.txt", "r", stdin); 
  // freopen("output.txt", "w", stdout); 
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int k;
  string s;
  cin >> k;
  // cout << "23" << endl;
  cin >> s;
  int len = s.length();
  if(len + 1 < k)
    cout << s;
  else{
  for(int i = 0; i < len; i++){
    if(i > k - 1){
      cout << "...";
      break;
    }
    cout << s[i];
  }
}


  return 0;
}


Measured memory_bytes: 3652
n=int(input())
a=list(map(int,input().split()))
time_sum=sum(a)

k=int(input())
d=[]

for i in range(k):
    p,x=map(int,input().split())
    d.append((p-1,x))

for j in range(k):
    print(time_sum-a[d[j][0]]+d[j][1])

Measured memory_bytes: 3064
n,m=map(int,input().split())
sc=[list(map(int, input().split())) for _ in range(m)]
for i in range(10**n):
  ii=str(i)
  if len(ii)==n and all([ii[s-1]==str(c) for s,c in sc]):
    print(ii)
    exit()
print(-1)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int k = scan.nextInt();
		String s = scan.next();
		
		byte[] sbyte = s.getBytes();
		sbyte[k-1] += 32;
		
		String sa = new String(sbyte);
		
		System.out.println(sa);
		
	}
}

Measured memory_bytes: 21972
#include <stdio.h>
#include <limits.h>

int min(int, int);

int main(void){
  
  int n,i,j,k,l,q,gomi,
    p[102],m[102][102];
  
  scanf("%d",&n);
  
  scanf("%d%d",&p[0],&p[1]);
  for(i=2; i<=n; i++){
    scanf("%d%d",&gomi,&p[i]);
  }
  
  for(i=1; i<n; i++){
    m[i][i] = 0;
  }
  for(l=2; l<=n; l++){
    for(i=1; i<=n-l+1; i++){
      j = i+l-1;
      m[i][j] = INT_MAX;
      for(k=i; k<j; k++){
	q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
	m[i][j] = min(m[i][j], q);
      }
    }
  }

  printf("%d\n",m[1][n]);

  return 0;
  
}

int min(int a, int b){
  if(a <= b) return a;
  return b;
}

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

int kakukurainowa(int n){
  int temp = 0;
  while(n > 0){
  temp += n % 10;
  n /= 10;
  }
  return temp;
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  
  int ans = 0;
  for(int i = 1; i <= N; ++i){
  	int temp = kakukurainowa(i);
    if(temp >= A && temp <= B){
     ans += i; 
    }
  }
  
  
  cout << ans << endl;
}

Measured memory_bytes: 256
one_twenty = (1..20).to_a
table = Array.new(156){[]}
1.upto(20){|k|
	one_twenty.combination(k){|arr|
		sum = arr.inject(:+)
		table[sum] << [arr.max, k] if sum < 156
	}
}
until (line = gets.chomp) == "0 0 0"
	n, k, s = line.split.map(&:to_i)
	puts table[s].count{|a, b| a <= n && b == k}
end


Measured memory_bytes: 89040
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n, x;
    cin >> n;
    vi p;
    for(int i = 0; i < n; i++){
        cin >> x;
        p.pb(x);
    }
    int ans = 0;
    for(int i = 1; i < (n-1); i++){
        if(p[i]>p[i-1] && p[i]<p[i+1]){
            ans++;
        }
        else if(p[i]<p[i-1] && p[i]>p[i+1]){
            ans++;
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>

using namespace std;

priority_queue<long long> q;
int n = 0, m = 0;
long long ans = 0;

int main()
{
	while(q.size())
		q.pop();
	cin >> n >> m;
	for(int i = 0; i < n; i ++)
	{
		long long temp;
		cin >> temp;
		q.push(temp);
	} 
	for(int i = 0; i < m; i ++)
	{
		long long temp = q.top();
		q.pop();
		temp /=  2;
		q.push(temp);
	}
	while(q.size())
	{
		ans += q.top();
		q.pop();
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 1400
#include <stdio.h>
 
int main(){
  int a, b;
  char op;
  while(scanf("%d %c %d", &a, &op, &b) && op != '?'){
    if(op == '+') a += b;
    else if(op == '-') a -= b;
    else if(op == '*') a *= b;
    else if(op == '/') a /= b;
    printf("%d\n", a);
  }
  return 0;
}


Measured memory_bytes: 2060
#include <bits/stdc++.h>
using namespace std;
int main(){
    string N;
    cin >> N;
    bool can = false;
    if (N.at(2) == N.at(1)){
        if (N.at(2) == N.at(3) || N.at(0) == N.at(1)) can = true;
    }
    if(can) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <stack>
#include <unordered_map>
using namespace std;

int main(){
    long long int n, m;
    cin >> n >> m;
    long long int count = 0;
    
    if(n * 2 < m){
        count += n;
        m -= n * 2;
        
        count += m / 4;
    }else{
        count += m / 2;
    }
    
    cout << count << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
int x,a;
signed main(){
    cin>>x>>a;
    if(x<a)cout<<0<<endl;
    else cout<<10<<endl;
    return 0;
}


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

int main() {
  string S;
  cin >> S;
  int cnt_N = 0, cnt_W = 0, cnt_S = 0, cnt_E = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == 'N') cnt_N++;
    else if (S[i] == 'W') cnt_W++;
    else if (S[i] == 'S') cnt_S++;
    else cnt_E++;
  }
  bool can = true;
  if (cnt_N == 0 || cnt_S == 0) {
    if (!(cnt_N == 0 && cnt_S == 0)) can = false;
  }
  if (cnt_W == 0 || cnt_E == 0) {
    if (!(cnt_W == 0 && cnt_E == 0)) can = false;
  }
  if (can) cout << "Yes";
  else cout << "No";
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long
#define lld long double
#define MOD 1000000007
#define inf 1000000000000000000ll
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll power(ll x,ll y, ll md=inf){ll res = 1;x%=md;while(y){if(y&1)res = (res*x)%md;x *= x; if(x>=md) x %= md; y >>= 1;}return res;}
 
using namespace std;


#define endl '\n'
#define int ll

signed main() {
	fast;

	int h,w;
	cin>>h>>w;

	pii v[200002];
	for(int i=0;i<h;i++) cin>>v[i].f>>v[i].s;

	map<int,int> mp;
	for(int i=1;i<=w;i++) mp[i] = 0;

	map<int,int> mini = {{0,w}};

	for(int i=0;i<h;i++) {
		int r = v[i].s;

		auto it = mp.lower_bound(v[i].f);
		int mn = inf;

		while(it!=mp.end() && it->f <= r) {
			mn = min(mn, r+1-(it->f)+(it->s));
			auto it1 = it++;
			auto it2 = mini.find(it1->s);
			if(it2->s==1) mini.erase(it2);
			else it2->s --;
			mp.erase(it1);
		}

		if(r+1<=w && mn<inf) {
			if(it!=mp.end() && it->f == r + 1) {
				if(it->s > mn) {
					auto it1 = mini.find(it->s);
					if(it1->s ==1) mini.erase(it1);
					else it1->s --;
					mini[mn]++;
					it->s = mn;
				}
			}
			else {
				mp.insert({r+1,mn});
				mini[mn]++;
			}
		}

		if(mini.size()) cout<<mini.begin()->f+i+1<<endl;
		else cout<<-1<<endl;

	}
}

Measured memory_bytes: 19252
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#include <limits>
#include <iomanip>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
    int N;
    cin >> N;
    vector<int>d1(N);
    vector<int>d2(N);
    for(int i=0;i<N;i++){
        cin >> d1[i] >> d2[i];
    }

    bool frg = false;
    for(int i=0;i<N-2;i++){
        if( (d1[i]==d2[i] && d1[i+1]==d2[i+1] ) && d1[i+2]==d2[i+2]){
            frg = true;
            break;
        }
    }

    if(frg){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3620
#include<iostream>
  
int main() {
  int A, B;
  std::cin >> A >> B;
  for(int ans = B*10; ans < (B+1)*10; ++ans) {
    if(ans*2/25 == A) {
      std::cout << ans << std::endl;
      return 0;
    }
  }

  std::cout << "-1" << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define MAX 1e9
 
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
const ld pi=acos(-1);
 
int main(){
    IOS;
    ll h,n;cin>>h>>n;
    ll sum=0;
    f(i,0,n){
        ll x;cin>>x;
        sum+=x;
    }
    if(sum>=h)cout<<"Yes";
    else cout<<"No";
    return 0;
}   


Measured memory_bytes: 256
n,x=map(int,input().split())
a=[1]*51
p=[1]*51
for i in range(1,51):
  a[i]=a[i-1]*2+3
  p[i]=p[i-1]*2+1
def f(N,X):
  if N==0:
    return 1
  if X==1:
    return 0
  if X<a[N-1]+2:
    return f(N-1,X-1)
  if X==a[N-1]+2:
    return p[N-1]+1
  if X<a[N-1]*2+3:
    return p[N-1]+1+f(N-1,X-2-a[N-1])
  else:
    return p[N-1]*2+1
print(f(n,x))

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {


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

		while(true){
			String moji = scan.next();
			int moji_len = moji.length();
			for(int cnt_len = 0; cnt_len < moji_len; cnt_len++){
				char moji_one = moji.charAt(cnt_len);
				if(Character.isLowerCase(moji_one))
					System.out.print(Character.toUpperCase(moji_one));
				else
					System.out.print(Character.toLowerCase(moji_one));
			}
			//?????????????´???§???????????°?????????????????\??????
			if(scan.hasNext())
				System.out.print(" ");
			else{
				System.out.print("\n");
				break;
			}
		}
		//????§????
		scan.close();
	}
}

Measured memory_bytes: 26820
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18

using namespace std;

int main(void){
  ll n;
  cin >> n;
  
  if (n % 10 == 7 || (n/10) % 10 == 7 || (n / 100) % 10 == 7)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
    

  return 0;
}


Measured memory_bytes: 3592
import collections
N = int(input())
Data = list(map(int, input().split()))
X = []
Y = []
for i in range(int(N/2)):
  X.append(Data[i*2])
  Y.append(Data[i*2+1])
Xc = collections.Counter(X)
Yc = collections.Counter(Y)
Xa = Xc.most_common()
Ya = Yc.most_common()
if Xa[0][0] != Ya[0][0]:
  print(N-(Xa[0][1] + Ya[0][1]))
  exit()
if len(Xc) != 1:
  Xb = Xa[1][1]
else:
  Xb = 0
if len(Yc) != 1:
  Yb = Ya[1][1]
else:
  Yb = 0
print(N - max(Xa[0][1] + Yb, Xb + Ya[0][1]))

Measured memory_bytes: 23776
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
	int k,a,b;cin >> k >> a >> b;
	int ret = 1;
	int pos = min(k,a-1);
	ret += pos;
	k -= pos;
	int ret1 = ret + k;
	int can = k/2;
	k -= can*2;
	ret -= can*a;
	ret += can*b;
	ret += k;
	cout << max(ret1,ret) << endl;



	return 0;
}

Measured memory_bytes: 3644
import std.algorithm;
import std.math;
import std.range;
import std.ascii;
import std.array;
import std.container;
import std.conv;
import std.numeric;
import std.stdio;
import std.string;
import std.typecons;

void log(A...)(A arg) {
    stderr.writeln(arg);
}

class UnreliableRollingHash(ulong P) {
    // fast but unreliable rolling hash
    // base is P, modulus is 2^64
    ulong[] H;
    this(in string s) { 
        auto N = s.length;
        this.H = new ulong[](N + 1);
        foreach (int i, c; s) {
            H[i + 1] = (H[i] * P + cast(int)(c));
        }
    }
    ulong hash(int l, int r) { // [l, r)
        return H[r] - H[l] * pow(P, r - l);
    }
}

void main() {
    int N, M; scanf("%d %d\n", &N, &M);
    auto s = readln.chomp;
    auto hasher = new UnreliableRollingHash!991(s);
    int l = 0, r = 1;
    bool[ulong] appeared;
    foreach (_; 0 .. M) {
        auto q = readln.chomp;
        switch (q) {
            case "L++": l++; break;
            case "L--": l--; break;
            case "R++": r++; break;
            case "R--": r--; break;
            default: assert(false);
        }
        appeared[hasher.hash(l, r)] = true;
    }
    writeln(appeared.keys.length);
}

Measured memory_bytes: 28372
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 100010
#define ll long long
using namespace std;
struct edge{int x, y, z, f, next;}a[N*2];
int n, m, x, y, l, p[N], flag[N], sum[10], ff, sum_m;
ll ans;
inline void add(int x, int y, int z){a[++l].x=x; a[l].y=y; a[l].z=z; a[l].f=0; a[l].next=p[x]; p[x]=l;}
inline void dfs(int x){
	sum[flag[x]]++;
	for(int i=p[x]; i; i=a[i].next)if(!a[i].f){
		sum_m++; a[i].f=a[i^1].f=1;
		if(flag[a[i].y]>=0){if(flag[a[i].y]!=(flag[x]+a[i].z+3)%3)ff=1;}
		else{flag[a[i].y]=(flag[x]+a[i].z+3)%3; dfs(a[i].y);}
	}
}
int main(){
	scanf("%d%d", &n, &m);
	l=1; memset(p, 0, sizeof(p));
	for(int i=1; i<=m; i++){scanf("%d%d", &x, &y); add(x, y, 1); add(y, x, -1);}
	for(int i=1; i<=n; i++)flag[i]=-1;
	ans=0;
	for(int i=1; i<=n; i++)if(flag[i]==-1){
		sum[0]=sum[1]=sum[2]=ff=sum_m=0;
		flag[i]=0; dfs(i);
		if(ff){x=sum[0]+sum[1]+sum[2]; ans+=(ll)x*x; continue;}
		if(!sum[0]||!sum[1]||!sum[2])ans+=sum_m;
		else ans+=(ll)sum[0]*sum[1]+(ll)sum[1]*sum[2]+(ll)sum[2]*sum[0];
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 6912
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
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; }

vector<vector<P>> edge(100000);
ll dist[100000];
int done[100000];

void dfs(int node, ll d){
    if(done[node]) return;
    done[node] = 1;
    dist[node] = d;
    for(auto p : edge[node]) dfs(p.first, d+p.second);
}

int main(void){
    int N; cin >> N;
    REP(i,N-1){
        int a,b,c; cin >> a >> b >> c;
        edge[a-1].push_back(P(b-1, c));
        edge[b-1].push_back(P(a-1,c));
    }
    int Q,K; cin >> Q >> K;
    int x[Q],y[Q]; REP(i,Q) cin >> x[i] >> y[i];

    REP(i,N) done[i]=0;
    dfs(K-1, 0);

    REP(i,Q){
        cout << dist[x[i]-1]+dist[y[i]-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 12288
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll a, b2;
  double b;
  scanf("%lld%lf", &a, &b);
  b2 = b * 10000;
  b2 += 10;
  b2 /= 100;
  printf("%lld", a * b2 / 100);
  return 0;
}

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

int main(){
    int k; string s; cin >> k >> s;
    cout << ((s.size() <= k)? s : s.substr(0,k) + "...") << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
   string s;
   cin>>s;
   int sum=0;
   for(int i=0;i<s.size();i++)
   {
       sum=sum+(s[i]-'0');
   }
   if(sum==0){cout<<"Yes"<<endl;}
   else if(sum<9){cout<<"No"<<endl;}
   else if(sum%9==0)
   {
       cout<<"Yes"<<endl;
   }
   else
   {
       cout<<"No"<<endl;
   }
   return 0;
}


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

constexpr int MOD = 1e9 + 7;
constexpr int CHOOSE_MAX = 2e5 + 10;

int64_t fac[CHOOSE_MAX];
int64_t inv[CHOOSE_MAX];

void prepare_binomial() {
  fac[0] = 1;
  for (int i = 1; i < CHOOSE_MAX; ++i) {
    fac[i] = fac[i - 1] * i % MOD;
  }
  inv[0] = inv[1] = 1;
  for (int i = 2; i < CHOOSE_MAX; ++i) {
    inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;
  }
  for (int i = 2; i < CHOOSE_MAX; ++i) {
    inv[i] = inv[i - 1] * inv[i] % MOD;
  }
}

int64_t binomial(int n, int m) {
  return fac[n] * (inv[n - m] * inv[m] % MOD) % MOD;
}

int main() {
  prepare_binomial();
  int h, w, a, b;
  scanf("%d %d %d %d", &h, &w, &a, &b);
  int64_t total = 0;
  for (int k = b + 1; k <= w; ++k) {
    int64_t tmp1 = binomial(h - a + k - 2, k - 1);
    int64_t tmp2 = binomial(a - 1 + w - k, w - k);
    total = (total + tmp1 * tmp2) % MOD;
  }
  printf("%d\n", (int)total);
  return 0;
}


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

#define ll long long
ll n,h,w,a,b,cnt=0;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n>>h>>w;
	for(ll i=0;i<n;i++){
		cin>>a>>b;
		if(a>=h && b>=w)
			cnt++;
	}
	cout<<cnt;
	return 0;
}

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

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

// code starts
#include<bits/stdc++.h>
using namespace std;

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

// code starts
int main()
{
  int n;
  cin >> n;
  ll ans = 0;
  int i,j;
  for(i=1;i<=n;i++)
  {
    for(j=i;j<=n;j+=i)
    {
      ans += j;
    }
  }
  cout << ans << "\n";
}



Measured memory_bytes: 3624
# -*- coding: utf-8 -*-

#############
# Libraries #
#############
import random
import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

D = int(input().strip())
C = list(map(int,input().split()))
S = [list(map(int, input().split())) for _ in range(D)]

schedule = []


for d in range(D):
  MAX = -10**20
  temp = None
  last = [-1 for i in range(26)]
  for j in range(26):
    s = 0
    for i in range(26):
      if i == j:
        last[i] = d
        s += S[d][i]
      else:
        s -= C[i]*(d-last[i])
    if s > MAX:
      MAX = s
      temp = j
  schedule.append(temp)
  
score = 0
last = [[-1] for i in range(26)]  

for d in range(D):
  t = schedule[d]
  last[t].append(d)
  score += S[d][t]
  

for i in range(26):
  last[i].append(D)
  for k in range(len(last[i])-1):
    g = last[i][k+1]-last[i][k]-1
    score -= C[i]*g*(g+1)//2

count = 2000000

while count:
  count -= 1
  prev = score
  d,q = random.choice(range(D)),random.choice(range(26))
  p = schedule[d]
  schedule[d] = q
  score -= S[d][p]
  score += S[d][q]
  
  pos = last[p].index(d)
  score -= C[p]*(last[p][pos]-last[p][pos-1])*(last[p][pos+1]-last[p][pos])
  last[p].remove(d)
  
  pos = bisect.bisect(last[q],d)
  score += C[q]*(d-last[q][pos-1])*(last[q][pos]-d)
  bisect.insort(last[q],d)
  if score<prev:
    score = prev
    bisect.insort(last[p],d)
    last[q].remove(d)
    schedule[d] = p
    
for i in schedule:
  print(i+1)


Measured memory_bytes: 85336
#include<stdio.h>
#include<math.h>
using namespace std;
int main(){
double x,y,s;
int n,k;
x=y=s=0;
while((scanf("%d,%d",&n,&k)),n!=0){
x=x+n*cos(M_PI*s/180);
y=y+n*sin(M_PI*s/180);
s=s+k;
}
printf("%d\n%d\n",int(y),int(x));
}

Measured memory_bytes: 1032
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const double PI=3.14151926535;
const ll INFl=(ll)9223372036854775807/2;
const int MAX=10000;
const ll tMOD=(ll)1e9+7;
const ll MOD=(ll)998244353;
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;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n;
double x[10],y[10];

int main(){
	cin>>n;
	REP(i,n)cin>>x[i]>>y[i];
	double ans=0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			double tt=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]))/(double)(n);
			ans+=tt;
		}
	}
	ans*=2;
	printf("%.10f",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;


template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}

#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {
	ll N;
	std::cin >> N;
	
	map<string, ll> dic;
	rep(i, 0, N) {
		string s;
		std::cin >> s;
		dic[s]++;
	}

	std::cout << "AC x " << dic["AC"] << endl;
	std::cout << "WA x " << dic["WA"] << endl;
	std::cout << "TLE x " << dic["TLE"] << endl;
	std::cout << "RE x " << dic["RE"] << endl;
	return 0;
}


Measured memory_bytes: 3636
// template version 1.6
// {{{ define basic macro
using namespace std;
#include <iostream>
#include <bits/stdc++.h>
// varibable settings
#define int long long
#define INF 1000000000000000000LL
// #define INF 2147483647
#define MOD 1000000007LL
// #define MOD 998244353LL
#define infile "../test/sample-1.in"

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)
template<class T, size_t N> size_t sza(const T (&array)[N]) { return N; }
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
template<class T=int> T in() {T x; cin>>x; return (x);}
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

// dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
#define fi first
#define se second

// }}}

int solve(){
  int n;cin>>n;
  int c[n]; rep(i, n) {cin>>c[i];}
  dump_1d(c, n);

  map<int, int> pos;
  map<int, int> last;
  rrep(i, n){
    if (last.count(c[i])>0) pos[i] = last[c[i]];
    last[c[i]] = i;
  }
  dump(pos);

  int dp[n+1] = {};
  dp[n] = 1;
  dp[n-1] = 1;

  rrep(i, n-1){
    dp[i] = dp[i+1]; // do nothing
    if (pos[i]>0 and pos[i]-i>1){
      dump(i, "hello");
      dp[i] += dp[pos[i]];
    }
    dp[i] %= MOD;
  }

  dump_1d(dp, n+1);
  cout << dp[0] << endl;

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 28416