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

int main()
 {

  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);

  int N, Q;
  cin >> N >> Q;
  int a, b;

  vector<int> adj[N];
  for (int i = 0; i < N - 1; i++)
    {
    cin >> a >> b;
    a--;
    b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  int p[Q];
  ll x[Q];
  ll c[N]{};
  for (int i = 0; i < Q; i++) {
    cin >> p[i] >> x[i];
    p[i]--;
    c[p[i]] += x[i];
  }
  ll t = 0;
  deque<int> q;
  q.push_back(0);
  int vis[N]{};
  vis[0] = 1;
  while(!q.empty()) {
    int u = q.front();
    q.pop_front();
    for (int i : adj[u]) {
      if (vis[i] == 1) continue;
      vis[i] = 1;
      c[i] += c[u];
      q.push_back(i);
    }
  }
  for (int i = 0; i < N; i++) {
    if (i == N - 1) {
      cout << c[i] << "\n";
    } else {
      cout << c[i] << " ";
    }
  }
  return 0;
}


Measured memory_bytes: 19444
#include <stdio.h>

int a,b ;

int main(void){

    scanf ("%d%d",&a,&b) ;
    
    if ( a%3==0 || b%3==0 || (a+b)%3==0 ){
        printf ("Possible\n") ;
    } else {
        printf ("Impossible\n") ;
    }
    
    return 0 ;
    
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

void solve() {
	int n, W;
	cin >> n >> W;
	
	vi w(n + 1), v(n + 1);
	for(int i = 1; i <= n; i++) cin >> w[i] >> v[i];
	
	vector<vector<ll>> dp(n + 1, vector<ll>(100001, (1LL << 60)));
	dp[0][0] = 0;
	for(int i = 1; i <= n; i++) {
		for(int j = 0; j <= 100000; j++) {
			if(dp[i - 1][j] == (1LL << 60)) continue;
			
			dp[i][j] = min(dp[i][j], dp[i - 1][j]);
			if(j + v[i] <= 1000001) dp[i][j + v[i]] = min(dp[i][j + v[i]], dp[i - 1][j] + w[i]);
		}
	}
	
	int mx = 0;
	for(int i = 0; i <= 100000; i++) {
		if(dp[n][i] <= W) mx = i;
	}
	
	cout << mx << endl;
}

int main(){
#define MULTITEST 0
#if MULTITEST   
 
    CASET {
        solve();
    }
    
#else

    solve();
    
#endif

    return 0;
}

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


int main(){
    ll N, M; cin >> N >> M;
    vector<vector<pair<ll,ll>>> G(N+1);
    rep(i, 0, M){
        ll v, u, w;
        cin >> v >> u >> w;
        G[u].push_back({v, w});
        G[v].push_back({u, w});
    }
    rep(i, 1, N) {
        G[i+1].push_back({i, 0});
    }

    ll srt = 1;
    constexpr ll INF = 1e18;
    vector<ll> d(N+1, INF);
    
    /* dijkstra's scope */{
        priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> que;
        que.push({0, srt});
        d[srt] = 0;
        while(!que.empty()){
            auto q = que.top();
            que.pop();
            if(q.first > d[q.second]) continue;
            for(auto g : G[q.second]){
                if(d[g.first] <= q.first + g.second) continue;
                d[g.first] = q.first + g.second;
                que.push({d[g.first], g.first});
            }
        }
    }

    if(d[N] == INF) cout << -1 << endl;
    else cout << d[N] << endl;
    return 0;
}

Measured memory_bytes: 15352
#include <stdio.h>
#include <algorithm>
using namespace std;
typedef long long int ll;
constexpr int kN = int(4E2 + 10);
constexpr ll kInf = ll(1E16 + 10);
ll dp[kN][kN], s[kN];
int a[kN];

ll val(int l, int r) {return s[r] - s[l - 1];}
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for (int i = 1; i <= n; i++) s[i] = s[i - 1] + a[i];
	for (int i = 1; i <= n; i++) dp[i][i] = 0;
	for (int i = 1; i < n; i++) {
		for (int j = 1; j <= n - i; j++) {
			dp[j][j + i] = kInf;
			for (int k = j; k < j + i; k++) {
				dp[j][j + i] = min(dp[j][j + i], dp[j][k] + dp[k + 1][j + i] + val(j, k) + val(k + 1, j + i));
			}
		}
	}
	printf("%lld\n", dp[1][n]);

}


