akhauriyash/Code-Regression huggingface dataset:
//package Atcoder;
import java.util.*;
import java.io.*;
public class Main
{
	static final int mod=(int)1e9+7;
	static final int inf=(int)1e9;
	static final long INF=(long)1e18;
	public static void main(String[] args)
	{
		FastScanner fs=new FastScanner();
		int factors[]=new int[1000001];
		for(int i=0;i<=factors.length-1;i++)
		{
			factors[i]=i;
		}
		for(int i=2;i*i<=factors.length-1;i++)
		{
			if(factors[i]==i)
			{
				for(int j=2*i;j<=factors.length-1;j+=i)
				{
					if(factors[j]==j)
					{
						factors[j]=i;
					}
				}
			}
		}
		int n=fs.nextInt();
		int gcd=0;
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
		{
			arr[i]=fs.nextInt();
			gcd=fs.gcd(gcd,arr[i]);
		}
		if(gcd>1)
		{
			System.out.println("not coprime");
			return;
		}
		boolean visited[]=new boolean[factors.length];
		boolean ok=true;
		int min=inf;
		for(int i=0;i<n;i++)
		{
			while(arr[i]!=1)
			{
			int sf=factors[arr[i]];
			if(visited[factors[arr[i]]])
			{
				ok=false;
			}
			visited[factors[arr[i]]]=true;
			while(arr[i]%sf==0)
				arr[i]/=sf;
			}
		}
		if(ok==true)
			System.out.println("pairwise coprime");
		else
			System.out.println("setwise coprime");
	}
}
class FastScanner 
{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		public String next() 
		{
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
			
		}
		
		long pow(long x,long n)
		{
			long res=1;
			while(n>0)
			{
			   	if(n%2!=0)
			   	{
			   		res=(res*x);n--;
			   	}
			   	else
			   	{
			   		x=(x*x);n/=2;
			   	}
			}
			return res;
		}
		int gcd(int a,int b)
		{
			if(b==0)
			{
				return a;
			}
			return gcd(b,a%b);
		}
		long longgcd(long a,long b)
		{
			if(b==0)
			{
				return a;
			}
			return longgcd(b,a%b);
		}
		int[] sort(int arr[])
		{
			ArrayList<Integer> list = new ArrayList<Integer>();
			for(int i:arr)list.add(i);
			Collections.sort(list);
			for(int i=0;i<arr.length;i++)
			{
				arr[i]=list.get(i);
			}
			return arr;
		}
		char[] charsort(char arr[])
	        {
	    	ArrayList<Character> list = new ArrayList<>();
	    	for(char c:arr)list.add(c);
	    	Collections.sort(list);
	    	for(int i=0;i<list.size();i++)
	    	{
	    		arr[i]=list.get(i);
	    	}
	    	return arr;
	        }
		long[] longsort(long arr[])
		{
			ArrayList<Long> list = new ArrayList<Long>();
			for(long i:arr)list.add(i);
			Collections.sort(list);
			for(int i=0;i<arr.length;i++)
			{
				arr[i]=list.get(i);
			}
			return arr;
		}
		public int nextInt() 
		{
			return Integer.parseInt(next());
		}
		public int[] readArray(int n)
		{
			int[] arr=new int[n];
			for (int i=0; i<n; i++) arr[i]=nextInt();
			return arr;
		}	
		public long nextLong()
		{
			return Long.parseLong(next());
		}
		public long[] longreadArray(int n) 
		{
			long[] a=new long[n];
			for (int i=0; i<n; i++) a[i]=nextLong();
			return a;
		}
}

Measured memory_bytes: 79052
import sys
def input(): return sys.stdin.readline().strip()


def main():
    N, K = map(int, input().split())
    A = [0] + list(map(int, input().split()))

    pos = A[1]
    visited = {1}
    while pos not in visited:
        visited.add(pos)
        pos = A[pos]
    
    start = pos
    loop = 1
    pos = A[pos]
    while pos != start:
        pos = A[pos]
        loop += 1
    
    dist = 0
    pos = 1
    while pos != start:
        pos = A[pos]
        dist += 1

    #print("dist={}, loop={}".format(dist, loop))
    
    if dist < K:
        K -= dist
        K %= loop
        pos = start
        for _ in range(K): pos = A[pos]
        print(pos)
    else:
        pos = 1
        for _ in range(K): pos = A[pos]
        print(pos)


if __name__ == "__main__":
    main()


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

int even[100];
int even_count;
int odd[100];
int odd_count = 0;

int main(int argc, const char * argv[]) {
    int K;
    int count = 0;
    
    cin >> K;
    for (int i = 1; i <= K; i++) {
        if (i % 2 == 0) {
            even[even_count++] = i;
        } else {
            odd[odd_count++] = i;
        }
    }
    
    for (int i = 0; i < even_count; i++) {
        for (int j = 0; j < odd_count; j++) {
            //cout << even[i] << "," << odd[j] << endl;
            count++;
        }
    }
    
    cout << count << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define pb push_back
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(),x.end()

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set=tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<int,ull> piu;
typedef vector<vector<int>> matrix;

const ll INF=1e18+123;
const ld EPS=1e-9;
const int inf=1e9+123;
const int MOD=1e9+7;
const int N=123;
const int M=1e6+123;
const int dx[]={0,0,1,-1};
const int dy[]={1,-1,0,0};

vector<pii>v;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if((n%2 && i+j==n) || (n%2==0 && i+j==n+1)){

            }
            else v.pb({i,j});
        }
    }
    cout<<sz(v)<<ndl;
    for(pii p : v){
        cout<<p.x<<" "<<p.y<<endl;
    }
    return 0;
}


