akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int selectionSort(int A[], int N){
    int sw = 0;

    for(int i = 0; i < N; i++){
        int minj = i;

        for(int j = i; j < N; j++){
            if(A[j] < A[minj]) minj = j;
        }
        swap(A[i], A[minj]);
        if(i != minj) sw++;
    }
    return sw;
} 

int main(){
    int A[100],N,sw;

    cin >> N;
    for(int i = 0; i < N; i++) cin >> A[i];
    sw = selectionSort(A, N);

    for(int i = 0; i < N; i++){
        if(i) cout << " ";
        cout << A[i];
    }
    cout << "\n" << sw << endl;

    return 0;
}


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

int main() {
  string s;
  cin >> s;
  if(s.size()==3){
	for(int i=2;i>=0;i--){
      cout << s.at(i);
    }
    cout << endl;
  }
  else{
    cout << s << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n,i;
	int a[100];

	scanf("%d", &n);

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

	printf("%d", a[n - 1]);
	for (i = n - 2; i >= 0; i--)
		printf(" %d", a[i]);

	putchar('\n');

	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;


vector<int>  dx = {1,-1,0,0};
vector<int>  dy = {0,0,1,-1};


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

	vector<int> A(n,0);
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}
	long ans = pow(3,n);

	long sub = 1;
	for (int i = 0; i < n; i++) {
		if (A[i] % 2 == 0) {
			sub *= 2;
		}
	}

	cout << ans - sub << endl;


	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a, b, k, times;
    
    while(1){
        scanf("%d %d",&a, &b);
        if(a == 0 && b == 0) break;
        if(a < b){
            k = b;
            b = a;
            a = k;
        }
        times = 0;
        do{
            a = a % b;
            k = b;
            b = a;
            a = k;
            times++;
        } while(b != 0);
        printf("%d %d\n",a, times);
    }
    return 0;
}



Measured memory_bytes: 1980
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CKDMC solver = new CKDMC();
        solver.solve(1, in, out);
        out.close();
    }

    static class CKDMC {
        static final char D = 'D';
        static final char M = 'M';
        static final char C = 'C';

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            char[] s = in.next().toCharArray();

            long[] dCountPrefix = new long[n + 1];
            for (int i = 0; i < n; i++) {
                dCountPrefix[i + 1] = dCountPrefix[i];
                if (s[i] == D) {
                    dCountPrefix[i + 1]++;
                }
            }
            // dCountPrefix[i] is the # of D in s[0]..s[i-1]. dCountPrefix[b]-dCountPrefix[a] is # D in s[a]..s[b-1]

            long[] mCountPrefix = new long[n + 1];
            for (int i = 0; i < n; i++) {
                mCountPrefix[i + 1] = mCountPrefix[i];
                if (s[i] == M) {
                    mCountPrefix[i + 1]++;
                }
            }

            int Q = in.nextInt();
            for (int q = 0; q < Q; q++) {
                int k = in.nextInt();
                long answer = 0;
                long dmCount = 0;
                for (int i = 0; i < n; i++) {
                    if (i - k >= 0 && s[i - k] == D) {
                        dmCount -= mCountPrefix[i] - mCountPrefix[i - k];
                    }
                    if (s[i] == M) {
                        dmCount += dCountPrefix[i] - dCountPrefix[Math.max(0, i - (k - 1))];
                    }
                    if (s[i] == C) {
                        answer += dmCount;
                    }
                }

                out.println(answer);
            }
        }

    }

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

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

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

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

    }
}



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

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

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

Measured memory_bytes: 3636
N, C, K = map(int, input().split())
T = []
for i in range(N):
    T += [int(input())]

sortT = sorted(T)
pre_ti = sortT[0]
ans = 1
c = 0
for ti in sortT:
    c += 1
    if ti - pre_ti <= K and c <= C:
        continue
    c = 1
    ans += 1
    pre_ti = ti

print(ans)


Measured memory_bytes: 77416
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

ll N, M;
struct room {ll fp; ll len; vector<ll> ne;};
vector<room> p;
queue<ll> q;


#define MOD 1000000007LL

