akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class A
{
	public static void Main()
	{
		string s = GetString();
		int iC = s.IndexOf("C");
		int iF = s.LastIndexOf("F");
		if((iC != -1) && (iF != -1) && (iC < iF))
			Console.WriteLine("Yes");
		else
			Console.WriteLine("No");
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}

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

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

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back
const int mod = 1e9+7;
int x[100005], y[100005];
ll dp[100005], cnt[100005];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    for(int i=0;i<n;i++){
        cin >> x[i];
    }
    for(int i=0;i<m;i++){
        cin >> y[i];
    }

    ll X = 0, Y = 0;
    memset(dp, 0, sizeof(dp));
    for(int i=1;i<n;i++){
        int dis = x[i]-x[i-1];
        cnt[i] = cnt[i-1] + 1;
        dp[i] = (dp[i-1] + dis*1ll*cnt[i])%mod;
    }
    for(int i=0;i<n;i++) X = (X + dp[i])%mod;
    
    memset(dp, 0, sizeof(dp));
    for(int i=1;i<m;i++){
        int dis = y[i]-y[i-1];
        cnt[i] = cnt[i-1] + 1;
        dp[i] = (dp[i-1] + dis*1ll*cnt[i])%mod;
    }
    for(int i=0;i<m;i++) Y = (Y + dp[i])%mod;

    printf("%lld\n", X*1ll*Y%mod);
}

Measured memory_bytes: 6080
#include <algorithm>
#include <bits/stdc++.h>
#include <numeric>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
long long MOD = 1e9 + 7;
using namespace std;

int main() {
  ll a, b;
  cin >> a >> b;
  ll i = 1;
  while (true) {
    if (a * i % b == 0) {
      cout << a * i << endl;
      break;
    }
    i++;
  }
  return 0;
}


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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;
using namespace std;

class MinCostFlow {
 private:
  typedef std::pair<ll, ll> P;
  struct Edge { ll to, cap, cost, rev; };
  const ll V;
  std::vector<std::vector<Edge>> G;
  std::vector<ll> h, dist, prevv, preve;

 public:
  explicit MinCostFlow(ll v) : V(v), G(v), h(v), dist(v), prevv(v), preve(v) {}

  void addEdge(ll from, ll to, ll cap, ll cost) {
    G[from].push_back({to, cap, cost, static_cast<ll>(G[to].size())});
    G[to].push_back({from, 0, -cost, static_cast<ll>(G[from].size())-1});
  }

  ll minCostFlow(ll s, ll t, ll f) {
    ll res = 0;
    for (ll i = 0; i < V; ++i) h[i] = 0;
    while (f > 0) {
      std::priority_queue<P, std::vector<P>, std::greater<P>> q;
      for (ll i = 0; i < V; ++i) dist[i] = 1e18;
      dist[s] = 0;
      q.push(P(0, s));
      while (!q.empty()) {
        P p = q.top(); q.pop();
        ll v = p.second;
        if (dist[v] < p.first) continue;
        for (ll i = 0; i < G[v].size(); ++i) {
          auto& e = G[v][i];
          if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {
            dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
            prevv[e.to] = v;
            preve[e.to] = i;
            q.push(P(dist[e.to], e.to));
          }
        }
      }
      if (dist[t] == 1e18) return -1;
      for (ll v = 0; v < V; ++v) h[v] += dist[v];
      ll d = f;
      for (ll v = t; v != s; v = prevv[v]) {
        d = std::min(d, G[prevv[v]][preve[v]].cap);
      }
      f -= d;
      res += d * h[t];
      for (ll v = t; v != s; v = prevv[v]) {
        Edge& e = G[prevv[v]][preve[v]];
        e.cap -= d;
        G[v][e.rev].cap += d;
      }
    }
    return res;
  }
};

const ll INF    = 1e11;
const ll OFFSET = 1e11;

vector<PLL> reds, blues;

signed main() {
  ll N, t=0;
  cin>>N;

  auto m = MinCostFlow(300000);
  rep(i,0,N) {
    ll x,y,c;
    cin>>x>>y>>c;
    m.addEdge(2*N, i, c, 0);
    m.addEdge(i, 2*N+2, INF, OFFSET - ( x+y));
    m.addEdge(i, 2*N+3, INF, OFFSET - (-x+y));
    m.addEdge(i, 2*N+4, INF, OFFSET - ( x-y));
    m.addEdge(i, 2*N+5, INF, OFFSET - (-x-y));
    t += c;
  }
  rep(i,0,N) {
    ll x,y,c;
    cin>>x>>y>>c;
    m.addEdge(N+i, 2*N+1, c, 0);
    m.addEdge(2*N+2, N+i, INF, OFFSET - (-x-y));
    m.addEdge(2*N+3, N+i, INF, OFFSET - ( x-y));
    m.addEdge(2*N+4, N+i, INF, OFFSET - (-x+y));
    m.addEdge(2*N+5, N+i, INF, OFFSET - ( x+y));
  }

  cout<<-1 * (m.minCostFlow(2*N, 2*N+1, t) - OFFSET*2*t)<<endl;
  return 0;
}