Measured memory_bytes: 384
import sys

n=int(input())
s=[int(input()) for i in range(n)]
score=sum(s)
if score%10!=0:
	print(score)
	sys.exit()
s.sort()
for j in range(n):
	if s[j]%10!=0:
		score-=s[j]
		print(score)
		sys.exit()
print(0)

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

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


int main() {

    long long n;
    cin >> n;

    long long a[n+100];
    rep(i,n)cin >> a[i];
    sort(a,a+n,greater<int>());

    long long tate=0;
    long long yoko=0;
    int count1 = 0;

    for(int i = 0;i<n;i++){

        if(count1==0 && a[i]==a[i+1]){
                tate = a[i];
                count1 = 1;
                i++;
        }

        else if(count1==1 && a[i]==a[i+1]){
                yoko = a[i];
                break;
        }
    }

    cout << tate*yoko << endl;

    
    return 0;

}


Measured memory_bytes: 1024
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; 
const int MAXN = 3e3 + 10; 
int n ; 
vector<double> v(MAXN) ; 
double dp[MAXN][MAXN] ; 
double dfs(int x,int curHeads){
	if ( x == n ){
		if ( curHeads > n / 2 ) return 1 ;
		return 0 ; 
	}
	if ( dp[x][curHeads] != -1 ) return dp[x][curHeads] ; 
	double ans = 0 ; 
	ans += v[x] * dfs(x+1,curHeads+1) ; 
	ans += (1.0-v[x]) * dfs(x+1,curHeads) ; 
	return dp[x][curHeads] = ans; 
}
int main(){
    fastio
    for(int i=0;i<MAXN;i++){
    	for(int j=0;j<MAXN;j++){
    		dp[i][j] = -1;
    	}
    }
    cin >> n ; 
    for(int i=0;i<n;i++){
    	cin >> v[i] ; 
    }
    cout << fixed << setprecision(12) << dfs(0,0) << endl;
    return 0 ;
}


Measured memory_bytes: 71424
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int N, K;
	cin >> N >> K;
	vector<int>m(N);
	
	for (int i = 0; i < N; i++)
	{
		cin >> m[i];
	}
	sort(m.begin(), m.end());
	int ans = 0;
	for (int i = N-1; i >N-1-K; i--)
	{
		ans += m[i];
	}
	cout << ans << endl;
	

	return 0;
}


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

using namespace std;

#define F first
#define S second
#define pb push_back
#define all(v) (v).begin(),(v).end()

typedef long long int ll;
typedef pair<ll,ll> ii;
typedef pair<string,ll> si;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<si> vsi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vsi> vvsi;

const int INF = 2000000000;
const ll INFLL = 1LL * INF * INF;
ll mod = (int)pow(10,9)+7;
// ll mulmod(ll a, ll b, ll mod) 
// { 
//     ll res = 0; // Initialize result 
//     a = a % mod; 
//     while (b > 0) 
//     { 
//         // If b is odd, add 'a' to result 
//         if (b % 2 == 1) 
//             res = (res + a) % mod; 
  
//         // Multiply 'a' with 2 
//         a = (a * 2) % mod; 
  
//         // Divide b by 2 
//         b /= 2; 
//     } 
  
//     // Return result 
//     return res % mod; 
// } 
// bool sieve[100005];

// void sieveoferat()
// {
// 	for(ll p = 2; p*p<100005 ; p++)
// 	{
// 		if(sieve[p])
// 		{
// 			for(int j = p*p; j<100005; j+=p)
// 				sieve[j] = false;
// 		}
// 	}
// }

// void dp(sp_1, sp_2.....)
// {
// 	if()//exit statement
// 	if()//using the memoization 
// 	ll ans = //default/dummy answer
// 	//recursions
// 			//max/min
// 	return memo[][].. = ans;

// }

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
 	cout.tie(NULL);
 	//memset(memo, -1, sizeof memo);
 	// memset(sieve, true, sizeof sieve);
 	// sieveoferat();
 	ll a,b,c,d;
 	cin>>a>>b>>c>>d;
 	ll tota = (b/c)  - (a/c) + ((a%c==0)?1:0) ;
 	ll totb =  (b/d) - (a/d)+((a%d==0)?1:0) ;
 	ll totab =  b/(c*d/__gcd(c,d)) - (a/(c*d/__gcd(c,d))) + ((a%(c*d/__gcd(c,d))==0)?1:0) ;
 	cout<<(b-a+1) - (tota+totb- (totab))<<endl;
 	

	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

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

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

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

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

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

signed main() {
  init();
  ll N;
  cin >> N;
  string S;
  cin >> S;
  ll count_W = 0;
  ll count_E = 0;

  rep(i, S.size()) {
    if (S[i] == 'W') {
      count_W++;
    } else {
      count_E++;
    }
  }

  ll t_W = 0;
  ll t_E = 0;
  ll mini = INF;
  rep(i, S.size()) {
    if (S[i] == 'W') {
      ll count = t_W + count_E - (t_E + 0);
      if (count < mini) {
        mini = count;
      }
    } else {
      ll count = t_W + count_E - (t_E + 1);
      if (count < mini) {
        mini = count;
      }
    }

    if (S[i] == 'W') {
      t_W++;
    } else {
      t_E++;
    }
  }
  COUT(mini);
  return 0;
}

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

