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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()

typedef long long lint;
typedef double Double;
typedef pair< int, int > pii;

int dx[6] = {0,1,1,0,-1,-1};

int dy[2][6] = {
	{1,1,0,-1,0,1},
	{1,0,-1,-1,-1,0}
};

int H, W, Q;
string hanic[55];

void rotate(int x, int y) {
	if (x == 0 || y == 0 || x == W - 1 || y == H - 1) return;
	
	int xp = x % 2;
	char piv = hanic[y + dy[xp][5]][x + dx[5]];
	
	for_rev(i,5,1) {
		hanic[y + dy[xp][i]][x + dx[i]] = hanic[y + dy[xp][i - 1]][x + dx[i - 1]];
	}
	
	hanic[y + dy[xp][0]][x + dx[0]] = piv;
}

void fall() {
	bool update = true;
	
	while (update) {
		update = false;
		
		for (int i = 1; i < H && !update; ++i)
		for (int j = 0; j < W && !update; ++j) {
			if (hanic[i][j] == '.') continue;
			
			bool fal = true;
			for_(d,2,5) {
				if (j == 0 && d == 4) continue;
				if (j == W - 1 && d == 2) continue;
				fal &= (hanic[i + dy[j % 2][d]][j + dx[d]] == '.');
			}
			
			if (fal) {
				hanic[i + dy[j % 2][3]][j + dx[3]] = hanic[i][j];
				hanic[i][j] = '.';
				update = true;
			}
		}
	}
}

bool vis[55][55];

void rec(int x, int y, char col, vector< pii >& vp) {
	vp.push_back(pii(x, y));
	vis[y][x] = 1;
	
	for_(d,0,6) {
		int nx = x + dx[d], ny = y + dy[x % 2][d];
		if (nx < 0 || nx >= W || ny < 0 || ny >= H) continue;
		if (vis[ny][nx]) continue;
		if (hanic[ny][nx] == col) rec(nx, ny, col, vp);
	}
}

bool vanish() {
	minit(vis, 0);
	bool res = false;
	
	for_(y,0,H) for_(x,0,W) {
		if (!vis[y][x] && hanic[y][x] != '.') {
			vector< pii > vp;
		
			rec(x, y, hanic[y][x], vp);
			
			if (vp.size() >= 3) {
				for (size_t i = 0; i < vp.size(); ++i) {
					pii p = vp[i];
					hanic[p.second][p.first] = '.';
				}
				
				res = true;
			}
		}
	}
	
	return res;
}

int main() {
	cin >> H >> W;
	
	for_(i,0,H) cin >> hanic[H - i - 1];
	
	fall();
	while (vanish()) fall();
	
	cin >> Q;
	for_(i,0,Q) {
		int x, y;
		cin >> x >> y;
		rotate(x, y);
		fall();
		while (vanish()) fall();
	}
	
	for_(i,0,H) cout << hanic[H - i - 1] << endl;
}


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

