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

static const int MAX=1e6+1;

vector<vector<int>> g(MAX); //有向グラフの隣接リスト
vector<int> out; //頂点をトポロジカルソートした配列
bool used[MAX]={};
int ind[MAX];

void bfs(int s){
    queue<int> q;
    q.push(s);
    used[s]=true;
    while(!q.empty()){
        int u=q.front(); q.pop();
        out.push_back(u);
        for(auto it=g[u].begin();it!=g[u].end();it++){
            int v=*it;
            ind[v]--;
            if(ind[v]==0&&used[v]==false){ //入次数が0になったら追加
                used[v]=true; //再訪しない
                q.push(v);
            }
        }
    }
}

void tsort(int N){
    for(int i=0;i<N;i++){
        ind[i]=0;
    }
    for(int u=0;u<N;u++){
        for(auto it=g[u].begin();it!=g[u].end();it++){
            int v=*it;
            ind[v]++; //各頂点の次数を計算
        }
    }
    for(int u=0;u<N;u++){
        if(ind[u]==0&&used[u]==false) bfs(u);
    }
    //for(int i=0;i<out.size();i++){
        //cout << out[i] << endl;
    //}
}

int main(){
    int N;
    cin >> N;
    vector<vector<int>> a(N,vector<int>(N-1));
    for(int i=0;i<N;i++){
        for(int j=0;j<N-1;j++){
            cin >> a[i][j];
            a[i][j]--;
        }
    }
    int res[N][N];
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            res[i][j]=-1;
        }
    }
    int tmp=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<N-1;j++){
            if(i>a[i][j]) continue;
            if(res[i][a[i][j]]==-1){
                res[i][a[i][j]]=tmp;
                res[a[i][j]][i]=tmp;
                tmp++;
            }
        }
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<N-2;j++){
            g[res[i][a[i][j]]].push_back(res[i][a[i][j+1]]);
        }
    }
    tsort(tmp);
    if(out.size()!=tmp){
        cout << -1 << endl;
    }else{
        int dp[tmp]={};
        int ans=0;
        for(auto u=out.begin();u!=out.end();u++){
            for(auto v=g[*u].begin();v!=g[*u].end();v++){
                dp[*v]=max(dp[*v],dp[*u]+1);
                ans=max(dp[*v],ans);
            }
        }
        cout << ans+1 << endl;
    }
}

Measured memory_bytes: 55540
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0 ; i < 10 ; ++i)
        for(int j = 0 ; j < 10 ; ++j)
            for(int k = 0 ; k < 10 ; ++k){
                queue < int > q;
                q.push(i); q.push(j); q.push(k);
                for(int p = 0 ; p < n && !q.empty() ; ++p)
                    if((int)(s[p] - '0') == q.front()) q.pop();
                ans += q.empty();
            }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