ll const INF = 10000000000000;

int main(){
	ll A,B,M;
	cin >> A >> B >> M;
	vector<ll> a(A);
	vector<ll> b(B);
	rep(i,A){
		cin >> a[i];
	}
	rep(i,B){
		cin >> b[i];
	}
	ll ans = INF;
	
	rep(i,M){
		ll x,y,c;
		cin >> x >> y >> c;
		x--,y--;
		ans = min(a[x]+b[y]-c, ans);
	}
	
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	
	ans = min(ans, a[0]+b[0]);
	
	cout << ans << endl;
	
    return 0;
}



Measured memory_bytes: 1792
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sn = new Scanner(System.in);
        for(int i=1; i<6; i++){
            int x = sn.nextInt();
            if(x == 0){
                System.out.println(i);
                break;
            }
        }
    }
}

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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 200007 , __ = 1000007 , mo = 998244353;

inline lint powa(lint a,lint t)
{
	lint b=1;
	while(t){if(t&1)b=b*a%mo;a=a*a%mo,t>>=1;}
	return b;
}

inline lint inva(lint a)
{
	return powa(a,mo-2);
}

bool isnp[__]={0};
int pri[__]={0},mune[__]={0},pcnt=0;

inline void fuck(int n=__-1)
{
	isnp[1]=1,mune[1]=1;
	for(int i=2;i<=n;i++)
	{
		if(!isnp[i])pri[++pcnt]=i,mune[i]=mo-1;
		for(int j=1;j<=pcnt && 1ll*i*pri[j]<=n;j++)
		{
			int a=i*pri[j];
			isnp[a]=1;
			if(i%pri[j]==0){mune[a]=0;break;}
			mune[a]=mo-mune[i];
		}
	}
}

int n,m=0,val[_],cnts[__]={0};
lint f[__]={0};

int main()
{
	n=ty();
	for(int i=1;i<=n;i++)val[i]=ty(),cnts[val[i]]++,m=max(m,val[i]);
	fuck(m);

	for(int i=1;i<=m;i++)for(int j=1;j<=m/i;j++)f[i]=(f[i]+1ll*j*cnts[j*i]%mo)%mo;
	lint ans=0;
	for(int d=1;d<=m;d++)
		for(int k=1;k<=m/d;k++)
			ans=(ans+f[d*k]*f[d*k]%mo*d%mo*mune[k]%mo*k%mo*k%mo)%mo;
	for(int i=1;i<=n;i++)ans=(ans-val[i]+mo)%mo;
	printf("%lld\n",ans*inva(2)%mo);

	return 0;
}


Measured memory_bytes: 21504
""" 貪欲法での攻略 """

import numpy as np

contest_types = 26
days = int(input())
cs = list(map(int, input().strip().split()))
ss = [list(map(int, input().strip().split())) for _ in range(days)]

cs = np.array(cs, dtype=np.int32)
ss = np.array(ss, dtype=np.int32)

last_days = np.array([-1] * contest_types, dtype=np.int32)
results = [0] * days

satisfaction = 0

for d in range(days):
    max_diff = - 1e9
    max_c_type = None
    for t in range(contest_types):
        diff = ss[d][t] - np.sum(cs * (d - last_days)) \
                        + cs[t] * (d - last_days[t])

        if diff > max_diff:
            max_diff = diff
            max_c_type = t

    results[d] = max_c_type

# 結果の出力
for t in results:
    print(t + 1)


Measured memory_bytes: 27572
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		String s = sc.next();
		StringBuilder sb = new StringBuilder(s);
		for (int i = sb.length() - 2; i >= 0; i--) {
			if (sb.charAt(i) == sb.charAt(i + 1)) {
				sb.delete(i + 1, i + 2);
			}
		}
		System.out.println(sb.length());
		sc.close();
	}
}

Measured memory_bytes: 27048
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());
#define pb push_back

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	bool ans=false;
	while(1) {
		if((ll)s.size()==3&&s=="ABC") {
			ans=true;
			break;
		}
		bool a=true,b=true,c=true;
		ll cnta=0,cntb=0,cntc=0;
		REP(j,(ll)s.size()) {
			if(s[j]=='A') {
				cnta++;
				if(!(j<(ll)s.size()-2&&s[j+1]=='B'&&s[j+2]=='C')) a=false;
			}
			if(s[j]=='B') {
				cntb++;
				if(!(j>0&&j<(ll)s.size()-1&&s[j-1]=='A'&&s[j+1]=='C')) b=false;
			}
			if(s[j]=='C') {
				cntc++;
				if(!(j>1&&s[j-1]=='B'&&s[j-2]=='A')) c=false;
			}
		}
		string t="";
		if(cnta&&a&&!b&&!c) {
			REP(j,(ll)s.size()) {
				t+=s[j];
				if(s[j]=='A') j+=2;
			}
		} else if(cntb&&!a&&b&&!c) {
			REP(j,(ll)s.size()) {
				if(j<(ll)s.size()-1&&s[j+1]=='B') {
					t+='B';
					j+=2;
				} else t+=s[j];
			}
		} else if(cntc&&!a&&!b&&c) {
			REP(j,(ll)s.size()) {
				if(j<(ll)s.size()-2&&s[j+2]=='C') {
					t+='C';
					j+=2;
				} else t+=s[j];
			}
		} else break;
		s=t;
	}
	if(ans) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}




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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 110