int main(){
  int n;
  cin>>n;
  vector<int>a(n);
  rep(i,n){
    cin>>a[i];
  }
 
  sort(a.begin(),a.end());

  string ans="YES";
  rep(i,n-1){
    if(a[i]==a[i+1]){
      ans="NO";
      break;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

int main()
{
    int H, W, h, w;
    cin >> H >> W >> h >> w;

    int a = 0;
    int b = 0;

    for (int y = 0; y < H; y += h) {
        for (int x = 0; x < W; x += w) {
            ++a;
            if (x + w - 1 < W && y + h - 1 < H)
                ++b;
        }
    }

    if (a == b) {
        cout << "No\n";
        return 0;
    }

    cout << "Yes\n";

    int p = b / (a - b) + 1;
    int n = -p - 1;

    vector<vector<int>> m(H, vector<int>(W, 0));
    for (int y = 0; y < H; y += h) {
        for (int x = 0; x < W; x += w) {
            m[y][x] = p;
            if (x + w - 1 < W && y + h - 1 < H)
                m[y + h - 1][x + w - 1] = n;
        }
    }

    for (int y = 0; y < H; ++y) {
        for (int x = 0; x < W; ++x) {
            if (x > 0)
                cout << ' ';
            cout << m[y][x];
        }
        cout << '\n';
    }

    return 0;
}


Measured memory_bytes: 2304
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <queue>

using namespace std;

long long lim = 1000000007;
int H, W;
vector<vector<long long>> combinations;
vector<vector<bool>> table;

long long get(int h, int w){
  if(h < 0 || h == H) return 0;
  if(w < 0 || w == W) return 0;
  if(table[h][w]) return 0;
  if(combinations[h][w] != -1) return combinations[h][w];

  combinations[h][w] = get(h-1, w) + get(h, w-1);
  if(combinations[h][w] > lim) combinations[h][w] %= lim;
  return combinations[h][w];
}

int main() {
  //
  cin >> H >> W;
  combinations.resize(H);
  table.resize(H);
  for (int i = 0; i < H; ++i) {
    combinations[i] = vector<long long>(W, -1);
    table[i] = vector<bool>(W, false);
  }

  char c;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      cin >> c;
      if(c == '#') table[i][j] = true;
    }
  }

  combinations[0][0] = 1;
  long long i = get(H-1, W-1);
  cout << i << endl;

//  for (int i = 0; i < H; ++i) {
//    for (int j = 0; j < W; ++j) {
//      cout << combinations[i][j] << " ";
//    }
//    cout << endl;
//  }


  return 0;
}




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


char decode(int a,int b){
	int x=a*5+b;
	if(x<26)return x+'a';
	return ".?! "[x-26];
}

int main(){
	string s;
	while(cin>>s){
		bool f=true;
		string res;
		if(s.size()%2){
			f=false;
		}
		for(int i=0;f&&i<s.size();i+=2){
			if('1'<=s[i]&&s[i]<='6' && '1'<=s[i+1]&&s[i+1]<='5'){
				res+=decode(s[i]-'1',s[i+1]-'1');
			}else f=false;
		}
		if(f)cout<<res;
		else cout<<"NA";
		cout<<endl;
	}
	return 0;
}

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

int main(){
  int n, m;  scanf("%d %d", &n, &m);
  int **graph;
  graph = (int**)malloc(sizeof(int*)*(n+22));
  for(int i=0; i<n+22; i++)
    graph[i] = malloc(sizeof(int)*(m+22));
  while(m--){
    int a, b;  scanf("%d %d", &a, &b);
    graph[a][++graph[a][0]] = b;
    graph[b][++graph[b][0]] = a;
  }

  int ans[100005] = {0}, anscount = 0;  ans[1] = 1;
  int queue[100000], front = 0, rear = 0, qsize = 100000;
  queue[rear++] = 1;
  while(front != rear){
    int now = queue[front];  front = (front+1)%qsize;
    for(int i=1; i<=graph[now][0]; i++)
      if(!ans[graph[now][i]]){
	ans[graph[now][i]] = now;
	queue[rear] = graph[now][i];
	rear = (rear+1)%qsize;
	anscount++;
      }
  }

  printf("Yes\n");
  for(int i=2; i<=n; i++)
    printf("%d\n", ans[i]);
  
  return 0;
}


Measured memory_bytes: 556664
#include <iostream>
#include <queue>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
int N = 0, M = 0;


void bfs(std::vector<std::vector<int>> G){
	std::vector<int> parent(N, -1);
	std::queue<int> q;
	int visit_cnt = 1;
	parent[0] = 0;
	q.push(0);

	while(!q.empty()){
		int f = q.front();
		q.pop();

		for(int i : G[f]){
			if(parent[i] != -1) continue;
			parent[i] = f;
			q.push(i);
			visit_cnt++;
		}
	}

	if(visit_cnt < N) std::cout << "No" << std::endl;
	else {
		std::cout << "Yes" << std::endl;
		for(int i = 1; i < N; i++) std::cout << (parent[i] + 1) << std::endl;
	}
	return;
}


int main(void){
	int a, b;
	std::cin >> N >> M;
	std::vector<std::vector<int>> G(N);
	rep(i, M){
	       std::cin >> a >> b;
	       G[a-1].push_back(b-1);
	       G[b-1].push_back(a-1);
	}

	bfs(G);
	return 0;
}


Measured memory_bytes: 15904
#include<stdio.h>
#include<math.h>
int prcheck(int n)
{
	int i, lim;
	lim = sqrt(n);
	if(!(n%2) && n!=2) return 0;
	for(i=3; i<=lim; i++)
		if(!(n%i)) return 0;
	return 1;
}
int main()
{
	int n;
	while(~scanf("%d" ,&n))
	{
		while(1)
			if(prcheck(n++)) break;
		printf("%d\n", --n);
	}
	return 0;
}

Measured memory_bytes: 888
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

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

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int main() {
    int a,b;
    cin >> a >> b;
    
    bool flag = false;
    rep(i, 1011) {
        int t_a = i * 0.08;
        int t_b = i * 0.10;

        if(a==t_a&&t_b==b) {
            print(i);
            flag = true;
            break;
        }
    }

    if(!flag) {
        print("-1");
    }
    return 0;
}


Measured memory_bytes: 256
mod = 10**9+7
N,K = map(int,input().split())
M = int(N**0.5)
dp = [[0]*M for _ in range(K+1)]
dp1 = [[0]*M for _ in range(K+1)]
dp2 = [[0]*M for _ in range(K+1)]

dp[0][0] = 1
dp1[0][0] = 1
dp2[0][0] = N
for m in range(1,M):
    dp[0][m] = 1
    dp1[0][m] = dp1[0][m-1]+dp[0][m]
    dp2[0][m] += dp2[0][m-1]+N//(m+1)*dp[0][m]

dp[1][0] = N
dp1[1][0] = N
dp2[1][0] = N**2
for m in range(1,M):
    dp[1][m] = N//(m+1)
    dp1[1][m] = dp1[1][m-1]+dp[1][m]
    dp2[1][m] += dp2[1][m-1]+N//(m+1)*dp[1][m]


for k in range(1,K):
    for m in range(M):
        dp[k+1][m] = dp1[k][M-1]+N//(m+1)*dp1[k-1][m]+dp2[k-1][M-1]-dp2[k-1][m]-M*dp1[k-1][M-1]
        dp[k+1][m] %= mod
        dp1[k+1][m] = dp1[k+1][m-1]+dp[k+1][m]
        dp1[k+1][m] %= mod
        dp2[k+1][m] = dp2[k+1][m-1]+N//(m+1)*dp[k+1][m]
        dp2[k+1][m] %= mod

print(dp[K][0])


Measured memory_bytes: 150524
#include <cstdio>

char p[10][10];

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

  int cnt = 0;

  for(int i = 0; i < H; i++){
    scanf("%s", p[i]);
    for(int j = 0; j < W; j++) if(p[i][j] == '#') cnt++;
  }

  int x = 0, y = 0; bool v = true;
  for(;;){
    if(p[x][y] != '#'){ v = false; break; }
    if(x == H - 1 && y == W - 1) break;

    bool d = false, r = false;
    if(x + 1 < H && p[x + 1][y] == '#') d = true;
    if(y + 1 < W && p[x][y + 1] == '#') r = true;

    if((d && r) || (!d && !r)){ v = false; break; }
    if(d) x++; else y++;
  }

  if(cnt != H + W - 1) v = false;

  puts(v ? "Possible" : "Impossible");
  return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    H, W = map(int, input().split())
    print("#"*(W+2))
    for _ in range(H):
        print("#{}#".format(input()))
    print("#"*(W+2))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 9092
//404 Not Found {=}7 (o)7 (x)7
#include<bits/stdc++.h>
using namespace std;
#define apppend push_back
#define endl "\n"
#define dbug(x) cout<<#x<<"="<<x<<endl

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;

const int maxn = 1e5, inf = 1e9, mod= 1e9+7;
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cout << setprecision(30);
    int n,mn=inf,ans=0,t;
    cin >> n;
    for(int  i = 0;i<n;i++)
    {
        cin >> t;
        ans += (t<=mn);
        mn = min(mn,t);
    }
    cout << ans;
    return 0;
}

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

