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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;

int N, M;
vector<pii> edge;

// n番目の辺が橋かどうか
bool isBridge(int n)
{
    int v = edge[n].first;
    vb visited(N+1, false);
    queue<int> q;
    q.push(v);

    while(!q.empty())
    {
        int a = q.front(); q.pop();
        visited[a] = true;
        REP(i, M)
        {
            if(i == n) continue;
            if(edge[i].first == a && !visited[edge[i].second]) q.push(edge[i].second);
            if(edge[i].second == a && !visited[edge[i].first]) q.push(edge[i].first);
        }
    }

    return !visited[edge[n].second];
}

void solve()
{
    cin >> N >> M;
    edge = vector<pii>(M); REP(i, M) cin >> edge[i].first >> edge[i].second;

    int ans = 0;
    REP(i, M)
    {
        if(isBridge(i)) ans++;
    }
    cout << ans << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    solve();

    return 0;
}

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

int main() {
    string S; cin >> S;
    string out = "AC";
 
    if (S.at(0) != 'A')
        out = "WA";
 
    int cnt = 0, length = S.size();
    for (int i = 1; i < length; i++) {
        if (isupper(S.at(i))) {
            if (i == 1 || i == length - 1 || S.at(i) != 'C')
                out = "WA";
            cnt++;
        }
    }
 
    if (cnt != 1)
        out = "WA";
 
    cout << out << endl;
 
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>

using namespace std;

int main(){
  int n;
  string s;
  cin >> n >> s;
  int count=0;
  for(int i=0;i<n-2;++i){
    if(s.substr(i, 3)=="ABC") count++;
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 256
//C
#include <iostream>
#include <vector>
#include <cmath>

bool count(int horiLine,int verLine,int K);
std::vector<std::vector<int>> cell(6,std::vector<int>(6,0)); //0:白、1:黒
int main() {
    int H,W,K;
    std::cin >> H >> W >> K;

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            char color;
            std::cin >> color;
            if(color == '#'){
                cell[i][j] = 1;
            }
        }
    }
    int cnt = 0;
    int maxptn_H = std::pow(2,H);
    int maxPtn_W = std::pow(2,W);
    for(int h=0;h<maxptn_H;h++){
        for(int w=0;w<maxPtn_W;w++){
            if(count(h,w,K)){
                cnt++;
            }

        }
    }
    std::cout << cnt;
    return 0;
}

bool count(int horiLine,int verLine,int K){
    int cnt = 0;
    for(int h=0;h<6;h++){
        if(((1 << h) & horiLine) != 0) {
            for (int w = 0; w <6; w++) {
                if (((1 << w) & verLine) != 0 && cell[h][w] == 1){
                    cnt++;
                }
            }
        }
    }
    return K == cnt;
}

Measured memory_bytes: 4024
fun main(arg: Array<String>) {
    val N = nextInt()
    val csf = Array(N - 1) { listOfInt() }
    repeat(N - 1) { n ->
        var t = 0
        for (m in n until N - 1) {
            val (c, s, f) = csf[m]
            if (t < s) t = s
            t = (t + f - 1) / f * f
            t += c
        }
        println(t)
    }
    println(0)
}
fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }


Measured memory_bytes: 37984
using System;
using System.Collections.Generic;
using System.Linq;

class E
{
	static void Main()
	{
		var s = Console.ReadLine();
		var t = Console.ReadLine();

		var d = Enumerable.Range('a', 26).ToDictionary(x => (char)x, x => new List<int>());
		for (var i = 0; i < s.Length; i++) d[s[i]].Add(i);

		int turn = 0, si = -1;
		foreach (var c in t)
		{
			if (d[c].Count == 0) { Console.WriteLine(-1); return; }

			var ci = Search(d[c], si);
			if (ci != d[c].Count)
			{
				si = d[c][ci];
			}
			else
			{
				turn++;
				si = d[c][0];
			}
		}
		Console.WriteLine((long)s.Length * turn + si + 1);
	}

	static int Search(IList<int> l, int v) => l.Count > 0 ? Search(l, v, 0, l.Count) : 0;
	static int Search(IList<int> l, int v, int start, int count)
	{
		if (count == 1) return start + (v < l[start] ? 0 : 1);
		var c = count / 2;
		var s = start + c;
		return v < l[s] ? Search(l, v, start, c) : Search(l, v, s, count - c);
	}
}


Measured memory_bytes: 15072
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int n;
  cin>>n;
  int p[n];
  REP(i,n)cin>>p[i];
  int ans=0;
  REP(i,n-2)if((p[i]-p[i+1])*(p[i+1]-p[i+2])>0)ans++;
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;