signed main()
{
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int ans = 0;
    for(int i = 0; i <= A; ++i) {
        for(int j = 0; j <= B; ++j) {
            for(int k = 0; k <= C; ++k) {
                if(500 * i + 100 * j + 50 * k == X) { ans++; }
            }
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
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();
		char prev = 'X';
		char[] arr = sc.next().toCharArray();
		int sum = 0;
		int count = 1;
		for (int i = 0; i < n; i++) {
			if (prev == arr[i]) {
				count++;
			} else {
				sum += count - 1;
				count = 1;
			}
			prev = arr[i];
		}
		sum += count - 1;
		System.out.println(Math.min(n - 1, sum + 2 * k));
	}
}


Measured memory_bytes: 26808
import java.util.Scanner;
public class Main {
    static final long INF = (long)Math.pow(10, 12);
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long min = INF;
        for (long i = 1; i <= Math.sqrt(N); i++) {
            if (N % i == 0) {
                min = Math.min(min, i + N / i - 2);
            }
        }
        System.out.println(min);
        sc.close();
    }
}

Measured memory_bytes: 23636
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
Scanner scan=new Scanner(System.in);
long a=scan.nextLong();
long b=scan.nextLong();
System.out.println(a+b/2);
}
}

Measured memory_bytes: 24020
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

int main(void){
    int A,B,C,D;
    cin>>A>>B>>C>>D;

    if((A+B)<(C+D)){
        cout<<"Right"<<endl;
    }
    else if((A+B)>(C+D)){
        cout<<"Left"<<endl;
    }
    else{
        cout<<"Balanced"<<endl;
    }

}


Measured memory_bytes: 256
//============================================================================
// 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

