akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ll n, p; cin >> n >> p;
    ll odd = 0, even = 0;
    rep(i,n){
        int num; cin >> num;
        if(num%2==0) even++;
        else odd++;
    }
    if(even==n){
        if(p==1) cout << 0 << endl;
        else {
            ll ans = pow(2,n);
            cout << ans << endl;
        }
    }else{
        ll ans = pow(2,n-1);
        cout << ans << endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
using Graph = vector<vector<int>>;
using Graph_Wei = vector<vector<pair<int,int>>>;
using ll = long long;

vector<bool> seen;

Graph G;
void dfs(int v,vector<bool>& seen,int& res){

    //現在の頂点以外が訪問済みならパス追加して処理終了
    bool end = true;
    for(int i=0;i < seen.size();i++) if(!seen[i] && v != i) end = false;
    if(end){
        res++;
        return;
    }

    seen[v] = true;
    for(auto nv:G[v]){
        if(seen[nv]) continue;
        dfs(nv,seen,res);

    }
    seen[v] = false;
}


int main() {
    int n,m;
    cin >> n >> m;
    //n個の配列で初期化
    G.assign(n, vector<int>());
    for(int i=0;i < m;i++){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);

    }

    int res=0;
    seen.assign(n,false);
    dfs(0,seen,res);

    cout << res << endl;
    



    return 0;

}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class Data{
public:
	ll v,w;
	double p;
};

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

	int N=in(),W=in();
	vector<Data> D(N);
	REP(i,N){
		D[i].v=in();
		D[i].w=in();
		D[i].p = (double)D[i].v/(double)D[i].w;
	}
	sort(ALL(D),[](Data& l,Data& r){return l.p>r.p;});
	double sum=0;
	int num=0;
	for(int i=0;i<N;i++){
		if(num+D[i].w>=W){
			sum += D[i].p*(W-num);
			break;
		}
		sum += D[i].v;
		num += D[i].w;
	}
	
	printf("%.10lf\n",sum);
	return 0;
}



Measured memory_bytes: 5188
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)*}
    };
}

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

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

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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (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")
    };
}

use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        k: usize,
        v: [i64; n]
    }
    let mut ans = 0;
    for i in 0..min(k, n) + 1 {
        for j in 0..min(k - i, n - i) + 1 {
            let mut l: Vec<i64> = v.iter().take(i).chain(v.iter().skip(n - j)).cloned().collect();
            l.sort_by(|x, y| y.cmp(x));
            for m in 0..k - i - j {
                if l.is_empty() {
                    break;
                }
                let x = *l.last().unwrap();
                if x < 0 {
                    l.pop();
                } else {
                    break;
                }
            }
            ans = max(ans, l.iter().sum());
        }
    }
    println!("{}", ans);
}


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

#define rep(i, a) for (int i = 0; i < (a); i++ )

 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    int N;
    cin >> N;
    int ans = 0;
    int now = 0;
    set<int> S;
    while(1) {
        ans++;
        now = now * 10 + 7;
        now %= N;
        if (S.count(now)) {
            cout << -1 << endl;
            break;
        }
        else if (now==0) {
            cout << ans << endl;
            break;
        }
        else {
            S.insert(now);
        }
    }
}


Measured memory_bytes: 50508
def main():
	N, A, B = map(int, input().split())
	X = list(map(int, input().split()))
	ans = 0
	for i in range(1, N):
		walk = (X[i]-X[i-1])*A
		if walk < B:
			ans += walk
		else:
			ans += B
	print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define PB push_back
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define mod 100000000
// #define int ll

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n;cin >> n;
	int a[n];
	for(int i=0;i<n-1;i++){
		int x;cin >> x;
		if(i==0) a[i] = a[i+1] = x;
		else{
			a[i+1] = x;
			if(a[i]>x) a[i] = x;
		}
	}
	int ans = 0;
	for(int i=0;i<n;i++) ans += a[i];
	cout << ans << endl;
	
 	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
graph = [[] for _ in range(N)] 
for _ in range(M):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

def bfs(goal, graph, seen, next_v):
    for x in graph[next_v[0][0]]:
        if x == goal:
            return True
        if x in seen:
            continue
        next_v.append((x,next_v[0][1]+1))
        seen.add(x)
    return False


next_v = [(0,0)]
seen = {0}
#bfs
while True:
    if len(next_v) == 0 or next_v[0][1] == 2:
        ans = "IMPOSSIBLE"
        break
    if bfs(N-1, graph, seen, next_v):
        ans = "POSSIBLE"
        break
    next_v.pop(0)
print(ans)

Measured memory_bytes: 52272
#include "bits/stdc++.h"

using namespace std;