int main(){
    int L, R;
    cin >> L >> R;

    int d;
    cin >> d;

    int ans = 0;
    for(int i=L; i<=R; ++i){
        if(i % d == 0) ans++;
    }


    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define endl '\n';

typedef long long ll;

using namespace std;

const string YES = "";
const string NO  = "";

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

    int a, b;

    cin >> a >> b;

    cout << ((a * b) % 2 ? "Odd" : "Even") << endl;

    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

class Unionfind{
	public:

		void init(int n){
			parent.resize(n);
			rank.resize(n);
			rep(i,n) parent[i]=i,rank[i]=0;
		}

		int find(int x){
			return (parent[x]==x) ? x : parent[x]= find(parent[x]);
		}

		void unite(int x,int y){
			x=find(x); y=find(y);
			if(x== y)return ;
	
			if(rank[x]<rank[y])
				parent[x]=y;
			else{
				parent[y]=x;
				if(rank[x] = rank[y])
					rank[x]++;
			}
		}

		bool same(int x, int y){
			return find(x) == find(y);
		}
	
	private:
		vi parent;
		vi rank;
};

struct edge{
	int a,b,c;
	bool operator<(edge tar) const{return c < tar.c;}
};

Unionfind uf,cur;
bool used[210];

int main(void){
	int n,m;
	while(cin >> n >> m,n|m){
		rep(i,210) used[i]=false;
		vector<pii> island(n);
		rep(i,n) {
			cin >> island[i].first;
			island[i].second=i+1;
		}
		
		sort(island.rbegin(),island.rend());
		vector<edge> road(m);
		rep(i,m){
			edge in;
			cin >> in.a >> in.b >> in.c;
			road[i]=in;
		}
		
		sort(road.begin(),road.end());
		
		bool enable=true;
		int ans=0;

		int prev=inf,num=0;
		uf.init(n+10);
		
		while(num<n){
			int cost=0;
			cur=uf;
			while(num<n&&prev==island[num].first)
				used[island[num++].second]=true;

			prev=island[num].first;
			rep(i,m){
				if(used[road[i].a]&&used[road[i].b]&&!cur.same(road[i].a,road[i].b)){
					cur.unite(road[i].a,road[i].b);
					cost+=road[i].c;
				}
			}
			bool check=true;
			rep(i,num){
				if(!cur.same(island[0].second,island[i].second))
					check=false;
			}
			if(check){
				uf=cur;
				ans+=cost;
			}else{
				ans=0;
				uf.init(n+1);
			}
		}
		
		rep(i,n){
			if(!uf.same(island[0].second,island[i].second))
				enable=false;
		}
		if(enable)
			cout << ans << endl;
		else
			cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 1464
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    ll n;cin>>n;
    vector<ll>d(n);
    rep(i,n)cin>>d[i];
    if(d[0]){
        cout<<0<<endl;
        return 0;
    }
    vector<ll>cnt(n);
    rep(i,n){
        cnt[d[i]]++;
    }
    ll cn=0;
    ll i=1;
    while(cnt[i]>0){
        cn+=cnt[i];
        i++;
    }
    if(cn!=n-1){
        cout<<0<<endl;
        return 0;
    }
    ll ans=1;
    ll j=1;
    while(cnt[j]>0){
        ll k=cnt[j];
        while(k){
            k--;
            ans*=cnt[j-1];
            ans%=mod;
        }
        j++;
    }
    cout<<ans<<endl;
}

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

int main (){
    long int MOD = 1000000007;
    long int n,ans=1,s;
    cin >> n;
    vector<int> a(n+1);
    a.at(0)=3;

    for(int i=0;i<n;i++){
        cin >> s;
        ans*=a.at(s);
        a.at(s)--;
        a.at(s+1)++;
        ans%=MOD;
    }
    ans%=MOD;
    cout << ans << endl;
}

Measured memory_bytes: 640
/*                                                                                 
	Author :- Gaurang_Kothiya
	
	Quote :- " Practice makes a man perfect. "		
*/  
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>  
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
#include <bitset>
#include <cstdint>
#include <initializer_list>
 
using namespace std;
using namespace __gnu_pbds;  
 
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> data_set; 
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ld long double
#define f(i,x,n) for(auto i=x;i<=n;i++)
#define fe(x,v)   for(auto &x :v)
#define nf(i,x,n) for(auto i=n;i>=x;i--)
#define all(a)   a.begin(),a.end()
#define rall(a)  a.rbegin(),a.rend()
#define gcd(a,b) __gcd(a,b)
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define RE rend()
#define RB rbegin()
#define B begin()
#define E end()
#define acc(v, x) accumulate(all(v), x)
#define p(a,b) pair<a,b>
#define F first
#define S second
#define sz size()
#define v(x) vector<x>
#define m(a,b) map<a,b>
#define u_m(a,b) unordered_map<a,b>
#define mm(a,b) multimap<a,b>
#define s(a) set<a>
#define us(a) unordered_set<a>
#define ms(a) multiset<a>
#define maxy __LONG_LONG_MAX__
#define miny INT_MIN
#define PI 3.14159265358979323846
const ll inf= 1e9;
const ll inf64= 1e18;
const ll MOD= 1e9 +7;



void Solve()
{
	ll n;
	cin>>n;
	string s="";
	while(n>0)
	{
		n--;
		char z= 'a' + n%26 ;
		s = z + s;
		
		n /=26;
	}
	cout<<s;
} 
 
signed main() 
{
	speed		
	
	
	int q=1;
	//cin>>q;
	
	while(q--)
	Solve();
	
	return 0;
} 

Measured memory_bytes: 3628
use proconio::input;
#[allow(unused_imports)]
use std::collections::HashSet;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

type pair = (usize, usize);

// max = (n-1)(n-2)/2
fn main() {
    input! {
        n: usize,
        mut d: [i32; n] 
    }
    let answer = solve(n, &mut d);
    println!("{}", answer);
}

fn solve(n: usize, d: &mut [i32]) -> i32 {
    // 1. sort
    d.sort();

    // 2. threshold should middle of d
    //     possible ways = diff between <left of middle> and <right of middle>
    let mid = n / 2;
    return d[mid] - d[mid-1];

}


Measured memory_bytes: 3264
#include<iostream>
using namespace std

;

int main(){

for(int a,b,t; ;){

cin>>a>>b;

if (a==0 && b==0){break;}

if (a>b){

t=a;

a=b;

b=t;

}

cout<<a<<" "<<b<<"\n";

}

return 0;

}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
#define int long long 
using namespace std;
const int MAXN = 1e6 + 10;
int N;
int a[1001][1001], vis[MAXN], prime[MAXN], tot;
void GetPhi() {
	vis[1] = 1;
	for(int i = 2; i; i++) {
		if(!vis[i]) prime[++tot] = i;
		if(tot == 1000) break; 
		for(int j = 1; j <= tot && (i * prime[j] <= 10000); j++) {
			vis[i * prime[j]] = 1;
			if(!(i % prime[j])) break;
		}
	}
}
int lcm(int x, int y) {
	if(x == 0 || y == 0) return x + y;
	return x / __gcd(x, y) * y;
}
main() {
	GetPhi();
	cin >> N;
	if(N == 2) {
		printf("4 7\n23 10");
		return 0;
	}
	for(int i = 1; i <= N; i++) 
		for(int j = 1; j <= N; j++)
			if(!((i + j) & 1)) a[i][j] = prime[(i + j) / 2] * prime[N + (i - j) / 2 + (N + 1) / 2];
	for(int i = 1; i <= N; i++)
		for(int j = 1; j <= N; j++)
			if(!a[i][j]) 
				a[i][j] = lcm(lcm(a[i - 1][j], a[i][j - 1]), lcm(a[i][j + 1], a[i + 1][j])) + 1;
	for(int i = 1; i <= N; i++, puts(""))
		for(int j = 1; j <= N; j++)
			cout << a[i][j] << " ";
	return 0;
}

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

int a[111],b[111],c[111],n,s;

int main()
{
	int i;
	cin>>n;
	for (i=1;i<n;i++)
	{
		cin>>b[i];
	}
	b[0]=b[n]=0x11111111;
	for (i=1;i<=n;i++)
	{
		s+=min(b[i],b[i-1]);
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

typedef  long long ll;

using namespace std;
vector<int> shop(1000001);

int main()
{
    int n, m; cin >> n >> m;
    ll ans = 0; //金額
    vector<pair <ll, ll> > P(n);
    for (int i = 0; i < n; i++){
        int a, b; cin >> a >> b;
        P[i] = make_pair(a, b);
    }
    sort(P.begin(), P.end());

    ll now = 0; //本数
    for (int i = 0; i < n; i++){
        if(now + P[i].second <= m){
            ans += (ll)(P[i].first * P[i].second);
            now += P[i].second;
        }
        else{
           ans += (m - now) * P[i].first;
           break;
        }
    }
    cout << ans << endl;
}

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


template <typename T>
ostream& operator<<(ostream& s, const vector<T> &vec){
    for(int i=0;i<vec.size();i++){
        if(i) s << ',';
        else s << '{';
        s <<setw(2)<< vec[i];
    }
    s << '}' << endl;
    return s;
}


int main(){
    int a;
    cin>>a;
    cout<<1-a<<endl;

    return 0;
}

Measured memory_bytes: 3612
#include <stdio.h>
#include <iostream>
#include <string>
#include <stdlib.h>
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>

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

using namespace std;
typedef long long ll;



int main(void)
{
	string s, t;
	cin >> s>>t;

	rep(i, s.size()) {
		if (s[i] != t[i]) {
			cout << "No";
			return 0;
		}

	}

	cout << "Yes";










	cout << endl;
}


Measured memory_bytes: 3628
// In the name of God

#include <bits/stdc++.h>

using namespace std;

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

	long long n;
	cin >> n;

	string s = "";

	while(n) {
		s += (char) ((n % 26 + 25) % 26 + 'a');
		n = (n - 1) / 26;
	}

	reverse(s.begin(), s.end());

	cout << s;

	
	return 0;
}


Measured memory_bytes: 3636
s = input()
k = int(input())
s = list(s)
ind = 0
anss = [[] for i in range(100)]
for i in range(len(s)-1):
  anss[ind].append(s[i])
  if s[i] != s[i+1] and i != len(s)-2:
    ind += 1
  elif i == len(s)-2:
    ind += 1
#print(ind)
#print(anss)
for i in range(100-ind):
  anss.remove([])
#print(anss)
f = 0
pf = 0
if len(anss) == 0:
  anss.append([])
if s[0] == s[len(s)-1] and s[len(s)-2] == s[len(s)-1] and len(anss)>1 and k > 1:
  if len(anss[0]) % 2 == 1:
    pf = 1
  anss[0] += anss[len(anss)-1]
  anss.remove(anss[len(anss)-1])
  anss[0].append(s[len(s)-1])
  if len(anss[0]) % 2 == 0 and pf == 1 and len(anss) > 1:
    f = 1
elif s[0] == s[len(s)-1] and k > 1:
  if len(anss[0]) % 2 == 1:
    pf = 1
  anss[0].append(s[len(s)-1])
  if len(anss[0]) % 2 == 0 and pf == 1 and len(anss) > 1:
    #print(len(anss[0]),pf)
    f = 1
elif s[len(s)-2] == s[len(s)-1] and k > 1:
  anss[len(anss)-1].append(s[len(s)-1])
else:
  anss.append([s[len(s)-1]])
pans = 0
#print(anss)
for i in anss:
  pans += len(i) // 2
#print(f)
if len(anss) == 1 and len(anss[0]) % 2 == 1:
  print((len(s)*k)//2)
elif f == 1:
  print(pans*k-1)
else:
  print(pans*k)

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


void solve(long long A, long long B, long long K){
    if(A+K-1 < B-K+1){
        for(long long i = A; i < A + K; ++i){
            cout << i << endl;
        }
        for(long long i = B - K + 1; i <= B; ++i){
            cout << i << endl;
        }
    }else if(A+K-1 >= B-K+1){
        for(long long i = A; i <= B; ++i){
            cout << i << endl;
        }
    }

}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long K;
    scanf("%lld",&K);
    solve(A, B, K);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{
    public static int gcd(int x, int y) {
        int max, min, temp;
        if(x > y){
            max = x;
            min = y;
        } else {
            max = y;
            min = x;
        }
        
        while(true){
            if(max % min == 0){
                return min;
            } else {
                temp = max % min;
                max = min;
                min = temp;
            }
        }
    }

    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        
        System.out.println(gcd(x, y));
    }
}



Measured memory_bytes: 26404
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


def main():
    # sys.stdin = open("sample.txt")
    N, K = Scanner.map_int()
    H = Scanner.map_int()
    H.sort()
    print(sum(H[:N - min(K, N)]))
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 83696
#include<stdio.h>
#include<string.h>
int main(){
  int n,m,k,i,j;
  int c[200];
  int a[200];
  scanf("%d",&n);
  for(i=0;i<n*2;i++)c[i]=i+1;
  scanf("%d",&m);
  for(i=0;i<m;i++){
    scanf("%d",&k);
    if(k){
      for(j=0;j<k;j++)a[j]=c[j];
      for(;j<2*n;j++) c[j-k]=c[j];
      for(j=0;j<k;j++)c[2*n-k+j]=a[j];
    }
    else{
      k=n;
      for(j=0;j<n;j++)a[j]=c[j];
      for(j=0;j<n;j++){
	c[j*2]=a[j];
	c[j*2+1]=c[k++];
      }
    }
  }
  for(i=0;i<n*2;i++)printf("%d\n",c[i]);  
  return 0;
}

Measured memory_bytes: 604
n,m=map(int,input().split())
a=set([int(input()) for j in range(m)])
dp=[0]*(n+1)
dp[0]=1
if not 1 in a:
    dp[1]=1
else:
    dp[1]=0
for i in range(n-1):
    if i+2 in a:
        dp[i+2]=0
    else:
        dp[i+2]=(dp[i+1]+dp[i])%(10**9+7)
print(dp[n])

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	int ans = 0;
	rep(i, n) {
		int tmp = a[i];
		while (tmp % 2 == 0) {
			tmp /= 2;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

var (
	x, a, b int
)

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

	if b-a <= 0 {
		fmt.Println("delicious")
	} else if (b-a)-x <= 0 {
		fmt.Println("safe")
	} else {
		fmt.Println("dangerous")
	}
}

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

int main(void){
    int X, Y, Z, K;
    
    cin >> X >> Y >> Z >> K;
    vector<long> A(X), B(Y), C(Z);
    vector<long> AB, ABC;

    for (int i = 0; i < X; i++) cin >> A[i];
    for (int i = 0; i < Y; i++) cin >> B[i];
    for (int i = 0; i < Z; i++) cin >> C[i];
    
    for (int i = 0; i < X; i++) {
        for (int j = 0; j < Y; j++) {
            AB.push_back(A[i] + B[j]);
        }
    }
    sort(AB.begin(), AB.end(), std::greater<long>());
    
    for (int i = 0; i < min(X*Y, K); i++) {
        for (int j = 0; j < Z; j++) {
            ABC.push_back(AB[i] + C[j]);
        }
    }
    sort(ABC.begin(), ABC.end(), std::greater<long>());
    
    for (int i = 0; i < K; i++) {
        cout << ABC[i] << endl;
    }
}


Measured memory_bytes: 43240
def main():
    N = int(input())
    mod = 10**9 + 7
    v = {'TTTT': 1}
    for _ in range(N):
        u = {}
        for c, k in v.items():
            c = c[1:]
            for i in 'ACGT':
                t = c + i
                if 'AGC' in t or 'GAC' in t or 'ACG' in t or (t[0] == 'A' and t[2:] == 'GC') or (t[:2] == 'AG' and t[3] == 'C'):
                    continue
                u[t] = (u.get(t, 0) + k) % mod
        v = u
    print(sum(v.values()) % mod)

main()


Measured memory_bytes: 3064
import java.util.*;
public class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] arr = new int[n];
		for(int i=0; i<n; i++) {
		    arr[i] = sc.nextInt();
		}
		
		System.out.println(solve(arr, k));
	}
	
	public static int solve(int[] arr, int k) {
	    int n = arr.length;
	    
	    if(n==0) {
	        return 0;
	    }
	    
	    int sum = 0;
	    
	    PriorityQueue<Integer> heap = new PriorityQueue(Collections.reverseOrder());
	    for(int i: arr) {
	        heap.add(i);
	        
	        if(heap.size() > k) {
	            heap.remove();
	        }
	    }
	    
	    while(heap.size() > 0) {
	        sum += heap.peek();
	        heap.remove();
	    }
	    return sum;
	}
}


Measured memory_bytes: 38988
#include <iostream>
#include <string>
int main()
{
    int num;
    std::cin >> num;
    std::cin.ignore();
    std::string arare;
    std::getline(std::cin, arare);
    std::string::size_type pos = arare.find("Y");
    std::string type;
    if (pos == std::string::npos){
       type = "Three"; 
    }
    else{
        type="Four";
    }
    std::cout << type;
}


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

int main() {
	int n, c, temp; int p = 0; cin >> n >> c; n++;
	for (int i = 0; i < c; i++) { cin >> temp; p += temp; }
	cout << (p % n == 0 ? p / n : p / n + 1) << endl;
	return 0;
}


Measured memory_bytes: 3100
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter

val br = BufferedReader(InputStreamReader(System.`in`))
val pw = PrintWriter(System.out)
fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    // 回答をここに書く
    val (AB, BC, CA) = listOfLong()
    println(AB* BC / 2)
}