//============================================================================
#define MAXSTACK 100
long stack[MAXSTACK];
short ptr;
//============================================================================
void dump(int *A, int N)
{
    int i;

    for (i=0; i<N; i++){
        if (i)
            printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
}
//============================================================================
void push(long val)
{
    if (MAXSTACK<=ptr)
        return;
    stack[ptr++]=val;
}
//----------------------------------------------------------------------------
long pop()
{
    if (!ptr)
        return 0;
    return stack[--ptr];
}
//============================================================================
void revpol(char *str)
{
    int i,n,*ary; long ope; char *ptr;//, str[100];

    ope=0;
    for (ptr=str; *ptr;){
        switch(*ptr){
            case '+': ope=pop()+ope; ptr++; break;
            case '-': ope=pop()-ope; ptr++; break;
            case '*': ope=pop()*ope; ptr++; break;
            case '/': ope=pop()/ope; ptr++; break;
            case  '0': case '1': case '2': case '3': case '4':
            case '5': case  '6': case '7': case '8': case '9':
                    push(ope);
                    ope = atoi(ptr);
                    while(isdigit(*ptr))
                        ptr++;
                    //printf("%ld entered %d\n", ope, ptr-str);
                break;
            default: ptr++;                 break;
        }
        //printf("%ld\n", ope);
    }
    printf("%ld\n", ope);
}
//============================================================================
int main(void)
{
    int i,n; char str[1000];

    memset(&str, 0, sizeof(str));
    gets(str);
    n=strlen(str);
    for (i=0; i<n; i++){
         //printf("%02X,", str[i]);
         if ('9'<(unsigned char)str[i])
             str[i]=0;
    }
    //printf("\n");
    //printf("%d %s\n", i, str);
    //revpol("500 132 + 132 - 2 * 100 10 10 * + - 50 50 50 50 + + + + 0 999 * + 24 +");
    revpol(str);
    return 0;
}
//============================================================================

Measured memory_bytes: 528
#include <iostream>
using namespace std;
int main(){
    string s,t; cin >> s >> t;
    int len_s = s.length();
    int cnt=0;
    for(int i=0;i<len_s;i++){
        if(s[i] != t[i]){
            cnt++;
        }
    }
    cout << cnt << "\n";
}

Measured memory_bytes: 3916
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define _GLIBCXX_DEBUG
static const int MAX = 1000000;


int gcd(int x, int y){
    int r;
    if(x < y) swap(x, y);

    while(y > 0){
        r = x % y;
        x = y;
        y = r;
    } 

    return x;
}


int main(){
    int x, y;

    cin >> x >> y;
    
    int answer = gcd(x, y);
    cout << answer << endl;

    return 0;
}


Measured memory_bytes: 3092
#include <stdio.h>

int main(void) {
  char s[100];
  int i;
  scanf("%s", s);
  for(i = 0; i < 10; ++i) {
    if(i == 3) printf("8");
    else printf("%c", s[i]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
ll sieve[1000001]={0},i,j;
ll power(ll p, ll k)
{
ll a=1;
while(k)
{
if(k&1)
a=(a*p);
p=(p*p);
k>>=1;
}
return a;
}
using namespace std;
  ll countDivisors(ll n) 
{ 
    ll cnt = 0; 
    for (ll i = 1; i <= sqrt(n); i++) { 
        if (n % i == 0) { 
            if (n / i == i) 
                cnt++; 
  
            else 
                cnt = cnt + 2; 
        } 
    } 
    return cnt; 
} 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 int tc=1;
//cin>>tc;
ll cas=1;
 while(tc--)
 {
	string s,t;
	cin>>s>>t;
	ll m=s.length(),n=t.length();
	ll dp[m+1][n+1]={0};
	for(i=0;i<=n;i++)
	dp[0][i]=0;
	for(i=0;i<=m;i++)
	dp[i][0]=0;
	for(i=0;i<m;i++)
	for(j=0;j<n;j++)
	{
		if(s[i]==t[j])
		{
			dp[i+1][j+1]=dp[i][j]+1;
		}
		else
		{
			dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
		}
	}
	ll len=dp[m][n],i=m,j=n;
	string ans;
	while(i>0 && j>0)
	{
		if(s[i-1]==t[j-1])
		{
			ans=s[i-1]+ans;
			i--;
			j--;
		}
		else if(dp[i-1][j]>dp[i][j-1])
		i--;
		else
		j--;
	}
	cout<<ans;
	cout<<"\n"; 
 } 
}


Measured memory_bytes: 70656
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


int L[200001], R[200001];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);


	int N;
	cin >> N;

	rep(i, N) {
		int l, r;
		cin >> l >> r;
		L[l + 100000]++;
		R[r + 100000]++;
	}

	ll kotae = -200000, kotae2 = 0;
	int l = 200000;
	int r = 0;

	while (l > r) {
		kotae += (l - r);
		while (r <= 200000 && !R[r]) r++;
		while (l >= 0 && !L[l]) l--;
		R[r]--;
		L[l]--;
		if (kotae2 < kotae + max(100000 - r, l - 100000)) {
			kotae2 = kotae + max(100000 - r, l - 100000);
		}
	}

	co(2 * max(kotae, kotae2));

	Would you please return 0;
}

Measured memory_bytes: 1920
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <set>
#include <string>
#include <utility>

using namespace std;

int main() {
  int n;

  cin >> n;

  deque<int> vals(n);
  bool exist[1000001] = {false};

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

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

  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int tar = vals[i];
    bool is_divisible = false;

    // 同じ数が存在する場合、その数はスキップ（必ず割り切れる）
    if (i < n - 1 && tar == vals[i + 1]) {
      // 次の値が同じならiを+1して次の値を参照
      while (tar == vals[i + 1]) {
        i++;
      }
      // 次の値が同じでなくなったら今参照している数もスキップ
      continue;
    }

    // 1である場合は必ずそれ以外の数で割り切れないのでカウントしてしまう
    if (tar == 1) {
      cnt++;
      continue;
    }

    // [1, sqrt(tar)]まで調査
    // 割り切れたらその数とtarをその数で割った数が約数であるため、
    // それらがexistにあるかどうかを確認すれば良い
    for (int j = 1; j * j <= tar; j++) {
      if (tar % j != 0) {
        continue;
      }

      if (exist[j]) {
        is_divisible = true;
        break;
      } else if (j != 1 && exist[tar / j]) {
        is_divisible = true;
        break;
      }
    }

    if (!is_divisible) {
      cnt++;
    }
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 4924
import java.util.Scanner;
 
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int t = sc.nextInt();
		int a = sc.nextInt();
		int[] h = new int[n];
		int index = 0;
		double abs = Double.MAX_VALUE;
		for(int i = 0; i <n; i++) {
			h[i] = sc.nextInt();
		}
		for(int i = 0; i < n; i++) {
			double temp =Math.abs(a-(t-(h[i]*0.006)));
			if(temp < abs) {
				abs = temp;
				index = i+1;
			}
		}
		System.out.println(index);
	}
}


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

typedef long long LL;

char s[1000];
LL ans=0;
LL num[70][2];
const LL mod=1e9+7;
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        LL a;
        scanf("%lld",&a);
        for(LL i=0;i<60;i++)
        {
            ans+=(1ll<<i)%mod*num[i][(a&1ll)^1ll]%mod;
            ans%=mod;
            num[i][a&1ll]++;
            a>>=1;
        }
    }
    printf("%lld",ans);
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
constexpr int INF = 1<<30;
constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int main(int argc, char** argv) {
  int N, X;
  cin >> N >> X;

  int ret = 1;
  int x = 0;
  for (int i=0; i<N; i++) {
    int L;
    cin >> L;
    x += L;
    if (x <= X) ret++;
  }

  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 256
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

// fn num_divisor(x: usize) -> usize {
//     let s = (x as f64).sqrt() as usize;
//     let mut cnt = 0;
//     for i in 1..s+1 {
//         if x%i==0 {
//             cnt += 1;
//         }
//     }
//     if s*s==x {
//         cnt*2-1
//     } else {
//         cnt*2
//     }
// }

#[fastout]
fn main() {
    input!{
        n: usize,
    }

    let mut ans = 0;
    for i in 1..n {
        ans += (n-1)/i;
        // debug!(ans);
    }

    println!("{}", ans);

}


Measured memory_bytes: 2204
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  char a[N];
  bool exist=0;
  for(int i=0; i<N; i++){
    cin >> a[i];
   if(a[i]=='Y') exist=1; 
  }
  
  if(exist) cout << "Four" << endl;
  else cout << "Three" << endl;
   

}

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

