akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
using namespace std;
const int N = 10;
char c[N][N];
char c1[N][N];
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>c[i][j];
		}
	}
	int ans=0;
	for(int s1=0;s1<(1<<n);s1++){
		for(int s2=0;s2<(1<<m);s2++){
			memcpy(c1,c,sizeof(c));
			for(int i=1;i<=n;i++){
				if(s1&(1<<(i-1))){
					for(int j=1;j<=m;j++){
						c1[i][j]='r';
					}
				}
			}
			for(int i=1;i<=m;i++){
				if(s2&(1<<(i-1))){
					for(int j=1;j<=n;j++){
						c1[j][i]='r';
					}
				}
			}
			int cnt=0;
			for(int i=1;i<=n;i++){
				for(int j=1;j<=m;j++){
					cnt+=(c1[i][j]=='#');
				}
			}
			if(cnt==k){
				ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <map>
typedef long long ll;
using namespace std;

int main() {
	int n,m,sum=0;
	int a[10005];
	cin >> n >> m;
	for (int i=0; i<m; i++) {
		cin >> a[i];
		sum+=a[i];
	}
	if (sum>n) cout << -1;
	else cout << n-sum;
	return 0;
}

Measured memory_bytes: 3604
#include<stdio.h>
int main(){
  int n,m,i,j,a[30]={},t;
  scanf("%d%d",&n,&m);
  for(i=0;i<n;i++){
    scanf("%d",&j);
    for(;j;j--){
      scanf("%d",&t);
      a[t-1]++;
    }
  }
  for(i=0;i<m;i++){
    if(a[i]==n) j++;
  }
  printf("%d",j);
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int n = a;
		
		for(;;){
			if ((n%2 == 0) && (n%a == 0)){
				break;
			}
			n = n+a;
		}
		System.out.println(n);			
		
	}

}


Measured memory_bytes: 21844
import sys
from collections import deque

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    H, W = map(int, input().split())
    grid = [input() for _ in range(H)]

    res = []
    for sh in range(H):
        for sw in range(W):
            if grid[sh][sw] == "#":
                continue
            maze = [[f_inf] * W for _ in range(H)]
            maze[sh][sw] = 0
            que = deque([[sh, sw]])
            while que:
                h, w = que.popleft()
                for dh, dw in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                    next_h, next_w = h + dh, w + dw
                    if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W or grid[next_h][
                        next_w] == "#":
                        continue
                    if maze[next_h][next_w] > maze[h][w] + 1:
                        maze[next_h][next_w] = maze[h][w] + 1
                        que.append([next_h, next_w])
                        res.append(maze[next_h][next_w])
    print(max(res))


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10488
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define erep(i,a,b) for(int i=a;i<=(int)(b);i++)
#define per(i,a,b) for(int i=(b)-1;i>(a);i--)
#define eper(i,a,b) for(int i=((int)(a));i>=b;i--)
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
const int INF=(1<<30)-1;
const int MOD=1000000007;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int n, k, ans, v[200050];
set<int> s;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n >> k;
    rep(i, 0, n) {
        int x; cin >> x;
        v[x]++;
    }
    sort(v, v+200005, greater<int>());
    int kd = 0;
    rep(i, 0, k) {
        kd += v[i]; 
    }
    printf("%d\n", n-kd);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;
using vb = vector<bool>;
const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define mp make_pair
#define pb push_back
#define has(c, i) ((c).find(i) != end(c))
#define FOR(i,a,b) for (ll i=(a); i<(b); i++)
#define FORD(i,a,b) for (ll i=ll(b)-1; i >= a; i--)

vector<vector<vector<double>>> dp;
ll n;

double compute(ll c1, ll c2, ll c3) {
  if(dp[c1][c2][c3] >= 0)
    return dp[c1][c2][c3];

  double val = (double) n / (double)(c1 + c2 + c3);
  
  if(c1) {
    val += compute(c1-1, c2, c3) * c1 / (double)(c1 + c2 + c3);
  }
  if(c2) {
    val += compute(c1+1, c2-1, c3) * c2 / (double)(c1 + c2 + c3);
  }
  if(c3) {
    val += compute(c1, c2+1, c3-1) * c3 / (double)(c1 + c2 + c3);
  }

  dp[c1][c2][c3] = val;
  return val;
}

int main() {
  cout << fixed << setprecision(10);

  cin >> n;
  vl a(n);
  ll c1 = 0, c2 = 0, c3 = 0;
  FOR(i,0,n) {
    cin >> a[i];
    switch(a[i]) {
    case 1:
      ++c1;
      break;
    case 2:
      ++c2;
      break;
    case 3:
      ++c3;
      break;
    }
  }

  dp.assign(n+1, vector<vector<double>>(n+1, vector<double>(n+1, -1.0)));
  dp[0][0][0] = 0;

  cout << compute(c1, c2, c3) << endl;
}


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

using namespace std;

/*****************************************/
/*         Function prototype            */
/*****************************************/

vector<vector<int> > list_to_mat(vector<vector<int> >& adj);
void dump_mat( vector<vector<int> >& mat);
void dfs(vector<vector<int> >& adj_list, int now, vector<int>& d, vector<int>& f, int *t);
void dfs_mat(vector<vector<int> >& adj_mat, int now, vector<int>& d, vector<int>& f, int* t);
/*****************************************/
/*            Main Function              */
/*****************************************/


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

  vector<vector<int> > list(n+1);
  for(int i=0; i<n; i++){
    int u,k; cin >> u >> k;
    vector<int> tmp(k);
    for(int j=0; j<k; j++) cin >> tmp[j];
    sort(tmp.begin(),tmp.end());
    list[u] = tmp;
  }
  int t=1;
  vector<int> d(n+1,-1);
  vector<int> f(n+1,-1);
  /*
  vector<vector<int> > adj_mat = list_to_mat(list); 
  
  for(int i=1; i<=n; i++){
    for(int j=1; j<=n; j++){
      cout << adj_mat[i][j] << " ";
    }
    cout << endl;
    }*/

  //  dfs_mat(adj_mat,1,d,f,&t);
  for(int i=1; i<=n; i++)
    if(d[i] == -1)
      dfs(list,i,d,f,&t);
  
  for(int i=1; i<=n; i++){
    cout << i << " " << d[i] << " " << f[i] << endl;
  }
}



/*****************************************/
/*            Implimentation             */
/*****************************************/


void dfs_mat(vector<vector<int> >& adj_mat, int now, vector<int>& d, vector<int>& f, int* t){
  d[now] = *t;
  (*t)++;
  
  for(int i=1; i<adj_mat.size(); i++){
    if(adj_mat[now][i] == 1 && d[i] == -1)
      dfs_mat(adj_mat, i, d, f, t);
  }

  f[now] = *t;
  (*t)++;
  return ;
}


void dfs(vector<vector<int> >& adj_list, int now, vector<int>& d, vector<int>& f, int* t){
  d[now] = *t;
  (*t)++;
  
  for(auto v : adj_list[now]){
    if(d[v] != -1 || v == 0) continue;
    dfs(adj_list, v, d, f, t);
  }
  f[now] = *t;
  (*t)++;
  return ;
}


vector<vector<int> > list_to_mat(vector<vector<int> >& adj){
  const int mat_size = (int)adj.size();
  vector<vector<int> > ans(mat_size,vector<int>(mat_size,0));
  for(int i=0; i<mat_size; i++){
    for(int j=0; j<adj[i].size(); j++){
      ans[i][adj[i][j]] = 1;
      ans[adj[i][j]][i] = 1;
    }
  }
  return ans;
}


void dump_mat( vector<vector<int> >& mat){
  
  const int mat_size = (int)mat.size();
  for(int i=0; i<mat_size; i++){
    for(int j=0; j<mat[i].size(); j++){
      cout << mat[i][j];
      if(j!=mat[i].size()-1)
	cout << " ";
      else
	cout << "\n";
    }
  }
}

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

int min2(int x,int y){
    return (x > y) ? y : x;
}

int abs(int a, int b){
    return (a > b) ? a-b : b-a;
}

int minFrog(int a[], int n){
    int dp[n];
    dp[0] = 0;
    dp[1] = abs(a[0],a[1]);
    for (int i = 2; i<n; i++){
        dp[i] = min2(abs(a[i],a[i-1])+dp[i-1],abs(a[i],a[i-2])+dp[i-2]);
    }
    return dp[n-1];
}

int main(){
    int N; cin >> N;
    int A[N];
    for (int i=0; i<N; i++){
        cin >> A[i];
    }
    cout << minFrog(A,N);
    return 0;
}


Measured memory_bytes: 4360
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n, m;
    cin >> n >> m;
    VL a(n);
    REP(i,n) a[i] = in();
    sort(ALL(a));

    vector<PL> p(m);
    REP(i,m){
        p[i].second = in();
        p[i].first = in();
    }
    sort(ALL(p));
    reverse(ALL(p));

    ll ans = 0;
    ll j = 0;
    REP(i,m){
        ll x = lower_bound(ALL(a), p[i].first) - a.begin();
        chmin(x, j + p[i].second);
        chmax(x, j);
        // cout << p[i].first << " " << p[i].second << " " << x << endl;
        ans += p[i].first * (x - j);
        j = x;
    }
    // cout << ans << endl;
    // cout << j << endl;
    FOR(i,j,n-1) ans += a[i];
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2560
fun main(args: Array<String>) {
    val l = readLine()!!.toCharArray()
    val l2 = readLine()!!.toCharArray()
    var a = 0
    for (i in 0 until l.size){
        if (l[i] != l2[i]){
            a += 1
        }
    }
    println(a)
}


Measured memory_bytes: 41792
#include <stdio.h>

int main(void)
{
	int s, t;
	int *p;
	int b;
	int i;

	s = t = 0;
	for (i = 0; i < 8; i++){
		scanf("%d", &b);
		p = &t + i / 4;
		*p += b;
	}
	printf("%d\n", b=fmax(s, t));

	return (0);
}

Measured memory_bytes: 596
def main():
    H, W = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(H)]
    
    B = []
    for i in range(H):
        for j in range(W):
            if A[i][j] % 2:
                if i < H - 1:
                    B.append(i + 1)
                    B.append(j + 1)
                    B.append(i + 2)
                    B.append(j + 1)
                    A[i][j] -= 1
                    A[i + 1][j] += 1
                    continue
                elif j < W - 1:
                    B.append(i + 1)
                    B.append(j + 1)
                    B.append(i + 1)
                    B.append(j + 2)
                    A[i][j] -= 1
                    A[i][j + 1] += 1
    
    print(int(len(B) / 4))
    for i in range(0, len(B), 4):
        for j in range(i, i + 4):
            if j != i :
                print("", B[j], end = "")
            else:
                print(B[j], end = "")
        print()