// 入力取得
fun next() = br.readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() =listOfString().map { it.toInt() }
fun listOfLong() =listOfString().map { it.toLong() }
fun listOfDouble() =listOfString().map { it.toDouble() }

// 約数のList
fun divisor(value : Long) : List<Long> {
    val max = Math.sqrt(value.toDouble()).toLong()
    return (1..max)
        .filter { value % it == 0L }
        .map { listOf(it, value / it) }
        .flatten()
        .sorted()
}

// 範囲内の素数を取得
// fromだけ指定すると戻り値の個数で素数判定ができる
fun prime(from : Long, to : Long = from) : List<Long> {
    return (from..to).filter { i ->
        val max = Math.sqrt(i.toDouble()).toLong()
        (2..max).all { j ->  i % j != 0L }
    }
}

// 素因数分解
fun decom(value : Long) : List<Long>{
    if (value == 1L) return listOf(1)
    val max = Math.sqrt(value.toDouble()).toLong()
    return prime(2, max).filter { value % it == 0L }
}

// 最大公約数
fun gcd(a : Long, b : Long) : Long {
    return if (a % b == 0L) b else gcd(b, a % b)
}

// 文字列を入れ替え
fun swap(base : String, a : String, b : String) : String {
    return base.map {
        when (it) {
            a.toCharArray()[0] -> b
            b.toCharArray()[0] -> a
            else -> it.toString()
        }
    }.joinToString()
}

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 35644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,p;cin >> n >> p;
	vector<int> a(1000001);
	ll k=p;
	for(ll i=2;i*i<=p;++i){
		while(k%i==0){
			a.at(i)++;
			k/=i;
		}
	}
	ll ans=1;
	rep(i,1000001){
		if(a.at(i)>=n) ans*=pow((ll)i,(a.at(i)/n));
	}
	if(k>1 && n==1) ans*=k;
	cout << ans << endl;
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;