Measured memory_bytes: 19712
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <numeric>
#include <string>
#include <cmath>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;


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

	if (n >= 30) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int h, w;
  cin>>h>>w;
  vector<string> s(h);
  REP(i,h){
    cin>>s[i];
  }
  vector<vector<long long>> dist(h*w, vector<long long>(h*w, INF));
  REP(i, h*w){
    dist[i][i] = 0;
  }
  auto conv = [&](int i, int j){
    int res;
    res = w*i + j;
    return res;
  };
  int dx[] = {1, 0, -1, 0};
  int dy[] = {0, 1, 0, -1};
  REP(i,h){
    REP(j,w){
      if(s[i][j] == '#')continue;
      REP(k,4){
        int ni = i + dx[k];
        int nj = j + dy[k];
        if(ni < 0 || ni >= h || nj < 0 || nj >= w){
          continue;
        }
        if(s[ni][nj] == '#')continue;
        int f = conv(i, j);
        int t = conv(ni, nj);
        dist[f][t] = dist[t][f] = 1;
      }
    }
  }
  REP(k,h*w){
    REP(i,h*w){
      REP(j,h*w){
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  long long ans = 0;
  REP(i,h*w){
    REP(j,h*w){
      if(dist[i][j] == INF)continue;
      ans = max(ans, dist[i][j]);
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1536
# 幅優先探索
from collections import deque

N = int(input())
links = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    links[a].append((b, c))
    links[b].append((a, c))

Q, K = map(int, input().split())

d = [float('inf')] * (N + 1)
d[K] = 0
q = deque([K])
while q:
    i = q.popleft()
    for j, c in links[i]:
        if d[i] + c < d[j]:
            d[j] = d[i] + c
            q.append(j)

result = []
for _ in range(Q):
    x, y = map(int, input().split())
    result.append(d[x] + d[y])
print('\n'.join(str(v) for v in result))
#print(*result, sep='\n')


Measured memory_bytes: 61784
fun main(args: Array<String>) {
        val input = read()
        println(someSums(input))
    }

    data class Inputs(val max: Int, val lower: Int, val higher: Int)

    fun read(): Inputs {
        val args = readLine()!!.split(' ').map { Integer.parseInt(it) }
        return Inputs(args[0], args[1], args[2])
    }

    fun someSums(inputs: Inputs): Int {
        val judge = { value: Int ->
            val sum = value.toString().sumBy { Integer.parseInt(it.toString()) }
            (inputs.lower <= sum && sum <= inputs.higher)
        }

        return (0..inputs.max).filter(judge).sum()
    }

Measured memory_bytes: 39108
#include <iomanip>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);

  int K, X;
  cin >> K >> X;
  if ((500 * K) >= X)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


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

int main(){
	string s;
 	cin >> s;
	
	long long ans=0;
	string ss;
	if(s.length()<2)ans=0;
	
	
	else {
		for(int i=0;i<s.length();i++){
			if(s[i]=='B' && s[i+1]=='C'){
				ss += "D";
				i++;
			}
			else ss+= s[i];
		}
		//cout << ss<<endl;
		long long count =0;
		for(int i=0;i<ss.length();i++){
			if(ss[i]=='D'){
				ans+=count;
			}
			if(ss[i]=='C' || ss[i]=='B'){
				count =0;
			}
			if(ss[i]=='A'){
				count ++;
			}
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 776
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 200000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;
struct Edge{
    int to;
    int next;
}edge[N];
int n,m;
int tot,head[N];
void addEdge(int from,int to){
    edge[++tot].to=to;
    edge[tot].next=head[from];
    head[from]=tot;
}
bool dfs(int s,int step){
    if(s==n&&step==2)
        return true;
    for(int i=head[s];i!=-1;i=edge[i].next){
        int to=edge[i].to;
        if(dfs(to,step+1))
            return true;
    }
    return false;
}
int main() {
    memset(head,-1,sizeof(head));
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        addEdge(x,y);
    }
 
    bool flag=dfs(1,0);
    if(flag)
        printf("POSSIBLE\n");
    else
        printf("IMPOSSIBLE\n");
    return 0;
}

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

int ans = 0;
int N;
int A[15], x[15][15], y[15][15];
int bit[15]{};

void solve() {
    int t = 0;
    for (int i = 0; i < N; i++) {
        if (bit[i] == 1) t++;
    }
    for (int i = 0; i < N; i++) {
        if (bit[i] == 0) continue;
        for (int j = 0; j < A[i]; j++) {
            if (bit[x[i][j]] != y[i][j]) return;
        }
    }
    ans = max(ans, t);
}

void rec(int k) {
    if (k == N) {
        solve();
        return;
    }
    rec(k + 1);
    bit[k] = 1;
    rec(k + 1);
    bit[k] = 0;
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        for (int j = 0; j < A[i]; j++) {
            cin >> x[i][j] >> y[i][j];
            x[i][j]--;
        }
    }
    rec(0);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N;
  bool K=false;
  cin>>N;
  vector<int>T(N+1);
  vector<int>X(N+1);
  vector<int>Y(N+1);
  for(int P=0;P<N;P++){
    cin>>T[P+1]>>X[P+1]>>Y[P+1];
    if(abs(X[P+1]-X[P])+abs(Y[P+1]-Y[P])>T[P+1]-T[P]||(abs(X[P+1]-X[P])+abs(Y[P+1]-Y[P]))%2!=(T[P+1]-T[P])%2){
      K=true;
    }
  }
  if(K==false){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 4160
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
int MOD=1e9+7;
#define INF 2*1e9
#define N 310000 
using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");

main(){
    int n,m;
    cin>>n>>m;
    pair<pii,int> p[400];
    rep(i,m){
        int l,r,x;
        cin>>l>>r>>x;
        p[i]={{r,l},x};
    }
    sort(p,p+m);
    int dp[400][400][400]={};
    dp[0][0][0]=1;
    rep(i,n){
        rep2(j,0,max(i-1,0)){
            rep2(k,0,max(0,j-1)){
                dp[i+1][i][k]=(dp[i+1][i][k]+dp[i][j][k])%MOD;
                dp[i+1][j][k]=(dp[i+1][j][k]+dp[i][j][k])%MOD;
                dp[i+1][i][j]=(dp[i+1][i][j]+dp[i][j][k])%MOD;
            }
        }
        int l=lower_bound(p,p+m,(pair<pii,int>){{i+1,0},0})-p;
        int r=upper_bound(p,p+m,(pair<pii,int>){{i+1,400},0})-p;
        rep2(j,0,i){
            rep2(k,0,max(0,j-1)){
                for(int ii=l;ii<r;ii++){
                    int count=1;
                    int s=p[ii].first.second;
                    if(s<=k){
                        count++;
                    }
                    if(s<=j){
                        count++;
                    }
                    if(count!=p[ii].second){
                        dp[i+1][j][k]=0;
                    }
                }
            }
        }
    }
    int ans=0;
    rep2(j,0,n-1){
        rep2(k,0,j){
            ans=(ans+dp[n][j][k])%MOD;
        }
    }
    cout<<ans;
    return 0;
}



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

int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}


int main(){
  int k;
  cin >> k;
  int ans = 0;
  for(int i=1; i<=k; i++){
    for(int j=1; j<=k; j++){
      for(int l=1; l<=k; l++){
        ans += gcd(gcd(i, j), l);
      }
    }

  }
  cout << ans << endl;
}

Measured memory_bytes: 3608
h,w,a,b=map(int, input().split())
n=h+w-2

mod=10**9+7
fc,inv=[1]*n,[1]*n
for i in range(1,n):
  fc[i]=i*fc[i-1]%mod
inv[n-1]=pow(fc[n-1],mod-2,mod)
for i in range(n-1,0,-1):
  inv[i-1]=inv[i]*i%mod
f=lambda a,b:fc[a+b]*inv[a]*inv[b]%mod

v=0
for x in range(b,w):
  v+=f(x,h-a-1)*f(w-1-x,a-1)%mod
print(v%mod)

Measured memory_bytes: 18804
#include <bits/stdc++.h>
using namespace std;
 
int main() {
string S;
cin >> S;
bool ans;
ans = 1;
int lo;
lo = S.size();
int i = 0;
lo--;
while(true){
    if(i == lo){
break;
    }
    
    if(S[i] != S[lo]){
        ans = 0;
    }
i++;
lo--;

}

lo = S.size();
i = 0;
lo--;
lo /= 2;
lo--;


while(true){
    if(i >= lo){
break;
    }
    
    if(S[i] != S[lo]){
        ans = 0;
    }
i++;
lo--;

}
i = S.size();
i += 3;
i /= 2;
i--;
lo = S.size();
lo--;
while(true){
    if(i >= lo){
break;
    }
    
    if(S[i] != S[lo]){
        ans = 0;
    }
i++;
lo--;

}
if(ans == 1){
cout << "Yes" << endl;
}
else{
    cout << "No" << endl;
}


}

Measured memory_bytes: 256
a,b,q=gets.split.map(&:to_i)
s=[]
a.times do
  s << gets.to_i
end
t=[]
b.times do
  t << gets.to_i
end
q.times do
  mx=1/0.0
  x=gets.to_i
  if x<s[0]
    ss=[s[0]]
  elsif x>s[-1]
    ss=[s[-1]]
  else
    l=0
    r=a-1
    while r-l>1
      m=(l+r)/2
      if x<s[m]
        r=m
      else
        l=m
      end
    end
    ss=[s[l],s[r]]
  end
  if x<t[0]
    tt=[t[0]]
  elsif x>t[-1]
    tt=[t[-1]]
  else
    l=0
    r=b-1
    while r-l>1
      m=(l+r)/2
      if x<t[m]
        r=m
      else
        l=m
      end
    end
    tt=[t[l],t[r]]
  end
  ss.each do |sx|
    tt.each do |tx|
      c=(tx-sx).abs+[(tx-x).abs,(sx-x).abs].min
      mx=c if c<mx
    end
  end
  puts mx
end


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

int main() {
	int t;
	cin >> t;
	int h,m,s;
	h = t / 3600;
	m = (t%3600)/60;
	s = t - h*3600 - m*60;
	cout << h <<":"<< m <<":"<< s << endl;
	return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
 
 
using namespace std;
 
double EPS = 1e-10;
 
 
double add(double a, double b){
  if(abs(a+b) < EPS * (abs(a)+abs(b)))return 0;
  return a+b;
}
 
struct point{
  double x, y;
  point(){}
  point(double x,double y) : x(x) , y(y){}
 
  point operator + (point p){
    return point(add(x,p.x), add(y,p.y));
  }
 
  point operator - (point p){
    return point(add(x,-p.x), add(y,-p.y));
  }

  bool operator == ( const point &p ) const {
    return abs(x-p.x) < EPS && abs(y-p.y) < EPS;
  }
};
 
bool cmp_x(const point& p, const point& q){
  if(p.x != q.x)return p.x<q.x;
  return p.y < q.y;
}

double cross(point a, point b) {
  return (a.x * b.y - a.y * b.x);
}

double norm(point a){
  return sqrt(a.x*a.x+a.y*a.y);
}

double dist(point a,point b){
  return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));
}

vector<point> normal_vector(point a){
  vector<point>res; 
  point b;
  b.x=-a.y, b.y=a.x;
  res.push_back(b);
  b.x=a.y, b.y=-a.x;
  res.push_back(b);

  return res;
}

double areaPol(vector<point> t){
  t.push_back(t[0]);
  int tsz=t.size();
  double area=0;
  for(int i=0;i<tsz-1;i++){
    area+=(t[i].x-t[i+1].x)*(t[i].y+t[i+1].y);
  }
  return abs(area)/2.0;
}

vector<point>N;

bool Binary_search(point x){
  int l=0,r=N.size(),mid=(l+r)/2;
 
  while(r-l>1){
    if(N[mid]==x)return true;
 
    if(x.x < N[mid].x ||(N[mid].x==x.x && x.y < N[mid].y))r=mid;
    else l=mid;
 
    mid=(l+r)/2;
  }
 
  if(N[mid]==x)return true;
  return false;
}

double solve(void){

  double res=0;

  for(int i=0;i<N.size();i++){
    for(int j=i+1;j<N.size();j++){

      vector<point> nv=normal_vector(N[j]-N[i]);
      point a=N[i]+nv[0],b=N[j]+nv[0];

      if(Binary_search(a) && Binary_search(b)){
	vector<point>c;
	c.push_back(N[i]);
	c.push_back(N[j]);
	c.push_back(b);
	c.push_back(a);
	res=max(res,areaPol(c));
      
      }
    }
  }
 return res;
}
 
int main(void){
  int n;
  point in;
 
  while(cin >> n){
    if(n==0)break;

    N.clear();   

    for(int i=0; i<n; i++){
      cin >> in.x >> in.y;
      N.push_back(in);
    }

    sort(N.begin(),N.end(),cmp_x);
    cout << (int)solve() << endl;
  }
 
  return 0;
}

Measured memory_bytes: 1348
#include <stdio.h>

/******
*	??°?????????
******/

int main(void)
{
	char number[1001]={0};		//?????????????????????
	int i;
	int num, sum;
	
	while(1){
		sum = 0 ;				//????¨?????????????
		num = 0 ;				//??°????????????
		scanf("%s", number);	//???????????\???
		if(number[0] == '0'){	//??\?????????????????????0?????¨?????????
			break;
		}
		else {
				i = 0;
				while(number[i] != '\0' ){
					num = number[i] - '0';		//??????????????°??????
					sum += num;					//??°???????¶?????????????
					i++;
				}
			printf("%d\n", sum);		//????¨?????????????
		}
	}
}

Measured memory_bytes: 964
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
    int N, M, now = 0, hole, maxi;
    long long result  = 1;
    bool canDo = true;
    vector<int> step;
    vector<long long> fib;

    scanf("%d %d", &N, &M);

    //連続した階段の数を配列にぶち込む
    for(int i = 0; i < M; i++){
        scanf("%d", &hole);
        if(hole == now)
            canDo = false;
        step.push_back(hole - now  - 1);
        now = hole + 1;
    }
    step.push_back(N - now);

    if(!canDo){
        cout << 0 << endl;
        return 0;
    }

    //stepをソート  O(N log N)
    sort(step.begin(), step.end());

    maxi = step.back();

    //フィボナッチ数列の計算
    fib.push_back(1);
    fib.push_back(1);
    for(int i = 2; i <= maxi; i++)
        fib.push_back((fib[i - 1] + fib[i - 2]) % 1000000007);

    //結果の計算
    for(const auto &e: step)
        result = result * fib[e] % 1000000007;

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 1400
object Main extends App {
  @scala.annotation.tailrec
  def loop(permutations: Seq[Seq[Int]], target: Seq[Int], count: Int): Option[Int] =
    permutations match {
      case Seq() => None
      case x :: _ if x == target => Some(count)
      case _ :: xs => loop(xs, target, count + 1)
    }
  val sc = new java.util.Scanner(System.in)
  val s = sc.nextInt()
  val P, Q = List.fill(s)(sc.nextInt())
  val permutations = (1 to s).permutations.toList
  val diff = for {
    p <- loop(permutations, P, 1)
    q <- loop(permutations, Q, 1)
  } yield math.abs(p - q)
  println(diff.getOrElse(0))
}


Measured memory_bytes: 68560
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>
#include <limits>
#include <map>
#include <set>
#include <functional>

using namespace std;

int main()
{
  int64_t X;
  int64_t K;
  int64_t D;

  cin >> X >> K >> D;
  X = abs(X);

  if (K < X / D) {
    cout << X - K * D << endl;
  }
  else if ((K - X / D) % 2 == 0) {
    cout << X % D << endl;
  }
  else {
    cout << D - X % D << endl;
  }

  return 0;
}


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

int main() {
  int N;
  string S;
  cin >> N >> S;
  
  int ans = 0;
  for (int i = 0; i < N-2; i++) {
     if (S.at(i)=='A' && S.at(i+1)=='B' && S.at(i+2)=='C') ans++;
  }
  cout << ans << endl;
  return 0; 
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) { 
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }
int main() {
  int N; cin>>N;
  double sum = 0.0;
  REP(i,N) {
    double d; string s;
    cin>>d>>s;
    if(s == "JPY") sum += d;
    else sum += 380000.0 * d;
  }
  cout << sum << endl;
  return 0;
}


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

int main()
{
	vector<int> N(101);
	int n,max=0;

	while (cin >> n){
		N[n]++;
	}

	for (int i = 0; i<N.size(); ++i){
		if (N[i] != 0)	{
			if (N[i] > max){
				max = N[i];
			}
		}
	}

	for (int i = 0; i < 100; ++i){
		if (N[i] == max)
			cout << i << endl;
	}

	return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll ar[200007],a,b, test, sum,t,x=0,p,q,y,i,j,k=0,l,cnt;
map<ll,ll>br,mp;
void func()
{
    k=0;
    while(k<=34)
    {
        if(k>0)
            mp[++k]=mp[k-1]*2;
        else
            mp[++k]=2;
    }
}
int main()
{
    func();
    ll test;
    cin>>a;
    cnt=0;
    for(i=1; i<=a; i++)
    {
        cin>>ar[i];
        br[ar[i]]++;
    }
    sort(ar+1,ar+a+1);

    for(i=a; i>=1; i--)
    {
        if(br[ar[i]]>=1)
        {
            for(j=k; j>=1; j--)
            {
                ll c=mp[j];
                x=c-ar[i];
                if(x>0)
                if(br[x]==1&&ar[i]!=x||br[x]>1)
                {
                    cnt++;
                    br[ar[i]]--;
                    br[x]--;
                    break;
                }

            }
        }
    }


    printf("%lld\n",cnt);
    return 0;
}


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

int main() {
  int n; cin >> n;
  if (n%2 == 0) cout << 0.5 << endl;
  else {
    double odd = (n+1)/2;
    cout << odd / n << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    
    for(int i=0;i<S.size();i++){
        if(i == K-1)
            cout << char(tolower(S[i]));
        else
            cout << S[i];
    }
    cout << endl;
}

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

int32_t main(){
    ios::sync_with_stdio(0);cin.tie(0);
    
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        arr[x-1]=i+1;
    }

    for(int i:arr){
        cout<<i<<" ";
    }

    return 0;
}

Measured memory_bytes: 1664
def get_avg(num_list):
    return sum(num_list) / len(num_list)

def calculate_deviation(num_list,avg):
    diff_list = []
    for num in num_list:
        diff_list.append(num-avg)
    return diff_list

def calculate_variance(num_list):
    total = 0
    for num in num_list:
        total += num**2
    return total/len(num_list)

def calculate_stdev(variance):
    return variance ** 0.5

while True:
    n = int(input())
    if n == 0:
        break
    else:
        data_set= list(map(float,input().split()))
        avg = get_avg(data_set)
        dev_list = calculate_deviation(data_set,avg)
        vrnc = calculate_variance(dev_list)
        print(calculate_stdev(vrnc))



Measured memory_bytes: 5724
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int D, N;

        public void Run()
        {
            {
                var line = Input.ReadIntArray();
                D = line[0];
                N = line[1];
            }

            int ret = 1;
            for (int i = 0; i < D; i++) ret *= 100;
            if (N == 100) ret *= 101;
            else ret *= N;

            Console.WriteLine(ret);
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

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

int main()
{
    ll n, m, i, j;
    cin >> n;
    m = n;
    vector<double> v(n);
    double k;
    for (ll i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    sort(v.begin(), v.end(), greater<int>());
    for (i = 0; i < n - 1; i++)
    {
        k = (v[m - 1] + v[m - 2]) / 2.;
        v[m - 2] = k;
        sort(v.begin(), v.begin() + m - 1, greater<int>());
        m--;
    }
    cout << setprecision(16) << v[0] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    
    if(a>b) a^=b^=a^=b;
    if(b>c) b^=c^=b^=c;
    if(a>b) a^=b^=a^=b;
    
    printf("%d %d %d\n",a,b,c);
    
    return 0;
}


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

int main() {
    int x;
    cin >> x;
    x /= 200;
    x = 10 - x;
    cout << x << endl;
}


Measured memory_bytes: 3604
import numpy as np
MOD = 998244353
def main():
    n, s = map(int, input().split())
    a = list(map(int, input().split()))
    dp = [np.zeros(s+1, dtype=np.int64) for i in range(n+1)]
    ans = 0
    for i in range(n):
        if a[i] <= s:
            dp[i+1][a[i]:] = dp[i][:-a[i]]
            dp[i+1][a[i]] += i+1
        dp[i+1][:s] += dp[i][:s]
        dp[i+1][dp[i+1] >= MOD] -= MOD
        ans += dp[i+1][s] * (n-i)
        ans %= MOD
#        print(dp[i+1], ans)
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 83196
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

/*

*/


void solve(){

    ll a,b,k;
    cin >> a >> b >> k;
    ll a1, a2;
    if(a<k){
        a1 = 0;
        a2 = max((ll)0,b-(k-a));
    }
    else{
        a1 = a-k;
        a2 = b;
    }

    cout << a1 << " " << a2 << endl;

}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i;
	char a[105],b[105];
	cin>>n;
	scanf("%s%s",a,b);
	for(i=0;i<n;++i)
	{
		cout<<a[i]<<b[i];
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int n;
    for(n = 0; n <= 10; ++n)
    {
        if(N <= 1000 * n)
        {
            break;    
        }
    }
    
    cout << (1000*n - N) << endl;

    return 0;    
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>

#define pb push_back
#define mp make_pair

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef long long ll;

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

  int c[51] = {0};

  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;

    c[a]++;
    c[b]++;
  }

  for (int i = 1; i <= n; ++i) {
    cout << c[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main(){
    
   ull N,M,ans=0; cin >> N >> M;
   
   if(2*N <= M){ans += N; M-=(2*N);  ans += (M/4);}
  else{ans += (M/2);}
   cout << ans << endl;
}

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

typedef long long ll;
typedef int i;
typedef string s;


#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (abs(a*b)/gcd(a,b))
#define sqr(a) (a*a)

#define tt int t; cin>>t; while(t--)
#define lo(i, a, b) for(int i=a; i<b; i++)
#define rlo(i, a) for(int i=a; i>0; i--)
#define be(a) a.begin(),a.end()
#define sz(x) x.size()
#define nl cout<<"\n";
#define sp cout<<" ";

#define op() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

int main()
{
    op();
    double r;
    cin>>r;
    printf("%f",2*r*acos(-1));
    nl;
    return 0;
}



Measured memory_bytes: 3804
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,c,k;
    cin>>n>>k>>c;
    string s;
    cin>>s;
    int l[n]={},r[n]={};
    int x=1;
    for(int i=0;i<n && x<=k;i++){
        if(s[i]=='o'){
            l[i]=x;
            x++;
            i+=c;
        }
    }
    x=k;
    for(int i=n-1;i>=0 && x;i--){
        if(s[i]=='o'){
            r[i]=x;
            x--;
            i-=c;
        }
    }
    for(int i=0;i<n;i++)if(l[i] && l[i]==r[i])cout<<i+1<<endl;
    return 0;
}


Measured memory_bytes: 5264
#include<bits/stdc++.h>
#define FOR0(i,n) for(int i=0;i<n;i++)
#define FOR1(i,n) for(int i=1;i<=n;i++)
#define FORl(i,l,n) for(int i=l;i<n;i++)
using namespace std;
#define pi pair<int,int>
#define pb push_back
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<int>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e14
ll mod = 1e9+7;
ll power(ll num,ll g,ll mod)
{
  if(g==0)return 1;
  if(g%2==1)return (num*power((num*num)%mod,g/2,mod))%mod;
  return power((num*num)%mod,g/2,mod);
}

  
int main() { 
	int n,a,b;
	cin >> n;
	vector< vi > v(n+1);
	map< pi, int > col;
	pi arr[n];
	for (int i = 0; i < n-1; i++){
		cin >> a >> b;
		v[a].pb(b);
		v[b].pb(a);
		arr[i] = mp(a,b);
	}
	int ans = 0;
	for (int i = 1; i <= n; i++){
		ans = max(ans, (int)v[i].size());
	}
	cout << ans << endl;
	queue<pi> qu;
	qu.push(mp(1,0));
	int color = 1;
	int visited[n+1]={};
	// visited[1] = 1;
	while(!qu.empty()){
		auto x = qu.front();
		// cout << x.ff << endl;
		visited[x.ff] = 1;
		qu.pop();
		color = 1;
		for (auto u : v[x.ff]){
			if (visited[u]==1) continue;
			if (color==x.ss) color++;
			col[mp(u,x.ff)] = color;
			col[mp(x.ff,u)] = color;
			qu.push(mp(u, color++));
		}
	}
	for (int i = 0; i < n-1; i++){
		cout << col[arr[i]] << endl;
	}

} 

Measured memory_bytes: 19712
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final int n = scanner.nextInt();
        final int k = scanner.nextInt();
        final Set<Integer> d = IntStream.range(0, k)
            .mapToObj(i -> scanner.nextInt())
            .collect(Collectors.toSet());
        for (int i = n; ; i++) {
            final String s = Integer.toString(i);
            final boolean any = IntStream.range(0, s.length())
                .map(j -> s.charAt(j) - '0')
                .anyMatch(d::contains);
            if (!any) {
                System.out.println(i);
                return;
            }
        }
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

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

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

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

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

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

Measured memory_bytes: 53552
n, m = map(int, input().split())
k = []
s = [0] * m

for i in range(m):
    x = list(map(int, input().split()))
    for j in range(x[0]):
        s[i] += 2**(x[1+j] - 1)

p = list(map(int, input().split()))

count = 0
for i in range(2**n):
    flg = True
    for j in range(m):
        if bin(i & s[j]).count("1") % 2 != p[j]:
            flg = False
            break
    if flg:
        count += 1

print(count)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
constexpr int MOD = 1e9 + 7;


ll progsum(ll a,ll d,ll n)
{
    return n * (2 * a + (n - 1) * d)/2;
}


int main()
{
    ll n,k;
    cin >> n >> k;
    ll r = 0;
    ll i = 0;
    for(i = k;i <= n + 1;i++)
    {
        ll series_min = progsum(0,1,i);
        ll series_max = progsum(n,-1,i);
        r += series_max - series_min + 1;
        r = r%MOD;
    }
    cout << r << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define cps CLOCKS_PER_SEC
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define eb emplace_back
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define fi first
#define se second
#define bitcount(x) __builtin_popcount(x)
#define bit(x) (1LL << x)
#define PI acos(-1.0)
#define EPS 1e-9

#define mod 1000000007
#define maxn 200005

using namespace std;

using namespace __gnu_pbds;
template<class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
///All indexing is 0-based
///methods: find_by_order(k); & order_of_key(k);
///To make it an ordered_multiset, use pairs of (value, time_of_insertion)
///to distinguish values which are similar

typedef long long ll;
typedef double ld;
typedef pair<ll, ll> par;

ll k,a,b;

int main()
{
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> k >> a >> b;
    for(int i=a;i<=b;i++)
        if(i%k==0){
                cout << "OK\n";
                return 0;
        }
            cout << "NG\n";
            return 0;





}


Measured memory_bytes: 3648
#include<stdio.h>
int main(){
    int k,n;
    scanf("%d %d",&k,&n);
    int a[n];
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    int max=0;
    for(int i=0;i<n-1;i++){
        if((a[i+1]-a[i])>max){
            max=a[i+1]-a[i];
        }
    }
    if((a[n-1]-a[0])<(k-max)){
        printf("%d\n",a[n-1]-a[0]);
        return 0;
    }
    printf("%d\n",k-max);
    return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
  long long N;
  cin >> N;
  long long qmax = sqrt(N);
  long long sum = 0;
  for (long long q=1;q<qmax+1;q++){
    if(N%q==0){
      long long m=N/q-1;
      if(m!=0){
      if((N/m)==(N%m)){
        sum = sum+m;
      }
    }
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
let counting_sort a b k n =
  let c = Array.make (k + 1) 0 in
  Array.iter (fun e -> c.(e) <- c.(e) + 1) a;
  Array.iteri (fun i _ -> if i <> 0 then c.(i) <- c.(i) + c.(i-1)) c;
  for i = n - 1 downto 0 do
    b.(c.( a.(i) ) - 1) <- a.(i);
    c.( a.(i) ) <- c.( a.(i) ) - 1;
  done

let () =
  let n = read_int () in
  let a = Array.init n (fun _ -> Scanf.scanf "%d " (fun e -> e)) in
  let b = Array.make n 0 in
  counting_sort a b 10000 n;
  print_int b.(0);
  for i = 1 to n - 1 do
    print_string " ";
    print_int b.(i);
  done;
  print_newline ()

Measured memory_bytes: 36208
#include<iostream>
#define maxn 10010
using namespace std;
int n,q;
int father[maxn];
int rank[maxn];

void init(){
	for(int i=0;i<n;i++)father[i]=i;
	for(int i=0;i<n;i++)rank[i]=0;
}

int find(int x){ // x???????????¢??????
	if(father[x]==x)return x; // ?????????????????????????????´??????x???????????????
	return father[x]=find(father[x]); // ??????????????§????????°??????????????????????????????(????????§?????????)
}

void unite(int x,int y){
	// father[find(x)]=find(y); // x????????¨y????????????????????????
	father[find(x)]=find(y);
}

int same(int x,int y){
	if(find(x)==find(y))return 1;
	else return 0;
}

int main(void){
	cin>>n>>q;
	init();
	while(q--){
		int com,x,y;
		cin>>com>>x>>y;
		if(com){
			cout<<same(x,y)<<endl;
		}else{
			unite(x,y);
		}
	}
	return 0;
}

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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/e.in", "r", stdin);
//  freopen("../IO/e.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}


constexpr int P = 1'000'000'007;
void solve(std::istream &in, std::ostream &out) {
  int n;
  in >> n;
  vector<vector<int>> graph(n+1);
  for (int i = 1, p; i <= n; ++i) {
    in >> p;
    graph[p].push_back(i);
  }
  int i2 = (P + 1) / 2;
  using dp_t = deque<array<int, 2>>;
  function<dp_t(int)> dfs = [&](int u) {
    dp_t res;
    int z = 0;
    for (int v : graph[u]) {
      dp_t rhs = dfs(v);
      if (rhs.size() > res.size())
        swap(rhs, res);
      z = max(z, (int) rhs.size());
      for (int depth = 0; depth < (int) rhs.size(); ++depth) {
        res[depth][1] = ((int64_t) res[depth][1] * rhs[depth][0] + (int64_t) res[depth][0] * rhs[depth][1]) % P;
        res[depth][0] = (int64_t) res[depth][0] * rhs[depth][0] % P;
      }
    }
    for (int depth = 0; depth < z; ++depth)
      res[depth][0] = (1 + P - res[depth][1]) % P;
    res.push_front({i2, i2});
    return res;
  };
  int p2 = 1;
  for (int i = 0; i <= n; ++i) (p2 *= 2) %= P;
  int ans = 0;
  dp_t dp = dfs(0);
  for (array<int, 2> d : dp) (ans += d[1]) %= P;
  out << (int64_t) ans * p2 % P << '\n';
}


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

ans = [0] * N
for i in range(N,0,-1):
    ts = sum(ans[i-1:N:i])
    if ts % 2 != A[i-1]: ans[i-1] = 1

print(sum(ans))
for i in range(N):
    if ans[i] == 1: print(i+1,end=' ')
print()

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

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<typename T> void view(T cont) {std::cout << cont << std::endl;}
template<typename T> void view(T* cont, ll sz) {rep(i, sz) std::cout << cont[i] << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<T>& v) {for (const auto& f: v) std::cout << f << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v: vv) {view(v);}}
#define INF 1000000000

int main(){
    int N; cin >> N;
    vector<int> h;
    rep(i, N) {
        int temp; cin >> temp;
        h.push_back(temp);
    }
    vector<int> dp(N);
    dp[0] = 0; dp[1] = abs(h[0] - h[1]);
    for (int i = 2; i < N; i++) {
        dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]),
                    dp[i - 2] + abs(h[i - 2] - h[i]));
    }
    // view(dp);
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1144
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
 
#define mod 1000000007
#define inf 1000000000
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}

int main(){
  ll a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  ll n;
  cin >> n;
  cout << a[n-1] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
#define ALL(a) (a).begin(), (a).end()
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int dy8[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dx8[] = {0, 1, 0, -1, 1, 1, -1, -1};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

unsigned GetDigit(unsigned num) { return to_string(num).length(); }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

ll nCr(int n, int r)
{
    if (n == r or n == 0)
        return 1;
    if (n < r)
        return 0;
    if (r == 1)
        return n;
    return nCr(n - 1, r - 1) + nCr(n - 1, r);
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{

    int X,N; cin >> X >> N;
    vector<int> p(N);
    REP(i,N) cin >> p[i];

    vector<bool> res(101,false);

    if(N==0){
        cout << X << endl;
        return 0;
    }

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

    int hold = 100000000, ans = 0;

    FOR(i,-10,102){
        if(!exist_in(p,i)){
            if(abs(X - i) < hold){
                hold = abs(X-i);
                ans = i;
            }
        }
    }

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


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

int main()
{
    ios::sync_with_stdio(false);

    int N, A, B; cin >> N >> A >> B;
    string S; cin >> S;


    auto japanese = 0, overseas = 0;
    for (auto i = 0; i < N; i++)
    {
        if (S[i] == 'a')
        {
            if (japanese + overseas < A+B)
            {
                japanese++;
                cout << "Yes" << "\n";
            }
            else cout << "No" << "\n";
        }
        if (S[i] == 'b')
        {
            if (japanese + overseas < A+B && overseas < B)
            {
                overseas++;
                cout << "Yes" << "\n";
            }
            else cout << "No" << "\n";
        }
        if (S[i] == 'c')
            cout << "No" << "\n";
    }
}


Measured memory_bytes: 848
#include <iomanip>
#include <random>
#include <time.h>
#include <vector>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <cstdlib>
#include <typeinfo>
#include <math.h>
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1e9;
ll h, w, sy, sx, gy, gx, dis[55][55], nx, ny;
ll dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
char yan[55][55];
ll habatan() {
	queue<P> yojo;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) dis[i][j] = inf;
	}
	yojo.push(P(sx, sy));
	dis[sx][sy] = 0;
	while (!yojo.empty()) {
		P siri = yojo.front();
		yojo.pop();
		if (siri.first == gx && siri.second == gy)break;
		for (int i = 0; i < 4; i++) {
			nx = siri.first + dx[i], ny = siri.second + dy[i];
			if (nx>=0&&ny>=0&&yan[nx][ny] != '#'&&dis[nx][ny] == inf) {
				yojo.push(P(nx, ny));
				dis[nx][ny] = dis[siri.first][siri.second] + 1;
			}
		}
	}
	return dis[gx][gy];
}
int main() {
	cin >> h >> w;
	ll cnt = 0;
	for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
		cin >> yan[i][j];
		if (yan[i][j] == '.')cnt++;
	}
	sx = sy = 0;
	gx = h, gy = w;
	gx--, gy--;
	
	if (habatan() == inf)cout << -1 << endl;
	else cout << cnt-habatan()-1 << endl;
	return 0;
}


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

int main (void) {
  int N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  vector<int> tbl(N + 1);
  for (int i = 1; i < N; i++) {
    if (S[i - 1] == 'A' && S[i] == 'C')
      tbl[i + 1] = tbl[i] + 1;
    else
      tbl[i + 1] = tbl[i];
  }
  for (int i = 0; i < Q; i++) {
    int l, r;
    cin >> l >> r;
    cout << tbl[r] - tbl[l] << endl;
  }
  return 0;
}

Measured memory_bytes: 1408