void Main() {
    int H, W, D;
    cin >> H >> W >> D;
    map<int, pair<int, int>> A;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            int a;
            cin >> a;
            A.insert(make_pair(a, make_pair(i, j)));
        }
    }

    int HW = H * W;
    map<int, vector<int>> accums;
    for (int i = 0; i < D; ++i) {
        vector<int> acc;
        acc.push_back(0);
        int curr = (i == 0 ? D : i);
        int next = i + D;
        while (next <= HW) {
            auto currA = A[curr];
            auto nextA = A[next];
            int cost = abs(currA.first - nextA.first) + abs(currA.second - nextA.second);
            acc.push_back(acc.back() + cost);
            curr = next;
            next += D;
        }
        accums.insert(make_pair(i, acc));
    }

    int Q;
    cin >> Q;
    for (int q = 0; q < Q; ++q) {
        int l, r;
        cin >> l >> r;

        const vector<int>& acc = accums[l % D];
        int ans = acc[r / D] - acc[l / D];
        cout << ans << endl;
    }
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 19080
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
const int M = 1e6+6;
vector<int> pr[M];
bool flag[M];
void sieve()
{
	for(int i=2;i<M;i++)
	{
		if(sz(pr[i]))
			continue;
		for(int j=i;j<M;j+=i)
			pr[j].pb(i);
	}
}
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	sieve();
	int n;
	cin>>n;
	bool f = 0;
	int g = 0;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		g = __gcd(g, x);
		for(auto u:pr[x])
		{
			if(flag[u])
				f = 1;
			flag[u] = 1;
		}
	}
	if(g!=1)
		cout<<"not coprime\n";
	else if(f)
		cout<<"setwise coprime\n";
	else
		cout<<"pairwise coprime\n";
	return 0;
}

Measured memory_bytes: 60036
#include <bits/stdc++.h>
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;

const int MAXN = 100055;

ll A[MAXN];

ll Ans = INFLL, sum;
int N;

void solve() {
	ll ret = 0;
	sum = 0;
	for(int i = 1; i <= N; i++) {
		sum += A[i];
		if(i&1) {
			if(0 < sum) continue;
			ll x = -sum + 1;
			sum += x;
			ret += x;
		} else {
			if(sum < 0) continue;
			ll x = sum + 1;
			sum -= x;
			ret += x;
		}
	}
	if(ret < Ans) Ans = ret;
}

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

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

	solve();
	for(int i = 1; i <= N; i++) A[i] = -A[i];
	solve();

	cout << Ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <queue>
#include <cstdio>
using namespace std;
int n, c, v, dp[500007];
int main() {
	scanf("%d",&n); dp[n]=1;
	for(int i=(n+2)/2;i>1;i--) dp[i]=dp[2*i-1]+2*dp[2*i]+dp[2*i+1];
	for(int i=2;i<=n;i++) c+=dp[i]*i;
	priority_queue<int> que;
	for(int i=0;i<n;i++) scanf("%d", &v), que.push(-v);
	for(int i=0;i<n;i++) {
		if(i) printf(" ");
		printf("%d", -que.top()); que.pop();
	}
	printf("\n%d\n", c);
	return 0;
}

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

const std::vector<int> v = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

int main() {
	int K;
	std::cin >> K;
	std::cout << v[K - 1] << '\n';
return 0;
}

Measured memory_bytes: 256
n,m,k = list(map(int,input().split()))

a = list(map(int,input().split()))
b = list(map(int,input().split()))

asum = [0]
bsum = [0]

for i in range(n):
    asum.append(asum[i] + a[i])
for i in range(m):
    bsum.append(bsum[i] + b[i])

best = m
answer = 0
for i in range(n+1):
    j = best
    while 1:
        if bsum[j] <= (k - asum[i]):
            best = j
            if answer < i + j:
                answer = i + j
            break
        j -= 1
        if j < 0:
            break

print(answer)

Measured memory_bytes: 47032
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>
#define intt long long

intt N;
std::string s1, s2;
int func() {
	for (int i = 0; i < N; ++i) {
		if (s1.substr(i) == s2.substr(0, N - i))
			return i + N;
	}
	return N * 2;
}

int main(){
	 std::cin >> N;
	 std::cin >> s1 >> s2;
	std::cout << func() << std::endl;

	return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
  using namespace std;
  int a[1000000];
  int main()
  {
      int k,s;
      cin>>k>>s;
      for(int i=0;i<=k;i++)
      {
         for(int j=0;j<=k;j++)
         {
             a[5000+i+j]++;
         }
    }
     int sum=0;
     for(int i=0;i<=k;i++)
     {
         int pos=s-i;
        if(pos<0)
         {
             continue;
           }
         sum+=a[5000+pos];
     }
     cout<<sum<<endl;
     return 0;
 }

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <limits>
#include <iterator>
#include <cmath>
#include <numeric>
#include <stack>
#include <queue>
#include <cassert>
#include <forward_list>
#include <chrono>
#include <deque>
#include <list>
#include <random>
#include <cstdio>
#include <sstream>

using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	cout << a * b / 2 << endl;

	return 0;
}

Measured memory_bytes: 632
from collections import deque
H,W=map(int,input().split())
S=[input() for i in range(H)]
checked=[[0 for i in range(W)] for m in range(H)]