#define pb push_back
#define mp make_pair

typedef long long ll;

const int inf = 1e9;
const ll linf = 1e18;
const ll mod = 1e9 + 7;

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

  ll sum = 0, cnt = 0, ans = linf;
  for(int i = 0; i < n; i++){
    sum += a[i];
    if(i%2){
      if(sum < 1){
        cnt += 1 - sum;
        sum = 1;
      }
    }else{
      if(sum > -1){
        cnt += sum + 1;
        sum = -1;
      }
    }
  }

  ans = min(ans, cnt);

  sum = 0, cnt = 0;
  for(int i = 0; i < n; i++){
    sum += a[i];
    if(i%2==0){
      if(sum < 1){
        cnt += 1 - sum;
        sum = 1;
      }
    }else{
      if(sum > -1){
        cnt += sum + 1;
        sum = -1;
      }
    }
  }

  ans = min(ans, cnt);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
 
int main(){
  int A[3+1][3+1];
  int N;
  int i,j,k;
  int b=0;
  int bingo = 0;
  
  for(i=0;i<3;i++){
    scanf("%d %d %d",&A[i][0],&A[i][1],&A[i][2]);
  }
  
  scanf("%d",&N);
  for(k=0;k<N;k++){
    scanf("%d",&b);
    for(i=0;i<3;i++){
      for(j=0;j<3;j++){
        if(A[i][j] == b) A[i][j] = -1;
      }
    }
  } 
  
  i=0;
  while(i<3){
    if(A[i][0] == -1 && A[i][1] == -1 && A[i][2] == -1){
      bingo =1;
      break;
    }
    if(A[0][i] == -1 && A[1][i] == -1 && A[2][i] == -1){
      bingo =1;
      break;
    }
    i++;
  }
  
  if(bingo != 1){
    if(A[0][0] == -1 && A[1][1] == -1 && A[2][2] == -1){
      bingo =1;
    }
    if(A[0][2] == -1 && A[1][1] == -1 && A[2][0] == -1){
      bingo =1;
    }
  }
  if(bingo) printf("Yes\n");
  else printf("No\n");
  
  return 0;
}

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  set<int> code, up;
  int a = stoi(S.substr(0,3));
  code.insert(a);
  up.insert(stoi(S.substr(0,2)));
  int sn = S[2] - '0';
  vector<int> add;
  for(auto u:up) {
    add.push_back( (u*10+sn)%100 );
    add.push_back(((u/10)*10+sn)%100 );
  }
  for(auto ad:add) {
    up.insert(ad);
  }
//    cout << " --- " << S[2] << endl;
//    for(auto u:up) {cout << u << " ";} cout << endl;
  for( int i=3;i<N;i++) {
    int sn = S[i] - '0';
    for(auto u:up) {
      code.insert( u*10 + sn );
    }
    vector<int> add;
    for(auto u:up) {
      add.push_back( (u*10+sn)%100 );
      add.push_back(((u/10)*10+sn)%100 );
    }
    for(auto ad:add) {
      up.insert(ad);
    }
//    cout << " --- " << S[i] << endl;
//    for(auto u:up) {cout << u << " ";} cout << endl;
  }
  cout << code.size() << endl;
//  for(auto c:code) cout << c << endl;
  
}



Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <deque>
#include <stack>

using namespace std;

int main(){
    string s,t;
    cin >> s >> t;
    cout << t+s << endl;
    return 0;
}

Measured memory_bytes: 3612
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**7)
MOD=10**9+7

n=int(input())
edge=[[] for _ in range(n)]
for _ in range(n-1):
    p,q = [int(i)-1 for i in input().split()]
    edge[p].append(q)
    edge[q].append(p)

    
used = [0]*n

def dfs(x):
    used[x] = 1
    cb=1; cw=1;
    for e in edge[x]:
        if used[e]: continue
        eb,ew = dfs(e)
        cb*=ew
        cb%=MOD
        cw*=(eb+ew)
        cw%=MOD        
    return (cb,cw)

print(sum(dfs(0))%MOD)



Measured memory_bytes: 100528
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

n = int(input())
modList = []
count = 0

for i in range(1,n+1):
    if i % 2 != 0:
        if len(make_divisors(i))==8:
            count = count + 1
            
print(count)

Measured memory_bytes: 3060
'use strict';

function main(stdin) {
  const input = stdin.split('\n');
  const N = Number(input.shift());
  const params = input[0].split(' ').map(v => parseInt(v, 10));

  let sum = 0;
  params.forEach(p => {
    sum += 1 / p;
  });
  
  console.log(1 / sum);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim());

Measured memory_bytes: 7372
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll a,b,x,n;
  cin >> x >> a >> b >> n;
  string s[n];
  for(int i=0;i<n;i++){
    cin >> s[i];
    if(s[i]=="nobiro"){
      x = max((ll)0,x+a);
    }else if(s[i]=="tidime"){
      x = max((ll)0,x+b);
    }else{
      x=0;
    }
  }
  cout << x << endl;
}



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

int po(int n){
    int ans = 1;
    for(int i = 0; i < n; i++){
        ans = ans * 10;
    }
    return ans;
}

