akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define in insert
#define ld long double


#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::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...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;
#define int ll
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e18;
const ll MAX_NODES =200001;
const ll MAX_LOG =50;
const ll maxn = 400000+1;
const ll md = (ll) 998244353;
 
inline ll add(ll a, ll b) {
  a += b;
  if (a >= md) a -= md;
  return a;
}
 
inline ll sub(ll a, ll b) {
  a -= b;
  if (a < 0) a += md;
  return a;
}
 
inline ll mul(ll a, ll b) {
  return (ll) ((long long) a * b % md);
}
 
inline ll power(ll a, long long b) {
  ll res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}
 
inline ll inv(ll a) {
  a %= md;
  if (a < 0) a += md;
  ll b = md, u = 0, v = 1;
  while (a) {
    ll t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += md;
  return u;
}

vector<int> fact(maxn+5);
void init (int n)
{
  fact[0] = 1;
  for(int i = 1;i<=n;i++)
  {
    fact[i] = mul(i,fact[i-1]);
  }
}
int nck(int n,int k)
{
  return mul(fact[n],mul(inv(fact[k]),inv(fact[n-k])));
}

int32_t main()
{ 

  IOS 
    int n,m,k;
    cin>>n>>m>>k;
    init(300002);
    int ans = 0;
    for(int i = n-1-k;i<=n-1;i++){
      int b = i+1;
      ans = add(ans,mul(nck(n-1,i),mul(m,power(m-1,b-1))));
    }
    cout<<ans<<endl;


  

  




}


Measured memory_bytes: 6284
#include<bits/stdc++.h>
using namespace std;
namespace fdata
{
inline char nextchar()
{
    static const int BS = 1 << 21;
    static char buf[BS], *st, *ed;
    if (st == ed)
        ed = buf + fread(st = buf, 1, BS, stdin);
    return st == ed ? -1 : *st++;
}
#ifdef lky233
#define nextchar getchar
#endif
template <typename Y>
inline void poread(Y &ret)
{
    ret = 0;
    char ch;
    while (!isdigit(ch = nextchar()))
        ;
    do
        ret = ret * 10 + ch - '0';
    while (isdigit(ch = nextchar()));
}
#undef nextcar
} // namespace fdata
using fdata::poread;
#define int long long
const int MAXN =  5e5 + 10;
const int MOD = 1e9 + 7;
inline int qpow(int a, int b)
{
	register int res = 1;
	for(; b; b >>= 1)
	{
		if(b & 1)
			res = (long long)res * a % MOD;
		a =  (long long)a * a % MOD;	
	}	
	return res;
}
int n;
int a[MAXN];
bool vis[MAXN];
int fac[MAXN], inv_fac[MAXN];
int s[MAXN], ans[MAXN];

inline int C(int n, int m)
{
	if(n < m)
		return 0;
	return (long long) fac[n] * inv_fac[n - m] % MOD * inv_fac[m] % MOD;
}

int tree[MAXN];
inline void add(int x, int d)
{
	for(; x <= n; x += (x & -x))
		tree[x] = (tree[x] + d) % MOD;
}
inline int ask(int x)
{
	register int res = 0;
	for(; x; x -= (x & -x))
		res = (res + tree[x]) % MOD;
	return res;
}

signed main()
{
#ifdef lky233
	freopen("testdata.in",  "r", stdin);
	freopen("testdata.out", "w", stdout);
#endif
	poread(n);
	for(register int i = 1; i <= n; ++i)
		poread(a[i]);
	fac[0] = fac[1] = 1;
	for(register int i = 2; i <= n; ++i)
		fac[i] = (long long)fac[i - 1] * i % MOD;
	inv_fac[n] = qpow(fac[n], MOD - 2);
	for(register int i = n - 1; i >= 0; --i)
		inv_fac[i] = (long long)inv_fac[i + 1] * (i + 1) % MOD;
	register int k = 0, sum = 0;
	for(register int i = 1; i <= n; ++i)
		a[i] ? vis[a[i]] = 1 : ++k;
	for(register int i = n; i >= 1; --i)
	{
		s[i] += s[i + 1];
		if(!vis[i])
		{
			++s[i];
			sum = (sum + i - 1) % MOD;
		}
	}
	register int pre = 0, rem = 0;
	for(register int i = 1; i <= n; ++i)
	{
		if(!a[i])
		{
			ans[i] = (ans[i] + MOD - pre) % MOD;
			if(k >= 2)
				ans[i] = (ans[i] + MOD - (long long)rem * C(k,2) % MOD * fac[k - 2] % MOD) % MOD;
			ans[i] = (ans[i] + sum * fac[k - 1] % MOD) % MOD;
			++rem;
		}
		else
		{
			ans[i] = (ans[i] + (long long)(a[i] - 1) * fac[k] % MOD) % MOD;
			ans[i] = (ans[i] + MOD - (long long)ask(a[i] - 1) * fac[k] % MOD) % MOD;
			if(k) ans[i] = (ans[i] + MOD - (long long)rem * (s[1] - s[a[i]]) % MOD * fac[k - 1] % MOD) % MOD;
			if(k) pre = (pre + (long long)s[a[i] + 1] * fac[k - 1] % MOD) % MOD;
			add(a[i], 1);
		}
	}
	register int res = fac[k];
	for(register int i = 1; i <= n; ++i)
		res = (res + fac[n - i] * ans[i] % MOD) % MOD;
	cerr << res << endl;
	printf("%lld\n", res);
	return 0;
	
}


Measured memory_bytes: 26240
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define float long double
#define IOS ios_base::sync_with_stdio(false), cin.tie(NULL)
const int mod = 1000000007;

bool prime[1000000]; 

void SieveOfEratosthenes() 
{
    int n = 1000000;
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        {  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
} 

void check(int n)
{
	if(prime[n])
  		cout<<n<<endl;
  	else
  	{
  		int i = n+1;
  		while(1)
  		{
  			if(prime[i])
  			{
  				cout<<i<<endl;
  				break;
  			}
  			else
  				i++;
  		}
  	}
}


int32_t main()
{
   int n;
   cin>>n;
   SieveOfEratosthenes();
   check(n);
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int>P;
const int N=1e5+5,M=131072;
int n,m,l[N],r[N],c[N],i;
bool b[N];
vector<int>t[N*3];
void ins(int l,int r,int x){
	for(l+=M-1,r+=M+1;l^r^1;l>>=1,r>>=1){
		if(!(l&1))t[l^1].push_back(x);
		if(r&1)t[r^1].push_back(x);
	}
}
set<int>s;
priority_queue<P,vector<P>,greater<P>>q;
inline void work(int x,ll d){
	vector<int>ve;
	for(x+=M;x;x>>=1)ve.insert(ve.end(),t[x].begin(),t[x].end()),t[x].clear();
	for(int x:ve)if(!b[x])b[x]=1,q.push({d+c[x],x});
}
int main(){
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;++i)scanf("%d%d%d",l+i,r+i,c+i),ins(l[i],r[i],i);
	for(i=1;i<=n;++i)s.insert(i);
	work(1,0);
	for(;!q.empty();){
		ll d;int x;tie(d,x)=q.top();q.pop();
		if(r[x]==n){printf("%lld\n",d);return 0;}
		for(auto it=s.lower_bound(l[x]);it!=s.end() && *it<=r[x];s.erase(it++))work(*it,d);
	}
	puts("-1");
	return 0;
}

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


int main(){
  long long n,i;
  cin >> n;
  vector<long long> a(n);
  for(i=0;i<n;++i){
    cin >> a[i];
  }
  long long ans1=0;
  long long ans2=0;
  long long nu=1;
  sort(a.begin(),a.end());
  for(i=0;i<n;++i){
    if(a[i]==a[i+1]){
      nu++;
    }else{
      if(nu>=2 && nu<=3){
        if(ans1>=ans2){
          ans2=max(ans2,a[i]);
        }else{
          ans1=max(ans1,a[i]);
        }
        nu=1;
      }else if(nu>=4){
        long long ma=max(ans1,ans2);
        ans1=max(ma,a[i]);
        ans2=max(ma,a[i]);
        nu=1;
      }
    }
  }
  long long ans=ans1*ans2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;
const int N=2e5+5;
char s1[N],s2[N];
int a[N],b[N];
int main() {
	scanf("%s %s",s1,s2);
	int len1=strlen(s1),len2=strlen(s2);
	if(len1!=len2)return puts("No"),0; 
	for(int i=1;i<len1;i++) {
		if(!a[s1[i]-'a']&&!b[s2[i]-'a'])a[s1[i]-'a']=s2[i]-'a',b[s2[i]-'a']=s1[i]-'a';
		if(a[s1[i]-'a']==s2[i]-'a'&&b[s2[i]-'a']==s1[i]-'a')continue;
		if(a[s1[i]-'a']!=(s2[i]-'a')||(b[s2[i]-'a']!=s1[i]-'a'))return puts("No"),0;
	}
	puts("Yes");
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18
#define PI 3.1415926535

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
  int H,W; cin >> H >> W;
  vector<vector<char>> s(H,vector<char>(W));
  rep(i,H)rep(j,W) cin >> s[i][j];

  vector<int> x = {0,1,0,-1};
  vector<int> y = {1,0,-1,0};

  bool ok = true;

  rep(i,H){
    rep(j,W){
      if(s[i][j] == '#'){
        bool flag = false;
        rep(k,4){
          if(i+x[k] >= 0 && i+x[k] < H && j+y[k] >= 0 && j+y[k] < W){
            if(s[i+x[k]][j+y[k]] == '#') flag = true;
          }
        }
        if(!flag) ok = false;
      }
    }
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}
   

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int tim;
  int c[1000];
  int t[1000];
  int ansc=0;
  cin >> n >> tim;
  for (int i = 0; i < n; i++) {
    cin >> c[i] >> t[i];
    if(i==0){
      ansc=c[0];
    } else {if(t[i]<=tim){
      if(ansc>=c[i]){
        ansc=c[i];
      }
    }
  }}
 
  if(ansc==c[0]&&t[0]>tim){
    cout << "TLE" << endl;
  } else {
    cout << ansc << endl;
  }
}

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


int acs(const void* a, const void* b){
	
	return *(int *)a - *(int *)b;	
}
int main(){
	long N,K;
	int p[1010];
	long ans=0;
	scanf("%ld%ld",&N,&K);
	
	long i,j;
	for(i=0;i<N;i++){
		scanf("%d",p+i);
	}
	
	qsort(p,N,sizeof(int),acs);
	

	for(i=0;i<K;i++) ans+=p[i];
	
	printf("%ld\n",ans);

	return 0;
}


Measured memory_bytes: 1740
//
// Created on 2020/07/05.
//

#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;


int main() {
    int h,w,k;
    cin>>h>>w>>k;
    vector<vector<bool>>grid(h,vector<bool>(w));
    for (int i = 0; i < h; ++i) {
        string tmp;
        cin>>tmp;
        for (int j = 0; j < w; ++j) {
            if(tmp[j] == '.') grid[i][j] = false;
            if(tmp[j] == '#') grid[i][j] = true;
        }
    }
    //n個の要素のbit全探索する
    int ans = 0;
    int n = h+w;
    for (int bit = 0; bit < (1<<n); ++bit) {
        auto n_grid = grid;
            for (int i = 0; i < h; ++i) {
                if(bit & (1<<i)){
                    //i個目の要素にフラグが立っていた時の処理
                    for (int j = 0; j < w; ++j) {
                        n_grid[i][j] = false;
                    }
                }
            }
        for (int i = h; i < h+w; ++i) {
            if(bit & (1<<i)){
                //i個目の要素にフラグが立っていた時の処理
                for (int j = 0; j < h; ++j) {
                    n_grid[j][i-h] = false;
                }
            }
        }
        int t_ans = 0;
        for (int l = 0; l < h; ++l) {
            for (int i = 0; i < w; ++i) {
                if(n_grid[l][i])t_ans ++;
            }
        }
        if(t_ans == k)ans++;
    }
    cout<<ans<<endl;
    return 0;
}



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

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

Measured memory_bytes: 256
# いろいろ高速化
class Rmq:
    # 平方分割
    # 値を変更すると元のリストの値も書き換わる
    # 検証: http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=3990681
    def __init__(self, a, sqrt_n=150, inf=(1<<31)-1):
        self.sqrt_n = sqrt_n
        if hasattr(a, "__iter__"):
            from itertools import zip_longest
            self.n = len(a)
            self.layer0 = [min(values) for values in zip_longest(*[iter(a)]*sqrt_n, fillvalue=inf)]
            self.layer1 = a
        elif isinstance(a, int):
            self.n = a
            self.layer0 = [inf] * ((a - 1) // sqrt_n + 1)
            self.layer1 = [inf] * a
        else:
            raise TypeError

    def get_min(self, l, r):
        sqrt_n = self.sqrt_n
        parent_l, parent_r = l//sqrt_n+1, (r-1)//sqrt_n
        if parent_l < parent_r:
            return min(min(self.layer0[parent_l:parent_r]),
                       min(self.layer1[l:parent_l*sqrt_n]),
                       min(self.layer1[parent_r*sqrt_n:r]))
        else:
            return min(self.layer1[l:r])

    def set_value(self, idx, val):
        self.layer1[idx] = val
        idx0 = idx // self.sqrt_n
        idx1 = idx0 * self.sqrt_n
        self.layer0[idx0] = min(self.layer1[idx1:idx1+self.sqrt_n])

    def chmin(self, idx, val):
        if self.layer1[idx] > val:
            self.layer1[idx] = val
            idx //= self.sqrt_n
            self.layer0[idx] = min(self.layer0[idx], val)

    def debug(self):
        print("layer0=", self.layer0)
        print("layer1=", self.layer1)

    def __getitem__(self, item):
        return self.layer1[item]

    def __setitem__(self, key, value):
        self.set_value(key, value)


from operator import itemgetter

N, M, *LRC = map(int, open(0).read().split())
LRC = list(zip(*[iter(LRC)]*3))
LRC.sort(key=itemgetter(0))

idx_LRC = 0
q = []

inf = 10**18
seg = Rmq(N+1, inf=inf)

seg.set_value(1, 0)
for v in range(1, N + 1):
    d = seg.get_min(v, N + 1)
    while idx_LRC < M:
        l, r, c = LRC[idx_LRC]
        if l <= v:
            seg.chmin(r, d+c)
            idx_LRC += 1
        else:
            break
ans = seg[N]
print(ans if ans != inf else -1)


Measured memory_bytes: 103724
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template<typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template<typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for(int i=0;i<((int)(v.size()));++i) {
    if (i) os << " ";
    os << v[i];
  }
  return os;
}
template<typename flow_t>
struct FordFulkerson {
  struct edge {
    int to;
    flow_t cap;
    int rev;
    bool isrev;
    int idx;
  };
  vector<vector<edge>> graph;
  vector<int> used;
  const flow_t INF;
  int timestamp;
  FordFulkerson(int n) : INF(numeric_limits<flow_t>::max()), timestamp(0) {
    graph.resize(n);
    used.assign(n, -1);
  }
  void add_edge(int from, int to, flow_t cap, int idx = -1) {
    graph[from].emplace_back((edge) {to, cap, (int) graph[to].size(), false, idx});
    graph[to].emplace_back((edge) {from, 0, (int) graph[from].size() - 1, true, idx});
  }
  flow_t dfs(int idx, const int t, flow_t flow) {
    if(idx == t) return flow;
    used[idx] = timestamp;
    for(auto &e: graph[idx]) {
      if(e.cap > 0 && used[e.to] != timestamp) {
        flow_t d = dfs(e.to, t, min(flow, e.cap));
        if(d > 0) {
          e.cap -= d;
          graph[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }
  flow_t max_flow(int s, int t) {
    flow_t flow = 0;
    for(flow_t f; (f = dfs(s, t, INF)) > 0; timestamp++) {
      flow += f;
    }
    return flow;
  }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n, m; cin >> n >> m;
  FordFulkerson<int> flow(n);
  for(int i=0;i<(m);++i) {
    int a, b, c; cin >> a >> b >> c;
    flow.add_edge(a, b, c);
  }
  cout << flow.max_flow(0, n-1) << endl;
}



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

int main(void)
{
     //??£??\??????????????£??\???????????????
    int n, k;

    cin >> n;
    vector<vector<bool> > A(n, vector<bool>(n, false));
    for(int i = 0; i < n; i++){
        cin >> k >> k;
        for(int j = 0; j < k; j++){
            int input;
            cin >> input;
            A[i][input-1] = true;
        }
    }

    vector<int> u(n, 1000000);
    u[0] = 0;

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(u[j] == i){
                for(int k = 0; k < n; k++){
                    if(A[j][k] == 1) u[k] = min(i+1, u[k]);
                }
            }
        }
    }
    for(int i = 0; i < n; i++){
        if(u[i] != 1000000) cout << i + 1 << " " << u[i] << endl;
        else cout << i + 1 << " " << "-1" << endl;
    }
    return 0;

}

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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

ll ts = 1000000007;

int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  cout << a + b + c + max(a, max(b, c)) * ((1 << k) - 1) << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;

bool used[27];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	string s; cin>>s;
	for(int i=0;i<s.length();i++)
	{
		used[s[i]-'a']=1;
	}
	if(s.length()<26)
	{
		for(int i=0;i<26;i++)
		{
			if(!used[i]) 
			{
				s+=char('a'+i); break;
			}
		}
		cout<<s<<'\n';
	}
	else
	{
		int id = -1;
		for(int i=int(s.length())-2;i>=0;i--)
		{
			if(s[i]<s[i+1])
			{
				id=i; break;
			}
		}
		if(id==-1)
		{
			cout<<-1<<'\n';
		}
		else
		{
			string t = s.substr(0, id);
			int idx2 = id+1; 
			for(int i=id+1;i<s.length();i++)
			{
				if(s[i]<s[idx2]&&s[i]>s[id])
				{
					idx2=i;
				}
			}
			t += s[idx2];
			cout<<t<<'\n';
		}
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; 
    int m;
    while(cin>>s){
    if(s=="-") break;
    cin>>m;
    for(int i=0; i<m; i++){
        int h; cin>>h;
        string tmp=s.substr(0,h);
        s.erase(0,h);
        s+=tmp;
    }
    cout<<s<<endl;
    }
    return 0;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

int main()
{
  int n, m;
  scanf("%d %d", &n, &m);
  printf("%s\n", m >= n ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp36 {
    class Program {
        static void Main(string[] args) {
            int N = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();

            //半開区間[0, i)のWの和
            int[] VW = new int[N + 1];
            VW[0] = 0;
            //半開区間[0, i)のEの和
            int[] VE = new int[N + 1];
            VE[0] = 0;

            //VWとVEを計算する
            for (int i = 0; i < N; i++) {
                if (S[i] == 'W') {
                    VW[i + 1] = VW[i] + 1;
                    VE[i + 1] = VE[i];
                } else if (S[i] == 'E') {
                    VW[i + 1] = VW[i];
                    VE[i + 1] = VE[i] + 1;
                }
            }
            //Console.WriteLine(string.Join(" ", VW));
            //Console.WriteLine(string.Join(" ", VE));

            int ans = N;

            for (int i = 0; i < N; i++) {
                ans = Math.Min(ans, VW[i] + VE[N] - VE[i + 1]);
            }

            Console.WriteLine(ans);
        }
    }
}


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

int main() {
  int a, b, x, A;
  
  cin >> a >> b;
  
  x = (a + b) % 2;
  
  if(x > 0)
    A = (a + b) / 2 + 1;
  else
    A = (a + b) / 2;
  
  cout << A << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int dp[110][110000];
typedef pair<int, int> P;
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<P> S;
    for (int i = 1; i * i <= N; i++) {
        S.push_back({i, 0});
        S.push_back({N/i, 0});
    }
    sort(S.begin(), S.end());
    S.erase(unique(S.begin(), S.end()), S.end());
    rep(i, S.size() - 1) {
        int l = N/S[i + 1].first;
        int r = N/S[i].first;
        S[i].second = r - l;
    }
    S.back().second = 1;
    map<int, int> mp;
    int m = S.size();
    rep(i, m) mp[S[i].first] = i;
    //rep(i, S.size()) cout << S[i].first << " " << S[i].second << endl;
    
    dp[0][mp[N]] = 1;
    rep(i, K) {
        RREP(j, m - 2, 0) dp[i][j] = (dp[i][j] + dp[i][j + 1]) % mod;
        rep(j, m) {
            int nj = mp[N/S[j].first];
            dp[i + 1][j] = (dp[i][nj] * S[j].second) % mod;
        }
    }
    // rep(i, K + 1)  {
    //     rep(j, m) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    int ans = 0;
    rep(i, m) ans = (ans + dp[K][i]) % mod;
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 92532
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#include<deque>
#include<iomanip>
using namespace std;
typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;


const int INF = 1000000000;
const ll BIG_NUM = 1000000000000000000;



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

	double e = (1.0 * l) / 3;
	double ans = e * e * e;
	cout << setprecision(20) << ans << endl;
	
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    double n,m,d;
    cin>>n>>m>>d;
    double ans;
    if(d==0){
        ans=(m-1)/n;
    }
    else{
        ans=2*(n-d)*(m-1)/(n*n);
    }

    cout<<fixed<<setprecision(10)<<ans<<endl;
}


 

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc  = new Scanner(System.in);
      	int a = sc.nextInt();
      	int b = sc.nextInt();
      	
      	if((a*b) % 2 == 0){
        	System.out.println("Even");
        }else{
        	System.out.println("Odd");
        }
    }
}

Measured memory_bytes: 35680
// B.

#include <iostream>
#include <cmath>

using namespace std;

int main(int argc, char *argv[]) {
	int a, b;
	cin >> a >> b;
	string s;
	cin >> s;
	bool ok = s.length() == a + 1 + b;
	if (ok) {
		for (int i = 0; i < a; ++i) {
			if (s[i] < '0' || s[i] > '9') {
				ok = false;
			}
		}
		if (s[a] != '-') {
			ok = false;
		}
		for (int i = a + 1; i < a + 1 + b; ++i) {
			if (s[i] < '0' || s[i] > '9') {
				ok = false;
			}
		}
	}
	cout << (ok ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAXN 100005
#define INF 100000000
#define MOD 998244353
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n;
string str;
int ans;
int cnt[7];
/*
1: R
2: G
3: B
4: RG
5: RB
6: GB
*/
int main()
{
    scanf("%d",&n);
    cin>>str;
    ans=1;
    cnt[0]=n;
    for(int i=0;i<3*n;i++)
    {
        if(str[i]=='R')
        {
            if(cnt[6]>0) {ans=1LL*cnt[6]*ans%MOD; cnt[6]--;}
            else if(cnt[2]) {ans=1LL*ans*cnt[2]%MOD; cnt[2]--; cnt[4]++;}
            else if(cnt[3]) {ans=1LL*ans*cnt[3]%MOD; cnt[3]--; cnt[5]++; }
            else {ans=1LL*ans*cnt[0]%MOD; cnt[0]--; cnt[1]++;}
        }
        else if(str[i]=='B')
        {
            if(cnt[4]>0) {ans=1LL*cnt[4]*ans%MOD; cnt[4]--;}
            else if(cnt[1]) {ans=1LL*ans*cnt[1]%MOD; cnt[1]--; cnt[5]++;}
            else if(cnt[2]) {ans=1LL*ans*cnt[2]%MOD; cnt[2]--; cnt[6]++; }
            else {ans=1LL*ans*cnt[0]%MOD; cnt[0]--; cnt[3]++;}
        }
        else
        {
            if(cnt[5]>0) {ans=1LL*cnt[5]*ans%MOD; cnt[5]--;}
            else if(cnt[1]) {ans=1LL*ans*cnt[1]%MOD; cnt[1]--; cnt[4]++;}
            else if(cnt[3]) {ans=1LL*ans*cnt[3]%MOD; cnt[3]--; cnt[6]++; }
            else {ans=1LL*ans*cnt[0]%MOD; cnt[0]--; cnt[2]++;}
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 900
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
int cnt;
struct Str{
	int len;
	char s[200];
	bool operator <(const Str &rhs)const{
		return len>rhs.len;
	}
}tmp;
char s[200];
priority_queue<Str>q;
void count(int lim,char ch){
	for(register int i=0;i<lim;i++){
		for(register int j=0;j<128;j++)s[j]=ch+i;
		printf("? %s\n",s);
		fflush(stdout);
		scanf("%d",&tmp.len);
		fflush(stdin);
		tmp.len=128-tmp.len;
		if(tmp.len){
			for(register int j=0;j<tmp.len;j++)tmp.s[j]=ch+i;
			q.push(tmp);
			//cout<<"q.push "<<tmp.len<<" "<<tmp.s<<endl;
		}
	}
}
void solve(){
	while(q.size()>1){
		Str s1=q.top();q.pop();
		Str s2=q.top();q.pop();
		//cout<<"s1:"<<s1.len<<" "<<s1.s<<endl;
		//cout<<"s2:"<<s2.len<<" "<<s2.s<<endl;
		for(register int i=0;i<s1.len;i++)s[i]=s1.s[i];
		s[s1.len]='\0';
		printf("? %s\n",s);
		fflush(stdout);
		int tot=0;
		scanf("%d",&tot);
		fflush(stdin);
		int i=0,j=0,k=0;
		while(i<s1.len&&j<s2.len){
			s[k]=s2.s[j];
			int now=k+1;
			for(register int l=i;l<s1.len;l++)s[now++]=s1.s[l];
			s[now]='\0';
			printf("? %s\n",s);
			fflush(stdout);
			scanf("%d",&cnt);
			fflush(stdin);
			if(cnt<tot){
				tot=cnt;
				j++;
			}
			else{
				s[k]=s1.s[i];
				i++;
			}
			k++;
		}
		if(i>=s1.len)for(;j<s2.len;j++,k++)s[k]=s2.s[j];
		else for(;i<s1.len;i++,k++)s[k]=s1.s[i];
		tmp.len=k;
		for(i=0;i<k;i++)tmp.s[i]=s[i];
		q.push(tmp);
	}
}
int main(){
	count(10,'0');
	count(26,'a');
	count(26,'A');
	solve();
	tmp=q.top();
	for(register int i=0;i<tmp.len;i++)s[i]=tmp.s[i];
	s[tmp.len]='\0';
	printf("! %s\n",s);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pl;
#define all(a) (a).begin(),(a).end()
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,n) for(ll (i)=(n)-1;(i)>=0;i--)
#define SHOW(x) cout << #x << ": " << x << endl;
const ll INF=1e18;
const int iINF = 1e9;
int main(){
    ll x,y,i = 1,cnt = 0;
    cin>>x>>y;
    while(i * x <= y){
        i *= 2;
        cnt++;
    }
    cout<<cnt<<endl;
}




Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

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

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  string s; cin >> s;
  set<char> set;
  for (int i = 0; i < s.size(); i++)
    set.insert(s[i]);
  if (set.size() == s.size()) outl("yes");
  else outl("no");
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


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

int main() {
    int s,w;
    cin >> s >> w;
    if(s <= w) cout << "unsafe" << endl;
    else cout << "safe" << endl;
    return 0;
}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int K = int.Parse(str[1]);
		int C = int.Parse(str[2]);
		int[]A = new int[K];
		int[]B = new int[K];
		string s = Console.ReadLine();
		int i1 = 0;
		int t1 = 0;
		while(i1<K){
			if(s.Substring(t1,1)=="o"){
				A[i1] = t1;
				i1++;
				t1 += C+1;
			} else {
				t1++;
			}
		}
		i1 = K-1;
		t1 = N-1;
		while(i1>=0){
			if(s.Substring(t1,1)=="o"){
				B[i1] = t1;
				i1--;
				t1 -= C+1;
			} else {
				t1--;
			}
		}
		for(var i=0;i<K;i++){
			if(A[i]==B[i]){
				Console.WriteLine(A[i]+1);
			}
		}
	}
}

Measured memory_bytes: 18516
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<ll> vec;
typedef vector<vec> mat;

// const ll mod = 1000000007;

mat mat_mul(mat &A, mat &B , ll mod){
    mat C(A.size(), vec(B[0].size()));
    for (int i = 0; i < A.size(); i++){
        for (int k = 0; k < B.size(); k++){
            for (int j = 0; j < B[0].size(); j++){
                A[i][k] %= mod;
                B[k][j] %= mod;
                C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % mod;
            }
        }
    }
    return C;
}

mat mat_pow(mat A, ll n, ll mod){
    mat B(A.size(), vec(A.size()));
    for (int i = 0; i < A.size(); i++){
        B[i][i] = 1;
    }
    while(n > 0){
        if(n & 1) B = mat_mul(B, A, mod);
        A = mat_mul(A, A, mod);
        n >>= 1;
    }
    return B;
}

bool C(ll x, ll ten, ll a, ll b){
    ll n = a + b * x;
    return n < ten;
}

int main(){
    ll L, a, b, m;
    cin >> L >> a >> b >> m;
    ll x = 0;
    ll s = a;
    mat X(1, vec(3));
    X[0][0] = x;  X[0][1] = a; X[0][2] = 1; 
    ll ten = 1;
    ll num_old = -1;
    ll num;
    rep(i, 18){
        ten *= 10;
        mat A(3, vec(3));
        A[0][0] = ten % m; A[0][1] = 0; A[0][2] = 0;
        A[1][0] = 1; A[1][1] = 1; A[1][2] = 0;
        A[2][0] = 0; A[2][1] = b % m; A[2][2] = 1;
        ll l = -1;
        ll r = L - 1;
        while(l < r - 1){
            ll mid = (l + r) / 2;
            if(C(mid, ten, a, b)) l = mid;
            else r = mid;
        }
        if(C(l+1, ten, a, b)) num = l + 1;
        else num = l;
        ll numd = num - num_old;
        num_old = num;
        // cout << numd << "abc" << endl;
        // cout << A[0][0] << endl;
        A = mat_pow(A, numd, m);
        // cout << A[0][0] << endl;
        X = mat_mul(X, A, m);
        // cout << X[0][0] << endl;
    }
    s = a + (b * (L - 1));
    // cout << s << endl;
    cout << X[0][0] << endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
	int n;
	vector<int> array;
	cin >> n;
	for (int i = 0;i < n;i++) {
		int buf=0;
		cin >> buf;
		array.push_back(buf);
	}

	int min = *std::min_element(array.begin(), array.end());
	int issum;
	for (int i = 1;i <= min;i++) {
		issum = 0;
		for (int j = 0;j < n;j++) {
			if (array[j] % i == 0)issum++;
		}
		if (issum == n)cout << i<<endl;
	}

	return 0;
}


Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
const int INF=1e9;
const int MOD= 1000000007;
int main(){
    int n,m;
    cin>>n>>m;
    vector<ll> a(n),dat(n);
    rep(i,m){
        int b;
        cin>>b;b--;
        a[b]++;
    }
    if(a[0]==0)
        dat[0]++;
    if(a[1]==0){
        if(a[0]==0)
            dat[1]++;
        dat[1]++;
    }
    for(int i=2;i<n;i++){
        if(a[i-2]==0) dat[i]+=dat[i-2];
        if(a[i-1]==0) dat[i]+=dat[i-1];
        dat[i]%=MOD;
    }
    cout<<dat[n-1];
}

Measured memory_bytes: 4772
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

const int N=2005;

struct E{
	int to,next;
}mem[N<<1];
int n,num,m,x,y,ans,inf,w,mn,now,d;
int head[N],dp[N][N],sum[N][N],f[N][N],son[N],g[N],sz[N];

void add(int x,int y){
	num++;
	mem[num].to=y; mem[num].next=head[x];
	head[x]=num;
}

void dfs(int k,int pre){
	int j,u;
	g[k]=1; sz[k]=1;
	for (j=head[k];j;j=mem[j].next){
		u=mem[j].to;
		if (u==pre) continue;
		dfs(u,k);
		sz[k]+=sz[u];
		d=max(d,g[k]+g[u]);
		g[k]=max(g[k],g[u]+1);
	}
}

void dfs1(int k,int pre){
	int j,u,i,l,cnt=0;
	dp[k][0]=1; dp[k][1]=0;
	for (j=head[k];j;j=mem[j].next){
		u=mem[j].to;
		if (u==pre) continue;
		dfs1(u,k);
	}
	for (j=head[k];j;j=mem[j].next){
		u=mem[j].to;
		if (u==pre) continue;
		son[++cnt]=u;
		dp[k][0]+=dp[u][0]; dp[k][1]+=dp[u][0];
		for (i=0;i<=m;i++)
			if (dp[u][i]!=inf) sum[k][i]+=dp[u][i];
	}
	for (i=1;i<=m;i++){
		l=min(i-1,m-i);
		for (j=1;j<=cnt;j++) if (dp[son[j]][i-1]!=inf){
			u=son[j];
			if (dp[u][l]==inf) w=0;
			else w=dp[u][l];
			dp[k][i]=min(dp[k][i],dp[u][i-1]+sum[k][l]-w);
		}
	}
}

void dfs2(int k,int pre){
	int j,u,i,l,cnt=0,w;
	for (i=0;i<=m;i++) ans=min(ans,dp[k][i]+f[k][m-i]);
	f[k][0]=n-sz[k];
	for (i=0;i<=m;i++)
		if (f[k][i]!=inf) sum[k][i]+=f[k][i];
	for (j=head[k];j;j=mem[j].next){
		u=mem[j].to;
		if (u==pre) continue;
		son[++cnt]=u;
	}
	for (i=1;i<=m;i++){
		l=min(i-1,m-i); mn=inf;
		if (f[k][i-1]!=inf){
			mn=f[k][i-1];
			if (f[k][l]!=inf) mn-=f[k][l];
		}
		now=mn;
		for (j=1;j<=cnt;j++){
			u=son[j];
			if (now!=inf){
				if (dp[u][l]!=inf) w=dp[u][l];
				else w=0;
				f[u][i]=min(f[u][i],now+sum[k][l]-w);
			}
			if (dp[u][i-1]!=inf){
				if (dp[u][l]!=inf) now=min(now,dp[u][i-1]-dp[u][l]);
				else now=min(now,dp[u][i-1]);
			}
		}
		now=mn;
		for (j=cnt;j>=1;j--){
			u=son[j];
			if (now!=inf){
				if (dp[u][l]!=inf) w=dp[u][l];
				else w=0;
				f[u][i]=min(f[u][i],now+sum[k][l]-w);
			}
			if (dp[u][i-1]!=inf){
				if (dp[u][l]!=inf) now=min(now,dp[u][i-1]-dp[u][l]);
				else now=min(now,dp[u][i-1]);
			}
		}
	}
	for (j=head[k];j;j=mem[j].next){
		u=mem[j].to;
		if (u==pre) continue;
		dfs2(u,k);
	}
}

int main(){
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	int i,j;
	scanf("%d%d",&n,&m); m++;
	for (i=1;i<n;i++){
		scanf("%d%d",&x,&y);
		add(x,y); add(y,x);
	}
	dfs(1,0);
	if (d<=m){
		printf("0\n");
		return 0;
	}
	memset(dp,0x3f,sizeof(dp)); inf=dp[0][0];
	dfs1(1,0); ans=dp[1][m];
	memset(f,0x3f,sizeof(f));
	f[1][0]=0;
	dfs2(1,0);
	printf("%d\n",ans);
	return 0;
}
/*
10 6
1 2
1 3
3 4
2 5
5 6
2 7
4 8
6 9
8 10
*/

Measured memory_bytes: 47616
A = list(map(int, input().split()))

midA = sum(A) - max(A) - min(A)
count = 0

count += max(A) - midA
diff = max(A) - (min(A) + count) 

while diff > 1:
    diff -= 2
    count += 1

if diff == 1:
    count += 2

print(count)

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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n;cin>>n;
  string s;cin>>s;
  int now=count(s.begin(), s.end(), 'E');
  int res= (1<<30);
  for(int i=0;i<n;i++){
    if(s[i]=='E')now--;
    res=min(now, res);
    if(s[i]=='W')now++;
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define LINF 3e18+7
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const double PI = acos(-1.0);
const double EPS = 1e-10;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<ll> a(N),b(N);
    priority_queue<pair<ll,ll>> pq;
    REP(i,N) cin >> a[i];
    REP(i,N){
        cin >> b[i];
        pq.push({b[i],i});
    }
    ll ans = 0;
    while(!pq.empty()){
        ll now = pq.top().first;
        ll idx = pq.top().second;
        pq.pop();

        if(now == a[idx]) continue;
        else if(a[idx] > now){
            cout << -1 << endl;
            return 0;
        }
        else{
            ll sa = b[idx] - a[idx];
            ll wa = b[(idx-1+N)%N] + b[(idx+1)%N];
            if(sa / wa <= 0){
                cout << -1 << endl;
                return 0;
            }
            ans += sa / wa;
            now -= (sa / wa) * wa;
            b[idx] = now;
            pq.push({b[idx],idx});
        }
    }
    cout << ans << endl;
}


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

int n;
long long a[255];
char s[255];

long long basis[60];

void add(long long x) {
    for (int i = 59; i >= 0; i--) {
        if (x & (1ll << i)) {
            if (basis[i] == 0) {
                basis[i] = x;
                break;
            }

            x ^= basis[i];
        }
    }
}
bool can(long long x) {
    for (int i = 59; i >= 0; i--) if (x & (1ll << i)) {
        x ^= basis[i];
    }

    return x == 0;
}
int main() {
    int _t;
    cin >> _t;

    while (_t--) {
        scanf("%d", &n);

        for (int i = 0; i < n; i++) {
            scanf("%lld", &a[i]);
        }

        scanf("%s", s);

        bool bad = false;

        for (int i = 0; i < n; i++) if (s[i] == '1') {
            memset(basis, 0, sizeof(basis));
            for (int j = i + 1; j < n; j++) if (s[j] == '0') {
                add(a[j]);
            }

            if (can(a[i])) continue;
            bad = true;
        }

        puts(bad ? "1" : "0");
    }

    return 0;
}


Measured memory_bytes: 3648
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var NM = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (N, M) = (NM[0], NM[1]);
        var a = new int[M];
        for (int i = 0; i < M; i++)
            a[i] = int.Parse(ReadLine());

        var isBroken = new bool[N];
        foreach (var _a in a)
            isBroken[_a] = true;

        var routeCounts = new long[N + 1];
        routeCounts[0] = 1;

        for (int i = 1; i <= N; i++)
        {
            var routeCount = 0L;
            if (i >= 1 && !isBroken[i - 1])
                routeCount += routeCounts[i - 1];
            if (i >= 2 && !isBroken[i - 2])
                routeCount += routeCounts[i - 2];

            routeCounts[i] = routeCount % 1_000_000_007;
        }

        WriteLine(routeCounts[N]);
    }
}


Measured memory_bytes: 32240
import sys
from scipy.sparse.csgraph import floyd_warshall as f
def main():
  n,m,l,*t=map(int,sys.stdin.buffer.read().split())
  d=[[0]*(n+1)for _ in range(n+1)]
  for a,b,c in zip(*[iter(t[:m*3])]*3):d[a][b]=c
  d=f(f(d,0)<=l)-1
  d[d>n]=-1
  d=d.astype('i2').astype('U')
  print('\n'.join(d[i]for i in zip(*[iter(t[m*3+1:])]*2)))
main()

Measured memory_bytes: 36200
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = 610;

int N, M;
vector <int> nv[MAXN];
ld pv[MAXN]; // prob to reach i
ld dp[MAXN]; // time to finish from i

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> N >> M;
    for (int i = 0; i < M; i++)
    {
        int x, y;
        cin >> x >> y;
        x--, y--;
        nv[x].push_back(y);
    }

    for (int i = 0; i < N; i++)
        pv[i] = dp[i] = 0;
    pv[0] = 1;

    for (int i = 0; i < N - 1; i++)
    {
        ld ng = nv[i].size();
        for (int x : nv[i])
            pv[x] += pv[i] * 1. / ng;
    }

    dp[N] = 0.0;
    for (int i = N - 2; i >= 0; i--)
    {
        ld ng = nv[i].size();
        dp[i] = 1.0;
        for (int x : nv[i])
            dp[i] += dp[x] * 1. / ng;
    }

    ld res = dp[0];
    for (int i = 0; i < N - 1; i++)
    {
        if (nv[i].size() <= 1) continue;

        for (int x : nv[i])
        {
            ld nl = ((dp[x]) - (dp[i] - 1)) / (nv[i].size() - 1.);
            res = min (res, dp[0] - pv[i] * nl);
        }
    }
    cout << fixed << setprecision(10);
    cout << res << "\n";
}

Measured memory_bytes: 1408
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;

#define MAX_N 200000

int par[MAX_N];
int rnk[MAX_N];

// 初期化
void init(int n){
	for(int i = 0; i < n; i++){
		par[i] = i;
		rnk[i] = 0;
	}
}

// x の親を返す
int find(int x){
	if(par[x] == x){
		return x;
	}
	return par[x] = find(par[x]);
}

// x と y を併合する
void unite(int x, int y){
	int x_par = find(x);
	int y_par = find(y);
	if(x_par == y_par){
		return;
	}
	
	if(rnk[x_par] < rnk[y_par]){
		par[x_par] = y_par;
	}else{
		par[y_par] = x_par;
		if(rnk[x_par] == rnk[y_par]){
			rnk[x_par]++;
		}
	}
}

// x, y が同じグループか判定
bool same(int x, int y){
	return (find(x) == find(y));
}

struct edge{
	int u, v, cost;
};

bool cmp(edge e1, edge e2){
	return e1.cost < e2.cost;
}

int main(){
	
	while(true){
		int n, m;
		cin >> n >> m;
		if(n == 0){
			break;
		}
		vector<edge> v;
		for(int i = 0; i < m; i++){
			edge e;
			cin >> e.u >> e.v >> e.cost;
			v.push_back(e);
		}
		sort(v.begin(), v.end(), cmp);
		init(2000);
		
		int cnt = 0;
		for(int i = 0; i < m; i++){
			edge e = v[i];
			if(!same(e.u, e.v)){
				unite(e.u, e.v);
				cnt++;
			}
			if(cnt == n / 2){
				cout << e.cost << endl;
				break;
			}
		}
	}
	
	return 0;
}




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

int main() {
    int d, e;
    while (cin >> d >> e, d || e) {
        double err = 1e9+7;
        for (int i = 0; i <= d; i++) {
            err = min(err, abs(sqrt(i * i + (d - i) * (d - i)) - e));
        }

        cout << err << endl;
    }

    return 0;
}



Measured memory_bytes: 3224
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string str;
    cin >> str;
    string a = "A";
    string b = "B";
    string c = "C";
    string bc = "BC";
    
    long ans = 0;

    if(str.length()<3){
        cout << ans  << endl;
        return 0;
    }

    long counta = 0, countbc = 0;

    for(int i=str.length()-1;i>0;i--){
        if((counta ==0)&&(countbc==0)){
            if(str.compare(i-1,2,bc)==0){
                countbc ++;
                i --;
            }
        }else if((counta==0)&&(countbc>0)){
            if(str.compare(i,1,a)==0){
                counta ++;
            }else if(str.compare(i-1,2,bc)==0){
                countbc ++;
                i--;
            }else{
                counta =0;
                countbc = 0;
            }
        }else if((counta>0)&&(countbc>0)){
            if(str.compare(i,1,a)==0){
                counta ++;
            }else if(str.compare(i-1,2,bc)==0){
                ans += counta * countbc;
                                counta = 0;
                countbc++;
                i--;
            }else{
                ans += counta * countbc;
                counta = 0;
                countbc = 0;
            }
        }
    }

    ans += counta * countbc;
    counta = 0;

    if(str.compare(0,1,a)==0){
        counta ++;
        ans += counta * countbc;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main{
	static int[][] m = new int[10][10];
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			String t = sc.next();
			String[] a = t.split(",");
			int x = Integer.parseInt(a[0]);
			int y = Integer.parseInt(a[1]);
			int s = Integer.parseInt(a[2]);
			paint(x, y, s);
		}
		sc.close();
		int cnt = 0;
		int[] d = new int[51];
		for(int i = 0; i < 10; i++) {
			for(int j = 0; j < 10; j++) {
				if(m[i][j] == 0) cnt++;
				d[m[i][j]]++;
			}
		}
		int max = 0;
		for(int i = 0; i < 51; i++) {
			if(d[i] != 0) {
				max = i;
			}
		}
		System.out.println(cnt);
		System.out.println(max);
	}
	static int[] d1x = {1, -1, 0, 0};
	static int[] d1y = {0, 0, 1, -1};
	static int[] d2x = {1, 1, -1, -1};
	static int[] d2y = {1, -1, 1, -1};
	static int[] d3x = {2, -2, 0, 0};
	static int[] d3y = {0, 0, -2, 2};
	static void paint(int x, int y, int s) {
		m[y][x]++;
		for(int i = 0; i < 4; i++) {
			if(check(x, y, d1x[i], d1y[i])) {
				m[y + d1y[i]][x + d1x[i]]++;
			}
		}
		if(s == 1) return;
		for(int i = 0; i < 4; i++) {
			if(check(x, y, d2x[i], d2y[i])) {
				m[y + d2y[i]][x + d2x[i]]++;
			}
		}
		if(s == 2) return;
		for(int i = 0; i < 4; i++) {
			if(check(x, y, d3x[i], d3y[i])) {
				m[y + d3y[i]][x + d3x[i]]++;
			}
		}
	}
	static boolean check(int x, int y, int dx, int dy) {
		int nx = x + dx;
		int ny = y + dy;
		if(nx >= 0 && nx < 10 && ny >= 0 && ny < 10) {
			return true;
		}else {
			return false;
		}
	}
}


Measured memory_bytes: 26112