count=0
count2=0
for h1 in range(H):
    for w1 in range(W):
        if S[h1][w1]=="#" and checked[h1][w1]==0:
            checked[h1][w1]=1
            stack=deque([[h1,w1,"#"]])
            kuro=1
            siro=0
            count2+=1
            visited=set([h1*400+w1])
            while stack:
                h,w,iro=stack.popleft()
                for y,x in [[-1,0],[1,0],[0,1],[0,-1]]:
                    Y,X=y+h,x+w
                    visitednum=Y*400+X
                    if 0<=Y<H and 0<=X<W and not visitednum in visited:
                        if iro=="#" and S[Y][X]==".":
                            siro+=1
                            visited.add(visitednum)
                            stack.append([Y,X,"."])
                        elif iro=="." and S[Y][X]=="#" and not visitednum in visited:
                            kuro+=1
                            checked[Y][X]=1
                            visited.add(visitednum)
                            stack.append([Y,X,"#"])
            count+=kuro*siro
print(count)


Measured memory_bytes: 57692
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <cstdint>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(ll i=(x);i<(y);i++)
#define disp(a) cout << a << endl;
typedef long long ll;
using namespace std;

bool comp(const int& a, const int& b) {
	return a > b;
}

int main()
{
	string s;
	cin >> s;
	
	if (s[2] == s[3] && s[4] == s[5]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int ans = 0;
        for(int i=A;i<=B;i++){
            if(i%10==0) continue;
            StringBuilder sb = new StringBuilder();
            int j=i;
            while(j>0){
                sb.append(j%10);
                j=j/10;
            }
            String s1 = sb.toString();
            String s2 = sb.reverse().toString();
            if(s1.equals(s2)) ans++;
        }

        System.out.println(ans);
    }
}



Measured memory_bytes: 38844
//https://atcoder.jp/contests/hitachi2020/tasks/hitachi2020_a
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}
int main() {
#if LOCAL&0
	std::ifstream in("./test/sample-1.in");
	//std::ifstream in("./input.txt");
	std::cin.rdbuf(in.rdbuf());
#else
	cin.tie(0);
	ios::sync_with_stdio(false);
#endif
	string S; cin>>S;
	string hi="hi";
	bool ans=true;
	if(S.size()%2!=0)ans=false;
	FOR(i,0,S.size()){
		if(S.at(i)!=hi.at(i%2))ans=false;
	}
	cout<<(ans?"Yes":"No")<<endl;
	return 0;
}

Measured memory_bytes: 256
from heapq import heappop, heappush, heapify

N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(reverse=True)

que = []
ans = 0
for d in range(1, M + 1):
    while AB and AB[-1][0] <= d:
        heappush(que, -AB.pop()[1])
    if que:
        ans += heappop(que)
print(-ans)


Measured memory_bytes: 17160
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
long long int mod=1e9+7;
bool debug=false;
typedef long long ll;
int main(){
	int n,m;
	cin>>n>>m;
	vector<int>a(n),b(n);
	rep(i,n)cin>>a[i];
	sort(a.begin(),a.end());
	int k,ok,ng,mid;
	rep(i,m){
		k=a[n-1]/2;
		a.erase(a.end()-1);
		/*
		rep(i,a.size()){
			cout<<a[i]<<" ";
		}
		cout<<endl;
		*/
		ok=-1;
		ng=n;
		while(ng-ok>1){
			mid=(ng+ok)/2;
			if(a[mid]<k) ok=mid;
			else ng=mid;
		}
		/*
		cout<<"ok"<<ok<<endl;
		*/
		a.insert(a.begin()+ok+1,k);
		/*
		rep(i,a.size()){
			cout<<a[i]<<" ";
		}
		cout<<endl;
		*/
	}
	long long int sum=0;
	rep(i,n) sum+=a[i];
	cout<<sum<<endl;


	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		// ?????????????????\???
		Scanner sc = new Scanner(System.in);
		int line = sc.nextInt();
		int column = sc.nextInt();

		// ????¬???????????????????
		int[][] table = new int[line + 1][column + 1];

		// ??\??????????????°???????????¨??????????¨???????????????¨???????¬??????????????????????
		for (int cnt1 = 0; cnt1 < line; cnt1++) {

			for (int cnt2 = 0; cnt2 < column; cnt2++) {

				table[cnt1][cnt2] = sc.nextInt();
				table[cnt1][column] += table[cnt1][cnt2];
				table[line][cnt2] += table[cnt1][cnt2];
			}
			table[line][column] += table[cnt1][column];
		}

		// ???????????????
		for (int cnt1 = 0; cnt1 <= line; cnt1++) {

			for (int cnt2 = 0; cnt2 <= column; cnt2++) {

				if (cnt2 != column) {
					System.out.print(table[cnt1][cnt2] + " ");

				} else {
					System.out.println(table[cnt1][cnt2]);
				}
			}
		}
		sc.close();
	}
}

Measured memory_bytes: 41480
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

s = input()
n = len(s)

def valid(s):
  s = 'x' + s
  return (
    s[1] == '1' and
    s[n] == '0' and
    all(s[i] == s[n-i] for i in range(1, n))
  )

if not valid(s):
  print(-1); exit()

top = 1
for i in range(n-1):
  v = i + 2
  print(top, v)
  if s[i] == '1':
    top = v


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