Measured memory_bytes: 2960
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long a = sc.nextLong();
		System.out.println(solver(n, a));
	}

	long solver(long n, long a) {
		long ans = n;
		if (n == 1) {
			return 1;
		}
		for (int i = 1; i <= 40; ++i) {
			// min ( k1 + k2 + ... ki + a*(i-1) )
			// k1*k2*k3*...*ki>=n
			long t = a * (i - 1);
			long maxK = f(i, n);
			long curK = 1;
			for (int j = 0; j < i; ++j) {
				if (curK * pow(maxK - 1, i - j) / pow(maxK - 1, i - j) == curK && curK * pow(maxK - 1, i - j) < n) {
					t += maxK;
					if (curK != curK * maxK / maxK) {
						curK = n;
					} else {
						curK *= maxK;
					}
				} else {
					t += maxK - 1;
					if (curK != curK * (maxK - 1) / (maxK - 1)) {
						curK = n;
					} else {
						curK *= maxK - 1;
					}
				}
			}
			ans = Math.min(ans, t);
		}
		return ans;
	}

	long f(long i, long n) {
		long ok = n;
		long ng = 0;
		out: while (ok - ng > 1) {
			long middle = (ok + ng) / 2;
			long v = 1;
			for (int k = 0; k < i; ++k) {
				if (v != v * middle / middle) {
					ok = middle;
					continue out;
				}
				v *= middle;
			}
			if (v >= n) {
				ok = middle;
			} else {
				ng = middle;
			}
		}
		return ok;
	}

	long pow(long a, long n) {
		long ret = 1;
		for (; n > 0; n >>= 1, a *= a) {
			if (n % 2 == 1) {
				ret *= a;
			}
		}
		return ret;
	}

	int solver2(int n, int a) {
		int[] dp = new int[2 * n];
		Arrays.fill(dp, Integer.MAX_VALUE >> 3);
		dp[0] = 0;
		for (int i = 0; i < n; ++i) {
			if (i != 0)
				for (int j = i; j < 2 * n; j += i) {
					dp[j] = Math.min(dp[j], dp[i] + a + j / i);
				}
			else {
				for (int j = 1; j < 2 * n; ++j) {
					dp[j] = j;
				}
			}
		}
		int ans = Integer.MAX_VALUE >> 3;
		for (int i = n; i < 2 * n; ++i) {
			ans = Math.min(ans, dp[i]);
		}
		return ans;
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 23380
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

int main() {
    ll H,W;
    cin >> H >> W;
    vector<vector<ll>> num(H,vector<ll>(W)),resw(H,vector<ll>(W)),resh(H,vector<ll>(W));;
    vector<vector<char>> C(H,vector<char>(W));

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> C[i][j];
            if(C[i][j]=='.')num[i][j]=1;
        }
    }
    for(int i=0;i<H;i++){
        int idx=0,ct=0;
        for(int j=0;j<W;j++){
            if(j==W-1 && C[i][j]=='.'){
                ct++;
                for(int l=idx;l<=j;l++) resw[i][l]=ct;
            } 
            if(C[i][j]=='.') {
                ct++;
            }
            else{
                for(int l=idx;l<j;l++) resw[i][l]=ct;
                ct=0;
                idx=j+1;
            }
        }
    }

    for(int i=0;i<W;i++){
        int idx=0,ct=0;
        for(int j=0;j<H;j++){
            
            if(j==H-1 && C[j][i]=='.'){
                ct++;
                for(int l=idx;l<=j;l++) resh[l][i]=ct;
            } 
            else if(C[j][i]=='.') {
                ct++;
            }
            else if(C[j][i]=='#'){
                for(int l=idx;l<j;l++) resh[l][i]=ct;
                ct=0;
                idx=j+1;
            }
        }
    }
    ll ans = 0;
    for(int i=0;i<H;i++){
        int idx=0,ct=0;
        for(int j=0;j<W;j++){
            ans=max(ans,resw[i][j]+resh[i][j]-1);
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 100224
import math
import queue
from collections import defaultdict

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def printQueue(q):
	r=qb
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
def dq():
	return queue.deque()
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1

n = readInt()
be = [0,0]
b_time = 0
for i in range(n):
	data = readInts()
	delta = abs(be[0]-data[1])+abs(be[1]-data[2])
	time = data[0]-b_time
	if delta<=time and delta%2==time%2:
		be = data[1:]
		b_time = data[0]
	else:
		print("No")
		exit()

print("Yes")

Measured memory_bytes: 9796
def main():
    R, G, B, N = map(int, input().split())
    R, G, B = sorted([R, G, B])
    result = 0
    for i in range(N // G + 1):
        for j in range(N // B + 1):
            if (N - G*i - B*j) < 0:
                break
            elif (N - G*i - B*j) % R == 0:
                result += 1
    print(result)
main()

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

#define LL long long
#define mods 1000000009

vector<int>v1[100100];
int ans=0;
int mm;
int ar[100100];

int dfs(int x,int cn)
{
    if(ar[x]==1)
    return 0;
    ar[x]=1;
    if(cn==mm)
    {
        ar[x]=0;
        ans++;
        return 0;
    }
    for(int i=0;i<v1[x].size();i++)
    {
        dfs(v1[x][i],cn+1);

    }
    ar[x]=0;

}

int main()
{
   // factorila();
    //freopen("amin.txt","w",stdout)
     int n,cn=1,a,b,i,j,l,k,k1,m,x,y;
     map<int,int>m1;
     scanf("%d",&n);
     scanf("%d",&m);
     for(i=0;i<m;i++)
     {
         cin>>x>>y;
         v1[x].push_back(y);
         v1[y].push_back(x);

     }

     mm=n;

     dfs(1,1);
     cout<<ans<<"\n";
}


Measured memory_bytes: 2560
from collections import defaultdict
N=int(input().strip())
points=defaultdict(list)
for i in range(N):
    S,P=input().strip().split()
    P=int(P)
    points[S].append((i+1,P))
for s in sorted(points.keys()):
    shps=points[s]
    for sh in sorted(shps,key=lambda x:-x[1]):
        print(sh[0])

Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
 
int main() {
    unsigned long long n;
    cin >> n;
 
    unsigned long long x;
 
    for (unsigned long long i = 1; i < n; i++) {
        if (i * i + i >= n) {
            break;
        }
        if (n % i == 0) {
            x += n / i - 1;
        }
    }
    
    cout << x << endl;
 
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;


void Main(){
    ll N, a;
    sll(N);
    set<ll> counter;
    bool is_ok = true;
    rep(i, N){
        sll(a);
        if(counter.find(a) != counter.end()){
            is_ok = false;
        }else{
            counter.insert(a);
        }
    }
    if(is_ok){
        cout << "YES" <<endl;
    }else{
        cout << "NO" <<endl;

    }
}

int main(){
    Main();
}

Measured memory_bytes: 12520
import java.util.*;

public class Main {
    public static void main (String[] args){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = sc.nextInt();
        int b= sc.nextInt();
        
        int diffA = Math.abs(x - a);
        int diffB = Math.abs(x - b);
        
        String output;
        if(diffA < diffB){
            output = "A";
        }else{
            output = "B";            
        }
        
        System.out.println(output);
    }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1e9+7;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}


typedef pair<ll, ll> pll;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i=0; i<N; i++) cin >> A[i];
    vector<ll> s(N+1);
    for (int i=0; i<N; i++){
        s[i+1] = (s[i] + A[i]) % MOD;
    }
    
    long long ans = 0;
    for (int i=0; i<N-1; i++){
        // cout << A[i] << " " << (s[N] - s[i+1])<< (A[i] * (s[N] - s[i])) << endl;
        ans += ((A[i]% MOD * mod(((s[N]%MOD) - (s[i+1]%MOD)), MOD)) % MOD) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 6416
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;

class in {
  int n;
public:
  in() {}
  in(int n_) : n(n_){};
  template <class T> operator T() { T ret; cin >> ret; return ret; }
  template <class T> operator vector<T>() { vector<T> ret(n); for (int i = 0; i < n; i++) cin >> ret[i]; return ret; }
};

template <std::uint_fast64_t Mod> class modint {
  using u64 = std::uint_fast64_t;
public:
  u64 a;
  constexpr modint(const u64 x = 0) noexcept : a(x % Mod) {}
  constexpr u64 val() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; }
  constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; }
  constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; }
  constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; }
  constexpr bool operator==(const modint rhs) const noexcept { return modint(*this).val() == rhs.val(); }
  modint &operator+=(const modint rhs) noexcept { a += rhs.a; if (a >= Mod) a -= Mod; return *this; }
  modint &operator-=(const modint rhs) noexcept { if (a < rhs.a) a += Mod; a -= rhs.a; return *this; }
  modint &operator*=(const modint rhs) noexcept { a = a * rhs.a % Mod; return *this; }
  modint &operator/=(modint rhs) noexcept { u64 exp = Mod - 2; while (exp) { if (exp % 2) *this *= rhs; rhs *= rhs; exp /= 2; } return *this; }
};
template <std::uint_fast64_t Mod>
ostream& operator<<(ostream& os, const modint<Mod>& m){ return os << m.a; }
const ll mod=(ll)1e9+7;
using mint = modint<mod>;
//}}}

const int kMaxBit = 64;
int bit0[kMaxBit];
int bit1[kMaxBit];

int main(){
  int N = in();
  vector<ll> A = in(N);

  mint ans = 0;
  rep(i, N){
    rep(b, kMaxBit){
      bit1[b] += ((A[i] >> b) & 1);
    }
  }
  rep(b, kMaxBit){
    bit0[b] = N - bit1[b];
  }

  rep(b, kMaxBit){
    ans += (1LL << b) % mod * bit0[b] % mod * bit1[b];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std ;
int n , l ;
string a[105] ;

int main()
{
	
	cin >> n >> l ;
	for ( int i = 0 ; i < n ; i++ )
	{
		cin >> a[i] ;
	}
	sort( a , a + n ) ;
	for ( int i = 0 ; i < n ; i++ )
	{
		cout << a[i] ;
	}
	cout << endl ;
	
	return 0 ;
	
} 

Measured memory_bytes: 256
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include <algorithm>
#include<initializer_list>
#include<map>
#include<set>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int>t(n + 2, 0);
	t[0] = t[n + 1] = 0;
	for (int i = 1; i < n + 1; i++) cin >> t[i];
	vector<int>v(n + 2, 0);
	v[0] = v[n + 1] = 0;
	for (int i = 1; i < n + 1; i++)cin >> v[i];
	int totalTime = 0;
	for (int i = 0; i < n + 2; i++)totalTime += t[i];
	vector<double>maxv(2 * totalTime + 1, 0);
	int timeSum = 0;
	for (int i = 1; i < t.size()-1; i++) {
		maxv[timeSum] = min(v[i], v[i - 1]);
		for (int j = timeSum + 1; j < timeSum + 2 * t[i]; j++) {
			maxv[j] = v[i];
		}
		timeSum += 2 * t[i];
	}
	maxv[0] = maxv[2*totalTime] = 0;

	for (int i = 1; i < maxv.size(); i++) {
		maxv[i] = min(maxv[i], maxv[i - 1] + 0.5);
	}
	for (int i = maxv.size() - 2; i >= 0; i--) {
		maxv[i] = min(maxv[i], maxv[i + 1] + 0.5);
	}
	double distance = 0;
	for (int i = 0; i < maxv.size() - 1; i++) {
		distance += 0.5*0.5*(maxv[i + 1] + maxv[i]);
	}
	printf("%.10f\n", distance);
	return 0;
}



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

int main(){
  int n;
  cin>>n;
  int cntAC=0;
  int cntWA=0;
  int cntTLE=0;
  int cntRE=0;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    if(s=="AC") cntAC++;
    if(s=="WA") cntWA++;
    if(s=="TLE") cntTLE++;
    if(s=="RE") cntRE++;
  }
  cout<<"AC"<<" "<<"x"<<" "<<cntAC<<endl;
  cout<<"WA"<<" "<<"x"<<" "<<cntWA<<endl;
  cout<<"TLE"<<" "<<"x"<<" "<<cntTLE<<endl;
  cout<<"RE"<<" "<<"x"<<" "<<cntRE<<endl;
}

Measured memory_bytes: 3632
n=int(input())
a=[int(i) for i in input().split()]

def somosomo(a):
    ans=[]
    if n%2==1:
        ans.append(0)
        for i in range(1,n//2+1):
            ans.append(i*2)
            ans.append(i*2)
        b=sorted(a)
        if b==ans:
            return True
        return False
    else:
        for i in range(1,n//2+1):
            ans.append(i*2-1)
            ans.append(i*2-1)
        b=sorted(a)
        if b==ans:
            return True
        return False

def two_ride(n):
    ans=1
    for i in range(n):
        ans*=2
        ans%=10**9+7
    return ans

if somosomo(a):
    print(two_ride(n//2))
else:
    print(0)

Measured memory_bytes: 19992
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

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

const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int INF_INT = 1e9;

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

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

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> check(N+1,0);
    for(int i = 0; i < M; i++){
        int a;
        cin >> a;
        check[a] = 1;
    }
    ll memo[N+1];
    for(int i = 0; i <= N; i++) memo[i] = 0;
    memo[N] = 1;
    for(int i = N-1; i >= 0; i--){
        if(check[i] == 1) continue;
        bool ex = false;
        if(i + 1 <= N){
            if(check[i+1] != 1){
                ex = true;
                memo[i] = (memo[i] + memo[i+1]) % MOD;
            }
        }
        if(i + 2 <= N){
            if(check[i+2] != 1){
                ex = true;
                memo[i] = (memo[i] + memo[i+2]) % MOD;
            }
        }
        if(!ex){
            memo[0] = 0;
            break;
        }
    }
    cout << memo[0] << endl;
    return 0;
}


Measured memory_bytes: 4580
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

s = input()
n = len(s)
if s.count('o') + 15 - n >= 8:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
const long double eps = 1e-10;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

ll gcd(ll a, ll b) {
    if (b == 0)return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}

int main() {
    init();

    ll a, b; cin >> a >> b;
    cout << lcm(a, b) << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
	string s;
	cin>>s;
	long long int ans=0,c=0;
	for(int i=0;i<s.length();i++){
		if(s[i]=='W'){
			ans+=c;
		}else{
			c++;
		}
	}
	cout<<ans;
}

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

int main() {
	static long long N, SUM[26] = {};
	string S, T;
	cin >> N >> S >> T;
	SUM[S[0] - 'a']++;
	for (int i = 1; i < S.size() - 1; i++) {
		SUM[S[i] - 'a'] += SUM[T[i] - 'a'];
		SUM[S[i] - 'a'] %= 1000000007;
	}
	cout << SUM[T[T.size() - 1] - 'a'] << endl;
}


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

using namespace std;

int main()
{
    int a;
    int b;
    int c;
    int k;
    cin >> a >> b >> c >> k;

    if(k<=a)
    {
        cout << k << "\n";
    }
    else if(k<=(a+b))
    {
        cout << a << "\n";
    }
    else if(k<=(a+b+c))
    {
        cout << a-(k-(a+b)) << "\n";
    }
    return 0;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
using ll = long long;

struct SegmentTree {
  int N;
  vector<ll> dat;
  SegmentTree(int n) {
    N = 1;
    while (N < n) N *= 2;
    dat.assign(2*N-1, lINF);
  }
  void update(int i, ll x) {
    i += N - 1;
    dat[i] = x;
    while (i > 0) {
      i = (i - 1) / 2;
      dat[i] = min(dat[i*2+1], dat[i*2+2]);
    }
  }
  ll query(int a, int b) { return query(a, b, 0, 0, N); }
  ll query(int a, int b, int i, int l, int r) {
    if(r <= a || b <= l) return lINF;
    if(a <= l && r <= b) return dat[i];
    ll vl = query(a, b, i*2+1, l, (l+r)/2);
    ll vr = query(a, b, i*2+2, (l+r)/2, r);
    return min(vl, vr);
  }
};

using T=tuple<int,int,int>;

int main(){
  int n,m;
  cin>>n>>m;
  vector<T>rng(m);
  rep(i,m){
    int l,r,c;
    cin>>l>>r>>c;
    l--;r--;
    rng[i]=make_tuple(r,l,c);
  }
  sort(rng.begin(),rng.end());
  SegmentTree min_d(n);
  min_d.update(0,0);
  rep(i,n-1)min_d.update(i+1,lINF);
  rep(i,m){
    int l,r,c;
    tie(r,l,c)=rng[i];
    ll mi=min_d.query(l,r+1);
    if(mi!=lINF){
      ll mi2=min_d.query(r,r+1);
      mi2=min(mi2,mi+c);
      min_d.update(r,mi2);
    }
  }
  ll ans=min_d.query(n-1,n);
  if(ans==lINF)cout<<-1<<endl;
  else cout<<ans<<endl;
  return(0);
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define MAXN 330
#define pii pair<int, int>
#define pll pair<long long, pair<long long, long long>>
#define ff first
#define ss second
#define ll long long
#define in_range(x, y, n) (x >= 0 and x < n and y >= 0 and y < n)
using namespace std;
const int mod = 1e9 + 7;
const ll oo = 1e17 + 7;
ll dist[MAXN][MAXN], fuel[MAXN][MAXN];

void floyd(int n, int li){

    for (int k = 0; k < n; k++){
        for (int i = 0; i < n; i++){
            for (int j = 0; j < n; j++){
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    for (int i=0; i<n; i++){
        for (int j=0; j<n;j++){
            if (dist[i][j] <= li) fuel[i][j] = 1;
        }
    }

    for (int k = 0; k < n; k++){
        for (int i = 0; i < n; i++){
            for (int j = 0; j < n; j++){
                fuel[i][j] = min(fuel[i][j], fuel[i][k] + fuel[k][j]);
            }
        }
    }
}

void init(int n){
    for (int i=0; i<n; i++){
        for (int j=0; j<n; j++){
            fuel[i][j] = dist[i][j] = oo;
        }
        fuel[i][i] = dist[i][i] = 0;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    // cout << LONG_LONG_MAX << endl;
    ll n, a , b, c, m ,q, l;
    cin >> n >> m >> l;
    init(n);

    for (int i=0; i<m; i++){
        cin >> a >> b >> c;
        a--, b--;
        if (c <= l){
            dist[a][b] = dist[b][a] = c;
        }
    }

    floyd(n, l);
    cin >> q;

    for (int i=0; i<q; i++){
        //cout << "ok" << endl;
        cin >> a >> b;
        a--, b--;
        if (fuel[a][b] == oo) cout << "-1" << endl;
        else {
            cout << fuel[a][b] - 1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 5184
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
int W,H;
bool inrange(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
#define MP make_pair
struct edge{int to,cap,rev;};//ikisaki youryou gyakuhen
class Dinic{//max flow
public:
    int n;
    vector<vector<edge> >G;//[MAX];
    vi level,iter;//[MAX];
    Dinic(int size){
        n=size;
        G=vector<vector<edge> >(n);
    }
    void add_edge(int from, int to, int cap){
        edge q={to,cap,int(G[to].size())};
        G[from].push_back(q);
        q={from,0,int(G[from].size()-1)};
        G[to].push_back(q);
    }
    int getmaxflow(int s,int t) {//from s to t,ford_fulkerson
        int flow=0;
        while(1){
            bfs(s);
            if(level[t]<0)return flow;
            iter=vi(n);
            int f;
            while((f=dfs(s,t,INF))>0)flow+=f;
        }
    }
private:
    void bfs(int s){
        level=vi(n,-1);
        queue<int>q;
        level[s]=0;
        q.push(s);
        while(!q.empty()){
            int v=q.front();q.pop();
            for(int i=0;i<G[v].size();i++){
                edge &e=G[v][i];
                if(e.cap>0&&level[e.to]<0){
                    level[e.to]=level[v]+1;
                    q.push(e.to);
                }
            }
        }
    }
    int dfs(int v,int t, int f) {
        if(v==t)return f;
        for(int &i=iter[v];i<G[v].size();i++){
            edge &e=G[v][i];
            if(level[v]>=level[e.to]||e.cap<=0) continue;
            int d =dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
        return 0;
    }
};

long long gcd(long long a, long long b) {return b ? gcd(b, a % b) : a;}
long long lcm(long long m, long long n ){if((0 == m )||( 0 == n ))return 0;
    return ((m / gcd(m, n)) * n);
}
signed main(){
    int a,b;
    while(cin>>a>>b,a+b){
        Dinic hoge(a+b+2);
        int source=a+b;
        int sink=a+b+1;
        vector<int>v(a);
        vector<int>u(b);
        rep(i,a)cin>>v[i];
        rep(j,b)cin>>u[j];
        rep(i,a)hoge.add_edge(source,i, 1);
        rep(i,b)hoge.add_edge(i+a,sink, 1);
        rep(i,a)rep(j,b){
            if(gcd(v[i],u[j])!=1)hoge.add_edge(i, j+a, 1);
        }
        cout<<hoge.getmaxflow(source, sink)<<endl;
    }
}



Measured memory_bytes: 11368
import math
N = int(input())

M = 0
A = 0
R = 0
C = 0
H = 0

n = 0
for n in range(N):
    X_n = list(input())
    # print(X_n)
    if (X_n[0]) == "M":
        M += 1
    if (X_n[0]) == "A":
        A += 1
    if (X_n[0]) == "R":
        R += 1
    if (X_n[0]) == "C":
        C += 1
    if (X_n[0]) == "H":
        H += 1
    n += 1



lisofnum = [M, A, R, C, H]
#print(lisofnum)
k = 0
cou = 0
for k in range(len(lisofnum)):
    if lisofnum[k] != 0:
        cou += 1
    k += 1
#print(cou)

if cou < 3:
    print(0)
else:
    print(M*A*R+M*A*C+M*A*H + M*R*C+M*R*H + M*C*H + A*R*C+A*R*H+A*C*H + R*C*H)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <array>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
using namespace std;
template <typename T> istream & operator >> (istream & is, vector<T> & vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;
using VI = vector<int>;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
	int a, b; CI a >> b;
	string s; CI s;
	if (s[b-1] >= 'A') s[b-1] = s[b-1] + 0x20;
	else s[b-1] = s[b-1] - 0x20;
	CO s EN;
}

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

void merge(list<pair<long long, long long>> &L, long long mn, long long mx)
{
    for (auto p=L.begin(); p!=L.end();)
    {
        if (mn<=p->first && p->second<=mx)
        {
            p = L.erase(p);
        }
        else if (p->first<=mn && mx<=p->second)
        {
            mn = p->first;
            mx = p->second;
            p = L.erase(p);
        }
        else if (mn<=p->first && p->first<=mx)
        {
            mx = p->second;
            p = L.erase(p);
        }
        else if (p->first<=mn && mn<=p->second)
        {
            mn = p->first;
            p = L.erase(p);
        }
        else
            p++;
    }
    L.push_back(make_pair(mn, mx));
}

int main()
{
    long long N, X, D;
    cin>>N>>X>>D;

    if (D<0)
    {
        X *= -1LL;
        D *= -1LL;
    }

    if (D==0)
    {
        cout<<(X==0 ? 1 : N+1)<<endl;
        return 0;
    }

    map<long long, list<pair<long long, long long>>> M;

    long long mn = 0;
    long long mx = 0;
    M[0].push_back(make_pair(0LL, 0LL));

    for (long long i=0; i<N; i++)
    {
        mn += i;
        mx += N-i-1;

        long long t = X*(i+1);
        list<pair<long long, long long>> &L = M[(t%D+D)%D];
        t -= (t%D+D)%D;
        t /= D;
        merge(L, t+mn, t+mx);
    }

    long long ans = 0;
    for (auto L: M)
        for (auto e: L.second)
            ans += e.second-e.first+1;
    cout<<ans<<endl;
}


Measured memory_bytes: 25216
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <string>
#include <utility>
#include <cassert>
#include <numeric>
#include <random>


using namespace std;
typedef long long ll;

ll pre[128], suf[128];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<ll> pesos;
  for (int i = 0; i < n; i++) {
    ll w;
    cin >> w;
    pesos.push_back(w);
  }


  pre[0] = pesos[0];
  for (int i = 1; i < n; i++) {
    pre[i] = pre[i-1] + pesos[i];
  }  
  suf[n-1] = pesos[n-1];
  for (int i = n-2; i >= 0; i--) {
    suf[i] = suf[i+1] + pesos[i];
  }

  ll res = 1e18;
  for (int i = 1; i < n-1; i++) {
    ll aux = abs(pre[i] - suf[i+1]);
    res = min(res, aux);
  }
  cout << res << endl;
  return 0;
}


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

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

  if(d == 0){
    if(n == 100){
      cout << 101 << endl;
    }else{
      cout << n << endl;
    }
  }else if(d==1){
    if(n == 100){
      cout << 10100 << endl;
    }else{
      cout << 100 * n << endl;
    }
  }else{
    if(n == 100){
      cout << 1010000 << endl;
    }else{
      cout << 10000 * n << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
program main
implicit None
	character(len =4)::a
	integer::n,i
	
	read*,a
	
	n = 0
	do i = 1,4
		if(a(i:i) == "2") n = n + 1
	enddo
	
	print 101,n
101 format(i0)
end program main

Measured memory_bytes: 768
#!/bin/bash
''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/input.txt"
exit $?
'''
import sys


def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    a, b, m = _ia()
    ai = list(_ia())
    bi = list(_ia())
    cmin = min(ai) + min(bi)
    for _ in range(m):
        xi, yi, ci = _ia()
        ctmp = ai[xi-1] + bi[yi-1] - ci
        if cmin > ctmp:
            cmin = ctmp
    return cmin


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


Measured memory_bytes: 64828
#!/usr/bin/env python3
from itertools import permutations
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, M: int, R: int, r: "List[int]", A: "List[int]", B: "List[int]", C: "List[int]"):
    inf = float("inf")
    md = [[inf] * N for _ in range(N)]
    for i in range(N):
        md[i][i] = 0
    for Ai, Bi, Ci in zip(A, B, C):
        Ai -= 1
        Bi -= 1
        md[Ai][Bi] = md[Bi][Ai] = Ci
    for k in range(N):
        for i in range(N):
            for j in range(N):
                md[i][j] = min(md[i][j], md[i][k] + md[k][j])

    def dist(path):
        return sum(md[p1 - 1][p2 - 1] for p1, p2 in zip(path, path[1:]))

    print(min(dist(path) for path in permutations(r)))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    R = int(next(tokens))  # type: int
    r = [int(next(tokens)) for _ in range(R)]  # type: "List[int]"
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    C = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
        C[i] = int(next(tokens))
    solve(N, M, R, r, A, B, C)


if __name__ == '__main__':
    main()


Measured memory_bytes: 58588
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(x, max(y, z))
#define MIN(x, y, z) min(x, min(y, z))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll 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(ret);
  return (ret);
}
const ll mod = 1000000007;
ll dp[100005][2];

signed main() {
  init();
  string S;
  cin >> S;

  dp[0][0] = 1;
  ll N = S.size();

  rep(i, S.size()) {
    if (S[i] == '0') {
      dp[i + 1][0] = dp[i][0];
      dp[i + 1][1] = dp[i][1];
    } else {
      dp[i + 1][1] = (dp[i][0] + dp[i][1]) % mod;
    }

    if (S[i] == '0') {
      (dp[i + 1][1] += dp[i][1] * 2 % mod) %= mod;
    } else {
      (dp[i + 1][0] += dp[i][0] * 2 % mod) %= mod;
      (dp[i + 1][1] += dp[i][1] * 2 % mod) %= mod;
    }
  }
  ll ans = (dp[N][0] + dp[N][1]) % mod;
  ANS;
  return 0;
}

Measured memory_bytes: 5268
#include <iostream>
#include <vector>

int main(){

    std::vector<int> vehicle_order;
    int input_data;

    while(std::cin >> input_data){
        if(input_data == 0){
            std::cout << vehicle_order.back() << std::endl;
            vehicle_order.pop_back();
        }else{
            vehicle_order.push_back(input_data);
        }
    }

    return 0;
}

Measured memory_bytes: 3120
#[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! vec_md {
    ( $ init : expr ; $ ( $ dim : expr ) ;* ) => { vec_md ! ( $ ( $ dim ) ;* => $ init ) };
    ( $ head : expr ; $ ( $ tail : expr ) ;* => $ init : expr ) => { vec ! [ vec_md ! ( $ ( $ tail ) ;* => $ init ) ; $ head ] };
    ( $ head : expr => $ init : expr ) => { vec ! [ $ init ; $ head ] };
}

#[allow(unused_macros)]
macro_rules! chmin {
    ( $ x : expr , $ y : expr ) => { if $ x > $ y { $ x = $ y ; true } else { false } };
}

#[allow(unused_macros)]
macro_rules! chmax {
    ( $ x : expr , $ y : expr ) => { if $ x < $ y { $ x = $ y ; true } else { false } };
}

fn main() {
    input! {
        n: usize, w: u64,
        wv: [(u64, usize); n]
    }
    let vmax = wv.iter().map(|&(_, v)| v).sum();
    let mut dp = vec_md![1u64 << 60;n+1;vmax+1];
    dp[0][0] = 0;
    for i in 0..n {
        for j in 0..vmax+1 {
            if j + wv[i].1 <= vmax {
                chmin!(dp[i+1][j + wv[i].1], dp[i][j] + wv[i].0);
            }
            chmin!(dp[i+1][j], dp[i][j]);
        }
    }

    let mut max = 0usize;
    for i in 0..vmax+1 {
        if dp[n][i] <= w {chmax!(max, i);}
    }
    println!("{}", max);
}


Measured memory_bytes: 106748
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
//  ba;
signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int s;
  cin >> s;
  int d = s % 100;
  int u = s / 100;
  if (u == 0 and d == 0 or (u > 12 and d > 12))
    cout << "NA" << endl;
  else if (0 < d and d < 13 and 0 < u and u < 13)
    cout << "AMBIGUOUS" << endl;
  else if (0 < d and d < 13)
    cout << "YYMM" << endl;
  else if (0 < u and u <13)
    cout << "MMYY" << endl;
  else cout << "NA" << endl;

  return 0;
}


Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
first_H = 0
finish = 0

for h in H:
    second_H = h
    if first_H <= second_H or first_H <= second_H - 1:
        first_H = max(second_H-1, first_H)
    else:
        print("No")
        finish = 1
        break
if finish != 1:
    print("Yes")

Measured memory_bytes: 63984
s = input()

g_num = 0
p_num = 0

win = 0
lose = 0

for i in range(0, len(s)):
    if i == 0:
        g_num += 1
        if s[0] == 'p':
            lose += 1
    else:
        if s[i] == 'p':
            if p_num < g_num:
                p_num += 1
            else:
                g_num += 1
                lose += 1
        else:
            if p_num < g_num:
                p_num += 1
                win += 1
            else:
                g_num += 1

print(win - lose)


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef std::vector<vector<int> > vvi;
typedef pair<int, int> pi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
#define inf (ll)1e9

#define debugone(x) cout << #x << " " << x << "\n"; cout.flush();
#define debugtwo(x) cout << #x << "-------------" << "\n";for(auto &it: x) cout << it << " ";cout << "\n"; cout.flush();
#define debugthree(x, i, j) cout << #x << "------------" << "\n";cout << "from " << i << " to " << j << "\n";for(ll k=i; k<=j; k++) cout << x[k] << " ";cout << "\n"; cout.flush();



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

	int n;
	cin >> n;
	int v[n], c[n];

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

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

	int maxi = -1e9;

	int x, y;

	for(int i=0; i< (1 << n); i++){
		x = 0;
		y = 0;
		for(int j=0; j<n; j++){
			if(i & (1 << j)){
				x+= v[j];
				y+= c[j];
			}
		}
		if(x - y > maxi){
			maxi = x - y;
		}
	}

	cout << maxi << endl;
	return 0;	

}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
char s[25];
  int count;
  scanf("%s",s);
  for(count=11;count!=3;count--){
  s[count+1]=s[count];
  }
  s[4]=' ';
  s[13]='\0';
  printf("%s\n",s);
return 0;
}

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

int main() {
	int N, L;
	cin >> N >> L;
	int abstaste = max(L, -L);
	int taste = L;
	//初期値はi=1のとき
	for (int i = 1; i < N+1; i++) {
		int abstastei = max (L + i - 1, -(L + i - 1));
		if (abstastei > abstaste) {
			break;
		}
		abstaste = abstastei;
		taste = L + i - 1;
	}
	int sumtaste = N*L - N + N * (N + 1) / 2;
	cout << sumtaste - taste << endl;
}

Measured memory_bytes: 3588