int main()
{
  ll A, B;
  ll r;
  ll pos;

  cin >> N >> M;

  p.resize(N+1);
  for (int i=1; i<=M; i++) {
    cin >> A >> B;
    p[A].ne.push_back(B);
    p[B].ne.push_back(A);
  }

  q.push(1);
  while(!q.empty()) {
    r = q.front();
//printf("pop %lld\n", r);
    q.pop();
    pos = p[r].len;
    for (auto it = p[r].ne.begin(); it != p[r].ne.end(); it++) {
      if (p[*it].len == 0 || p[*it].len > pos+1) {
        p[*it].len = pos+1;
        p[*it].fp = r;
        q.push(*it);
      }
    }
  }

  for (int i=2; i<=N; i++) {
    if (p[i].fp == 0) {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  for (int i=2; i<=N; i++) {
    cout << p[i].fp <<endl;
  }

  return 0;
}


Measured memory_bytes: 13756
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
// const lint MOD = 998244353;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    ll n,k;cin>>n>>k;
    vector<ll> v(n);
    rep(i,n) cin>>v[i];
    int count[40];
    Fill(count,0);
    rep(i,n){
        rep(j,40){
            if(v[i]&1LL<<j){
                count[j]++;
            }
        }
    }
    ll ans = 0,x = 0;
    for(int i = 39; i >= 0;i--){
        if(count[i]*2 < n && (x | 1LL<<i) <= k) x |= 1LL<<i;
    }
    rep(i,n){
        ans += v[i]^x;
    }
    cout << ans << endl;
}



Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include <cmath>
#include<map>

using namespace std;

long long i,j,k,n,m,N,M,ans,X,A,B;

double x;


int main()
{
  cin>>X;
  
  A=0;
  B=0;

  for(i=0;i<=X;i++)
  {
    N=i*i*i*i*i;
    if(2*N>=X)
    {
      n=i;
      break;
    }
  }
  
  for(i=n;i<=X;i++)
  {
    for(j=0;j<=i;j++)
    {
      N=i*i*i*i*i;
      M=j*j*j*j*j;
      if(N-M==X)
      {
        A=i;
        B=j;
        break;
      }
      else if(N+M==X)
      {
        A=i;
        B=-j;
        break;
      }
      else if(-N-M==X)
      {
        A=-i;
        B=j;
        break;
      }
      else if(-N+M==X)
      {
        A=-i;
        B=-j;
        break;
      }
    }
    
    if(A!=0) break;
    
  }
  
  cout<<A<<" "<<B;
  
}

Measured memory_bytes: 3596
use std::io;

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();
    let ans = s.trim().chars().map(|mut c| {
        if c == '?' {
            c = 'D';
        }
        c.to_string()
    }).collect::<String>();
    println!("{}", ans);
}


Measured memory_bytes: 2460
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */



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

    int K; cin >> K;
    if(K < 100) { cout << 0 << endl; return 0; }

    int r = K%100;
    int q = K/100;

    if(r <= 5*q) cout << 1 << endl;
    else cout << 0 << endl;
    


    return 0;
}


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

using namespace std;
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007
#define INF (1<<28)
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define floot10 cout<<fixed<<setprecision(10);
#define int long long