const int inf=1e9+10;
const int maxn=16;

int dp[1<<maxn][maxn],dp2[1<<maxn],n,m,cost[maxn][maxn]; 
vector <int> g[1<<maxn]; 

int main(){
	for(int i=0;i<maxn;i++) for(int j=0;j<maxn;j++) 
		cost[i][j]=0;
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int u,v,c;
		scanf("%d%d%d",&u,&v,&c);
		u--; v--;
		cost[u][v]=c;
		cost[v][u]=c;
	}
	for(int mask=0;mask<(1<<n);mask++) 
		for(int i=0;i<n;i++) for(int j=0;j<n;j++)
			if((mask&(1<<i))&&(mask&(1<<j)))
				dp2[mask]=dp2[mask]+cost[i][j];
	for(int mask=0;mask<(1<<n);mask++) dp2[mask]=dp2[mask]/2;
	for(int mask=0;mask<(1<<n);mask++) for(int i=0;i<n;i++) dp[mask][i]=-inf;
	for(int mask=0;mask<(1<<n);mask++) if(mask&1) dp[mask][0]=dp2[mask];
	for(int mask=0;mask<(1<<n);mask++)
		for(int i=0;i<n;i++){
			if((dp[mask][i]==-inf)||!(mask&(1<<i))) continue;
			for(int mask2=(1<<n)-1-mask;mask2>0;mask2=(mask2-1)&((1<<n)-1-mask)){
				for(int j=0;j<n;j++){
					if(mask2&(1<<j)&&cost[i][j]>0){
						dp[mask|mask2][j]=max(dp[mask|mask2][j],dp[mask][i]+cost[i][j]+dp2[mask2]);
					}
				}
			}
		}
	printf("%d\n",dp2[(1<<n)-1]-dp[(1<<n)-1][n-1]);
	return 0;
}