#define ll long long

void In_Out() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
#endif
}

void display_arr(std::vector<int> v) {
	for (auto ele : v) {
		cout << ele << " ";
	}
	cout << endl;
}

ll max_value_ans(int n, int w, vector<int> wts, vector<int> vals) {
	// dp array that stores the max value we can have at  cell (i, x): where i gives the subset of
	// items choosen from [1, i] set of items and x is the current weight of our knapsack, i.e. 0 <= x <= w and 0 <= i <= n
	// i == 0 means no item is selected and w == 0 means we have a knapsack with 0kg capacity
	ll dp[n + 1][w + 1] = {0};
	// As when capacity of knapsack == 0, we cannot get any money irrespective of the items we consider
	for (int i = 0; i < n + 1; i++)
		dp[i][0] = 0;
	// As when we donot select any item, we get 0 money irrespective of the size of knapsack available
	for (int j = 0; j < w + 1; j++)
		dp[0][j] = 0;
	for (int i = 1; i < n + 1; i++) {
		// fill the cells for the subset [1, i]
		for (int j = 1; j < w + 1; j++) {
			if (wts[i - 1] > j)
				dp[i][j] = dp[i - 1][j];
			else {
				// now here wts[i] <= j (knapsacks capacity), so
				dp[i][j] = max(dp[i - 1][j], vals[i - 1] + dp[i - 1][j - wts[i - 1]]);
			}
		}
	}
	// for (int i = 0; i < n + 1; i++) {
	// 	for (int j =  0; j < w + 1; j++)
	// 		cout << dp[i][j] << " ";
	// 	cout << endl;
	// }
	return dp[n][w];
}