signed main(){
	int n,p;
	cin>>n>>p;
	if(n==1){
		cout<<p<<endl;
		return 0;
	}
	int ans=1;
	for(int i=2;i*i<=p;i++){
		if(p%i==0){
			int cnt=0;
			while(1){
				if(p%i==0){
					p/=i;
					cnt++;
				}
				else break;
			}
			int hoge=cnt/n;
			ans*=pow(i,hoge);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
import collections

S1 = collections.deque()
S2 = collections.deque()
S3 = collections.deque()

for i, j in enumerate(input()):
    if j == '\\':
        S1.append(i)
    elif j == '/':
        if S1:
            left_edge = S1.pop()
            new_puddle = i - left_edge
            while True:
                if S2:
                    if S2[-1] > left_edge:
                        S2.pop()
                        new_puddle += S3.pop()
                    else:
                        break
                else:
                    break
            S2.append(left_edge)
            S3.append(new_puddle)
        else:
            pass


print(sum(S3))

print(len(S3), *list(S3))

Measured memory_bytes: 8388
#include <iostream>

using namespace std;

int main() {
	int c1, c2, c3;
	while (cin >> c1 >> c2 >> c3) {
		int u20 = 0;
		for (int i = 1; i <= 10; i++) {
			if (i == c1 || i == c2 || i == c3)
				continue;
			if (c1 + c2 + i <= 20)
				u20++;
		}
		if (u20 >= 4)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 62;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  ll x, k, d;
  cin >> x >> k >> d;
  ll num = abs(x)/d;
  if(k <= num) cout << abs(x) - k*d << endl;
  else {
    if(x >= 0) {
      x -= d*num;
      if((k-num)%2==1) x-=d;
      cout << abs(x) << endl;
    }
    else {
      x += d*num;
      if((k-num)%2==1) x += d;
      cout << abs(x) << endl;
    }
  }
}


Measured memory_bytes: 3632
A,B,C = map(int,input().split())

List_one = [0]*B
List_one = list(map(int,input().split()))

List_one.append(C)
#LIst_one = List_one + [C]
#print (List_one)

List_one.sort()# List_two=List_one.sort()としたらNoneを返してしまう。
#print(List_one)

x = List_one.index(C)

if x>=B-x:
    print(B-x)
else:
    print(x)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ll long long
#define mod 998244353
#define N 109
using namespace std;
__int128 bit[N];
int n;
char a[N];
map<pair<__int128,int>,int> mp;
int dfs(__int128 now,int n)
{
	if (n==0) return 1;
	if (n==1) return (int)now+1;
	if (mp.count(make_pair(now,n))) return mp[make_pair(now,n)];
	int ret=(ll)((__int128)now&bit[n-1]?2:1)*dfs(now&(bit[n-1]-1),n-1)%mod;
	for (int i=1;i*2<=n;i++)
	{
		__int128 next=bit[i]-1;
		for (int j=1;j*i<=n;j++)
		{
			for (int k=0;k<i;k++)
				if (!(now&(bit[n-1-i*(j-1)-k])))
					if (next&bit[i-1-k]) next^=bit[i-1-k];
			if (j>1) ret=(ret+(ll)dfs(next,i)*dfs(now&(bit[n-i*j]-1),n-i*j)%mod)%mod;
		}
	}
	return mp[make_pair(now,n)]=ret;
}
int main()
{
	cin>>a;
	n=strlen(a);
	__int128 now=0;
	for (int i=0;i<n;i++) now=now<<1|(a[i]-'0');
	bit[0]=1;
	for (int i=1;i<=n;i++) bit[i]=bit[i-1]<<1;
	printf("%d\n",dfs(now,n));
	return 0;
}


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

const int INF = 1001001001;
//const ll INF = 1000000000000000000;

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

	string ans = "No";
	int x = a, y = b, z = c;
	while (k) {
		if (x < y) {
			if (y < z) {
				ans = "Yes";
				break;
			}
			else {
				z *= 2;
				k--;
			}
		}
		else {
			y *= 2;
			k--;
		}
	}
	if (x < y and y < z) ans = "Yes";
	cout << ans;
	return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

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; }

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }





long long GCD(long long x, long long y) {
    return (y ? GCD(y, x%y) : x);
}

long long A, B;

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

    while (cin >> A >> B) {
        long long g = GCD(A, B);
        cout << A/g * B << endl;
    }
}


















Measured memory_bytes: 256
# if true

# include <iostream>

using Int = long long;

Int gcd(Int x, Int y)
{
    if (x < y) std::swap(x, y);

    Int temp{};
    while (x % y != 0)
    {
        temp = y;
        y = x % y;
        x = temp;
    }

    return y;
}

Int lcm(Int x, Int y)
{
    return x * y / gcd(x, y);
}

int main()
{

    Int A, B, C, D;
    std::cin >> A >> B >> C >> D;

    Int CD = lcm(C, D);
    --A;

    Int multiplesOfC  = (B / C ) - (A / C );
    Int multiplesOfD  = (B / D ) - (A / D );
    Int multiplesOfCD = (B / CD) - (A / CD);


    std::cout << (B - A) - (multiplesOfC + multiplesOfD - multiplesOfCD);

    return 0;
}

# endif

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

int main(){
    int a, b, c, d;
    cin >> a >> b;
    for(int i = b-a+1; i < b+a-1; i++){
        cout << i << " ";
    }
    cout << b+a-1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <climits>
#include <iomanip>
 
using namespace std;

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
 	
	int n;
	cin >> n;

	string a, b;
	cin >> a >> b;

	vector<long long> dp(n);

	const int MODULO = 1000000007;

	int start = 1;
	if (a[0] == b[0]) {
		dp[0] = 3;
	}
	else  {
		dp[0] = 6;
		dp[1] = 6;
		start = 2;
	}

	for (int i = start; i < n; ++i) {
		if (a[i] == b[i]) 
		{
			if (a[i - 1] == b[i - 1])
				dp[i] = (dp[i - 1] * 2) % MODULO;
			else {
				dp[i] = dp[i - 1];
			}
		} else {
			if (a[i - 1] == b[i - 1])
				dp[i] = (dp[i - 1] * 2) % MODULO;
			else {
				dp[i] = (dp[i - 1] * 3) % MODULO;
			}
			++i;
			dp[i] = dp[i - 1];
		}
	}

	cout << dp[n - 1] << endl;

	return 0;
}

Measured memory_bytes: 256
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():

    S = input()
    S = S[::-1]
    MOD = 10 ** 9 + 7

    dp = [0] * 13
    dp[0] = 1

    mul = 1
    for i in range(len(S)):
        next_dp = [0] * 13
        if S[i] == '?':
            for k in range(10):
                for j in range(13):
                    jj = ((k * mul) + j) % 13
                    next_dp[jj] += dp[j]
                    next_dp[jj] %= MOD
        else:
            num = int(S[i])
            for j in range(13):
                jj = ((num * mul) + j) % 13
                next_dp[jj] += dp[j]
                next_dp[jj] %= MOD

        mul = mul * 10 % 13
        dp = next_dp

    print(dp[5])


if __name__ == '__main__':
    solve()


Measured memory_bytes: 43116
#include <iostream>
using namespace std;
const int MAXN = 2e5 + 1;
int n, m, i, j, k, z;
long long a[MAXN], b[MAXN];
int main()
{
	ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
    cin >> n >> m >> k;
	for (i = 1; i <= n; ++i)
		cin >> a[i], a[i] += a[i - 1];
	for (i = 1; i <= m; ++i)
		cin >> b[i], b[i] += b[i - 1];
	z = 0, i = 0, j = m;
	while (a[i] <= k && i <= n)
	{
		while (b[j] > k - a[i])
			--j;
		z = max(z, i + j);
		++i;
	}
	cout << z;
    return 0;
}

Measured memory_bytes: 6288
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	_, _, m := io.NextInt(), io.NextInt(), io.NextInt()
	points := map[point]struct{}{}
	cntX, cntY := map[int]int{}, map[int]int{}
	for i := 0; i < m; i++ {
		xi, yi := io.NextInt(), io.NextInt()
		points[point{xi, yi}] = struct{}{}
		cntX[xi]++
		cntY[yi]++
	}
	sortedX := sortedKeys(cntX)
	sortedY := sortedKeys(cntY)
	for i := 0; i < len(sortedX); i++ {
		if i > 0 && cntX[sortedX[i]] < cntX[sortedX[i-1]] {
			break
		}
		for j := 0; j < len(sortedY); j++ {
			if j > 0 && cntY[sortedY[j]] < cntY[sortedY[j-1]] {
				break
			}
			x, y := sortedX[i], sortedY[j]
			if _, ok := points[point{x, y}]; !ok {
				Log("not exists")
				io.Println(cntX[x] + cntY[y])
				return
			}
		}
	}
	x, y := sortedX[0], sortedY[0]
	io.Println(cntX[x] + cntY[y] - 1)
}