int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   ll n, a, b;
   cin >> n >> a >> b;
   if (a > b) swap(a, b);
   if ((b - a) % 2 == 0)
      cout << (b - a) / 2 << '\n';
   else {
      ll ans = 0;
      if (a - 1 < n - b) {
         ll x = a - 1;
         a -= x;
         b -= x;
         --b;
         ans += 1 + x + (b - a) / 2;
      }
      else {
         ll x = n - b;
         b += x;
         a += x;
         ++a;
         ans += 1 + x + (b - a) / 2;
      }
      cout << ans << '\n';
   }
   return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

int main() {
  for (ll i = 1; i <= 9; ++i) {
    for (ll j = 1; j <= 9; ++j) {
      cout << i << "x" << j << "=" << i*j << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3052
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    S=ST()
    S+=S[0]
    def is_ok():
        for i,s in enumerate(S[1:-1],start=1):
            if ans[i]==(s=="o"):
                ans[i+1]=ans[i-1]
            else:
                ans[i+1]=ans[i-1]^1
        ok = (ans[0]==ans[-1])
        if ans[0]==(S[0]=="o"):
            if ans[1]!=ans[-2]:
                ok=False
        else:
            if ans[1]==ans[-2]:
                ok=False
        return ok

    for bit in range(1<<2):
        ans=[0]*(N+1)
        for i in range(2):
            ans[i] = bit>>i&1
        if is_ok():
            ans="".join(map(str,ans[:-1]))
            print(ans.replace("1","S").replace("0","W"))
                
            return
    print(-1)
if __name__ == '__main__':
    main()

Measured memory_bytes: 11636
/*
A - AtCoder Beginner Contest 999
abc111
*/
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <cstring>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define PI 3.141592653589793
#define MOD 1000000007LL
typedef long long ll;
using namespace std;
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; }

int main() {
    string n;
    cin >> n;
    for (int i = 0; i < 3; i++){
        if (n[i] == '1')
            n[i] = '9';
        else
            n[i] = '1';
    }
    REP(i, 3) {
        cout << n[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3008
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;



int main(){
    ll A[3];
    rep(i, 3){
        cin >> A[i];
    }

    if(A[0] + A[1] + A[2] >= 22){
        cout << "bust" << endl;
    }else{
        cout << "win" << endl;
    }

    return 0;
}

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

#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)

int main(void){
  char x;
  r(i,3){
    r(j,3){
      cin>>x;
      if(i==0&&j==0)cout<<x;
      if(i==1&&j==1)cout<<x;
      if(i==2&&j==2)cout<<x;
    }
  }
  cout<<endl;

return 0;}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        X = int(input())

        while not self.is_prime(X):
            X += 1

        print(X)

    def is_prime(self, n):
        for i in range(2, n + 1):
            if i * i > n:
                break
            if n % i == 0:
                return False
        return n != 1


# Run main
if __name__ == '__main__':
    AtCoder().main()


Measured memory_bytes: 39152
N = int(input())
A = list(map(int,input().split()))
hashmap = {}
for a in A:
    if a not in hashmap:
        hashmap[a] = 0
    hashmap[a]+=1

len1 = 0
len2 = 0

for k,v in hashmap.items():
    if v>=4:
        len1, len2 = max(len1,k), max(len2,k)
    elif v>=2:
        if len1<k:
            len1, len2 = k, len1
        else:
            len2 = max(len2,k)
print(len1*len2)

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

using namespace std;

#ifndef errOut
#define errOut(s)
#endif

using Value = int64_t;
using Result = int64_t;

Result calc(const std::vector<Value>& as) {
  if (as[0]) {
    return -1;
  }
  Result ret = 0;
  Value lastValue = 0;
  for (Value idx = as.size() - 1; idx >= 0; --idx) {
    Value const a = as[idx];
    if (lastValue - a > 1) {
      return -1;
    }
    if (a >= lastValue) {
      ret += lastValue;
    } else {
      ret += lastValue - a;
    }
    lastValue = a;
  }
  return ret;
}

int main() {
  Value n;
  std::cin >> n;
  std::vector<Value> as(n, 0);
  for (Value i = 0; i < n; ++i) {
    std::cin >> as[i];
  }
  std::cout << calc(as) << std::endl;
  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
using namespace std;
void dfs(int, int, int);
int coun=0,go;
int main()
{
	int n;
	while (1){
		coun = 0;
		cin >> n >> go;
		if (n + go == 0)break;
		for (int i = 0; i < 9; i++){
			dfs(n, i, i);
		}
		cout << coun << endl;
	}
}
void dfs(int n, int sum, int to){
	if (n == 1 && sum == go){
		coun++;
	}
	for (int i = to + 1; i < 10; i++){
		dfs(n - 1, sum + i, i);
	}
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();

		if (a <= 8 && b <= 8) {
			System.out.println("Yay!");
		} else {
			System.out.println(":(");
		}
	}

}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define ll long long
using namespace std;

int main(){
    int n;
    cin>>n;
    vector<double> p(n);
    for(int i=0 ; i<n ; i++)
    cin>>p[i];
    
    vector<vector<double>> dp(n,vector<double>(n/2 +1));
    dp[0][0]=p[0];
    dp[0][1]=1-p[0];
    for(int i=1 ; i<n ; i++){
        dp[i][0]=dp[i-1][0]*p[i];
        for(int j=1 ; j<=min(i+1,n/2) ; j++){
            dp[i][j]=p[i]*dp[i-1][j] + (1-p[i])*dp[i-1][j-1];
        }
    }
    double ans=0;
    for(int i=0 ; i<dp[n-1].size() ; i++){
        ans+=dp[n-1][i];
    }
    printf("%.9lf\n",ans);
    return 0;
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;
  cin >> c;
  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
/*
AuThOr Gwj
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define debug_pair(A) cerr<<A.FIR<<" "<<A.SEC<<endl;
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
string s;int K;
LL dp[301][301][301],sum1[301],sum2[2][301];
int n=0,a[305],cnt=0;
const int MOD=998244353; 
int main(){
	fastio;
	cin>>s>>K;
	K=min(300,K);
	rep(i,s.length()){
		if(s[i]=='0'){
			a[++n]=cnt;
//			cout<<cnt<<" ";
			cnt=0;
		}
		else{
			cnt++;
		}
	}
	a[++n]=cnt;
	reverse(a+1,a+1+n);
	dp[0][0][0]=1;
	int now=0,pre=1;
	sum2[pre][0]=1;
	rb(i,1,n){
		memset(sum1,0,sizeof(sum1));
		memset(sum2[now],0,sizeof(sum2[now]));
		rb(j,0,K){
			rb(k,j,K){
				dp[i][j][k]+=dp[i-1][j][k];
				if(j){
					sum1[k-j]+=dp[i-1][j-1][k-1];
				}
				if(j>a[i]){
					sum1[k-j]-=dp[i-1][j-a[i]-1][k-a[i]-1];
					sum1[k-j]+=MOD;
				} 
				sum2[pre][k]-=dp[i-1][j][k];
				sum2[pre][k]+=MOD;
				sum2[pre][k]%=MOD;
				sum1[k-j]%=MOD;
				dp[i][j][k]+=sum1[k-j];
				dp[i][j][k]%=MOD;
				dp[i][j][k]+=sum2[pre][k];
				dp[i][j][k]%=MOD;
				sum2[now][k]+=dp[i][j][k];
				sum2[now][k]%=MOD;
				dp[i][j][k]%=MOD;
//				cout<<i<<" "<<j<<" "<<k<<" "<<dp[i][j][k]<<endl;
			}
		}
		swap(pre,now);
	}
	LL res=0;
	rb(k,0,K){
		res+=dp[n][0][k];
		res%=MOD;
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 110440
void main() {
    string s = readln.chomp;
    int n = s.to!int;
    int m;
    foreach (x; s) {
        m += x -'0';
    }
    writeln(n % m == 0 ? "Yes" : "No");
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.uni;

Measured memory_bytes: 256
import numpy as np


N, M, X = map(int, input().split())
C = []
A = [[] for _ in range(N)]
for i in range(N):
    c, *a = map(int, input().split())
    C.append(c)
    A[i] = a

ans = 10**10
for bit in range(2**N):
    tc = 0
    ta = np.zeros(M)
    for i in range(N):
        if bit & (1 << i):
            tc += C[i]
            ta += np.array(A[i])
    if min(ta) >= X:
        ans = min(tc, ans)
if ans == 10**10:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 27188
object Main {
  import scala.io.StdIn._
  import scala.annotation.tailrec
  def main(args: Array[String]): Unit = {
    val Array(n, k, _*) = readLine().split(' ').map(_.toLong)
    def calc(x: Long, k: Long) = Math.abs(x - k)
    @tailrec
    def loop(x: Long, min: Long, history: Set[Long]): Long =
      if (min == 0L) 0L
      else if (history.contains(x)) min
      else {
        val newX = if (x > k) x % k else k - x
        val newMin = Math.min(newX, min)
        loop(newX, newMin, history + x)
      }
    println(loop(n, Long.MaxValue, Set.empty))
  }
}

Measured memory_bytes: 25544
S = input()
if (S[0] == S[1] and S[2] == S[3] and S[0] != S[2]) or (S[0] == S[2] and S[1] == S[3] and S[0] != S[1]) or (S[0] == S[3] and S[1] == S[2] and S[0] != S[1]): print("Yes")
else: print("No")  

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
const long long INF = 1LL << 60;
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...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

int main() {
  int k, a,b;
  int tmp = 0;
  cin >> k >> a >> b;
  for(int i = a; i <= b; i++){
    if (i%k==0){
      tmp = 1;
    }
  }
  if (tmp)cout <<"OK";
  else cout << "NG"; 

return 0;
}

Measured memory_bytes: 3624
def sieve(n):
  is_prime = [True for _ in range(n+1)]
  is_prime[0] = False
  for i in range(2, n+1):
    if is_prime[i-1]:
      j = 2 * i
      while j <= n:
        is_prime[j-1] = False
        j += i
  table = [i for i in range(1, n+1) if is_prime[i-1]]
  return table

N = int(input())
A = list(map(int, input().split()))
Amax = max(A)
lis = [0]*(Amax+1)
for i in range(N):
  lis[A[i]] += 1
table = sieve(Amax)
setwise = False
for t in table:
  cnt = sum(lis[t:Amax+1:t])
  if cnt==N:
    print('not coprime')
    break
  if 2<=cnt<N:
    setwise=True
else:
  if setwise==True:
    print('setwise coprime')
  else:
    print('pairwise coprime')


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

using ll = long long;
using ul = unsigned long;
using ull = unsigned long long;
#define vec vector
#define rep(_i,_n) for(ll _i = 0; _i < _n; _i++)
#define rep2(_i,_s,_n) for(ll _i = _s; _i < _n; _i++)
#define elif else if
#define push(_a) push_back(_a)
#define fullSort(_a) sort(_a.begin(), _a.end())
#define inputVecI(_name, _n) vec<int> _name(_n);rep(_i, _n)cin >> _name[_i];
#define inputVecL(_name, _n) vec<long> _name(_n);rep(_i, _n)cin >> _name[_i];
#define inputVecLL(_name, _n) vec<ll> _name(_n);rep(_i, _n)cin >> _name[_i];
#define inputVecS(_name, _n) vec<string> _name(_n);rep(_i, _n)cin >> _name[_i];
#define findMaxIdx(_name) distance(_name.begin(), max_element(_name.begin(), _name.end()))
#define printVec(_vec) cout << "{";rep(i, _vec.size()-1)cout << _vec[i] << ",";cout << _vec[_vec.size()-1];cout << "}\n";
#define append(_x) push_back(_x)
#define mapLoop(_i, _name) for(auto i = _name.begin(); i != _name.end(); i++)


int main()
{
    string buf;
    cin >> buf;
    if(buf[1] == 'R'){
      cout << "ABC" << endl;
    }
    else{
      cout << "ARC" << endl;
    }
    return 0;
}


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

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

    for (int i = 0; i < x.size(); i++) {
        int tmp = ((x[i] - 'A' + 1 + n)%26 == 0) ? 26 : (x[i] - 'A' + n + 1)%26;
        putchar(tmp + 'A' - 1);
    }
    puts("");
}


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

typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin>>n;
  vector<pair<ll,ll>> times(n);
  for(ll i=0;i<n;i++)
    cin>>times[i].second>>times[i].first;
  sort(times.begin(),times.end());
  ll cur_time =0;
  ll ok=1;
  for(ll i=0;i<n;i++){
  	cur_time+=times[i].second;
    if(cur_time>times[i].first)
      ok=0;
  }
  if(!ok)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
    
  return 0;
}

Measured memory_bytes: 6348
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner (System.in);
		int n=sc.nextInt();
		int[] arr=new int[n];
		for (int i=0;i<n;i++)arr[i]=sc.nextInt();
		int j=1;
		int c=0;
		for(int i=0;i<n;i++) {
			if(arr[i]==j)j++;
			else c++;
		}
		if (c==n)System.out.println(-1);
		else System.out.println(c);
	}
} 

Measured memory_bytes: 87604
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

bool comp(const P x, const P y){
    return x.second < y.second;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<P> a(n);
    rep(i, n) {
        cin >> a[i].first;
        a[i].second = i;
    }

    sort(all(a));
    rep(i, n) {
        a[i].first = i;
    }

    sort(all(a), comp);

    int ans = 0;
    rep(i, n/2) {
        if(a[i*2+1].first%2 == 0) {
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string>
using namespace std;

int main() {
	double x1, y1, x2, y2, num, ans = 0, dou = 1, xx;
	cin >> x1 >> y1 >> x2 >> y2;
	num = (x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1);
	while (dou < num) {
		dou *= 10;
	}
	xx = dou;
	for (int i = 0; i < 100; i++) {
		for (int j = 0; j < i; j++) {
			dou *= 0.1;
		}
		if (dou < 0.000001)break;
		for (int j = 0; j < 10; j++) {
			ans += dou;
			//cout << ans << " " << j << " " << dou << endl;
			if (ans*ans > num) {
				ans -= dou;
				break;
			}
		}
		dou = xx;
	}
	printf("%f\n", ans);
	//cout << ans;

	return 0;
}

Measured memory_bytes: 3220
class Node:
    def __init__(self):
        self.parent = -1
        self.left = -1
        self.right = -1

def getDepth(u):
    d = 0
    while Nodes[u].parent != -1:
        u = Nodes[u].parent
        d += 1
    return d

def printChildren(u):
    c = Nodes[u].left
    output_list = []
    while c != -1:
        output_list.append(c)
        c = Nodes[c].right
    return output_list

# ノードの情報を出力する。
def printNodes(u):
    output_str = "node " + str(u) + ": parent = " + str(Nodes[u].parent) + ", depth = " + str(getDepth(u))
    if -1 == Nodes[u].parent:
        output_str = output_str + ", root, "
    elif Nodes[u].left != -1:
        output_str = output_str + ", internal node, "
    else:
        output_str = output_str + ", leaf, "
    # output_str += printChildren(u)
    print(output_str, "[{}]".format(", ".join(map(str, printChildren(u)))), sep="")

Nodes = []
for i in range(100000):
    tmp_obj = Node()
    Nodes.append(tmp_obj)

# 入力
n = int(input())


for tmp_count in range(n):
    input_val = list(map(int, input().split()))
    if 0 != input_val[1]:
        # 最も左の子の情報
        Nodes[input_val[0]].left = input_val[2]
        # 親の情報
        Nodes[input_val[2]].parent = input_val[0]
        
        for i in range(input_val[1] - 1):
            # 右の兄弟の情報
            Nodes[input_val[i+2]].right = input_val[i+3]
            # 親の情報
            Nodes[input_val[i+3]].parent = input_val[0]

for i in range(n):
    printNodes(i)


Measured memory_bytes: 33648
#include <iostream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;

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

    uint64_t a, b, k = 0;
    cin >> a;
    cin >> b;
    cin >> k;
    assert(1 <= a && a <= 100);
    assert(1 <= b && b <= 100);
    assert(1 <= k);

    vector<int64_t> divs;
    int64_t length = min(a, b);
    for(size_t i = 1; i <= length; ++i)
    {
        if (a % i == 0 && b % i == 0) {
            divs.push_back(i);
            //cout << i << endl;
        }
    }
    assert(k <= divs.size());

    cout << divs.at(divs.size() - k) << endl;
}

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

/**
 * vector<int>ar(3);
 * for(auto&e:ar){
 *     scanf("%d",&e);
 * }
 * sort(ar.begin(),ar.end())
 * int sum=accumulate(ar.begin(),ar.end(),0);
 ***/

int main(){
    double pai=3.141592653589;
    int n,ans=0;
    scanf("%d",&n);
    int a[n];
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++){
        int minj=i;
        int flag=0;
        for(int j=i;j<n;j++){
            if(a[j]<a[minj]){
                minj=j;
                flag=1;
            }
        }
        int tmp=a[i];
        a[i]=a[minj];
        a[minj]=tmp;
        ans+=flag;
    }
    for(int i =0;i<n-1;i++){
        printf("%d ",a[i]);
    }
    printf("%d\n",a[n-1]);
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1172
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.nextLine();
        sc.close();

        Map<String, Integer> nextHolidayMap = new HashMap<>();

        nextHolidayMap.put("SUN", 7);
        nextHolidayMap.put("MON", 6);
        nextHolidayMap.put("TUE", 5);
        nextHolidayMap.put("WED", 4);
        nextHolidayMap.put("THU", 3);
        nextHolidayMap.put("FRI", 2);
        nextHolidayMap.put("SAT", 1);

        System.out.println(nextHolidayMap.get(S));
    }

}

Measured memory_bytes: 23764
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#define ull unsigned long long
#define ll long long
#define Pr pair<ull,ll>
#define mp make_pair
using namespace std;
const int N=20,Hs=233;//-----------------debug--------------------//
map<ull,ll> cnt[20];
/*Pr cnt[100000];
bool have[100000];*/
char s[N*2];
int rec[N];
int n;
ll ans;
void update(){
	ull val=0;
	for (int i=1;i<=rec[0];++i) val=val*Hs+(s[rec[i]]-'a'+1);
	for (int i=n,p=rec[0];i>=1;--i){
		if (rec[p]==i&&p>0){--p; continue;}
		val=val*Hs+(s[i]-'a'+1);
	}
	++cnt[rec[0]][val];
}
void dfs1(int x){
	if (x==n+1){
		update();
		return;
	}
	rec[++rec[0]]=x; dfs1(x+1);
	--rec[0]; dfs1(x+1);
}
void calc(){
	ull val=0;
	for (int i=rec[0];i>=1;--i) val=val*Hs+(s[rec[i]]-'a'+1);
	for (int i=n+1,p=1;i<=2*n;++i){
		if (p<=rec[0]&&rec[p]==i){++p; continue;}
		val=val*Hs+(s[i]-'a'+1);
	}
	if (cnt[rec[0]].find(val)==cnt[rec[0]].end()) return;
	ans+=cnt[rec[0]][val];
}
void dfs2(int x){
	if (x==2*n+1){
		calc();
		return;
	}
	rec[++rec[0]]=x; dfs2(x+1);
	--rec[0]; dfs2(x+1);
}

int main(){
#ifndef ONLINE_JUDGE
	//freopen("a.in","r",stdin);
#endif
	scanf("%d",&n);
	scanf("%s",s+1);
	ans=0;
	dfs1(1);
	dfs2(n+1);
	printf("%lld\n",ans);
}


Measured memory_bytes: 16640
#include <iostream>
#include <vector>
#define T 1001
#define M 1000000007
#define E e[x][i]
#define S e[x].size()
using namespace std;
typedef long long ll;
ll func(int);
int N,s,t,j;
string n[T];
vector<int> e[T];
 
main(){
  cin>>N;
  for(j=0;j<N;j++) cin>>n[j];
  while(--N) cin>>s>>t,e[s-1].push_back(t-1);
  cout<<func(0)%M<<endl;
}

ll func(int x){
  ll res=0,i;
  if(!S){
    if(n[x]=="E") return 1;
    return 2;
  }
  if(n[x][0]=='E'){
    res++;
    for(i=0;i<S;i++) res*=func(E);
    if(n[x]=="E?") res++;
  }
  else if(n[x][0]=='A'){
    for(i=0;i<S;i++) res+=func(E);
    if(n[x]=="A?") res++;
  }else{
    res++;
    for(i=0;i<S;i++) res*=(1+func(E));
    if(n[x]=="R") res--;
  }
  return res%M;
}

Measured memory_bytes: 1360
#include <stdio.h>
int main(void) {
    int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    if (x >= r && y >= r && x + r <= W && y + r <= H) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 580
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <string>

using namespace std;

int main() {

	set<int> s;
	s.insert(6);
	int d = 6;
	for (int i = 0; d <= 300000; i++) {
		if (i % 2 == 0) d += 2;
		else d += 5;
		s.insert(d);
	}
	//cout << "Finish!" << endl;

	while (1) {
		int n;
		cin >> n;
		if (n==1) break;

		vector<int> v;
		
		d = 6;
		bool flag = false;
		for (int i = 0; d <= n; i++) {
			//cout << "i : " <<i<<" d : "<<d<<endl;
			if (flag) {
				if (i % 2 != 0) d += 2;
				else d += 5;
			}
			flag = true;
			if (n%d == 0 && (s.find(n/d)!=s.end() || n/d == 1)) {
				bool t = true;

				for (int k = 2; k*k <= d; k++) {
					if (d%k == 0) {
						if (k % 7 == 1 || k % 7 == 6) {
							t = false;
							break;
						}
					}
				}

				/*
				for (set<int>::iterator it = s.begin(); it != s.end(); it++) {
					if (d%*it == 0 && *it < d) {
						t = false;
						break;
					}
				}
				*/

				if(t) v.push_back(d);
			}
		}

		cout << n<<":";
		for (int i = 0; i < v.size(); i++) cout << " " << v[i];
		cout << endl;

	}


	return 0;
}

Measured memory_bytes: 7080
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <queue>
typedef long long ll;
using namespace std;
const int N=100010;
int a[N];
int main()
{
    int n;
    cin>>n;
    int x;
    ll sum=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&x);
        sum+=x;
        a[x]++;
    }

    int q;
    cin>>q;
    while(q--)
    {
        int b,c;
        cin>>b>>c;
        sum+=(c-b)*a[b];
        a[c]+=a[b];
        a[b]=0;
        cout<<sum<<endl;
     }


    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
 
using namespace std;
 
#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)
 
//cout << fixed << setprecision(20) << p << endl;
 
template <class T> inline T bigmod(T p,T e,T M){
    LL ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n,m,a,b;
	cin>>n>>m;
	set<pair<int,int>>s;
	for(int i=0;i<m;i++){
		cin>>a>>b;
		s.insert(make_pair(a,b));
	}
	bool ret=false;
	for(int i=2;i<n;i++){
		if(s.count(make_pair(1,i)) && s.count(make_pair(i,n))){
			ret=true;
		}
	}	
	
	cout<<(ret?"POSSIBLE":"IMPOSSIBLE")<<endl;
	return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define siz(v) (ll)(v).size()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, x, n) for (ll i = x; i < (ll)(n); i++)
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
//cin.tie(0);
//ios::sync_with_stdio(false);

signed main()
{
    int n;
    cin >> n;
    long double sum = 0;
    vector<double> v(n);
    rep(i, n)
    {
        cin >> v[i];
        sum += 1.0 / (v[i]);
    }

    cout<<fixed<<setprecision(20)<<1.0/sum<<endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func gcd(x, y int) int {
	for y > 0 {
		x, y = y, x%y
	}
	return x
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	fmt.Println(lcm(a, b))
}


Measured memory_bytes: 512
#include<iostream>

using namespace std;

int main() {

    int A[100][100];
    int B[100];
    int C[100] = {0};

    int n, m;

    cin >> n >> m;

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

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

    for (int i = 0; i < n; i ++) {
        for (int j = 0; j < m; j++) {
            C[i] += A[i][j] * B[j];
        }
    }

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

    return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define DIM (long long)1007
#define INF (long long)100000007

using namespace std;
using namespace __gnu_pbds;

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

ll n,m,i,j,k,sum,f1,f2,v1,v2,res;
ll a[DIM][DIM];
ll dp[DIM][DIM];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> m;
    char x;
    for(i=1; i<=n; i++){
        for(j=1; j<=m; j++){
            cin >> x;
            if(x=='#') a[i][j]=1;
        }
    }
    dp[1][1]=1;
    a[1][1]=1;
    ll mod=1e9+7;
    for(i=1; i<=n; i++){
        for(j=1; j<=m; j++){
            if(a[i][j]==0){
            dp[i][j]=dp[i-1][j]+dp[i][j-1];
             dp[i][j]%=mod;
            }

        }
    }

    cout << dp[n][m] << endl;




    return 0;
}


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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        ll x;
        cin >> x;
        if (x % 2) {
            cout << "first" << endl;
            return 0;
        }
    }
    cout << "second" << endl;
    return 0;
}


Measured memory_bytes: 256