Measured memory_bytes: 4224
n = int(input())
h_array = [int(x) for x in input().split()]
res = [0 for x in range(n)]
for index in range(n):
    if index == 1:
        res[index] = abs(h_array[index] -h_array[index-1])
        continue
    elif index == 0:
        res[index] = 0
        continue
    res[index] = min(abs(h_array[index] - h_array[index - 1]) + res[index - 1],
                     abs(h_array[index] - h_array[index - 2]) + res[index - 2])
print(res[-1])


Measured memory_bytes: 13800
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<P,int>
#define vpp vector<PP>
#define fi first
#define se second
#define INF 1e9
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(x) (x).begin(),(x).end()
int main(){
    string st;
    cin>>st;
    int n=st.length();
    int p=0;
    REP(i,n){
        p+=(st[i]=='p');
    }
    cout<<n/2-p<<endl;
    return 0;
}

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

typedef pair<long long ,int> P;

int ans,n;
int b[50],c[50];
long long adj[50],mask;
string a[50];
vector<string> d[50];
map< P, int> memo;

int rec(long long can,int sum, int l){
  if(!can)return 0;
  if(memo.find(P(can,l)) != memo.end())return memo[P(can,l)];

  /*
  for(int i=0;i<n;i++){
    cout << ((can>>i)&1);
  }
  cout << endl;
  */

  int tmp = 0;
  for(int i=l;i<n;i++)
    if( (can>>i)&1 )tmp += b[i];
  if(tmp + sum <= ans)return 0;
  
  tmp = 0;
  for(int i=l;i<n;i++){
    if( (can>>i)&1 ){
      tmp = max(tmp,rec( (adj[i]^mask) & can,sum+b[i],i+1) + b[i]);
    }
  }

  if(ans<sum + tmp)ans = sum+tmp;
  if(can<(1LL<<15))memo[P(can,l)] = tmp;
  return tmp;
}