func sortedKeys(mp map[int]int) []int {
	keys := make([]int, len(mp))
	idx := 0
	for k := range mp {
		keys[idx] = k
		idx++
	}
	sort.Slice(keys, func(i, j int) bool { return mp[keys[i]] > mp[keys[j]] })
	return keys
}

type point struct{ x, y int }

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// NextInt returns an integer from stdin
func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

// Println is a wrapper of fmt.Fprintln
func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

// Log outputs a to stderr
func Log(a ...interface{}) {
	fmt.Fprintln(os.Stderr, a...)
}


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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) ;
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;

int dx[4]{0, 1, 0, -1};
int dy[4]{1, 0, -1, 0};

int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	string s; cin >> s;
	ll res{0};
	for (ll i = 0; i < 3;)
	{
		ll j = i;
		if (s[i] == 'R')
		{
			while ((i+1) < 3 && s[i+1] == 'R')
				++i;
			res = max(res, i - j+1);
		}
		++i;
	}
	std::cout << res<< std::endl;
	
	return 0;
}


Measured memory_bytes: 3648
import math
from functools import reduce
from itertools import combinations_with_replacement

def gcd(*nums):
    return reduce(math.gcd, nums)

def combs(k):
    res = []
    for a in range(1, k + 1):
        for b in range(1, k + 1):
            for c in range(1, k + 1):
                res.append(gcd(a, b, c))
    print(sum(res))

combs(int(input()))


Measured memory_bytes: 189008
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair < int,int > PII;
typedef pair < ll,ll > PLL;
#define pb push_back
//#all(x) (x).begin(),(x).end()

//int const N = 1;
int const MOD = 1e9 + 7;

ll bigmod(ll a, ll b)
{
    if(b==0)
        return 1 % MOD;
    ll x = bigmod(a,b/2);
    x = (x * x) % MOD;
    if(b%2)
        x = (x * a) % MOD;
    return x;
}

int const N = 3e5 + 10;
ll dp[1010][1010];
string s[1010];
int h,w;