int main() {
	// In_Out();
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n, w;
	cin >> n >> w;
	std::vector<int> values(n);
	std::vector<int> weights(n);
	for (int i = 0; i < n; i++) {
		cin >> weights[i] >> values[i];
	}
	cout << max_value_ans(n, w, weights, values) << endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1e5 + 9;
ll pf[N];
ll sf[N];
ll a[N];
ll pref[N];

int main(){
  fastIO;
  int n, k;
  cin >> n >> k;
  for(int i = 1; i <= n; i ++ ){
    cin >> a[i];
    pref[i] = pref[i - 1] + a[i];
  }
  for(int i = 1; i <= n; i ++ ){
    pf[i] = max(pf[i - 1], pf[i - 1] + a[i]);
  }
  for(int i = n; i >= 1; i -- ){
    sf[i] = max(sf[i + 1], sf[i + 1] + a[i]);
  }
  int l, r;
  ll res = 0;
  for(int i = 1; i <= n - k + 1; i ++ ){
    l = i;
    r = i + k - 1;
    res = max(res, max(pref[r] - pref[l - 1],0ll) + pf[l - 1] + sf[r + 1]);
  }
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    lli n;
    cin>>n;
    lli i,j,k,ans=0;
    
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
        {
            for(k=1;k<=n;k++)
            {
                ans+=__gcd(i,__gcd(j,k));
            }
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>
#define max(a,b) (a>b?a:b)
int main(){
  int a,b,c,k,i=1;
  scanf("%d%d%d%d",&a,&b,&c,&k);
  while(k){i*=2;k--;}
  printf("%d",a+b+c+max(a,max(b,c))*(i-1));
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) int(a.size())
const int N=2e5+10;

int gi() {
	int x=0,o=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,fa[N],cnt[2],ans[N];
vi E[N],vec[3];
bool col[N];

void dfs(int u,int ff,bool col) {
	fa[u]=ff;::col[u]=col;++cnt[col];
	for(auto v:E[u]) if(v^ff) dfs(v,u,col^1);
}

void out(int y) {
	cout<<vec[y].back()<<' ';vec[y].pop_back();
}

void out2(int x,int y) {
	ans[x]=vec[y].back();vec[y].pop_back();
}

int main() {
	cin>>n;
	for(int i=1,u,v;i<n;i++) u=gi(),v=gi(),E[u].pb(v),E[v].pb(u);
	dfs(1,0,0);
	for(int i=1;i<=n;i++) vec[i%3].pb(i);
	if(cnt[0]>cnt[1]) {
		swap(cnt[0],cnt[1]);
		for(int i=1;i<=n;i++) col[i]^=1;
	}
	if(cnt[0]<=sz(vec[0])) {
		for(int i=1;i<=n;i++)
			if(col[i]==0) out2(i,0);
		for(int i=1;i<=n;i++)
			if(col[i]==1) {
				for(int j=0;j<3;j++) if(!vec[j].empty()) { out2(i,j);break; }
			}
		for(int i=1;i<=n;i++) cout<<ans[i]<<' ';
	}
	else {
		for(int i=1;i<=n;i++) {
			if(col[i]==0) {
				if(!vec[1].empty()) out(1);
				else out(0);
			}
			else {
				if(!vec[2].empty()) out(2);
				else out(0);
			}
		}
	}
	return 0;
}


Measured memory_bytes: 20216
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;
typedef long long ll;

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

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;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////

int main() {
    ll n; cin >> n;
    vector<ll> a(n), b(n), c(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(), a.end());
    rep(i,n) cin >> b[i];
    sort(b.begin(), b.end());
    rep(i,n) cin >> c[i];
    sort(c.begin(), c.end());

    ll ans = 0;
    rep(i,n) {
        ll x = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
        ll y = upper_bound(c.begin(), c.end(), b[i]) - c.begin();
        y = n - y;
        // cout << x << ' ' << y << endl;
        ans += x*y;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  // rdp[i][j] = [i, n)
  long long rdp[n + 1][16];
  // ldp[i][j] = [0, i)
  long long ldp[n + 1][16];
  long long pw4[40] = {0};
  pw4[0] = 1;
  for (int i = 0; i < 39; i++)
    pw4[i + 1] = pw4[i] * 4;
  for (int i = 0; i < 16; i++) {
    rdp[n][i] = 0;
    rdp[n - 1][i] = i * 2;
  }
  for (int i = n - 2; i >= 0; i--) {
    int k = 0;
    for (int j = 0; j < 16; j++) {
      while (a[i] * pw4[j] > a[i + 1] * pw4[k] && k < 16)
        k++;
      if (k < 16) {
        rdp[i][j] = j * 2 + rdp[i + 1][k];
      } else {
        rdp[i][j] = rdp[i][j - 1] + (n - i) * 2;
      }
    }
  }
  for (int i = 0; i < 16; i++) {
    ldp[0][i] = 0;
    ldp[1][i] = i * 2 + 1;
  }
  for (int i = 1; i < n; i++) {
    int k = 0;
    for (int j = 0; j < 16; j++) {
      while (a[i - 1] * pw4[k] < a[i] * pw4[j] && k < 16)
        k++;
      if (k < 16) {
        ldp[i + 1][j] = j * 2 + ldp[i][k] + 1;
      } else {
        ldp[i + 1][j] = ldp[i + 1][j - 1] + (i + 1) * 2;
      }
    }
  }
  long long ans = rdp[0][0];
  for (int i = 0; i < n; i++) {
    ans = min(ans, ldp[i + 1][0] + rdp[i + 1][0]);
  }
  cout << ans << endl;
  return 0;
}


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

typedef long long int ll;
ll powk(ll a, ll n = 2){
    ll r = 1;
    for(ll i = 0;i < n;i++){
        r *= a;
    }

    return r;
}

int main()
{
    ll n;
    cin >> n;
    vector<string> s(n);
    for(ll i = 0;i < n;i++){
        cin >> s[i];
    }

    ll ans = 0;
    sort(s.begin(),s.end());
    for(ll i = 0;i < n - 1;i++){
        if(s[i] != s[i + 1]){
            ans++;
        }
    }

    ans++;

    cout << ans;

    return 0;
}

Measured memory_bytes: 9544
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

struct mint {
  ll x;
  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;
  }
};

mint factorial(ll n) {
  mint answer = 1;
  while (n > 1) {
    answer *= n;
    n--;
  }
  return answer;
}

mint combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

mint permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

// setprecision(8) 桁数指定
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
// for (auto p : prime_factor(n)) {
//	while (p.second--) {
//		cout << p.first << endl;
//	}
//}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

vector<ll> Eratosthenes(const ll N) {
  bool is_prime[1000000 + 1];
  vector<ll> P;
  for (ll i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  for (ll i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (ll j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      P.emplace_back(i);
    }
  }
  return P;
}

typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

int main() {
  char c;
  cin >> c;
  c++;
  cout << c << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int dx[5] = { -1, 0, 0, 0, 1 };
const int dy[5] = {  0,-1, 0, 1, 0 };
int stage[10][10];
int cnt[10][10];

int Color(int y, int x ){
	int tmp = stage[y][x];
	rep (i, 5 ){
		int nx = x + dx[i];
		int ny = y + dy[i];
		if (nx >= 10 || ny >= 10 || nx < 0 || ny < 0 ) continue;
		tmp += cnt[ny][nx];
	} // end rep

	return tmp%2;
}

int solve(){
	for (int y = 1; y < 10; y++)
		rep (x, 10 )
			if (Color(y-1, x ) ) cnt[y][x]=1;
	rep (i, 10 )
			if (Color(9, i ) ) return -1;

	int ret=0;
	rep (y, 10 ) rep (x, 10 ) ret+=cnt[y][x];

	return ret;
}

int ans[10][10];

void bit_dfs(){

	int res = -1;
	rep (i, 1<<10 ){
		memset (cnt, 0, sizeof (cnt ) );
		rep (j, 10 ) cnt[0][9-j]=(i>>j)&1;
		int t = solve();
		if (t >= 0 && (res < 0 || res > t ) ){
			res = t;
			memcpy (ans, cnt, sizeof(cnt ) );
		} // end if
	} // end rep
}

int main()
{
	int T; scanf("%d", &T );
	while (T--){
		memset (ans, 0, sizeof(ans ) );
		memset (cnt, 0, sizeof(cnt ) );
		memset (stage, 0, sizeof(stage ) );
		rep (y, 10 ) rep (x, 10 ) cin >> stage[y][x];
		bit_dfs();
		rep (y, 10 ) rep (x, 10 ) cout << ans[y][x] << (x < 9 ? ' ' : '\n' );
	} // end while
	return 0;
}

Measured memory_bytes: 1240
n = int(input())
INF = float('inf')
dp = [INF]*(n+1)
dp[0] = 0
# 配ればいい
for i in range(n):
    for j in range(7):
        if i+6**j < n+1:
            dp[i+6**j] = min(dp[i+6**j], dp[i]+1)
        if i+9**j < n+1:
            dp[i+9**j] = min(dp[i+9**j], dp[i]+1)

print(dp[-1])


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

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

    string s;
    cin >> s;

    s[5] = ' ';
    s[13] = ' ';

    cout << s << endl;
    return 0;
}

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

using namespace std;

int cnt[55][55];

int main(){
        int n,m;
        cin >> n >> m;
        char s;
        for(int j = 1;j<=n;j++){
                for(int i = 1;i<=m;i++){
                        cin >> s;
                        if(s == '#')cnt[j][i]++;
                }
        }
        for(int j = 1;j<=n;j++){
                for(int i = 1;i<=m;i++){
                        if(cnt[j][i] == 1)cout << "#";
                        else cout << cnt[j-1][i]+cnt[j+1][i]+cnt[j][i+1]+cnt[j][i-1]+cnt[j+1][i+1]+cnt[j-1][i-1]+cnt[j+1][i-1]+cnt[j-1][i+1];
                }
                cout << "\n";
        }
        return 0;
}
         

Measured memory_bytes: 256
def main():
    paramN = input()
    params = list(map(lambda x: int(x), input().split(' ')))
    if len(list(filter(lambda x: x == 0, params))) > 0:
        print(0)
    else:
        result = 1
        for p in params:
            result *= p
            if result > pow(10, 18):
                print(-1)
                return
        print(result)

main()

Measured memory_bytes: 21616
import Control.Monad
import Data.Graph.Inductive.Internal.Queue

main :: IO()
main = do
  [n, q] <- fmap (map read . words) getLine :: IO[Int]
  ps <- replicateM n $ fmap words getLine :: IO [[String]]
  mapM_ (putStrLn . unwords)  $ solve ps q

solve :: [[String]] -> Int -> [[String]]
solve ps q = innerSolve q 0 $ intoQueue ps mkQueue
  where
    innerSolve :: Int -> Int -> Queue (String, Int) -> [[String]]
    innerSolve q elapsed que
      | queueEmpty que = []
      | v <= q = [w, show finished]:(innerSolve q finished queG)
      | v > q  = innerSolve q (elapsed + q) (queuePut (w, v - q) queG)
      where
        ((w, v), queG) = queueGet que
        finished = elapsed + v

intoQueue :: [[String]] -> Queue (String, Int) -> Queue (String, Int)
intoQueue [] que = que
intoQueue (p:ps) que = intoQueue ps $ queuePut (w, read v) que
  where
    (w:v:_) = p



Measured memory_bytes: 57628
// using no_way as a way
// using no_limitation as a limitation

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = (1e-9);
typedef long long ll;
typedef unsigned long long ull;
#define flush fflush(stdout), cout.flush()
#define all(v) ((v).begin()),((v).end())
#define rall(v) ((v).rbegin()),((v).rend())
#define clr(v,line) memset(v,line,sizeof(v))
#define rep(i,n) for(int(i)=0;(i)<(int)(n);(i)++)
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define RT(x) return cout<<x, 0;
//#define lcm(a,b) (a*(b/__gcd(a,b)))
#define P 1000000007
#define endl '\n'
// const int dx[] = {1,-1,0,0,1,-1,1,-1};
// const int dy[] = {0,0,1,-1,1,-1,-1,1};
// const int dxhorse[] = {-2,-2,-1,-1,1,1,2,2};
// const int dyhorse[] = {1,-1,2,-2,2,-2,1,-1};
 
void file() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
void fast()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
}


int main(int argc, char const *argv[])
{
   
    fast();
    
    string s; cin>>s;
    cout<<(count(all(s), '7')?"Yes":"No");
}

Measured memory_bytes: 3636
import sys

h, *ppp = map(int, sys.stdin.buffer.read().split())
n = 1 << (h - 1)
ppp = [p + n - 1 for p in ppp]
MOD = 10 ** 9 + 7

cumprods = [1] * (2 * n)  # 根から頂点vまでの経路の累積積
cumprods_rev = [1] * n  # ..の逆数
cumprods_through = [0] * n  # 木1の根から木2の根まで、木1の i 番目の葉を経由する経路の積
for i in range(2, 2 * n):
    cumprods[i] = cumprods[i >> 1] * i % MOD
for i in range(n):
    cumprods_rev[i] = pow(cumprods[i], MOD - 2, MOD)
    cumprods_through[i] = cumprods[i + n] * cumprods[ppp[i]] % MOD

# 現在考慮中の木1側のLCAを起点として、木2側の各頂点に至るまでの累積積
# 木1からたどり着かないものは0
cumprods_from_tree1 = [0] * (2 * n)

ans = 0

for lca in range(1, n):
    digit = h - lca.bit_length()
    leftmost_leaf_in_left_subtree = lca << digit
    leftmost_leaf_in_right_subtree = ((lca << 1) + 1) << (digit - 1)
    rightmost_leaf_in_right_subtree = (lca + 1) << digit

    rev = cumprods_rev[lca >> 1]
    for leaf in range(leftmost_leaf_in_left_subtree, leftmost_leaf_in_right_subtree):
        v = ppp[leaf - n]
        cp = cumprods_through[leaf - n] * rev % MOD
        while v > 1:
            cumprods_from_tree1[v] += cp * cumprods_rev[v >> 1] % MOD
            v >>= 1

    rev = cumprods_rev[lca]
    for leaf in range(leftmost_leaf_in_right_subtree, rightmost_leaf_in_right_subtree):
        v = ppp[leaf - n]
        cp = cumprods_through[leaf - n] * rev % MOD
        while v > 1:
            ans = (ans + cumprods_from_tree1[v ^ 1] * cp * cumprods_rev[v >> 2]) % MOD
            v >>= 1

    for leaf in range(leftmost_leaf_in_left_subtree, leftmost_leaf_in_right_subtree):
        v = ppp[leaf - n]
        while cumprods_from_tree1[v] != 0:
            cumprods_from_tree1[v] = 0
            v >>= 1

print(ans)


Measured memory_bytes: 108424
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
//        int t = in.nextInt();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
            int n = in.nextInt();
            int[][] arr = new int[n][2];
            for (int i = 0; i < n; i++) {
                arr[i][0] = in.nextInt();
                arr[i][1] = i+1;
            }
            Arrays.sort(arr, (o1, o2) -> o1[0] - o2[0]);
            for (int i = 0; i < n; i++) {
                out.print(arr[i][1] + " ");
            }
            out.println();
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public char nextChar() {
            return next().charAt(0);
        }

        public String nextLine() throws IOException {
            return reader.readLine().trim();
        }
    }
}


Measured memory_bytes: 43712
#include <stdio.h>
int main() {
    int N;
    scanf("%d", &N);
    int array[N];
    for(int i=0;i <= N-1;i++){
        scanf("%d",&array[i]);
    }
    int max=array[0];
    for(int i=1;i<=N-1;i++){
        if(max<=array[i]){
            max=array[i];
        }
    }
    int sum=0;
    for(int i=0;i<=N-1;i++){
        sum=sum+array[i];
    }
    if(2*max<sum){
        printf("Yes");
    }else if(2*max>=sum){
        printf("No");
    }
 
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <bitset>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
using ppp = pair<pair<int, int>, pair<int, int>>;
#define MOD 1000000007
#define INF 1LL << 59
const int MAX = 510000;
const long long mod = 917120411LL;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int sieve[1000010];
void make_sieve()
{
    for (int i = 0; i < 1000010; ++i)
        sieve[i] = true;
    sieve[0] = sieve[1] = false;
    for (int i = 0; i * i < 1000010; ++i)
    {
        if (sieve[i])
        {
            for (int j = 2; j * i < 1000010; ++j)
            {
                sieve[i * j] = false;
            }
        }
    }
}

ll GCD(ll a, ll b)
{
    if (a < b)
        swap(a, b);
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
ll pow_mod(ll x, ll n)
{
    ll res = 1;
    while (n)
    {
        if (n & 1)
        {
            res = res * x;
        }
        x = x * x;
        n >>= 1;
    }
    return res;
}

int a[200010];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int N;
    cin >> N;

    vector<int> v;

    for (int i = 1; i <= N; ++i)
    {
        int t;
        cin >> t;
        v.push_back(t);
        a[t] = i;
    }

    ll ans = 0;

    set<ll> used = {0, N + 1};

    for (int i = 1; i <= N; ++i)
    {
        ll r, l;

        auto itr = used.lower_bound(a[i]);
        r = *itr;
        l = *(--itr);

        ans += i * (a[i] - l) * (r - a[i]);
        used.insert(a[i]);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 11252
N = int(input())
words = []
flag = 0

for i in range(N):
  word = input()
  if i != 0:
    if word in words:
      flag = 1
    if word[0] != words[i-1][-1]:
      flag = 1
      
  words.append(word)

if flag:
  print("No")
else:
  print("Yes")
      


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c;
  cin >> a >> b;
  c = a+b;
  if(c % 2 == 0){
  cout << c/2 << endl;
  }else{
    cout << (c+1)/2 << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int ama=sc.nextInt();

		long iti=0;
		long zer=0;

		int tmp=0;
		for(int i=0; i<N; i++) {
			tmp=sc.nextInt();
			if(tmp%2==0) {
				zer++;
			}
			else {
				iti++;
			}
		}

		long[] iti_tor=new long[(int)iti+1];
		long[] zer_tor=new long[(int)zer+1];

		for(int i=0; i<=iti; i++) {
			iti_tor[i]=Combi((int)iti,i);
		}

		for(int i=0; i<=zer; i++) {
			zer_tor[i]=Combi((int)zer,i);
		}

		long kisu_wa_k=0;
		long kisu_wa_g=0;

		for(int i=1; i<=iti; i+=2) {
			kisu_wa_k+=iti_tor[i];
		}

		for(int i=0; i<=iti; i+=2) {
			kisu_wa_g+=iti_tor[i];
		}

		long gw=0;

		for(int i=0; i<=zer; i++) {
			gw+=zer_tor[i];
		}
		if(ama==1) {
			System.out.println(kisu_wa_k*gw);
		}
		else {
			System.out.println(kisu_wa_g*gw);
		}
	}

	public static long Combi(int n,int r) {		// nCr
		if(r==0 || r==n) return 1L;

		if(r>n-r) {
			r=n-r;
		}

		int[] bunsi=new int[r];
		int[] bunbo=new int[r];

		for(int k=0; k<r; k++) {
			bunsi[k]=n-r+k+1;
			bunbo[k]=k+1;
		}

		for(int p=2; p<=r; p++) {
			int pivot=bunbo[p-1];
			if(pivot>1) {
				int offset=(n-r)%p;
				for(int k=p-1; k<r; k+=p) {
					bunsi[k-offset]/=pivot;
					bunbo[k]/=pivot;
				}
			}
		}

		long kotae=1;

		for(int k=0; k<r; k++) {
			if(bunsi[k]>1) {
				kotae*=bunsi[k];
			}
		}

		return kotae;
	}
}

Measured memory_bytes: 21844
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      n: usize,
      s1: chars,
      s2: chars,
    }

    const MOD: usize = 1e9 as usize + 7;
    let mut prev = 0;
    let mut i = 0;
    let mut ans = 1;
    while i < n {
        if s1[i] == s2[i] {
            i += 1;
            ans *= match prev {
                0 => 3,
                1 => 2,
                2 => 1,
                _ => panic!()
            };
            ans %= MOD;
            prev = 1;
        } else {
            i += 2;
            ans *= match prev {
                0 => 6,
                1 => 2,
                2 => 3,
                _ => panic!()
            };
            ans %= MOD;
            prev = 2;
        }
    }
    println!("{}", ans);
}


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

int main(){

int n;
cin>>n;
int64_t a[n],b[n];

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

sort(a,a+n);
sort(b,b+n);

double a1 = (a[n/2]+a[(n-1)/2])/(2*1.0);
double b1 = (b[n/2]+b[(n-1)/2])/(2*1.0);
if(n%2==0)
{
    cout<< (int)((b1-a1)*2 +1);

}
else{cout<< (int)(b1-a1+1);}



return 0; }


Measured memory_bytes: 6724
const main = (lines: string) => {
  const data = lines.split("\n");
  const [N, X] = data[0].split(" ").map(str => parseInt(str));
  const points = data[1].split(" ").map(str => parseInt(str));
  let sumOfPoint = 0;
  let answer = 1;

  points.forEach((point, index) => {
    sumOfPoint += point;
    if (sumOfPoint <= X) {
      answer += 1;
    }
  });

  console.log(answer);
};

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <algorithm>
#include <iostream>
typedef long long ll;
using namespace std;
const ll N_MAX = 100;

int main(void) {
  ll N;
  ll B[N_MAX];
  ll ans;

  cin >> N;
  for (int i = 1; i <= N-1; i++) {
    cin >> B[i];
  }
  ans = B[1];
  for (size_t i = 1; i < N-1; i++) {
    ans += min(B[i], B[i+1]);
  }
  ans += B[N-1];
  cout << ans << endl;
  return 0;
}


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

int main(){
 int h, w;
 char s[52][52];
 //char *s;
 cin>>h>>w;
 //s = new char[h+2][w+2];
 for(int i=1;i<=h; i++)
  for(int j=1;j<=w; j++)cin>>s[i][j];
 for(int i=1; i<=h; i++)
  for(int j=1;j<=w; j++)
   if(s[i][j]=='#'&&s[i+1][j]!='#'&&
   s[i-1][j]!='#'&&s[i][j+1]!='#'&&s[i][j-1]!='#'){
    cout<<"No\n";
    return 0;
   }
 cout<<"Yes\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int M=1e5+10;
int vis[10*M];
int main()
{
    ll n,x,m;
    cin>>n>>x>>m;
    vis[x]=1;
    ll res=x;
    for(int i=2;i<=n;i++)
    {
        x=x*x%m;
        if(vis[x])
        {
            int len=i-vis[x];
            n=n-i+1;
            ll sum=0;
            for(int j=vis[x];j<i;j++)
            {
                sum+=x;
                x=x*x%m;
            }
            ll tt=n/len;
            while(tt--) res+=sum;
            tt=n%len;
            while(tt--)
            {
                res+=x;
                x=x*x%m;
            }
            break;
        }
        vis[x]=i;
        res+=x;
    }
    cout<<res;
    return 0;
}


Measured memory_bytes: 3976
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def read_a_int(): return int(read())


def read_ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 998244353
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

N, S = read_ints()
A = read_ints()

# 惜しかったですね
# https://youtu.be/-fTsuyin-a8?t=9680

'''
dp[i][j]...[,i)の数の中の部分集合で、和をjにすることのできる通りの総数

更新則
dp[i + 1][j] = 2 * dp[i][j] + dp[i][j - A[i]]

∵
A[i]の使い方は3通り
1. 最初の部分集合に選ばれない
2. 部分集合の部分集合に選ばれない
3. Sを構成する和に選ばれる
1,2の遷移先は同じところから来るので×2がつく
'''

dp = [[0] * (S + 1) for _ in ra(N + 1)]
dp[0][0] = 1
for i, j in product(ra(N), ra(S + 1)):
    dp[i + 1][j] = 2 * dp[i][j]
    if j - A[i] >= 0:
        dp[i + 1][j] += dp[i][j - A[i]]
    dp[i + 1][j] %= MOD

# print(*dp, sep='\n')
print(dp[-1][-1])


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

int main(){
  int n,k,q;cin >> n >> k >> q;
  int a[q];rep(i,q)cin >> a[i];
  int p[n];
  for(int i=0;i<n;i++){
    p[i] = k;
  }
  for(int i=0;i<q;i++){
    p[a[i]-1] += 1;
  }
  for(int i=0;i<n;i++){
    p[i] -= q;
    if(p[i] <= 0)cout << "No" << endl;
    else cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

vector<int> divisor(int n){
  vector<int> ret;
  for(int i=1; i*i<=n; i++){
    if(n%i==0){
      ret.push_back(i);
      if(i!=n/i) ret.push_back(n/i);
    }
  }
  return ret;
}

int main(){
  int N;
  cin >> N;
  vector<int> v;

  map<int,int> uq;
  rep(i,N){
    int a;
    cin >> a;
    v.push_back(a);
    uq[a]++;
  }
  sort(ALLOF(v));

  int ret = 0;
  map<int,int> m;
  rep(i,N){
    vector<int> res = divisor(v[i]);

    bool flg = true;
    if(uq[v[i]] > 1) flg = false;
    else{
      rep(j,res.size()){
        if(m.count(res[j]) > 0){
          flg = false;
          break;
        }
      }
    }
    if(flg) ret++;
    m[v[i]] = 1;
  }

  cout << ret << endl;
  
  return 0;
}


Measured memory_bytes: 22564
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/
signed main(){
	int n;
	cin>>n;
	int a[17];
	int x[17][17];
	int y[17][17];
	rep(i,n){
		cin>>a[i];
		rep(j,a[i]){
			cin>>x[i][j]>>y[i][j];
		}
	}
	int ans=0;
	rep(bit,1<<n){
		int shoujiki[17];
		rep(i,n){
			if(bit&(1<<i)) shoujiki[i]=1;
			else shoujiki[i]=0;
		}
		int to[17][17];
		int ok=1;
		rep(i,n){
			if(shoujiki[i]){
				rep(j,a[i]){
					if(y[i][j]){
						if(shoujiki[x[i][j]-1]==0) ok=0;
					}else{
						if(shoujiki[x[i][j]-1]==1) ok=0;
					}

				}
			}
		}
		if(ok){
			int cnt=0;
			rep(i,n){
				if(shoujiki[i]==1) cnt++;
			}
			chmax(ans,cnt);
		}
	}

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



Measured memory_bytes: 3620
#include <iostream>
using namespace std;
int main() {
    char s[10];
    scanf("%s", s);
    int a[26] = {};
    for (int i = 0; i < 4; ++i) {
        a[s[i] - 'A']++;
    }
    for (int i = 0; i < 26; ++i) {
        if (a[i] != 0 && a[i] != 2) {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
ll a[100005],b[100005],c[100005];
ll f[5][100005],sum[100005],ans;
int main(){
	int n;cin>>n;
	for(int i=1;i<=n;++i)
		cin>>a[i],f[1][i]=1;
	for(int i=1;i<=n;++i)
		cin>>b[i];
	for(int i=1;i<=n;++i)	
		cin>>c[i];
	sort(a+1,a+n+1); sort(b+1,b+n+1); sort(c+1,c+n+1);
	for(int i=1;i<=n;++i)
		sum[i]=sum[i-1]+f[1][i];
	for(int i=1;i<=n;++i){
		int o=lower_bound(a+1,a+n+1,b[i])-a;
		if(o>n||a[o]>=b[i]) --o;
		f[2][i]+=sum[o];
	}
	memset(sum,0,sizeof(sum));
	for(int i=1;i<=n;++i) sum[i]=sum[i-1]+f[2][i];
	for(int i=1;i<=n;++i){
		int o=lower_bound(b+1,b+n+1,c[i])-b;
		if(o>n||b[o]>=c[i]) --o;
		f[3][i]+=sum[o];ans+=f[3][i];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 6528
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int x = sc.nextInt();

        List<String> result = new ArrayList<>();
        for (int i = x - (k - 1); i <= x + (k - 1); i++) {
            if (i >= -1000000 && i <= 1000000) {
                result.add(Integer.toString(i));
            }
        }

        System.out.println(String.join(" ", result));
    }
}


Measured memory_bytes: 23764