int main(){
  while(cin >> n, n){
    for(int i=0;i<n;i++){
      cin >> a[i] >> b[i] >> c[i];
      d[i].resize(c[i]);
      for(int j=0;j<c[i];j++)cin >> d[i][j];
    }
    string mine = a[0];

    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
	if(b[i] < b[j]){
	  swap(a[i],a[j]);
	  swap(b[i],b[j]);
	  swap(c[i],c[j]);
	  swap(d[i],d[j]);
	}
      }
    }

    map<string,int> m;
    for(int i=0;i<n;i++)m[a[i]] = i;
    mask = (1LL<<n) -1LL;

    for(int i=0;i<n;i++){
      adj[i] = 1LL<<i;
      for(int j=0;j<c[i];j++)adj[i] |= 1LL << m[d[i][j]];
    }


    ans = 0; memo.clear();
    rec(adj[m[mine]]^mask,b[m[mine]],0);
    cout << ans << endl;
  }
}

Measured memory_bytes: 1340
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
using namespace std;
int main()
{
  int n;
  cin >> n;
  int tmp;
  int m = 0;
  int sum = 0;
  REP(i,n){
    cin >> tmp;
    m = max(tmp, m);
    sum += tmp;
  }
  // cout << m << endl;
  // cout << sum << endl;
  if(m < sum - m){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)
	a--
	fmt.Println((b-((b/c)+(b/d)-(b/lcm(c,d))))-(a-((a/c)+(a/d)-(a/lcm(c, d)))))
}

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

func lcm (a, b int) int {
	return (a*b)/gcd(a, b)
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int h, w, k; scanf("%d%d%d", &h, &w, &k);
	std::vector<std::string> s(h);
	for(auto& v: s) cin >> v;

	int ans = 0;
	for(int i = 0; i < (1 << h); i++) {
		for(int j = 0; j < (1 << w); j++) {
			auto t = s;
			for(int k = 0; k < h; k++) {
				if(i >> k & 1) continue;
				for(int l = 0; l < w; l++) t[k][l] = '.';
			}
			for(int l = 0; l < w; l++) {
				if(j >> l & 1) continue;
				for(int k = 0; k < h; k++) t[k][l] = '.';
			}

			int cnt = 0;
			for(int k = 0; k < h; k++) for(int l = 0; l < w; l++) cnt += (t[k][l] == '#');
			ans += (cnt == k);
		}
	}
	printf("%d\n", ans);
	return 0;
}


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