ll DP(int i,int j)
{
    if(i >= h  or j >= w)
        return 0;
    if(i == h-1 and j == w - 1)
        return 1;
    if(s[i][j] == '#') return 0;

    ll &r = dp[i][j] ;

    if(r != -1) return r;
    r = DP(i+1,j) + DP(i,j+1);
    r %= MOD;

    return r;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    memset(dp,-1,sizeof dp);

    cin >>  h >> w;

    for(int i = 0; i < h; i++)
        cin >> s[i] ;
    cout << DP(0,0);
    return 0;
}




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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (int &ai: a) cin >> ai;
    int q; cin >> q;
    while (q--) {
        int k; cin >> k;
        cout << lower_bound(a.begin(), a.end(), k) - a.begin() << endl;
    }
    return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll n; cin >> n;
    ll w; cin >> w;
    vector <vector <ll>> dp(n+1, vector <ll>(w+1, 0));
    for(int i=1; i<=n ;i++){
        ll we; cin >> we;
        ll va; cin >> va;
        for(int j=0; j<we; j++){
            dp[i][j] = dp[i-1][j];
        }
        for(int j=we; j<=w; j++){
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-we] + va);
        }
    }
    ll ans = 0;
    REP(i, w+1){
        ans = max(ans, dp[n][i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
//#define INF (1 <<29)
//const int INF = int(100 * 200 * (1e5 + 1));
const int INF = 1 << 29;
int N, M, R;
int d[201][201];
int r[8];
int min_cost = INF;
//int min_cost = INF;

void dfs(int from_idx, int dist, int used) {

    if (used == (1 << R) - 1) {
        min_cost = min(min_cost, dist);
        return;
    }

    for (int to_idx = 0; to_idx < R; ++to_idx) if (!(used >> to_idx & 1)) {
        if (dist == -1) {
            dfs(to_idx, 0, used | 1 << to_idx);
        } else {
            dfs(to_idx, dist + d[r[from_idx]][r[to_idx]], used | 1 << to_idx);
        }
    }
}


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

    cin >> N >> M >> R;

    for (int i = 1; i <= N; ++i) {
        fill(d[i] + 1, d[i] + N + 1, min_cost);
        d[i][i] = 0;
    }
    for (int i = 0; i < R; ++i) {
        cin >> r[i];
    }
    int a, b, c;
    for (int i = 0; i < M; ++i) {
        cin >> a >> b >> c;
        if (d[a][b] > c) d[a][b] = d[b][a] = c;
    }
    for (int k = 1; k <= N; ++k) {
        for (int i = 1; i <= N; ++i) {
            for (int j = 1; j <= N; ++j) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    dfs(0, -1, 0);

    cout << min_cost << '\n';

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <bitset>
#include <string>

typedef long long ll;

using namespace std;

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

  ll A[N];
  for (int i = 0; i < N; i++) cin >> A[i];
  
  ll X = 1ll << 40;

  int i = 40;
  while (K < X) {
    X >>= 1;
    i--;
  }

  //cout << i << endl;
  X = 0;
  for (; i >= 0; i--) {
    int count = 0;
    for (int n = 0; n < N; n++) {
      if (A[n] & 1ll << i) count++;
    }
    //cout << count << " ";
    if (count < (N + 1) / 2 && X + (1ll << i) <= K) X += 1ll << i;
  }

  //cout << X << endl;

  ll ans = 0;
  for (int n = 0; n < N; n++) ans += X ^ A[n];
  cout << ans << endl;
  
}


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

int main(){
	int n,l;
	cin >> n >> l;
	int sum = 0;
	int zero = 100000000;
	int a;
	for(int i = 1;i <= n;i++){
		sum += l + i - 1;
		if(abs(l + i - 1) < zero){
			a = i;
			zero = abs(l + i - 1);
		}
	}
	sum -= l + a - 1;
	cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

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

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 1000000;
const int N = 10000;

struct mint {
    ll x;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {if ((x+=a.x)>=MOD) x-=MOD; return *this;}
    mint& operator-=(const mint a) {if ((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
    mint& operator*=(const mint a) {(x*=a.x)%=MOD; return *this;}
    mint operator+(const mint a) const {mint res(*this); return res+=a;}
    mint operator-(const mint a) const {mint res(*this); return res-=a;}
    mint operator*(const mint a) const {mint res(*this); return res*=a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(MOD-2);}
    mint& operator/=(const mint a) { return (*this) *= a.inv();}
    mint operator/(const mint a) const {mint res(*this); return res/=a;}
};

int main() {
	int n;cin>>n;
	ll a[N];
	rep(i,n) cin>>a[i];
	int c[MAX+1];
	rep(i,MAX+1) c[i]=0;
	bool p[1000];
	rep(i,1000) p[i]=true;
	p[0]=p[1]=false;
	for(int i=2;i<1000;i++){
		if(!p[i]) continue;
		for(int j=2*i;j<1000;j+=i) p[j]=false;
	}
	rep(i,n){
		ll t=a[i];
		rep(i,1000){
			if(t==1) break;
			if(!p[i]) continue;
			int tc=0;
			while(t%i==0) {tc++;t/=i;}
			c[i]=max(tc,c[i]);
		}
		if(t>1) c[t]=1;
	}
	mint b=1;
	rep1(i,MAX) b*=mint(i).pow(c[i]);
	mint ans=0;
	rep(i,n) ans+=b/a[i];
	cout<<ans.x<<endl;
}


Measured memory_bytes: 4224
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

int num = 0;

int solve(int N, std::vector<int> r){
  int ans = 0;

  std::vector<int> check(N);

  for(int i = 0; i < N; i++){
    if(i == r[r[i]]){
      ans++;
      check[num] = r[i];
      num++;
      r[r[i]] = -1;
      }
  }

  return ans;
}

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

  std::vector<int> r(N);

  for(int i = 0; i < N; i++){
    std::cin >> r[i];
    r[i] -= 1;
  }

  int result = solve(N, r);

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


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

using ll = long long;
using Pi = pair < int , int >;

int N;
int color[100005] = {};
int cmax = 0;

vector < Pi > G[100005];

void coloring(int node, int uc)
{
    int cnt = 0;
    for ( auto &x : G[node] ) {
        if ( color[x.second] != 0 ) continue;
        cnt++;
        if ( cnt == uc ) cnt++;
        color[x.second] = cnt;
        coloring(x.first, cnt);
        cmax = max(cmax, cnt);
    }
}

int main()
{
    cin >> N;
    
    for ( int i = 0; i < N - 1; i++ ) {
        int a, b;
        cin >> a >> b; --a, --b;
        G[a].emplace_back(b, i);
        G[b].emplace_back(a, i);
    }

    coloring(0, 0);
    
    cout << cmax << endl;
    for ( int i = 0; i < N - 1; i++ ) {
        cout << color[i] << endl;
    }

    return ( 0 );
}


Measured memory_bytes: 7424
n, k, *a = map(int, open(0).read().split())
now = 0
st = set()
ls = []
while not now in st:
    st.add(now)
    ls.append(now)
    now = a[now]-1
bi = ls.index(now)
lp = len(ls) - bi
if k<=bi: print(ls[k]+1)
else:
    k -= bi
    k %= lp
    print(ls[bi+k]+1)

Measured memory_bytes: 129924
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n;
    cin>>n;
    vector<int>a(n+1),b(n+1);
    for(int i=1; i<=n; ++i)cin>>a[i];
    for(int i=n; i>=1; --i){
        int odd=0;
        for(int j=i*2; j<=n; j+=i){
            odd^=b[j];
        }
        b[i]=odd^a[i];
    }
    int cnt=0;
    vector<int>c;
    for(int i=1; i<=n; ++i){
        if(b[i]==1)cnt++,c.push_back(i);
    }
    cout<<cnt<<endl;
    rep(i,c.size())cout<<c[i]<<" ";
    return 0;
}

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ms memset
#define MOD 1000000007
#define MOD2 1000000009
#define sp fixed<<setprecision
#define sz(x) (int)(x).size()
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
ll fpow(ll x,ll y,ll p=MOD){x=x%p;ll sum=1;while(y){if(y&1)sum=sum*x;sum%=p;y=y>>1;x=x*x;x%=p;}return sum;}
ll inv(ll a,ll m=MOD){ll c=m;ll y=0,x=1;if(m==1)return 0;while(a>1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=c;return x;}
ll add(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return (a%MOD + b%MOD + MOD)%MOD;}
ll sub(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return (a%MOD - b%MOD + MOD)%MOD;}
ll mul(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return ((a%MOD)*(b%MOD) + MOD)%MOD;}
void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (sz(name)) {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}
ll spf[1000005];
int main(){
    setIO();
    ll n,x,m;
    cin>>n>>x>>m;
    vector<ll>v;
    ll sum = x;
    ll seed  = x;
    map<ll,ll>memo;
    memo[x]=1;
    v.pb(x);
    for(int i=2;i<=min(m,n);i++){
      seed  = (seed*seed)%m;
      if(memo[seed]){
        ll len = i-memo[seed];
        //v.pb(seed);
        //sum+=seed;
        ll rem = n-i+1;
        ll q=rem/len;
        ll r =rem%len;
        ll tmp = 0;
        for(int j=memo[seed]-1;j<v.size();j++)
          tmp+=v[j];
        sum+=tmp*q;
        for(int j=memo[seed]-1;j<memo[seed]-1+r;j++)
          sum+=v[j];
        break;
      }
      memo[seed]=i;
      v.pb(seed);
      sum+=seed;
    }


    cout<<sum;

}


Measured memory_bytes: 6776
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


bool solve(){
  int n, f, d;
  int connect[51][51] = {};
  vector<int> vec[31];
  
  scanf("%d",&n);

  if(n == 0) return false;
  
  for(int i=0;i<n;i++){
    scanf("%d", &f);
    for(int j=0;j<f;j++){
      scanf("%d", &d);
      vec[d].push_back(i);
    }
    connect[i][i] = true;
  }


  
  for(int i=1;i<=30;i++){
    for(int p=0;p<n;p++){
      for(int j=0;j<vec[i].size();j++){
        for(int k=0;k<vec[i].size();k++){
          if(connect[p][vec[i][j]]) connect[p][vec[i][k]] = true;
        }
      }
    }

    bool flag = true;
    for(int j=0;j<n;j++){
      bool f2 = false;
      for(int k=0;k<vec[i].size();k++){
        f2 |= connect[j][vec[i][k]];
      }
      flag &= f2;
    }
    
    if(flag){
      printf("%d\n",i);
      return true;
    }
  }

  puts("-1");
  
  return true;
}

int main(){
  while(solve());
  return 0;
}



Measured memory_bytes: 3256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <list>
#include <numeric>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}*/

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

	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];

	// 2の倍数と4の倍数が大事

	// 4の倍数の両端は2の倍数じゃなくてもよい
	vector<ll> pro(n);
	rep(i, n) {
		if (a[i] % 4 == 0) {
			pro[i] = 4;
		}
		else if (a[i] % 2 == 0) {
			pro[i] = 2;
		}
		else
			pro[i] = 1;
	}

	vector<int> pnum(3, 0);
	// 1 2 4
	rep(i, n) {
		if (pro[i] == 1) pnum[0]++;
		else if (pro[i] == 2) pnum[1]++;
		else pnum[2]++;
	}

	bool can = true;

	// 始めに2の倍数じゃないのを置いた方がいい
	// 4の倍数一つで最大2つのそれ以外をまかなえる
	if (pnum[0] == 0) {
		can = true;
	}
	else if (pnum[0] == 1) {
		if (pnum[2] >= 1) can = true;
		else can = false;
	}
	else {
		if (pnum[2] < pnum[0] - 1) {
			can = false;
		}
		else {
			if (pnum[2] == pnum[0] - 1) {
				if (pnum[1] == 0) can = true;
				else can = false;
			}
			else {
				can = true;
			}
		}
	}

	if (can) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_map>
#include<stack>
#include<random>
#include<set>
#include<map>
#include<functional>
using namespace std;
#define int long long
#define inf 1145141919
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int>P;
typedef pair<int, P> PP;
struct edge { int to, cost; };
const long long mod = 10000000;

signed main() {
	string s; cin >> s;
	int k; cin >> k;
	rep(i, s.size()) {
		int c = ('{'-s[i])%26;
		if (k >= c ) {
			s[i] = 'a';
			k -= c;
		}
	}
	char c = 'a'+((s[s.size() - 1] - 'a') + k)%26;
	s[s.size() - 1] = c;
	cout << s << endl;
}

Measured memory_bytes: 512
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        ulong[] input = Console.ReadLine().Split().Select(i => ulong.Parse(i)).ToArray();
        ulong A = input[0];
        ulong B = input[1];
        ulong C = input[2];
        ulong D = input[3];
        ulong lcm = Lcm(C, D);

        ulong divisible = (B / C + B / D - B / lcm) - ((A - 1) / C + (A - 1) / D - (A - 1) / lcm);

        ulong ans = B - (A - 1) - divisible;

        Console.WriteLine(ans);
    }

    static ulong Lcm(ulong a, ulong b)
    {
        return a * b / Gcd(a, b);
    }

    static ulong Gcd(ulong a, ulong b)
    {
        if (a < b)
        {
            return Gcd(b, a);
        }
        ulong d = 0;
        do {
            d = a % b;
            a = b;
            b = d;
        } while (d != 0);
        return a;
    }
}

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

int main(){
	int n, m, k, x;
	cin >> n >> m;
	vector<int> food(m, 0);
	int cnt = 0;
	for(int i=0; i<n; i++){
		cin >> k;
		for(int j=0; j<k; j++){
			cin >> x;
			food[x-1] = food[x-1] + 1;
		}
	}
	for(int i=0; i<m; i++){
		if(food[i]==n)
			cnt++;
	}
	cout << cnt << endl;
}


Measured memory_bytes: 256
fn curtain() -> Result<i32, &'static str> {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input)
        .map_err(|e| "input error")?;
    let ab : Vec<i32> = input.trim_right()
        .split_whitespace()
        .filter_map(|e| e.parse::<i32>().ok())
        .collect();
    let a = ab[0];
    let b = ab[1];
    let c = a - 2 * b;

    Ok(if c < 0 {
        0
    }
    else {
        c
    })
}

fn main() {
    println!("{}", curtain().unwrap());
}

Measured memory_bytes: 4352
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n;
	cin>>n;
	P p[100000];
	for(int i=0; i<n; i++){
		int a, b; cin>>a>>b;
		p[i]=P(a, b);
	}
	sort(p, p+n);
	cout<<p[n-1].first+p[n-1].second<<endl;
	return 0;
}

Measured memory_bytes: 1660
H, W = map(int, input().split())
S = [list(input()) for i in range(H)]
grid = []
for i in range(H+2):
    grid.append([0]*(W+2))
    
idxes = []
tmpIdxes = []
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            idxes.append([i,j])
            tmpIdxes.append([i+1, j+1])
            
for tmpIdx in tmpIdxes:
    grid[tmpIdx[0]-1][tmpIdx[1]-1] += 1
    grid[tmpIdx[0]-1][tmpIdx[1]] += 1
    grid[tmpIdx[0]-1][tmpIdx[1]+1] += 1
    grid[tmpIdx[0]][tmpIdx[1]-1] += 1
    grid[tmpIdx[0]][tmpIdx[1]+1] += 1
    grid[tmpIdx[0]+1][tmpIdx[1]-1] += 1
    grid[tmpIdx[0]+1][tmpIdx[1]] += 1
    grid[tmpIdx[0]+1][tmpIdx[1]+1] += 1

for tmpIdx in tmpIdxes:
    grid[tmpIdx[0]][tmpIdx[1]] = "#"

for i in range(H):
    for j in range(W):
        if j != W-1:
            print(grid[i + 1][j + 1], end="")
        else:
            print(grid[i + 1][j + 1])


Measured memory_bytes: 4084
#include<iostream>
#include<queue>
#include<algorithm>
#include<vector>
#include<deque>
#include<climits>
#include<cassert>
#include<cstring>

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)

using namespace std;

struct Edge { int dst, w; };
struct Data {
  int cur, w;
  bool operator < ( const Data &data ) const {
    if( w != data.w ) return w > data.w;
    return cur < data.cur;
  }
};

#define MAX_V 2000

int V,E;
vector<Edge> G[MAX_V];
int mini[MAX_V][MAX_V];

void dijkstra(int sp) {
  rep(i,V) mini[sp][i] = INT_MAX;
  mini[sp][sp] = 0;
  priority_queue<Data> Q;
  Q.push((Data){sp,0});
  while( !Q.empty() ) {
    Data data = Q.top(); Q.pop();
    int cur = data.cur;
    rep(i,(int)G[cur].size()) {
      Edge &e = G[cur][i];
      if( mini[sp][e.dst] > data.w + e.w ) {
	mini[sp][e.dst] = data.w + e.w;
	Q.push((Data){e.dst,mini[sp][e.dst]});
      }
    }
  }
}

typedef pair<int,int> ii;
bool used[MAX_V];
void compute() {
  rep(i,V) dijkstra(i);
  int maxi = 0;
  rep(i,V) REP(j,i+1,V) maxi = max(maxi,mini[i][j]);
  vector<ii> vec;
  rep(i,V) REP(j,i+1,V) {
    if( maxi == mini[i][j] ) {
      vec.push_back(ii(i,j));
      used[i] = used[j] = true;
    }
  }
  rep(i,V) if( !used[i] ) {
    rep(j,(int)vec.size()) {
      int s = vec[j].first, t = vec[j].second;
      if( mini[s][i] + mini[i][t] == maxi ) {
	used[i] = true;
	break;
      }
    }
  }
  int answer = 0;
  rep(i,V) answer += !used[i];
  cout << answer << endl;
  rep(i,V) if( !used[i] ) cout << i + 1 << endl;

}

int main() {
  cin >> V >> E;
  rep(i,E) {
    int s,t,d;
    cin >> s >> t >> d;
    --s, --t;
    G[s].push_back((Edge){t,d});
    G[t].push_back((Edge){s,d});
  }
  compute();
  return 0;
}

Measured memory_bytes: 31128
n=int(input())
h=list(map(int, input().split()))
dp=[0 for i in range(n)]
#dp[1]=abs(h[1]-h[0])
for i in range(n):
    if i<1:
        dp[i+1]=abs(h[i+1]-h[i])+dp[i]
    elif i==n-1:
        dp[i]=min(dp[i], abs(h[i]-h[i-1])+dp[i-1])
    else:
        dp[i+1]=min(abs(h[i+1]-h[i])+dp[i],abs(h[i+1]-h[i-1])+dp[i-1])
print(dp[n-1])
#print(dp)


Measured memory_bytes: 13908
h, w = map(int, input().split())
rs = [input() for _ in range(h)]
rows = []

#.だけの行を省いてrowsに格納
for r in rs:
  if '#' in r: rows.append(r)

ansrows = zip(*[c for c in zip(*rows) if '#' in c])

for r in list(ansrows):
  print(''.join(r))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    string S;
    cin >> N;
    cin >> S;
    int sensor = 0;
    if(N != S.size()){
        sensor = 1;
    }
    if(N % 2 ==1){
        sensor = 1;
    }
    for (int i = 0; i < N / 2; i++){
        if(S.at(i) != S.at(N / 2 + i)){
            sensor = 1;
            break;
        }   
    }
    if(sensor == 0){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
}

Measured memory_bytes: 256