o=998244353
f=[1]
for i in range(1,2500100):f.append(f[-1]*i%o)
def c(n,k):return f[n]*pow(f[n-k],o-2,o)*pow(f[k],o-2,o)
n,m=map(int,input().split())
w=3*m
u=n-1
a=c(w+u,u)-n*c(n+m-2,u)
if u>m:
 for i in range(m+1,min(w,n)+1):
  if w-i+1&1:a=(a-c(n,i)*c((w-i)//2+u,u))%o
print(a%o)

Measured memory_bytes: 107256
N = int(input())
A = list(map(int, input().split()))
b = {}
p = 0

for a in A:
  if not a in b:
    b[a] = 1
  else:
    b[a] += 1
    
for v in b.values():
  p += v * (v - 1) // 2
  
for a in A:
  d = b[a]
  ans = p - (d * (d - 1) // 2) + ((d - 1) * (d - 2) // 2)
  print(ans)

Measured memory_bytes: 24996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
double pi = 3.14159265359;
#define rep(i, n) for (int i = 0; i < n; i++)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// auto mod int
const int mod = 1000000007;

int main() {
    int n;
    cin >> n;
    int a[n];
    rep (i, n) cin >> a[i];
    int r = 0, b = 0, g = 0; // r>=b>=g
    ll ans = 1;
    rep (i, n) {
        if (a[i] == r && a[i] == b && a[i] == g) {
            (ans *= 3) %= mod;
            r++;
        } else if (a[i] == r && a[i] == b) {
            (ans *= 2) %= mod;
            r++;
        } else if (a[i] == r) {
            r++;
        } else if (a[i] == b & a[i] == g) {
            (ans *= 2) %= mod;
            b++;
        } else if (a[i] == b) {
            b++;
        } else if (a[i] == g) {
            g++;
        } else
            ans = 0;
    }
    cout << ans << "\n";
}


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

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

  int n;
  cin >> n;
  vector< vector<int> > v(n, vector<int>(n, 0));
  for(int i = 0; i < n; i++){
    int u, k; cin >> u >> k;
    u--;
    for(int j = 0; j < k; j++){
      int a; cin >> a;
      a--;
      v[u][a] = 1;
    }
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(j == n-1) cout << v[i][j];
      else cout << v[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}

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

const int MOD = 998244353;
const int MAXN = 1600;
int N;
char A[MAXN][MAXN];

int par[MAXN];
int val[MAXN];
int getPar(int a) {
	return par[a] == -1 ? a : (par[a] = getPar(par[a]));
}
bool merge(int a, int b) {
	a = getPar(a), b = getPar(b);
	if (a == b) return false;
	val[a] ^= val[b];
	par[b] = a;
	return true;
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N;
	for (int i = 1; i < N; i++) {
		cin >> (A[i]+1);
	}

	memset(par, -1, sizeof(par));

	int ans = 0;

	for (int z = 0; z < 2; z++) {
		int numRect = (N - z) / 2 + 1;
		int numEdge = 0;
		int numBad = 0;
		for (int i = 1; i < N; i++) {
			for (int j = i+z; j < N && i + j <= N; j += 2) {
				int u = j - i;
				int v = i + j;
				bool canOn = true;
				bool canOff = true;
				for (char c : {A[i][j], A[j][i], A[N-i][N-j], A[N-j][N-i]}) {
					if (c == 'x') canOn = false;
					else if (c == 'o') canOff = false;
				}
				if (canOn && canOff) {
					// it's an edge
					numEdge ++;
					numBad += merge(u, v);
				} else if (canOn) {
					val[getPar(u)] ^= 1;
					val[getPar(v)] ^= 1;
				} else if (canOff) {
					// nothing
				} else {
					cout << 0 << '\n';
					exit(0);
				}
			}
		}
		if (numRect % 2 == 0) {
			ans += numEdge;
		} else {
			ans += numEdge - numBad;
			for (int u = z; u <= N; u += 2) {
				if (par[u] != -1) continue;
				if (val[u]) {
					cout << 0 << '\n';
					exit(0);
				}
			}
		}
	}
	int realAns = 1;
	while (ans--) { realAns <<= 1; if (realAns >= MOD) realAns -= MOD; }
	cout << realAns << '\n';

	return 0;
}


Measured memory_bytes: 2688
//#define _GLIBCXX_DEBUG
//#pragma GCC optimize "trapv"
#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;

// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
// #pragma optimization_level 3
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


#define pb push_back 
#define f first
#define s second
#define min3(a, b, c) min(min(a, b), c)
#define max3(a, b, c) max(max(a, b), c)
#define all(v) v.begin(), v.end()

typedef long long ll;
typedef double ld;
typedef long double lld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

template <class T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

const int INF = 1e9;
//const ll INF = 1e18;
const ll mod = 1000000007;
// const ll mod = 998244353;

void solve(int tc){
	int n, m;
	cin >> n >> m;
	vvl dp(n, vl(m, 0));

	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		for(int j = 0; j < m; j++){
			if(s[j] == '#') dp[i][j] = -1;
		}
	}
	dp[0][0] = 1;
	for(int i = 1; i < m; i++){
		if(dp[0][i] == -1) dp[0][i] = 0;
		else dp[0][i] = dp[0][i-1];
	}
	for(int i = 1; i < n; i++){
		if(dp[i][0] == -1) dp[i][0] = 0;
		else dp[i][0] = dp[i-1][0];
	}

	for(int i = 1; i < n; i++){
		for(int j = 1; j < m; j++){
			if(dp[i][j] == -1) dp[i][j] = 0;
			else dp[i][j] = (dp[i][j-1] + dp[i-1][j])%mod; 
		}
	}

	cout << dp[n-1][m-1] << "\n";


}

int main(){
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);
	
	int tc = 1;
	//cin >> tc;
	for (int t = 0; t < tc; t++) solve(t);

	return 0;
}

Measured memory_bytes: 11448
S = str(input())
N = len(S)
flag = 1
for i in range(0,N,2):
    if S[i]!="R" and S[i]!="U" and S[i]!="D":
        flag = 0
        break
for j in range(1,N,2):
    if S[j]!="L" and S[j]!="U" and S[j]!="D":
        flag = 0
        break
if flag==1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>

int main()
{
	char c;
	std::cin >> c;

	if ( c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o' ){
		std::cout << "vowel" << std::endl;
	}else{
		std::cout << "consonant" << std::endl;
	}

	return 0;
}

Measured memory_bytes: 256
<?php
  $input=explode(' ',trim(fgets(STDIN)));
  $five=0;
  $seven=0;
  foreach ($input as $i) {
    if ($i==="5") {
      $five+=1;
    } elseif ($i==="7") {
      $seven+=1;
    }
  }
  if ($five===2 && $seven===1) {
    echo "YES"."\n";
  } else {
    echo "NO"."\n";
  }
?>

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

long long int H, W, a[55][55];
vector<pair<int, int>> p;
char s[55];

int main(){
    scanf("%lld%lld", &H, &W);
    for(int i = 0; i < H; ++i){
        scanf("%s", s);
        for(int j = 0; j < W; ++j) {
            a[i + 1][j + 1] = !(s[j] ^ '#');
            if(a[i + 1][j + 1])p.push_back({i + 1, j + 1});
        }
    }
    for(auto i : p){
        if(!(a[i.first][i.second - 1] | a[i.first][i.second + 1] | a[i.first - 1][i.second] | a[i.first + 1][i.second]))return 0 & puts("No");
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int M=1e9+7;
int n,cnt,flag[26];
char s[100005];
signed main(){
	scanf("%lld",&n);
	scanf("%s",s+1);
	for (int i=1;i<=n;i++)flag[s[i]-'a']++;
	int ans=1;
	for (int i=0;i<26;i++)(ans*=flag[i]+1)%=M;
	printf("%lld\n",(ans+M-1)%M);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;

int n, m;
// vector<int> G[100];
int G[10][10];

int main(void){
	cin >> n >> m;
	rep(i, m){
		int a, b; cin >> a >> b;
		a--; b--;
		// G[a].pb(b);
		// G[b].pb(a);
		G[a][b] = G[b][a] = 1;
	}

	// 0してん
	vector<int> v(n - 1);
    reps(i, 1, n) v[i - 1] = i;
    sort(v.begin(), v.end());
    int ans = 0;
    do{
        int now = 0;
        rep(i, v.size()){
        	if(G[now][v[i]] == 0) break;
      		now = v[i];
        	if(i == v.size() - 1){
        		ans++;
	        	/*printf("k\n");
	        	rep(i, v.size()){
	        		printf("%d ", v[i]);
	        	}
	        	printf("\n");
	        	*/
	        	}
	        	
        }
    }while(next_permutation(v.begin(), v.end()));
    printf("%d\n", ans);
	return 0;
}


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

int N, M;
vector<vector<int>> G(100000, vector<int>(0));

int main()
{
  cin >> N >> M;
  vector<int> H(N);
  for (int i = 0; i < N; i++)
  {
    cin >> H.at(i);
  }
  for (int i = 0; i < M; i++)
  {
    int A, B;
    cin >> A >> B;
    A--;
    B--;
    G.at(A).push_back(B);
    G.at(B).push_back(A);
  }

  int ans = 0;
  for (int i = 0; i < N; i++)
  {
    int flag = true;
    // 展望台iに対して
    for (int j = 0; j < G.at(i).size(); j++)
    {
      // 展望台iに隣接する全ての展望台G.at(i).at(j)と高さを比べる
      if (H.at(G.at(i).at(j)) >= H.at(i))
      {
        // 隣接する展望台の高さの方が高いとき
        flag = false;
      }
    }
    if (flag)
    {
      ans++;
    }
  }

  cout << ans << endl;
}

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

int main(){
  int N;
  int a[110];
  cin >>N;
  for(int i=0;i<N;++i)cin>>a[i];
  int Alice = 0;
  int Takeshi = 0;
  sort(a,a+N,greater<int>());
  for(int i = 0; i<N ; ++i){
    if(i%2==0)Alice += a[i];
    else Takeshi += a[i];
  }
  cout <<Alice - Takeshi<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFLL = LLONG_MAX / 3;
const double eps = (1e-9);

bool is_es(string s) {
  int len = s.size() / 2;
  if (s.substr(0, len) == s.substr(len, len)) return true;
  else return false;
}

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

  string s;
  cin >> s;
  if (s.size() % 2 == 0) {
    s.pop_back(); s.pop_back();
  } else {
    s.pop_back();
  }

  while (s.size() >= 0) {
    if (is_es(s)) {
      cout << s.size() << endl;
      break;
    }
    s.pop_back(); s.pop_back();
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;
    
    bool ans = true;
    if (S.at(0) != 'A') ans = false;
    
    set<char> small;
    char a = 'a';
    for (int j = 0; j < 26; j++){
        small.insert(a);
        a += 1;
    }
    int count = 0;
    for (int i = 1; i < S.size(); i++){
        if (small.count(S.at(i))) continue;
        else{
            if (S.at(i) == 'C'){
                if (i == 1 || i == S.size() - 1) ans = false;
                if (count != 0) ans = false;
                count++;
            }
            else ans = false;
        }
    }
    
    if (count == 0) ans = false;
    
    if (ans) cout << "AC" << endl;
    else cout << "WA" << endl;
}


Measured memory_bytes: 256
use std::io;

fn main()
{
    let mut n_str = String::new();
    let mut k_str = String::new();
    let mut x_str = String::new();
    let mut y_str = String::new();

    io::stdin().read_line(&mut n_str).expect("");
    io::stdin().read_line(&mut k_str).expect("");
    io::stdin().read_line(&mut x_str).expect("");
    io::stdin().read_line(&mut y_str).expect("");

    let n:u32 = n_str.trim().parse().expect("");
    let k:u32 = k_str.trim().parse().expect("");
    let x:u32 = x_str.trim().parse().expect("");
    let y:u32 = y_str.trim().parse().expect("");

    let   to_k = x * if n > k { k   } else { n };
    let from_k = y * if n > k { n-k } else { 0 };

    println!("{}", to_k + from_k);
}


Measured memory_bytes: 380
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdio>
#include <list>
#include <queue>
using namespace std;

#define int long long
#define INF 1e18

signed main() {
    int a, b; cin >> a >> b;
    int ans = max(a, b) + max(max(a, b) - 1, min(a, b));
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
	int arr[200000];
	int pre[200001]={0};
int main()
{
	int n;
	cin >> n;

	int i;
	for(i=0;i<n;i++)
	{
		cin >> arr[i];
	}
	for(i=n-1;i >=0; i--)
	{
		pre[i] = (pre[i+1] + arr[i])%mod;
	}
	long long ans = 0;
	for(i=0;i<n-1;i++)
	{
		ans += (1LL*arr[i]*pre[i+1])%mod;
		ans = ans%mod;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 5160
#include<bits/stdc++.h>
 #include <ext/pb_ds/tree_policy.hpp>
 #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
 #define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          1000000007
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        3e18
 #define sm         -2e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> 
  
void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("gin.txt", "r", stdin);
    freopen("gout.txt", "w", stdout);
   
    #endif
}


vector<vii> gp;
vii dp;
void dfs(int i)
{
  dp[i]=1;
  for(auto x:gp[i])
  {
    if(!dp[x]) dfs(x);
    dp[i] = max(dp[i],dp[x]+1);
  }

}

void solve()
{
  
  int n,m;
  cin >> n >> m;  
  
  gp.assign(n+1,vii());
  dp.assign(n+1,0);
  forf(i,0,m)
  {
    int u,v;
    cin >> u >> v;
    gp[u].pb(v);
  
  }
  
  int an = -1;

  forf(i,1,n+1)
  if(!dp[i])
  {
    dfs(i);
    an = max(an,dp[i]-1);
  }

  cout<<an;

}


int32_t main()
{
  pr_init();
  //fastio;
  
  auto start = high_resolution_clock::now(); 
 
  solve();
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
   // cout << "Time taken by function: "
   //       << duration.count() << " microseconds" << endl; 

 }
      
      

Measured memory_bytes: 11316
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var a, b string
	fmt.Scan(&a, &b)

	c, _ := strconv.Atoi(a + b)
	for i := 1; ; i++ {
		if c == i*i {
			fmt.Println("Yes")
			return
		}
		if c < i*i {
			break
		}
	}
	fmt.Println("No")
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  if(s=="Cloudy")
    cout<<"Rainy";
  if(s=="Sunny")
    cout<<"Cloudy";
  if(s=="Rainy")
    cout<<"Sunny";
  return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;
const long long mod = 998244353;

long long mod_pow(long long a, long long k){
  long long ret = 1;
  while(k > 0){
    if(k&1) ret *= a, ret %= mod;
    a *= a, a %= mod;
    k /= 2;
  }
  return ret;
}

int main(){
  long long N, A, B, K;
  cin >> N >> A >> B >> K;
  vector<long long> F(N+1), F_inv(N+1);
  F[0] = 1;
  for(int i = 0; i < N; ++i) F[i+1] = (F[i]*(i+1))%mod;
  F_inv[N] = mod_pow(F[N],mod-2);
  for(int i = N-1; i >= 0; --i) F_inv[i] = (F_inv[i+1]*(i+1))%mod;
  long long ans = 0;
  for(long long i = 0; i <= N; ++i){
    if(i*A > K) break;
    if((K-i*A)%B) continue;
    long long j = (K-i*A)/B;
    if(j > N) continue;
    ans += (((((F[N]*F_inv[i])%mod)*F_inv[N-i])%mod)*((((F[N]*F_inv[j])%mod)*F_inv[N-j])%mod))%mod;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  string s;
  cin >> s;
  int count = 0,ans = 0;
  for(int i = 0; i < s.size(); i++){
    if(s.at(i) == 'A' || s.at(i) == 'C' || s.at(i) == 'G' || s.at(i) == 'T'){
      count++;
    }else{
      if(ans < count)
        ans = count;
      count = 0;
    }
  }
  cout << max(ans,count) << endl;
}


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

using namespace std;

#define MP make_pair
#define PB push_back
#define f first
#define s second

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;

//int dr1[] = {-1, 0, 1, 0};
//int dc1[] = {0, 1, 0, -1};
//int dr3[] = {0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1, -1, 1, 0, 0};
//int dc3[] = {3, 2, 1, 0, -1, -2, -3, -2, -1, 0, 1, 2, 0, 0, -1, 1};
const int MOD = 1000000007;
const int INF = 1000000007;

ll modx(ll a)
{
    return (a%MOD+MOD)%MOD;
}

ll times(ll a, ll b)
{
    return modx(modx(a)*modx(b));
}

ll add(ll a, ll b)
{
    return modx(modx(a)+modx(b));
}

ll sub(ll a, ll b)
{
    return modx(MOD+modx(a)-modx(b));
}

ll fastExp(ll base, ll exp)
{
    if(exp == 0LL)
    {
        return 1LL;
    }

    if(exp%2==0)
    {
        return fastExp(times(base, base), exp/2);
    }
    else
    {
        return times(base, fastExp(times(base, base), exp/2));
    }
}


const int MAXN = (int)1e5+1;
ll N, W, dp[2*MAXN];
pll wv[MAXN];


int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> W;
    for(int i=1; i<MAXN; i++)
    {
        dp[i] = INF;
    }
    for(int i=0; i<N; i++)
    {
        cin >> wv[i].f >> wv[i].s;
        for(int j=MAXN-1; j>=0; j--)
        {
            dp[j+wv[i].s] = min(dp[j+wv[i].s], dp[j] + wv[i].f);
        }
    }
    for(int i=MAXN-1; i>=0; i--)
    {
        if(dp[i] <= W)
        {
            cout << i;
            break;
        }
    }


    return 0;
}


Measured memory_bytes: 1024
N, A, B=map(int, input().split())
if (B-A)%2==0:
  print((B-A)//2)
else:
  if A==1 or B==N:
    ans=(B-A-1)//2+1
  else:
    ans=min(A-1, N-B)+(B-A-1)//2+1
  print(ans)


Measured memory_bytes: 2940
#include <cstdio>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <stack>
#include <vector>
#include <queue>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <set>
#include <bitset>
#include <map>
#define INF 0x3f3f3f3f
#define ULL unsigned long long
#define LL long long
#define N 10100
#define eps 10e-9
#define MOD 100000000
#define mem(a,n) memset(a,n,sizeof(a))
#define fread freopen("in.txt","r",stdin)
#define fwrite freopen("out.txt","w",stdout)
using namespace std;
const double PI=acos(-1.0);
int main()
{
	ios::sync_with_stdio(false);
	int a,b;
	cin>>a>>b;
	if(a%3==0||b%3==0||(a+b)%3==0){
		cout<<"Possible"<<endl;
	}else{
		cout<<"Impossible"<<endl;
	}
	return 0;
}


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

int main(void){
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	
	if(a*b<c*d)printf("%d\n",c*d);
	else printf("%d\n",a*b);
	
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;


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

    if(s=="AAA"||s=="BBB")cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
from sys import stdin


def main():
    n = int(stdin.readline())
    a = map(int, stdin.readline().split())
    r = [0] * 13
    for ai in a:
        r[int(ai / 400)] += 1
    min = 0
    for i in range(8):
        if r[i] > 0:
            min += 1
    max = min
    for i in range(8, 13):
        max += r[i]
    if min == 0:
        min = 1
    print(min, max)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
def e_two_currencies(INF = float('inf')):
    # 参考: https://atcoder.jp/contests/abc164/submissions/12429145
    import heapq
    N, M, S = map(int, input().split())

    Edges = [[] for _ in range(N)]
    max_a = 0
    for _ in range(M):
        u, v, a, b = [int(i) for i in input().split()]
        Edges[u - 1].append((v - 1, a, b))
        Edges[v - 1].append((u - 1, a, b))
        max_a = max(max_a, a)

    Exchanges = []
    Times = []
    for n in range(N):
        c, d = [int(i) for i in input().split()]
        Exchanges.append(c)
        Times.append(d)

    max_coin = max_a * N
    initial_silver = min(S, max_coin)  # 制約上、これ以上持っていても同じこと

    # dist[i][j]: 都市 i へ銀貨の枚数 j で向かうための最短時間
    dist = [[INF] * (max_coin + 1) for _ in range(N)]
    dist[0][initial_silver] = 0
    # (所要時間, 手持ちの銀貨の枚数, 都市番号) heap で扱いやすいようにこの順にする
    queue = [(0, initial_silver, 0)]

    while queue:
        time, silver, city = heapq.heappop(queue)
        if dist[city][silver] < time:  # これまでの最短時間より長い。探索不要
            continue

        # 都市 city で銀貨に交換することを考える。交換しても銀貨が必要最大量に届かず、
        # 移動して銀貨に交換する時間がこれまでの最短時間より短い場合、移動を検討する
        # 同じ頂点 (city, silver) に複数回行く意味はないので、更新は 1 回分のみ
        if (silver + Exchanges[city] < max_coin
                and time + Times[city] < dist[city][silver + Exchanges[city]]):
            dist[city][silver + Exchanges[city]] = time + Times[city]
            heapq.heappush(queue, (time + Times[city], silver + Exchanges[city], city))

        # 都市 city から鉄道で移動する。
        for next_city, a, b in Edges[city]:
            # 運賃以上の銀貨を持っており、移動すると最短時間を更新できる
            if silver >= a and time + b < dist[next_city][silver - a]:
                dist[next_city][silver - a] = time + b
                heapq.heappush(queue, (time + b, silver - a, next_city))

    # 都市 1→1 は省く (明らかに 0 分)。また、残った銀貨の枚数は関係ない
    ans = [min(d) for d in dist[1:]]
    return ' '.join(map(str, ans))

print(e_two_currencies())

Measured memory_bytes: 26192
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
int f,p;
string s;
map<char,int>m;
int bns1();
int g_A(){
  int r=0;
  if(s[p]=='('){
    p++;
    r=bns1();
    p++;
  }
  else{
    while(isdigit(s[p])){
      r=r*10+(s[p]-'0');
      p++;
    }
  }
  return r;
}
int bns3(){
  int res=g_A();
  while(m[s[p]]==3){
    int t=p++;
    if(s[t]=='+')res+=g_A();
    if(s[t]=='-')res-=g_A();
    if(s[t]=='*')res*=g_A();
  }
  return res;
}
int bns2(){
  int res=bns3();
  while(m[s[p]]==2){
    int t=p++;
    if(s[t]=='+')res+=bns3();
    if(s[t]=='-')res-=bns3();
    if(s[t]=='*')res*=bns3();
  }
  return res;
}
int bns1(){
  int res=bns2();
  while(m[s[p]]==1){
    int t=p++;
    if(s[t]=='+')res+=bns2();
    if(s[t]=='-')res-=bns2();
    if(s[t]=='*')res*=bns2();
  }
  return res;
}
int dfs(){
  int res=LLONG_MIN;
  r(i,3)r(j,3)r(k,3){
    m['+']=i+1;
    m['-']=j+1;
    m['*']=k+1;
    p=0;
    res=max(res,bns1());
  }
  return res;
}
main(){
  cin>>s;s[(int)s.size()+10000]='(';
  cout<<dfs()<<endl;
}

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

#define true 1

int main(){
    int aux, i, r, n = 0;
    scanf("%d", &aux);
    while(true){
        if(aux == 2){
            n = aux;
            break;
        }
        for(i = 2; i < aux; i++){
            r = aux % i;
            if(r == 0)
                break;
            if(aux - 1 == i){
                n = aux;
                break;
            }
        }
        if(n != 0)
            break;
        else
            aux = aux + 1;
    }
    printf("%d", n);
    return 0;
}

Measured memory_bytes: 2172
/*input
coffee
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define ld long double
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define F first
#define S second
#define endl '\n'

using namespace std;
using namespace __gnu_pbds; 

template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}


void init(ll* a,ll n,ll val){
	for(ll i=0;i<n;i++)
		a[i]=val;
}



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);	
	ll t=1,i,j;
	string s;
	cin>>s;
	if(s[2]==s[3]&&s[4]==s[5]){
		cout<<"Yes\n";
	}else cout<<"No\n";
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> h(N);
  for (int i = 0; i < N; i++) {
    cin >> h.at(i);
  }
  vector<int> answer(N);
  answer.at(1) = abs(h.at(1)-h.at(0));
  for (int i = 2; i < N; i++) {
    answer.at(i) = min((answer.at(i-1)+abs(h.at(i)-h.at(i-1))),(answer.at(i-2)+abs(h.at(i)-h.at(i-2))));
  }
  cout << answer.at(N-1) <<endl;
}

Measured memory_bytes: 4056
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

int main()
{
	double n;
	cin>>n;
	if(fmod(n,2))cout<<setprecision(15)<<((n-fmod(n,2))/2+1)/n<<endl;
	else cout<<setprecision(15)<<(n/2)/n<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1e9
#define LINF 1e18
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
#define int long long
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int dx[]={0,1,0,-1,1,-1};
int dy[]={1,0,-1,0,1,-1};
struct edge{int to,cost;};
typedef pair<int,int> P;

bool isupper(char c){if('A'<=c&&c<='Z')return 1;return 0;}
bool islower(char c){if('a'<=c&&c<='z')return 1;return 0;}
bool isPrime(int x){if(x==1)return 0;if(x==2)return 1;if(x%2==0)return 0;for(int i=3;i*i<=x;i++)if(x%i==0)return 0;return 1;}
bool iskaibun(string s){for(int i=0;i<s.size()/2;i++)if(s[i]!=s[s.size()-i-1])return 0;return 1;}
bool isnumber(char c){return ('0'<=c&&c<='9');}
bool isalpha(char c){return (isupper(c)&&islower(c));}
void printvi(vector<int> v){rep(i,0,v.size()){if(i)cout<<" ";cout<<v[i];}cout<<endl;}
void printvil(vector<int> v){rep(i,0,v.size()){cout<<v[i]<<endl;}}
void printvvi(vector<vector<int>> v){
    rep(i,0,v.size()){
        rep(j,0,v[i].size())cout<<v[i][j];
        cout<<endl;
    }
}
void printvstr(vector<string> v){
    rep(i,0,v.size()){
        cout<<v[i]<<endl;
    }
}

signed main (){
    int n;
    cin>>n;
    vector<int> v(n);
    rep(i,0,n)cin>>v[i];
    int ma=0;
    int ans=0;
    rep(i,0,n){
        if(v[i]>=ma){
            ma=v[i];
            ans++;
        }
    }
    cout<<ans<<endl;

    




}
/*
(()()())
*/


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

#define maxn 100005

using namespace std;
typedef long long ll;

int main(){
  #define TASK "ABC"
 // freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout);
  ios_base::sync_with_stdio(0);

  int n;
  cin >> n;

  set < pair < ll, ll > > s;
  vector < ll > a(n);
  vector < ll > b(n);

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

  int cnt = 0;
  ll ans = 0;

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

    if (a[i] == b[i])
      cnt ++;
    else
      s.insert(make_pair(-b[i], i));
  }


  while (!s.empty() && cnt < n){
    int id = s.begin() -> second;

    int l = (id + n - 1) % n;
    int r = (id + 1) % n;

    if (b[id] < a[id])
      break;

    s.erase(s.begin());

    int ret = (b[id] - max(max(b[l], b[r]), a[id]) + b[l] + b[r] - 1) / (b[l] + b[r]);
    ret = max(ret, 1);

    b[id] -= (b[l] + b[r]) * ret;

   // cerr << b[l] << ' ' << b[id] << ' ' << b[r] << ' ' << ret << '\n';
    ans += ret;

    if (b[id] < a[id])
      break;

    if (b[id] > a[id])
      s.insert(make_pair(-b[id], id));

    if (b[id] == a[id])
      cnt++;
  }

  if (cnt < n)
    ans = -1;

  cout << ans;

  return 0;
}


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

int main( void )
{
  int N, x;
  cin >> N >> x;
  vector<int> a( N );
  int count = 0;

  for( int i = 0; i < N; i++ )
    cin >> a.at( i );

  sort( a.begin(), a.end() );

  for( int i = 0; i < N - 1; i++ ) {
    if( x >= a.at( i ) ) {
    x -= a.at( i );
    count++;
    }
    else 
      break;
  }

  if( x == a.at( N - 1 ) )
    count++;

  cout << count << endl;

}
    

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

int point[101][3] = { 0 };
int player[200][3] = { 0 };

int main()
{
	int n;
	int sum;

	int i, j;

	scanf("%d", &n);

	for (j = 0; j < n; j++)
	{
		for (i = 0; i < 3; i++)
		{
			scanf("%d", &player[j][i]);

			point[player[j][i]][i] += 1;
		}
	}

	for (i = 0; i < n; i++)
	{
		sum = 0;

		for (j = 0; j < 3; j++)
		{
			if (point[player[i][j]][j] == 1)
			{
				sum += player[i][j];
			}
		}
		printf("%d\n", sum);
	}

	return 0;
}


Measured memory_bytes: 3188
#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 int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
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...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e6 + 10;

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n;
	cin >> n;
	map<string, int> m;
	for(int i = 0; i < n; i++) {
		string s;
		cin >> s;
		m[s]++;
	}
	cout << "AC x " << m["AC"] << endl;
	cout << "WA x " << m["WA"] << endl;
	cout << "TLE x " << m["TLE"] << endl; 
	cout << "RE x " << m["RE"] << endl;  

	return 0;
}

Measured memory_bytes: 3668
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<cctype>
using namespace std;
typedef long long ll;

int a, b;
int d[15][15];
struct edge {
	int x, y, z;
	edge() { x = y = z = 0; }
	edge(int a, int b, int c) { x = a, y = b, z = c; }
}ans[15][15];
int vis[300][300];

int main() {
	scanf("%d%d", &a, &b);
	for(int i = 1; i <= a; i ++)
		for(int j = 1; j <= b; j ++) scanf("%d", &d[i][j]);
	for(int i = 0; i <= 100; i ++)
		for(int j = 0; j <= 100; j ++)
			for(int k = 0; k <= 100; k ++) {
				bool flag = 0;
				for(int t1 = 1; t1 <= a; t1 ++)
					for(int t2 = 1; t2 <= b; t2 ++)
						if(i*t1+j*t2+k < d[t1][t2]) flag = 1;
				if(flag) continue;
				for(int t1 = 1; t1 <= a; t1 ++)
					for(int t2 = 1; t2 <= b; t2 ++)
						if(i*t1+j*t2+k == d[t1][t2]) ans[t1][t2] = edge(i+1, j+1, k);
				break;
			}
	bool chk = 0;
	for(int i = 1; i <= a; i ++)
		for(int j = 1; j <= b; j ++) if(ans[i][j].x == 0) { puts("Impossible"); return 0; }
	puts("Possible"); int n = 200;
	for(int i = 1; i <= a; i ++)
		for(int j = 1; j <= b; j ++) if(!vis[ans[i][j].x][ans[i][j].y]) n ++, vis[ans[i][j].x][ans[i][j].y] = 1;
	printf("202 %d\n", n); memset(vis, 0, sizeof vis);
	for(int i = 1; i < 101; i ++) printf("%d %d X\n", i, i+1);
	for(int i = 102; i < 202; i ++) printf("%d %d Y\n", i, i+1);
	for(int i = 1; i <= a; i ++)
		for(int j = 1; j <= b; j ++) if(ans[i][j].x) {
			if(!vis[ans[i][j].x][ans[i][j].y]) printf("%d %d %d\n", ans[i][j].x, 202-ans[i][j].y+1, ans[i][j].z);
			vis[ans[i][j].x][ans[i][j].y] = 1;
		}
	puts("1 202");
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main() {
  int a,b;
  cin >> a >> b;
  if (a+b>=10) cout << "error";
  if (a+b<10) cout << a+b;
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>

using namespace std;

int main()
{
    int n, k;
    long double p[200010] = {};
    long double s[200110] = {};
    long double max = -1;

    cin >> n >> k;

    for (int i = 0; i < n; i++) {
        cin >> p[i];
        p[i] = (p[i] + 1) / 2;
    }

    for (int i = 0; i < n; i++) {
        s[i+1] = s[i] + p[i];
    }

    for (int i = 0; i < n-k+1; i++) {
        if (max < s[i+k] - s[i]) {
            max = s[i+k] - s[i];
        }
    }

    cout << fixed << setprecision(12) << max << endl;
}


Measured memory_bytes: 6656
use std::io::*;
use std::str::FromStr;

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

fn main() {
    let n: usize = read();
    let a: usize = read();
    let b: usize = read();
    let maxb = n - a + 1;
    let minb = (n + a - 1) / a;
    if b < minb || maxb < b {
        println!("{}", -1);
        return;
    }
    let mut m = n;
    let mut restb = b;
    let mut seq = Vec::<usize>::new();
    while m > 0 {
        assert!(restb != 0);
        let usable = std::cmp::min(a, m - (restb - 1));
        for i in m-usable..m {
            seq.push(i);
        }
        restb -= 1;
        m -= usable;
    }
    for i in 0..n {
        if i != 0 { print!(" "); }
        print!("{}", seq[i] + 1);
    }
    println!("");
}

Measured memory_bytes: 11384
#include <iostream>
using namespace std;
long long n, dp[105][25] = { 0 }, a[105] = { 0 };
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	dp[0][a[0]] = 1;
	for (int i = 1; i <= n - 2; i++) {
		for (int j = 0; j <= 20; j++) {
			if (j-a[i]<0) {
				dp[i][j] = dp[i - 1][j + a[i]];
			}
			else if (j + a[i] > 20) {
				dp[i][j] = dp[i - 1][j - a[i]];
			}
			else {
				dp[i][j] = dp[i - 1][j - a[i]] + dp[i - 1][j + a[i]];
			}
		}
	}
	cout << dp[n - 2][a[n - 1]] << endl;
	return 0;
}

Measured memory_bytes: 3108
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#define numarr 110000
using namespace std;

int main() {
	int N, M, X[numarr], Xd[numarr], ans = 0, getneed, i;
	cin >> N >> M;
	for (i = 0; i < M; i++)
		cin >> X[i];
	if (N < M)
	{
		getneed = M - N;
		sort(X, X + M, less<int>());
		for (i = 1; i < M; i++)
			Xd[i - 1] = X[i] - X[i - 1];
		sort(Xd, Xd + M-1, less<int>());
		for (i = 0; i < getneed; i++)
		{
			ans += Xd[i];
		}
	}
		cout << ans << endl;
}

Measured memory_bytes: 1024
//Road to Millionaire

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int n;cin>>n;
    vector<int>a;
    rep(i,0,n){
        int t;cin>>t;
        if(!a.empty())if(t==a[a.size()-1])continue;
        a.pb(t);
    }
    n=a.size();
    int m=1000,k=0;
    rep(i,0,n-1){
        if(a[i]<a[i+1]){
            k+=m/a[i];
            m=m%a[i];
        }else{
            m+=k*a[i];
            k=0;
        }
    }
    m+=k*a[a.size()-1];
    cout<<m<<nnn;
    return 0;
}

Measured memory_bytes: 3636
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    int minus = 0;
    ll sum = 0;
    rep(i, N){
        cin >> A[i];
        if (A[i] < 0){
            minus++;
            A[i] *= -1;
        }
        sum += A[i];
    }

    if(minus % 2 == 0){
        cout << sum << endl;
    } else {
        sort(all(A));
        sum -= 2 * A[0];
        cout << sum << endl;
    }

}

Measured memory_bytes: 640
n,k = map(int,input().split())
p = list(map(int,input().split()))

m = max(p)
l = [0]
for i in range(1,m + 1):
    l.append(l[-1] + i)
for i in range(1,len(l)):
    l[i]/=i
for i in range(n):
    p[i] = l[p[i]]

#累積和
for i in range(1,len(p)):
    p[i]+=p[i - 1]
p=[0]+p

ans = 0
for i in range(len(p) - k):
    ans = max(ans,p[i + k] - p[i])

print(ans)

Measured memory_bytes: 24548
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define FOR(i, a, b) for(i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define comp(a, b) int comp(const void *a, const void *b)
#define MOD  1000000007

typedef unsigned int uint;
typedef unsigned long ulong;
typedef long long ll;
typedef unsigned long long ull;

void TF_print(char boolean, char T[], char F[]){
    if(boolean){
        printf("%s\n", T);
    }else{
        printf("%s\n", F);
    }
}

int main(){
    uint A, B, C, D, E, F;
    scanf("%u %u %u %u %u %u", &A, &B, &C, &D, &E, &F);
    A *= 100, B *= 100;
    double max = -1.0;
    uint s_water = 0, suger_in = 0;
    uint a, b, c, d;

    REP(a, F/A + 1){
        REP(b, (F - a * A)/B + 1){
            REP(c, (F - a * A - b * B)/C + 1){
                REP(d, (F - a * A - b * B - c * C)/D + 1){

                    uint water = A * a + B * b;
                    uint suger = c * C + d * D;
                    if((a > 0 || b > 0) && a * A + b * B + c * C + d * D <= F){
                        if(100 * suger <= E * water && max < 100.0 * suger/(1.0 * suger + 1.0 * water)){
                            max = 100.0 * suger/(1.0 * suger + 1.0 * water);
                            s_water = suger + water;
                            suger_in = suger;
                        }
                    }

                }
            }
        }
    }
    printf("%u %u\n", s_water, suger_in);
    return 0;
}

/*
最大化最小化問題は, 制約が多ければ全探索したほうが早い
*/

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

typedef long long ll;
const int maxn = 2e5+10;
const int mod = 1e9+7;

int a[maxn];

int main(void){
	int d,s,t;
	cin >> d >> s >> t;
	if(d<=s*t) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;	
	return 0;
}



Measured memory_bytes: 3592
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


#define FACSIZE 2002

ll invfac[FACSIZE];
ll fac[FACSIZE];

ll mod_pow(ll ,ll );
ll mod_add(ll ,ll );
ll mod_mul(ll ,ll );
ll mod_div(ll ,ll );
void make_fact(ll );
void make_invfact(ll );



int main(void){

  ll m,k;
  cin>>m>>k;

  if( 1LL << m <= k ){
    cout << -1 << endl;
  }
  else if(k==0){
    for(ll i=0;i< (1LL<<m) ; i++ ){
      cout << i << " " << i << " ";
    }
    cout << endl;
  }
  else if(m==1){
    if(k!=0)cout << -1 << endl;
  }
  else{
    cout << 0 << " " << k << " " << 0 << " ";

    for(ll i=1;i< (1LL<<m) ; i++ ){
      if(i!=k) cout << i << " ";
    }
    cout << k << " ";
    for(ll i= (1LL<<m)-1; i>=1 ; i-- ){
      if(i!=k) cout << i << " ";
    }
    cout << endl;
  }

  return 0;

}

ll mod_pow(ll x,ll r){
  if(r==0) return 1;
  else if(r==1) return x%mod;
  else if(r%2==0){
    ll t=mod_pow(x,r/2)%mod;
    return t*t %mod;
  } 
  else{
    ll t=mod_pow(x,r/2)%mod;
    ll k= t*t %mod;
    return k*x%mod;
  } 
}
ll mod_add(ll a,ll b){
  return (a+b)%mod;
}

ll mod_mul(ll a,ll b){
  return (a*b)%mod;
}

ll mod_div(ll a,ll b){
  return mod_mul(a,mod_pow(b,mod-2));
}

void make_fact(ll n){
  fac[0]=1;
  rep(i,n){
    fac[i+1]=mod_mul(fac[i],i+1);
  }  
}

void make_invfact(ll n){
  invfac[n]= mod_pow( fac[n] ,mod-2);
  for(int i=n-1;i>=0;i--){
    invfac[i]=mod_mul(invfac[i+1],i+1);
  }

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	int n,k;
	cin>>n>>k;
	
	vi cnt(n,0);
	REP(i,k){
		int d;
		cin>>d;
		
		REP(j,d){
			int a;
			cin>>a;
			cnt[a-1]++;
		}
	}
	
	int ans=0;
	REP(i,n){
		if(cnt[i]==0) ans++;
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 3632