int main(){

    int a, b; cin >> a >> b;
    int keta;
    for(int i = 5; i >= 0; i--){
        if(b / po(i) != 0){
            keta = i + 1;
            break;
        }
    }


    int n = b + po(keta) * a;
    //cout << n << endl;

    bool flag = false;
    for(int i = 1; i < 1100; i++){
        if(n == i*i) flag = true;
    }

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 384
import sys

def main(s):
    intl=[int(w) for w in s]
    intl.reverse()
    ps=0
    for i in range(2**(len(s)-1)):
        l=[x for x in intl]
        j=i
        e=0
        for k in range(1,len(s)):
            e=(e+1)*(j&1)
            l[k]=l[k]*(10**e)
            j>>=1
        ps=ps+sum(l)
    return ps

s=sys.stdin.readline().strip()

print(main(s))


Measured memory_bytes: 9204
#include<stdio.h>

int main(){
  int a,b;
  scanf("%d",&a);
  printf("%d:",a);
  b=2;
  while(a>=b*b){
    if(a%b==0){
      printf(" %d",b);
      a=a/b;
    } else {
      b++;
    }
  }
  printf(" %d\n",a);
  return 0;
}

Measured memory_bytes: 1028
#include <algorithm>
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
using namespace std;

int main()
{
    long long N;
    cin >> N;
    long long A, B;
    cin >> A >> B;
    
    long long sum = (N / (A+B)) * A;
    long long amari = N % (A+B);
    sum += min(amari, A);
    
    cout << sum << endl;
}

Measured memory_bytes: 256
Q = 10**9+7
def getInv(N):#Qはmod
    inv = [0] * (N + 1)
    inv[0] = 1
    inv[1] = 1
    for i in range(2, N + 1):
        inv[i] = (-(Q // i) * inv[Q%i]) % Q
    return inv

B, W = map( int, input().split())
Z = getInv(B+W)
I = [1]*(B+W+1)
for i in range(1,B+W+1):
    I[i] = (I[i-1]*Z[i])%Q

F = [1]*(B+W+1)
for i in range(1,B+W+1):
    F[i] = F[i-1]*i%Q
w = 0
b = 0
for i in range(1,B+W+1):
    if i - 1 < B and i - 1 < W:
        print(I[2])
    # elif i - 1 == W and i - 1< B:
    #     w = pow(I[2],i-1,Q)
    #     print(((1 -  w)%Q*I[2]%Q + w)%Q)
    elif i - 1 >= W and i - 1< B: #i > B
        w += F[i-2]*I[i-1-W]%Q*I[W-1]%Q*pow(I[2],i-1,Q)%Q
        w %= Q
        print(((1 -  w)%Q*I[2]%Q + w)%Q)
    # elif i - 1 == B and i - 1 < W:
    #     b = pow(I[2],i-1,Q)
    #     print((1-b)%Q*I[2]%Q)
    elif i - 1 >= B and i - 1 < W: #i > W
        b += F[i-2]*I[i-1-B]%Q*I[B-1]%Q*pow(I[2],i-1,Q)%Q
        b %= Q
        print((1-b)%Q*I[2]%Q)
    # elif i - 1 == B and i - 1 == W:
    #     w = pow(I[2],i-1,Q)
    #     b = pow(I[2],i-1,Q)
    #     print(((1 -  w - b)%Q*I[2]%Q + w)%Q)
    else:
        w += F[i-2]*I[i-1-W]%Q*I[W-1]%Q*pow(I[2],i-1,Q)%Q
        w %= Q
        b += F[i-2]*I[i-1-B]%Q*I[B-1]%Q*pow(I[2],i-1,Q)%Q
        b %= Q
        print(((1 -  w - b)%Q*I[2]%Q + w)%Q)


Measured memory_bytes: 28912
import sys

def is_stable(in_data, out_data):
    len_data = len(in_data)

    for i in range(len_data):
        for j in range(i+1, len_data):
            for a in range(len_data):
                for b in range(a+1, len_data):
                    if in_data[i][1] == in_data[j][1] and\
                       in_data[i] == out_data[b] and\
                       in_data[j] == out_data[a]:
                        return False

    return True

def bubble_sort(data, n):
    for i in range(n):
        for j in range(n-1, i, -1):
            if data[j][1] < data[j-1][1]:
                data[j], data[j-1] = data[j-1], data[j]

def selection_sort(data, n):
    for i in range(n):
        minj = i                # ??¨?????????????????????????°??????¨??????
        for j in range(i, n):
            if data[j][1] < data[minj][1]:
                minj = j

        data[i], data[minj] = data[minj], data[i]

def main():
    n = int(sys.stdin.readline().strip())
    card1 = sys.stdin.readline().strip().split(' ')

    card2 = card1[::]
    bubble_sort(card2, n)
    print(' '.join(card2))
    
    if is_stable(card1, card2):
        print('Stable')
    else:
        print('Not stable')

    card2 = card1[::]
    selection_sort(card2, n)
    print(' '.join(card2))
    
    if is_stable(card1, card2):
        print('Stable')
    else:
        print('Not stable')

if __name__ == '__main__':
    main()
    

Measured memory_bytes: 7876
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<iostream>
#include<queue>
using namespace std;
const int maxn=100005;
typedef long long ll;
const int inf=0x3fffffff;
const int mod=1000000007;

int w,h;
priority_queue<int, vector<int>, std::greater<int> > qw,qh;

int pw[maxn],ph[maxn];

int pdw(int x) {
    if(x!=pw[x])pw[x]=pdw(pw[x]);
    return pw[x];
}
int pdh(int x) {
    if(x!=ph[x])ph[x]=pdh(ph[x]);
    return ph[x];
}

pair<int,int> get() {
    if(qw.empty()) {
        if(qh.empty())return make_pair(-1,-1);
        int tt = qh.top();
        qh.pop();
        return make_pair(tt,1);
    } else {
        if(qh.empty()) {
            int tt = qw.top();
            qw.pop();
            return make_pair(tt,0);
        } else {
            int tw = qw.top();
            int th = qh.top();
            if(tw<th) {
                qw.pop();
                return make_pair(tw,0);
            } else {
                qh.pop();
                return make_pair(th,1);
            }
        }
    }
}

int main() {
    //freopen("in.cpp","r",stdin);
    cin>>w>>h;
    for(int i=0; i<=w; i++)pw[i]=i;
    for(int i=0; i<=h; i++)ph[i]=i;
    for(int i=0; i<w; i++) {
        int x;
        cin>>x;
        qw.push(x);
    }
    for(int i=0; i<h; i++) {
        int x;
        cin>>x;
        qh.push(x);
    }
    int cw=0,ch=0;
    ll ret=0;
    while(1) {
        pair<int,int> top = get();
        if(top.first==-1)break;
        if(top.second==0) {

            ret += top.first * (ll(h + 1 - ch));
            cw++;
        } else {
            ret += top.first * (ll(w+1 - cw));
            ch++;
        }
    }
    cout<<ret<<endl;
    return 0;
}


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

using namespace std;

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

int main(){
    int H,W; cin >> H >> W;
    vector<vector<char> > grid(H, vector<char>(W));
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> grid[i][j];
        }
    }

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(grid[i][j] == '.') continue;
            int cnt = 0;
            for(int k=0;k<4;k++){
                int ni = i + dx[k];
                int nj = j + dy[k];
                if(ni < 0 || ni >= H || nj < 0 || nj >= W) continue;
                if(grid[ni][nj] == '#') cnt++;
            }
            if(cnt == 0){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(int i = 0; i < (int)n; i++)
using namespace std;

int main(){
  int n;
  cin >> n;
  int maxnum = 1;
  int max = 0;
  for(int i = 1; i <= n; i++){
    int j = i;
    int cnt = 0;
    while(j%2==0){
      j = j / 2;
      cnt++;
    }
    if(cnt>max){
      max = cnt;
      maxnum = i;
    }
  }
  cout << maxnum << endl;
  return 0;
}


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

int N,M;
vector<int> G[100005];
int cc[100005];
int d[100005];

int Ans[100005];

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

  int root=-1;
  queue<int> Q;
  for(int i=0;i<N;i++){
    if(cc[i]==0){
      root=i;
      Q.push(i);
    }
  }
  while(!Q.empty()){
    int pos=Q.front();
    Q.pop();
    for(int to:G[pos]){
      d[to]=max(d[to],d[pos]+1);
      cc[to]--;
      if(cc[to]==0)Q.push(to);
    }
  }
  for(int i=0;i<N;i++){
    for(int to:G[i]){
      if(d[i]+1 != d[to])continue;
      Ans[to]=i;
    }
  }
  
  Ans[root]=-1;
  for(int i=0;i<N;i++){
    cout<<Ans[i]+1<<endl;
  }
  return 0;
}


Measured memory_bytes: 7424
#include <iostream>

using namespace std;

int main()
{
  int N,D,k=0,i,v;
  cin>>N>>D;
  k=2*D+1;
  if(N%k==0){
  v=N/k;
  }
  else{
   v=N/k+1;
  }
 cout<<v;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <iostream>
using namespace std;
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
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
void YN(bool f){ cout << (f ? "YES" : "NO");}
void yn(bool f){ cout << (f ? "yes" : "no");}
void YeNo(bool f) {cout << (f ? "Yes" : "No");}
signed main(){
    int n; cin >> n;
    map<string, int>mp;
    rep(i,n){
        string s; cin >> s;
        sort(all(s));
        mp[s]++;
    }
    int ans = 0;
    for(auto itr : mp){
        ans += (itr.second * (itr.second - 1 ))/2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 11136
using System;
using System.Collections.Generic;
 class Program
 {
     static void Main(string[] args)
     {
         double data0 = 0, data1 = 0, data2 = 0;

         String nyuryoku;
         string[] data;
         var strList = new List<string>();
              
         while (true)
         {
             nyuryoku = Console.ReadLine();
 
             if (nyuryoku == "0 0")
                 break;
             data0++;
             strList.Add(nyuryoku);
         }
         for (int k = 0; k < data0; k++)
         {
             data = strList[k].Split(' ');
             for (int i = 0; i < int.Parse(data[0]); i++)
             {
                 for (int j = 0; j < int.Parse(data[1]); j++)
                 {
                     if (i == 0 | i == (int.Parse(data[0]) -1 ))
                         Console.Write("#");
                     else
                     {
                         if (j == 0 | j == (int.Parse(data[1]) -1 ))
                             Console.Write("#");
                         else
                             Console.Write(".");
                     }
                      
                         
                 }
                 Console.Write("\n");
             }
             Console.Write("\n");
         }
 
      }
 }



Measured memory_bytes: 15900