int main() {
    long long W, H, x, y;
    cin >> W >> H >> x >> y;
    double res = (double)(W) * H / 2;
    cout << fixed << setprecision(10) << res << " ";

    if (x*2 == W && y * 2 == H) cout << 1 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long num[41],ppow[41];
int a[41];
void cal(long long x)
{
    int pos=0;
    while(x)
    {
        a[pos++]=x%2;
        x/=2;
    }
    long long t=0;
    for(int i=0;i<pos;i++)
    {
        if(a[i]==1)
        {
            for(int j=0;j<i;j++)
                num[j]+=ppow[i-1];
            num[i]+=t+1;
        }
        t+=a[i]*ppow[i];
    }
}
int main()
{
    ppow[0]=1;
    for(int i=1;i<=40;i++)
        ppow[i]=ppow[i-1]*2;
    long long a,b,ans=0;
    scanf("%lld%lld",&a,&b);
    cal(b);
    for(int i=0;i<=40;i++)
        num[i]*=-1;
    if(a) cal(a-1);
    for(int i=0;i<=40;i++)
        num[i]*=-1,ans+=num[i]%2*ppow[i];
    printf("%lld\n",ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N;
    vi a(N);
    cin >> a;
    vi v(20);
    REP(i, N) {
        v[a[i] / 400]++;
    }
    dump(v);
    int mn = 0;
    REP(i, 20) {
        if (i < 8 && v[i] > 0)
            mn++;
        if (i >= 8 && v[i] > 0)
            mn = max(mn, 1);
    }
    REP(i, 20) {
        if (i < 8 && v[i] > 0)
            ans++;
        if (i >= 8)
            ans += v[i];
    }
    cout << mn << " " << ans << endl;
}

Measured memory_bytes: 3564
#include<stdio.h>

int main(void) {
    int n,i,j;
    scanf("%d",&n);
    int a[n];
    int b[n];
    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    if (n%2 == 0) {
        for (j=0;j<n/2;j++) {
            b[j] = a[n-1-(j*2)];
        }
        for (j=0;j<n/2;j++) {
            b[j+n/2] = a[2*j];
        }
    } else {
        for (j=0;j<n/2+1;j++) {
            b[j] = a[n-1-(j*2)];
        }
        for (j=0;j<n/2;j++) {
            b[j+n/2+1] = a[2*j+1];
        }
    }
    for (i = 0; i < n; i++) {
        printf("%d ", b[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <algorithm>
#include <cctype>
#include <string>

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

using namespace std;

const int imax=1234567;

int n;
string S;
size_t cur=0;

int digit();
int number();
string expression();

int digit(){
	return S[cur++]-'0';
}

int number(){
	int res=digit();
	while(isdigit(S[cur])){
		res=res*10+digit();
	}
	return res;
}



string expression(void){
	string rec="";
	while(cur < n){
		//cout << cur << endl;
		if(rec.size()>=imax)
			return rec;

		if(isupper(S[cur])){
		
			rec+=S[cur++];

		}else if(isdigit(S[cur])){

			int r=number();
			string c="";

			if(S[cur]=='('){
				cur++;
				c=expression();
			}else
				c=S[cur++];

			rep(i,r){
				if(rec.size()>=imax)
					return rec;
				rec+=c;
			}
		}else if(S[cur]==')'){
			cur++;
			return rec;
		}

	}
	return rec;
}

int main(void){
	int i;
	while(cin >> S >> i){
		if(S=="0")
			break;
		n=S.size();
		cur=0;
		string res=expression();
		if(i>=res.size())
			cout << 0 << endl;
		else
			cout << res[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 7408
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,a,b;
  cin>>x>>a>>b;
  if(a-b>=0){
    cout<<"delicious"<<endl;
  }else if(b-a<=x){
    cout<<"safe"<<endl;
  }else{
    cout<<"dangerous"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int m, f, r = 0;
  
  while( m >= -2){
    cin >> m >> f >> r;
    
    if( m == -1 && f == -1 && r == -1){
      break;
    }
    else if(m == -1 || f == -1 || m + f < 30){
      cout << "F" << endl;
    }
    else if(50 <= m + f && m + f < 65){
      cout << "C" << endl;
    }
    else if(30 <= m + f && m + f < 50 && r >= 50){
      cout << "C" << endl;
    }
    else if(30 <= m + f && m + f < 50){
      cout << "D" << endl;
    }
    else if(65 <= m + f && m + f < 80){
      cout << "B" << endl;
    }
    else if(m + f >= 80){
      cout << "A" << endl;
    }
  }
  
}


Measured memory_bytes: 3104
#include<iostream>
#include<string>
using namespace std;
int main(void){
  string s1,s2,s3;
  cin>>s1>>s2>>s3;
  s1[0]-=32;
  s2[0]-=32;
  s3[0]-=32;
  cout<<s1[0]<<s2[0]<<s3[0]<<endl;
  return 0;
}

Measured memory_bytes: 256
function A(){
   var max=0;
   var ary=[];
   for(var i=1;i<=8;i++){
      for(var j=1;j<=8;j++){
         if(yx[i][j]!=".")continue;
         var cnt=seach(i,j,"x","o");
         if(cnt>max){ary=[i,j];max=cnt;}
      }
   }
   return ary;
}
function B(){
   var max=0;
   var ary=[];
   for(var i=8;i>=1;i--){
      for(var j=8;j>=1;j--){
         if(yx[i][j]!=".")continue;
         var cnt=seach(i,j,"o","x");
         if(cnt>max){ary=[i,j];max=cnt;}
      }
   }
   return ary;
}
function seach(y,x,a,b){
   var dy=[-1,-1,-1,0,0,1,1,1];
   var dx=[-1,0,1,-1,1,-1,0,1];
   var sum=0;
   for(var i=0;i<8;i++){
      var DY=dy[i];
      var DX=dx[i];
      var cnt=0;
      var k=1; 
      while(true){
         if(yx[y+DY*k][x+DX*k]=="f" || yx[y+DY*k][x+DX*k]==".")break;
         else if(yx[y+DY*k][x+DX*k]==a)cnt++;
         else if(yx[y+DY*k][x+DX*k]==b){sum+=cnt;break;}
         k++;
      }
   }
   return sum;
}
function change(y,x,a,b){
   yx[y][x]=b;
   var dy=[-1,-1,-1,0,0,1,1,1];
   var dx=[-1,0,1,-1,1,-1,0,1];
   var cnt=0;
   for(var i=0;i<8;i++){
      var DY=dy[i];
      var DX=dx[i];
      var cnt=0;
      var k=1;
      var flag=false;
      while(true){
         if(yx[y+DY*k][x+DX*k]=="f" || yx[y+DY*k][x+DX*k]==".")break;
         else if(yx[y+DY*k][x+DX*k]==a)flag=true;
         else if(yx[y+DY*k][x+DX*k]==b){
            if(flag){
               while(k--)yx[y+DY*k][x+DX*k]=b;
            }
            break;
         }
         k++;
      }
   }
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var yx=[];
yx.push("ffffffffff".split(""));
arr.forEach(function(v){
   v="f"+v+"f";
   yx.push(v.split(""));
});
yx.push("ffffffffff".split(""));
var pass=0;
while(true){
   var ansA=A();
   if(ansA.length==0)pass++;
   else {pass=0;change(ansA[0],ansA[1],"x","o");}
   var ansB=B();
   if(ansB.length==0)pass++;
   else {pass=0;change(ansB[0],ansB[1],"o","x");}
   if(pass>=2)break;
}
yx.shift();
yx.pop();
console.log(yx.join("\n").replace(/\,|f/g,""));

Measured memory_bytes: 15908
import sys
sys.setrecursionlimit(10**7)
# レベルnバーガーの下からx層に含まれるパティの枚数
def f(n,x):
  if n==0:
    return 0 if x<=0 else 1
  elif x<=1+a[n-1]:
    return f(n-1,x-1)
  else:
    return p[n-1]+1+f(n-1,x-2-a[n-1])

n,x=map(int,input().split())
a,p=[1],[1]
for i in range(n):
  a.append(a[i]*2+3)
  p.append(p[i]*2+1)

print(f(n,x))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<(int)n;i++)
const ll INF = (1LL<<60);

struct edge{
    ll to,cost;
};
vector<vector<edge> > G1(100010),G2(100010);
ll n,m,s,t;
vector<ll> minyen(100010), minsn(100010);


void dijkstra1(int s){
    rep(i,n){
        minyen[i] = INF;
    }
    minyen[s] = 0;
    priority_queue<P,vector<P>,greater<P> > pq;
    pq.emplace(0,s);
    while(!pq.empty()){
        P p = pq.top();
        pq.pop();
        int v = p.second;

        if(minyen[v]<p.first) continue;
        for(auto &e : G1[v]){
            if(minyen[e.to] > minyen[v] + e.cost){
                minyen[e.to] = minyen[v]+e.cost;
                pq.emplace(minyen[e.to],e.to);
            }
        }
    }
}

void dijkstra2(int t){
    rep(i,n){
        minsn[i] = INF;
    }
    minsn[t] = 0;
    priority_queue<P,vector<P>,greater<P> > pq;
    pq.emplace(0,t);
    while(!pq.empty()){
        P p = pq.top();
        pq.pop();
        int v = p.second;

        if(minsn[v]<p.first) continue;
        for(auto &e : G2[v]){
            if(minsn[e.to] > minsn[v] + e.cost){
                minsn[e.to] = minsn[v]+e.cost;
                pq.emplace(minsn[e.to],e.to);
            }
        }
    }
}

int main(){
    cin >> n >> m >> s >> t;
    s--; t--;
    rep(i,m){
        ll u,v,a,b ; cin >> u >> v >> a >> b;
        u--; v--;
        G1[u].push_back((edge){v,a}); G1[v].push_back((edge){u,a});
        G2[u].push_back((edge){v,b}); G2[v].push_back((edge){u,b});
    }
    minyen.resize(n); minsn.resize(n);

    dijkstra1(s);
    dijkstra2(t);
    ll money = 1000000000000000;
    ll mi = INF;
    vector<ll> res(n);
    for(int i=n-1;i>=0;i--){
        mi = min(mi, minyen[i]+minsn[i]);
        res[i] = money-mi;
    }
    rep(i,n) cout << res[i] << endl;
}

Measured memory_bytes: 21100
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
typedef pair<int,int> ipair;
#define pb push_back
#define MP make_pair
#define ff first
#define ss second
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define ABS(x) ((x)<0?-(x):(x))
 
ll mod = 1000000007;


//cout<<fixed<<setprecision(2)<<d;

void prin(double x,double y){
	cout<<fixed<<setprecision(7)<<x;
	cout<<" ";
	cout<<fixed<<setprecision(7)<<y;
	cout<<endl;
}

int main(){
	
	ios::sync_with_stdio(false);
	cin.tie(0);
 
	string ss,tt;
	cin>>ss;
	cin>>tt;

	ll m,n;
	m = ss.length();
	n = tt.length();

	ll mat[m][26];
	for(int i=0;i<26;i++){
		mat[m-1][i] = -1;
	}
	mat[m-1][ss[m-1]-'a'] = m-1;

	for(int i=m-2;i>-1;i--){
		for(int j=0;j<26;j++){
			mat[i][j] = mat[i+1][j];
		}
		mat[i][ss[i]-'a'] = i; 
	}


	for(int i=0;i<n;i++){
		if(mat[0][tt[i]-'a']==-1){cout<<-1<<endl;return 0;}
	}

	ll cnt = 0,p=0;
	for(int i=0;i<n;i++){
		p = mat[p][tt[i]-'a'];
		//cout<<p<<endl;
		if(p==-1){cnt += m;p = 0;i--;}
		else{p++;}

		if(i<(n-1)&&p>(m-1)){p = 0;cnt += m;}
	}

	cnt += p;

	cout<<cnt<<endl;

	return 0;
}
 
//-------------------------//




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

int main(){
  int N;
  cin >> N;
  
  vector<string> item(N);
  
  for(int i = 0; i < N; i++){
    string item1;
    cin >> item1;
    item.at(i) = item1;
  }

  int cnt = 1;
  sort(item.begin(),item.end());
  for(int i = 0; i < N - 1;i++){
	  if(item.at(i) != item.at(i+1))
	    cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 9520
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define NO NULL
struct node{
  int key;
  struct node *p,*l,*r;
};
typedef struct node *Node;
Node root;

void insert(int k){
  Node y=NO;
  Node x=root;
  Node z;
  z=malloc(sizeof(struct node));
  z->key=k;
  z->l=NO;
  z->r=NO;
  while(x!=NO){
    y=x;
    if(z->key < x->key)x=x->l;
    else x=x->r;
  }
  z->p=y;
  if(y==NO)root=z;
  else if(z->key<y->key)y->l=z;
  else y->r=z;
}
void inorder(Node u){
  if(u==NO)return;
  inorder(u->l);
  printf(" %d",u->key);
  inorder(u->r);
}
void preorder(Node u){
  if(u==NO)return;
  printf(" %d",u->key);
  preorder(u->l);
  preorder(u->r);
}
int main(){
  int n,i,j;;
  char c[20];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",c);
    if(c[0]=='i'){
      scanf("%d",&j);
      insert(j);
    }
    else{
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}



Measured memory_bytes: 25240
S = input()
if S == "RSR" or S == "RSS" or S == "SRS" or S == "SSR":
    print(1)
    exit(0)
if S == "RRS" or S == "SRR":
    print(2)
    exit(0)
if S == "RRR":
    print(3)
    exit(0)
print(0)
exit(0)

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

int main() {
  string s;
  cin >> s;
  int a = s.find("AC");
  if (a != string::npos) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,K=MI()
    A=LI()
    ans=[]
    for i in range(K,N):
        if A[i]>A[i-K]:
            ans.append("Yes")
        else:
            ans.append("No")
            
    for s in ans:
        print(s)

main()


Measured memory_bytes: 107076
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll Mod = 1000000007;
int main() {
  int N;
  cin >> N;
  ll A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[i] -= i+1;
  }
  sort(A,A+N);
  ll ans = 0;
  ll b = A[N/2];
  for (int i = 0; i < N; i++) {
    ans += abs(A[i] - b);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N; cin >> N;
    string S; cin >> S;
    ll res = 0;
    int L = 0, R = N - 1;
    while (1) {
        for(; L < N; L++) if (S[L] == 'W') break;
        for(; R >= 0; R--) if (S[R] == 'R') break;
        if (L>R) break;
        res++;
        swap(S[L], S[R]);
    }
    cout << res << endl;
}


Measured memory_bytes: 3756