if __name__ == "__main__":
    main()

Measured memory_bytes: 20404
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cout << #x " => " << (x) << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 28;
constexpr lint   INFL = 1LL << 60;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  int a, b, q;
  cin >> a >> b >> q;
  vector<lint> s(a), t(b), x(q);
  rep (i, a) cin >> s[i];
  rep (i, b) cin >> t[i];
  rep (i, q) cin >> x[i];
  vector<pair<lint, lint>> slr(a), tlr(b);
  rep (i, a) {
    int idx = lower_bound(all(t), s[i]) - t.begin();
    if (idx < b) slr[i].second = t[idx] - s[i];
    else slr[i].second = INFL;
    if (idx) slr[i].first = s[i] - t[--idx];
    else slr[i].first = INFL;
  }
  rep (i, b) {
    int idx = lower_bound(all(s), t[i]) - s.begin();
    if (idx < a) tlr[i].second = s[idx] - t[i];
    else tlr[i].second = INFL;
    if (idx) tlr[i].first = t[i] - s[--idx];
    else tlr[i].first = INFL;
  }
  vector<lint> ans(q);
  rep (i, q) {
    lint mini = LLONG_MAX, sum;
    int  tidx = lower_bound(all(t), x[i]) - t.begin();
    if (tidx < b) {
      sum  = t[tidx] - x[i] + min(tlr[tidx].first, tlr[tidx].second);
      mini = min(mini, sum);
    }
    if (tidx) {
      --tidx;
      sum  = x[i] - t[tidx] + min(tlr[tidx].first, tlr[tidx].second);
      mini = min(mini, sum);
    }
    int sidx = lower_bound(all(s), x[i]) - s.begin();
    if (sidx < a) {
      sum  = s[sidx] - x[i] + min(slr[sidx].first, slr[sidx].second);
      mini = min(mini, sum);
    }
    if (sidx) {
      --sidx;
      sum  = x[i] - s[sidx] + min(slr[sidx].first, slr[sidx].second);
      mini = min(mini, sum);
    }
    ans[i] = mini;
  }
  allrep (x, ans) cout << x << "\n";
  return 0;
}

Measured memory_bytes: 7552
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define nyan "(=^･ω･^=)"
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    cout << n-k+1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
 
void mul(ll &x, ll y){
	x *= y;
	// if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}

void solve()
{
	int n;
	cin >> n;
	int a[n];
	set<int> st;
	for(int i = 0; i < n; ++i){
		cin >> a[i];
	}
	int mn = inf, res = 0;
	for(int i = 0; i < n; ++i){
		mn = min(mn, a[i]);
		if(a[i] <= mn) ++res;
	}
	cout << res;

}

 
 
int main()
{
    Red;
  	// int T; cin >> T; while(T--)
    solve();
    return 0;
}

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

int main(void){
    int n,m;
    while(cin>>n>>m, n|m){
        vector<int> a(n);
        rep(i,n){
            cin>>a[i];
        }
        int res = 0;
        rep(i,n)rep(j,i){
            int sum = a[i]+a[j];
            if(sum <= m){
                res = max(res,sum);
            }
        }
        if(res == 0) cout<<"NONE"<<endl;
        else cout<<res<<endl;
    }    
    return 0;
}



Measured memory_bytes: 3056
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
//#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

vector<int> init(int size){
  vector<int> par(size,-1);
  return par;
}

int root(int x, vector<int>& par){
  if(par[x] < 0){
    return x;
  }else{
    return par[x] = root(par[x],par);
  }
}

bool same(int x, int y, vector<int>& par){
  return root(x, par) == root(y, par);
}

void unite(int x, int y, vector<int>& par){
  x = root(x, par), y = root(y, par);
  if(same(x,y, par))return;
  par[x] += par[y];
  par[y] = x;
}

int size(int x, vector<int>& par){
  return -par[root(x, par)];
}

int pow(int x, int n){
  if(n == 0)return 1;
  if(n % 2 == 0)return pow(x * x % MOD, n/2);
  else return x * pow(x, n-1) % MOD;
}


signed main(){
  int n,a,b,c,d;string s;cin>>n>>a>>b>>c>>d>>s;a--;b--;c--;d--;
  bool can = true;
  if(c < d){
    repd(i,b,d){
      if(s[i] == '#' && s[i+1] == '#'){
        can = false;break;
      }
    }
    repd(i,a,c){
      if(s[i] == '#' && s[i+1] == '#'){
        can = false;break;
      }
    }
  }else{
    repd(i,a,c){
      if((s[i] == '#' && s[i+1] == '#')){
        can = false;break;
      }
    }
    int cnt = 0;
    repd(i,b,d+1){
      if(s[i] == '.' && s[i-1] == '.' && s[i+1] == '.')cnt++;
      if(s[i] == '#' && s[i+1] == '#'){
        can = false;break;
      }
    }
    if(cnt == 0)can = false;
  }
  cout << (can ? "Yes" : "No") << endl;
}


Measured memory_bytes: 640
import Control.Applicative
import Data.List
import qualified Control.Monad as Monad
import Text.Printf

main :: IO ()
main = calcList  

calcList :: IO()
calcList = do 
  ns <- fmap(fmap (read :: String -> Int) . words) .lines <$> getContents 
  let list = tail $ foldl1 (++) ns
  let min = minimum list 
  let max= maximum list 
  let sum = foldl1 (+) list 
  printf "%d %d %d\n" min max sum


Measured memory_bytes: 11220
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647 >> 1); // 10^9 + 5000
static const ll LLINF = (9223372036854775807 >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;

namespace Kunitaka{
    template<
        typename TYPE,
        std::size_t SIZE
    >
    std::size_t array_length(const TYPE (&array)[SIZE])
    {
        return SIZE;
    }
}
using namespace Kunitaka;
namespace Printer{
    void br(){
        cout << endl;
    }

    void loop_cnt(int i){
        cout << "i = " << i << endl;
    }

    void loop_cnt(int i, int j){
        cout << "i = " << i << ", " << "j = " << j << endl;
    }

    template<class T>
    void print(T x){
        cout << x << endl;
    }

    template<class T, class S>
    void print(T x, S y){
        cout << x << "," << y << endl;
    }

    template<class T, class S, class U>
    void print(T x, S y, U z){
        cout << x << "," << y << "," << z << endl;
    }

    template<class T, class S>
    void print(pair<T, S> p){
        cout << p.first << ", " << p.second << endl;
    }

    template<
        typename TYPE,
        std::size_t SIZE
    >
    void print(const TYPE (&array)[SIZE]){
        int lim = array_length(array);
        for(int i=0; i<lim; i++){
            if(i) cout << " ";
            cout << array[i];
        }
        cout << endl;
    }

    template<class S>
    void print(vector<S> v){
        for(int i=0; i<v.size(); i++){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    template<class S>
    void print(vector<vector<S> > vv){
        for(int i=0; i<vv.size(); i++){
            for(int j=0; j<vv[i].size(); j++){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }

    void yesno(bool x){
        if(x) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
};
using namespace Printer;

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//


    // input
    cout << fixed << setprecision(10);
    int N, M; cin >> N >> M; 
    string str; cin >> str;

    ll ans = 0;
    vector<int> v(N+1, 0);
    int bef = 0;
    for(int i=N; i>=0; i--){
        if(i == N) {
            bef = i;
            v[i] = i;
            continue;
        }
        if(str[i] == '1'){
            v[i] = bef;
        }
        else{
            bef = i;
            v[i] = i;
        }
    }
    vector<int> path;
    int now = N;
    while(1){
        ans++;
        int next = now - M;
        if(next < 0){
            if(now != 0) path.push_back(now);
            break;
        }
        if(now == v[next]){
            cout << -1 << endl;
            return 0;
        }
        path.push_back(now - v[next]);
        now = v[next]; 
    }
    reverse(ALL(path));

    print(path);
    
    return 0;
}


Measured memory_bytes: 1912
import java.util.*;
import java.math.*;

public class Main {

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

    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
    }

    int k = 1;
    int l = 1;

    for (int i = 0; i < n; i++) {
      k *= 3;

      if (a[i]%2 == 0) {
        l *= 2;
      }
    }

    System.out.println(k-l);


  }

}


Measured memory_bytes: 21716
k = int(input())
if k < 10:
    print(k)
else:
    k -= 9
    run= {}
    run[1] = {i: 1 for i in range(0, 10)}
    now_dig = 1
    flag = 0
    flag2 = 0
    ans = 0
    while flag == 0:
        now_dig += 1
        run[now_dig] = {}
        for num in range(0, 10):
            if num == 0:
                run[now_dig][num] = run[now_dig-1][num] + run[now_dig-1][num+1]
            elif num == 9:
                run[now_dig][num] = run[now_dig-1][num-1] + run[now_dig-1][num]
            else:
                run[now_dig][num] = run[now_dig-1][num-1] + run[now_dig-1][num] + run[now_dig-1][num+1]
            if num != 0 and k - run[now_dig][num] > 0:
                k -= run[now_dig][num]
            elif num != 0:
                flag = 1
                # print(k, now_dig, num)
                ans += num*pow(10, now_dig-1)
                while now_dig > 1:
                    now_dig -= 1
                    if num == 0:
                        now_num = 0
                        end = 1
                    elif num == 9:
                        now_num = 8
                        end = 9
                    else:
                        now_num = num - 1
                        end = num + 1
                    while k - run[now_dig][now_num] > 0 and now_num <= end:
                        k -= run[now_dig][now_num]
                        now_num += 1
                    ans += now_num*pow(10, now_dig-1)
                    num = now_num
                break
        # print(now_dig, run[now_dig])

    print(ans)


Measured memory_bytes: 3064
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h> //STL include
typedef long long ll;// long long int
const ll INF = 10000000000;//INFinity
using namespace std;//namespace

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

//#define int long long // yabai

#define dump(x)  cout << #x << " = " << (x) << endl;// debug cout

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

#define ALL(obj) (obj).begin(),(obj).end()// iterator

#define pb(a) push_back(a)//push_back
#define mp make_pair// make_pair


int main(){
    vector<bool> prime(100001,true);
    FOR(i,2,317)if(prime[i])for(int j=2;i*j<=100000;++j)prime[i*j]=false;
    prime[0]=false;prime[1]=false;
    vector<int>similar(100001,0);
    FOR(i,3,100000)similar[i]=(i%2==1&&prime[i]&&prime[(i+1)/2]?similar[i-1]+1:similar[i-1]);

    int q;
    cin>>q;
    
    vector<pair<int,int>> p(q);
    REP(i,q)cin>>p[i].first>>p[i].second;
    //REP(i,q)cout<<accumulate(similar.begin()+p[i].first,similar.begin()+p[i].second+1,0)<<endl;

    REP(i,q)cout<< similar[p[i].second] - similar[p[i].first-1] <<endl;
    

    


    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
typedef long long ll;
using namespace std;

int main(){
  string s,t,u;
  cin>>s>>t;
  int a,b;
  cin>>a>>b;
  cin>>u;
  if(s==u) a--;
  else b--;
  cout<<a<<" "<<b<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>

using namespace std;

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

	int x;
	cin >> x;
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			if (i * j == x) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>
 
using namespace std;
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
int main(){
	int a, b, n; cin >> n;
	a = b = 0;
 
	REP(i, n){
		int val; cin >> val;
		if( val % 4 == 0 ) a++;
		else if( val % 2 == 0) b++;
	}
 
	b = max(0, b - 1);
 
	if( a >= (n - b) / 2 ){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
 
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    string s, t; cin >> s >> t;
    int n = sz(s);
    int cnt = 0;
    rep(i, n) if (s[i]!=t[i]) cnt++;
    cout << cnt << endl;
}

Measured memory_bytes: 3860
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;

const int maxN = 300000;
const int INF = maxN*2; // tmp num
int main(){
  int N;
  string S;
  cin >> N >> S;
  int Ecnt[maxN+1];
  int Wcnt[maxN+1];
  Wcnt[0] = 0;
  for(int i=0;i<N;i++)
    Wcnt[i+1]=Wcnt[i]+(S[i]=='W'?1:0);
  Ecnt[N] = 0;
  for(int i=N-1;i>=0;i--)
    Ecnt[i]=Ecnt[i+1]+(S[i]=='E'?1:0);
  int ans = INF;
  for(int i=0;i<N;i++){ // leader
    // cerr<< i << ": "<< Wcnt[i] << ", " << Ecnt[i+1]<<endl;
    ans = min(ans, Wcnt[i]+Ecnt[i+1]);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3076
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const long long mod = 1e9+7;

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

  vector<bool> oks(N + 1, true);
  int _a;
  for(int i = 0; i < M; ++i) {
    cin >> _a;
    oks[_a] = false;
  }

  vector<long long> dp(N + 1, 0);
  dp[0] = 1;
  for(int now = 0; now < N; ++now) {
    for (int next = now + 1; next <= min(N, now + 2); ++next) {
      if(oks[next]){
        dp[next] += dp[now];
        dp[next] %= mod;
      }
    }
  }

  cout << dp[N] << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define REP(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define INF 1000000000
#define ll long long

using namespace std;

typedef pair<int, int> P;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int N, ans;
ll int a;
set<ll int> s;

int main(){
    scanf("%d", &N);

    REP(i, N){
        scanf("%lld", &a);
        if(s.find(a) == s.end()){
            s.insert(a);
        } else {
            s.erase(a);
        }
    }

	printf("%d\n", s.size());

	return 0;
}

Measured memory_bytes: 4864
import java.util.*;
public class Main {
	
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int[] l = new int[N];
		for(int i=0;i<N;i++) {
			l[i] = sc.nextInt();
		}
		System.out.println((int) finpoit(N,l,A,B,C,0,0,0,0));
		
	}
	
	//A用の棒(合成後の長さ), B,C同様と現在の消費ポイントあら最終ポイントを返す
	public static double finpoit(int N,int[]l, int A,int B, int C, int a, int b, int c, int cur) {
		if(cur==N) {
			if(a>0 && b>0 && c>0)  return Math.abs(A-a)+Math.abs(B-b)+Math.abs(C-c) -30;
			else return Double.POSITIVE_INFINITY;
		}
		else {
			double c1 = finpoit(N,l,A,B,C,a+l[cur],b,c,cur+1)+10;
			double c2 = finpoit(N,l,A,B,C,a,b+l[cur],c,cur+1)+10;
			double c3 = finpoit(N,l,A,B,C,a,b,c+l[cur],cur+1)+10;
			double c4 = finpoit(N,l,A,B,C,a,b,c,cur+1);
			return Math.min(Math.min(c1, c2), Math.min(c3, c4));
		}
	}
}


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


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

	string S;
	cin >> S;

	vector<int> l(Q), r(Q);
	for (int i = 0; i < Q; ++i) {
		cin >> l[i] >> r[i];
		--l[i]; --r[i];
	}

	vector<int> sums1(N + 1), sums2(N + 1);
	for (int i = 0; i < N; ++i) {
		if (i < N - 1 && S[i] == 'A' && S[i + 1] == 'C') {
			sums1[i + 1] = sums1[i] + 1;
		}
		else {
			sums1[i + 1] = sums1[i];
		}
	}
	for (int i = 0; i < N; ++i) {
		sums2[i + 1] = sums1[i];
	}

	for (int i = 0; i < Q; ++i) {
		cout << min(sums2[r[i] + 1], sums1[r[i] + 1]) - max(sums2[l[i]], sums1[l[i]]) << endl;
	}
}


Measured memory_bytes: 2688
#include<stdio.h>
int main(void)
{
  int n;
  scanf("%d",&n);

  int h[n], i, count, j, max;

  for (i=0; i<n; i++){
    scanf("%d",&h[i]);
  }

  count=1;
  max = h[0];

  for (i=0; i<n-1; i++){
    j=i+1;
    if(h[j]>=h[i]&&h[j]>=max){
      count++;
      max=h[j];
    }
  }

  printf("%d",count);

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<'YES'<<endl;}else{cout<<'NO'<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 200002
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
typedef pair<int,ll> Pil;
typedef pair<ll,ll> Pll;
typedef pair<string,int> Psi;
typedef pair<Psi,int> Psii;

const int inf=1000000000;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

ll d[13][100001]={};
int r[100000]={};
int l[100000]={};
int t[100000]={};
int main() {
	int k,x;
	cin>>k>>x;
	cout<<x-k+1;
	rep(i,2*k-2){
		cout<<" "<<(x-k+2+i);
	}
	cout<<endl;
	return 0;
}


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


int main () {
    string str;
  	int m;
    cin >> str;
    cin >> m;
  	int n = str.length();
  	set <string> st;
    for (int i = 0; i < n; i++)
        for (int j = 1; i + j <= n && j <= 5; j++)
            st.insert(str.substr(i, j));
    auto itr = st.begin();
    cout << *next(itr, m-1) << endl;
}


Measured memory_bytes: 1664
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1000010;
ll n,ans,a[N];
int len,m,x,s,vis[N];
int main(){
	scanf("%lld%d%d",&n,&x,&m);
	a[1]=x;
	for(int i=2;i<=n;i++){
		a[i]=1ll*a[i-1]*a[i-1]%m;
		if(vis[a[i]]){
			len=i-vis[a[i]];
			s=vis[a[i]];
			break;
		}
		vis[a[i]]=i;
	}
	if(!len){
		s=1;
		len=n;
	}
	for(int i=1;i<=s+len-1;i++)
		a[i]+=a[i-1];
	ans+=a[s-1];
	if((n-s+1)%len)
		ans+=(a[s+len-1]-a[s-1])*((n-s+1)/len)+a[(n-s)%len+s]-a[s-1];
	else ans+=(a[s+len-1]-a[s-1])*((n-s+1)/len);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3992
/**
 * D - RGB Tripletsc
 * https://atcoder.jp/contests/abc162/tasks/abc162_d
 */
#include <bits/stdc++.h>
using namespace std;

int main() {
    // R, G, B のみからなる、長さ N の文字列 S があります。
    int N;
    string S;
    cin >> N >> S;

    // 以下の 2 つの条件をともに満たす組 (i, j, k) (1≤i<j<k≤N) の数を求めてください。
    // Si≠Sj かつ Si≠Sk かつ Sj≠Sk である
    // j−i≠k−j である
    long long r = 0, g = 0, b = 0;
    for (long long i = 0; i < N; i++) {
        if (S[i] == 'R') {
            r++;
        } else if (S[i] == 'G') {
            g++;
        } else if (S[i] == 'B') {
            b++;
        }
    }

    // Si≠Sj かつ Si≠Sk かつ Sj≠Sk である
    // RとGとBの組み合わせによって決まる
    long long cnt = r * g * b;

    for (long long i = 0; i < N; i++) {
        for (long long j = i + 1; j < N; j++) {
            long long k = 2 * j - i;
            if (k >= N) {
                continue;
            }

            // Si≠Sj かつ Si≠Sk かつ Sj≠Sk である
            if  (S[i] != S[j] && S[i] != S[k] && S[j] != S[k]) {
                cnt -= 1;
            }
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end() 
#define SZ(x) (int)x.size()
#define f first
#define s second
const int MAXN=7;
const int MAXK=18;
const int INF = 1e9;
const ll MOD = 1e9+7;

ll N,R,C,K,a;
vector<pair<double,ll>> pos,neg;
vi A;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>N>>K;
	ll c=0;
	bool hazero=0;
	for(int i=0;i<N;++i){
		cin>>a;
		if(a==0){hazero=1;continue;}
		A.pb(abs(a));
		double H = log2((double)abs(a));
		if(a>0)pos.pb(H,c);
		else if(a<0)neg.pb(H,c);
		++c;
	}
	N=SZ(pos)+SZ(neg);
	if(N<K){
		cout<<0;
		return 0;
	}
	sort(ALL(pos));reverse(ALL(pos));
	sort(ALL(neg));reverse(ALL(neg));
	if((SZ(pos) == 0) && K%2==1){
		if(hazero){cout<<0;return 0;}
		reverse(ALL(neg));
		// choose the smallest few
		ll ans=1;
		for (int i=0;i<K;++i){
			ans=ans*abs(A[neg[i].s])%MOD;
		}
		cout<<(MOD-ans)%MOD;
		return 0;
	}else if(N==K && SZ(neg)%2==1){
		if(hazero){cout<<0;return 0;}
		// choose the smallest few
		ll ans=1;
		for(auto i:A)ans=ans*i%MOD;
		cout<<(MOD-ans)%MOD;
		return 0;
	}else {
		ld maxsum=-1;
		ll num_neg=0;
		for(int n=0;n<=K;n+=2){
			ll p=K-n;
			// cerr<<p<<' '<<n<<'\n';
			ld cur=0;
			if(p>SZ(pos)||n>SZ(neg))continue;
			for(int i=0;i<p;++i)cur+=pos[i].f;
			for(int i=0;i<n;++i)cur+=neg[i].f;
			// cout<<cur<<'\n';
			if(cur>maxsum){
				num_neg=n;
				maxsum=cur;
			}
		}
		ll p=K-num_neg;
		ll cur=1;
		for(int i=0;i<p;++i)cur=cur*A[pos[i].s]%MOD;
		for(int i=0;i<num_neg;++i)cur=cur*A[neg[i].s]%MOD;
		cout<<cur;
	}
}

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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 100007;
const int MOD = 1e9 + 7;

int n;
int a[MAXN];
LL frac[MAXN];

void init ();
void input ();
void work ();



int main()
{
	init();
	input();
	work();
}



void init ()
{
	// Init Everything Here
	
	ios::sync_with_stdio ( false );

	frac[0] = 1;
	lp ( i, 1, MAXN ) frac[i] = ( frac[i-1] * i ) % MOD;
}

void input ()
{
	// input method

	scanf ( "%d", &n );
	lpi ( i, 1, n ) scanf ( "%d", &a[i] );
}

void work ()
{
	// main work

	LL ans = 1;

	int np = 1, no = 0;
	lpi ( i, 1, n ){
		if ( a[i] < np ) ans = ( ans * ( i - no ) ) % MOD, ++no;
		else np += 2;
	}
	ans = ( frac[n-no] * ans ) % MOD;
//	lp ( i, 0, no ) ans = ( ans * 2 ) % MOD;
	printf ( "%lld\n", ans );
}

Measured memory_bytes: 1408
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	H, W := nextInt(), nextInt()
	S := make([]string, H)
	for i := 0; i < H; i++ {
		S[i] = next()
	}

	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			if S[i][j] == '.' {
				continue
			}

			// up
			if i != 0 && S[i-1][j] == '#' {
				continue
			}
			// down
			if i != H-1 && S[i+1][j] == '#' {
				continue
			}
			// left
			if j != 0 && S[i][j-1] == '#' {
				continue
			}
			// right
			if j != W-1 && S[i][j+1] == '#' {
				continue
			}

			fmt.Println("No")
			return
		}
	}

	fmt.Println("Yes")
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
// combination mod prime
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};
 int main() {
  int x, y;
  cin >> x >> y;
  if ((x+y)%3) {
    cout << 0 << endl;
    return 0;
  }
  int n = (x+y)/3;
  x -= n; y -= n;
  if (x < 0 || y < 0) {
    cout << 0 << endl;
    return 0;
  }
  combination c(x+y);
  mint ans = c(x+y,x);
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 10624
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

//macro
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define EPS (1e-8)
#define equals(a,b)(fabs((a)-(b))<EPS)

using ll = long long;
using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vvll = vector<vll>;
//func
template<typename A, typename T>void assign2d(A&arr, ll H, ll W, T t) { arr.resize(H); REP(i, H) arr[i].assign(W, t); }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); REP(i, n)os << v[i] << (i == n - 1 ? "" : " "); return os; }
template <class T = int> inline T IN() { T x; cin >> x; return x; }
template<class T> inline void OUT(const T &x) { cout << x << "\n"; }
void YESNO(bool c) { OUT(c ? "YES" : "NO"); };
void YesNo(bool c) { OUT(c ? "Yes" : "No"); };
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); /*cout << fixed << setprecision(6);*/ } } pre__;

int main() {
	string S;
	cin >> S;
	YesNo(S[0] == '9' || S[1] == '9');
}

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

int main()
{
    int S,h,m,s;
    scanf("%d",&S);
    s=S%60;
    S/=60;
    m=S%60;
    S/=60;
    h=S;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}

Measured memory_bytes: 1860
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    A, B, C, K = [int(i) for i in input().split()]

    ans = 0

    if A >= K:
        ans += K
        return ans
    else:
        ans += A
        K -= A

    if B >= K:
        return ans
    else:
        K -= B

    return ans-K


if __name__ == "__main__":
    print(main())


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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef pair<int,int> ii;

long long n,k,mod,c[305][305],f[305][305],g[305][305],h[305][305];

int main(){
    cin.tie(0),cout.tie(0),ios::sync_with_stdio(0);
    cin >> n >> k >> mod;
    c[0][0] = 1;
    for(int i = 1;i<=300;i++){
        c[i][0] = 1;
        for(int j = 1;j<=i;j++){
            c[i][j] = c[i-1][j-1] + c[i-1][j];
            c[i][j]%=mod;
        }
    }
    for(int i = 0;i<=302;i++)
        h[0][i] = 1;
    for(int i = 1;i<=n;i++){
        for(int j = k;j>=0;j--){
            f[i][j] = h[i-1][j+1]%mod;
            g[i][j] = g[i][j+1]+f[i][j];
            g[i][j]%=mod;
        }
        for(int j = 0;j<=k;j++){
            for(int l =1;l<=i;l++){
                h[i][j] += ((h[i-l][j]*g[l][j]%mod)*c[i-1][l-1])%mod;
                h[i][j]%=mod;
            }
        }
    }
    cout<<h[n][1]%mod;
}


Measured memory_bytes: 3200
N = int(input().strip())
A = list(map(int, input().strip().split()))

if N % 2 == 0:
  dp = [[0 for _ in range(N)] for _ in range(2)]
  dp[0][0] = A[0]
  dp[1][1] = A[1]
  for i in range(2, N):
    if i % 2 == 0:
      dp[0][i] = dp[0][i-2] + A[i]
    else:
      dp[1][i] = max(dp[1][i-2], dp[0][i-3]) + A[i]
  print(max(dp[-1][-1], dp[-2][-2]))
else:
  dp = [[0 for _ in range(N)] for _ in range(3)]
  dp[0][0] = A[0]
  dp[1][1] = A[1]
  dp[2][2] = A[2]
  for i in range(2, N):
    if i % 2 == 0:
      dp[0][i] = dp[0][i-2] + A[i]
      dp[2][i] = max(dp[0][i-4], dp[1][i-3], dp[2][i-2]) + A[i]
    else:
      dp[1][i] = max(dp[1][i-2], dp[0][i-3]) + A[i]
  print(max(dp[-1][-1], dp[-2][-2], dp[-3][-3]))


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

typedef long long ll;

const int maxn = 1e5 + 10, mod = 1e9 + 7;
int n, m;
ll ans, x[maxn], y[maxn], w[maxn], h[maxn];

int main(){
	scanf("%d%d", &n, &m);
	n--; m--;

	for(int i = 1; i <= n + 1; i++){
		scanf("%lld", x + i);
		w[i - 1] = x[i] - x[i - 1];
	}

	for(int i = 1; i <= m + 1; i++){
		scanf("%lld", y + i);
		h[i - 1] = y[i] - y[i - 1];
	}

	ll row = 0;

	for(int i = 1; i <= n; i++){
		row = (row + (w[i] * i % mod) * (n - i + 1)) % mod;
	}

	for(int i = 1; i <= m; i++){
		ans = (ans + (h[i] * row % mod) * i * (m - i + 1)) % mod;
	}

//	printf("%lld\n", row);

	printf("%lld\n", ans);

	return 0;
}

/*

5 3
1 2 4 5 6
1 2 3

*/


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << -1; return;}
#define mkp make_pair
#define cerr if (0) cerr

void solve() {
    string t; cin >> t;
    loop(i, t.size())
        cout << (t[i] == '?' ? 'D' : t[i]);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

Measured memory_bytes: 3772
import sys
from operator import or_
input=sys.stdin.readline


class SegTree():
    def __init__(self, N, e=float("inf"), operator_func=min):
        self.e = e
        self.size = N
        self.node = [self.e] * (2*N)
        self.op = operator_func

    def set_list(self, l):
        for i in range(self.size):
            self.node[i+self.size-1] = l[i]
        for i in range(self.size-1)[::-1]:
            self.node[i] = self.op(self.node[2*i+1], self.node[2*i+2])
    
    def update(self, k, x):
        k += self.size - 1
        self.node[k] = x
        while k >= 0:
            k = (k - 1) // 2
            self.node[k] = self.op(self.node[2*k+1], self.node[2*k+2])

    def get(self, l, r):
        x = self.e
        l += self.size; r += self.size
        a, b = [], []

        while l<r:
            if l&1:
                a += [l-1]; l += 1
            if r&1:
                r -= 1; b += [r-1]
            l >>= 1; r >>= 1

        for i in a+(b[::-1]):
            x = self.op(x, self.node[i])
        return x


def main():
    N = int(input())
    S = list(input())[:-1]
    trees = {chr(97+i):SegTree(N, e=False, operator_func=or_) for i in range(26)}

    for i, s in enumerate(S):
        trees[s].update(i, True)

    Q = int(input())
    for _ in range(Q):
        mode, i, v = input().split()
        if mode=="1":
            i = int(i)-1
            trees[S[i]].update(i, False)
            trees[v].update(i, True)
            S[i] = v
        else:
            i = int(i)-1
            v = int(v)
            ans = 0
            for j in range(26):
                ans += trees[chr(97+j)].get(i, v)
            print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 272960
n,k=map(int,input().split())
A=list(map(int,input().split()))

last=[-1]*(2*10**5+1)
nex=[-1]*n
prog=[0]*n

for i,a in enumerate(A*2):
    l=last[a]
    last[a]=i%n
    if nex[l]==-1 and l!=-1:
        nex[l]=(i+1)%n
        if i>=n or i+1==n:
            prog[l]=1
if nex[-1]==0:
    prog[-1]+=1

flag=False #いっぱいループ済か
stage=0
now=0
roop=[-1]*n
while True:
    if roop[now]!=-1 and flag==False:
        flag=True
        rr=stage-roop[now]
        stage=k-1-(k-1-stage)%rr
    if stage+prog[now]>=k:
        break
    roop[now]=stage
    stage+=prog[now]
    now=nex[now]

A=A[now:]+A if k-1-stage else A[now:]
check=[0]*(2*10**5+1)
stack=[]
for a in A:
    if check[a]:
        while check[a]:
            check[stack.pop()]=0
        continue
    stack.append(a)
    check[a]=1

print(*stack)


Measured memory_bytes: 41220