akhauriyash/Code-Regression huggingface dataset:
import math
def eratos(n):
    isprime = [True for i in range(n+1)]
    isprime[0] = False
    isprime[1] = False
    for i in range(2, int(math.sqrt(n))+13):
        if isprime[i]:
            j = i + i
        while j <= n:
            isprime[j] = False
            j = j + i
    return isprime
N = int(input())
ans = 0
is_prime = eratos(10**6+13)
for i in range(2, 10**6+14):
    if not is_prime[i]:
        continue
    x = i
    while N % x == 0:
        ans += 1
        N //= x
        x *= i
        # print(N)
if ans == 0 and N != 1:
    ans += 1
elif N > 10**6:
    ans += 1
print(ans)

Measured memory_bytes: 141568
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;



const long double PI = 3.14159265359;
const int MAX_N = 100010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s, t; cin >> s >> t;
	vector<char>a(26, '*'), b(26, '*');
	rep(i, s.size()) {
		if (a[s[i] - 'a'] == '*')a[s[i] - 'a'] = t[i];
		else if(a[s[i]-'a']!=t[i]){
			cout << "No" << endl; return 0;
		}
		if (b[t[i] - 'a'] == '*') {
			b[t[i] - 'a'] = s[i];
		}
		else if (b[t[i] - 'a'] != s[i]) {
			cout << "No" << endl; return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

int main() {
    //
    string str;
    int h, w, k;
    int kekka = 0;

    cin >> h >> w >> k;

    vector<string> vec(h);

    for (int i = 0; i < h; i++) { cin >> vec.at(i); }

    for (int i = 0; i < (1 << h); i++) {
        for (int j = 0; j < (1 << w); j++) {
            int cnt = 0;
            for (int x = 0; x < h; x++) {
                for (int y = 0; y < w; y++) {
                    //
                    if (i >> x & 1) continue;
                    if (j >> y & 1) continue;
                    if (vec.at(x).at(y) == '#') cnt++;
                }
            }
                if (cnt == k) kekka++;
        }
    }

    cout << kekka;
    //
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << 0 << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N;
    int H[114514];
    cin >> N;
    REP(i,N){
        cin >> H[i];
    }
    int Ans=0;
    int num=0;
    REP(i,N){
        if(H[i]>=H[i+1] && i!=N-1){
            num++;
        }else{
            Ans=max(Ans,num);
            num=0;
        }
    }
    cout << Ans << endl;
  return 0;
}



Measured memory_bytes: 1024
#include<stdio.h>
int main(void){
    int a, b, c, poi = 1, count =0;
    if(scanf("%d %d %d", &a, &b, &c) ==1){};
    
    while(1){
	
	if (c>0){
	    count +=1;
	    c-= 1;
	    poi = 0;
	}
	if(b>0){
	    count +=1;
	    b -= 1;
	    poi = 1;
	}
	else if (a>0 && poi ==0){
	    a -= 1;
	    poi = 1;
	}
	else {
	    if (poi==1 && c>0) count +=1;
	    break;
	}
    }
    printf("%d\n", count);
    return 0;
}


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

using namespace std;
int inf = 1 << 29;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for(auto& i : v) cin >> i;

    vector<int> cost(n,inf);
    cost[0] = 0;
    for(int i = 0; i < n; i++) {
        if(i - 1 >= 0) {
            cost[i] = min(cost[i], cost[i-1] + abs(v[i]-v[i-1]));
        }
        if(i - 2 >= 0) {
            cost[i] = min(cost[i], cost[i-2] + abs(v[i]-v[i-2]));
        }
    }

    cout << cost[n-1] << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
using namespace std;
int main(void){
    
    string S, T;
    cin >> S >> T;
    
    int ans = 0;
    for(int i = 0; i < S.size(); i++){
        if(S[i] != T[i]) ans++;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 3392
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

//template<typename A, size_t N, typename T>
//void Fill(A(&array)[N], const T &val) {
	//std::fill((T*)array, (T*)(array + N), val);
//}

//変数

//解法
void solve() {

	ll N;
	cin >> N;

	if (N < 10) {
		cout << N;
	}
	else if (N < 100) {
		cout << 9;
	}
	else if (N < 1000) {
		cout << 9 + N - 99;
	}
	else if (N < 10000) {
		cout << 9 + 900;
	}
	else if (N < 100000) {
		cout << 9 + 900 + N - 9999;
	}
	else {
		cout << 90909;
	}
}

int main() {

	//入力

	solve();
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define inf 0x7fffffff
#define RG register
#define inf 0x7fffffff
#define mkp make_pair
#define maxn 100205
typedef unsigned int U;
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const  double eps = 1e-8;
const double pi = acos(-1);
inline ll read(){
    ll x = 0, f = 1;
    char ch = getchar();
    while(ch > '9' || ch < '0') {if(ch == '-') f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x *10 + ch -'0';ch = getchar();}
    return x * f;
}
int n,k;
int fac[4000005],inv[4000005];
int f[2005][2005];
int qpow(int a,int b){
	int ans=1,base=a;
	while(b){
		if(b&1) ans=1ll*ans*base%mod;
		base=1ll*base*base%mod;
		b>>=1;
	}
	return ans;
}
int C(int n,int m){return 1ll*fac[n]*inv[m]%mod*inv[n-m]%mod;}
int main(){
	int i,j,u,v,e,w;
	//freopen("a.out","r",stdin);
	//freopen("a.ans","w",stdout);n
	n=read(),k=read();
	if(k==1) {puts("1");return 0;}
	fac[0]=1;
	for(i=1;i<=n*k;i++) fac[i]=1ll*fac[i-1]*i%mod;
	inv[n*k]=qpow(fac[n*k],mod-2);
	for(i=n*k-1;i>=0;i--) inv[i]=1ll*inv[i+1]*(i+1)%mod;
	f[0][0]=1;
	for(i=0;i<=n;i++){
		for(j=i;j<=n;j++){
			if(i+1<=j) f[i+1][j]=(f[i+1][j]+f[i][j])%mod;
			if(j+1<=n) f[i][j+1]=(f[i][j+1]+1ll*f[i][j]*C(i+(k-1)*j+k-2,k-2)%mod)%mod;
		}
	}
	printf("%d\n",1ll*f[n][n]*fac[n]%mod);
	return 0;
}
/*
8
0 0 0 0
0 0 1 1
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 0
1 1 1 1
*/

Measured memory_bytes: 48672
function Main(input){
  var X = parseInt(input.split(' ')[0]);  // total
  var Y = parseInt(input.split(' ')[1]);  // human space
  var Z = parseInt(input.split(' ')[2]);  // void space

  var N = 1; // human count
  var x = 0; // space
  while(true){
    x = (N * Y) + (N + 1) * Z;
    if(x > X) break;
    N++;
  }
  console.log(--N);
}

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

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

using ll = long long;
using ld = long double;

const ll llinf = (ll)1e18;
const int intinf = 1e9;
const int MOD =  (int)(1e9 + 7);
const ld EPS =  1e-7;


void solve() {
	char c;
	cin >> c;

	if (c >= 'A' && c <= 'Z') {
		cout << "A\n";
	} else {
		cout << "a\n";
	}
}

int main(){
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int t = 1;
	// cin >> t;
	while (t--){
		solve();
	}

	return 0;
}

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

// dump macro{{{
// http://www.creativ.xyz/dump-cpp-652
#define DUMPOUT cerr // 変数ダンプ先。coutかcerr

#ifdef PCM
// 引数はいくつでもどんな型でも可（ストリーム出力演算子があればOK）
#define dump(...) DUMPOUT<<"  "; \
  DUMPOUT<<#__VA_ARGS__; \
  DUMPOUT<<":=> "; \
  dump_func(__VA_ARGS__); DUMPOUT<<"in ["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl;
#define dump_1d(x,n) DUMPOUT <<"  " \
  <<#x<<"["<<#n<<"]"<<":=> {"; \
  rep(i,n){ DUMPOUT << x[i] << (((i)==(n-1))?"}":", "); } DUMPOUT <<" in [" << __LINE__ << "]" << endl;

#define dump_2d(x,n,m) DUMPOUT <<"  " \
    <<#x<<"["<<#n<<"]"<<"["<<#m<<"]"<<":=> \n"; \
    rep(i,n)rep(j,m){ DUMPOUT << ((j==0)?"     |":" ") << x[i][j] << (((j)==(m-1))?"|\n":" "); } \
    DUMPOUT <<"  in [" << __LINE__ << "]" << endl;
#else
#define dump(...) 42
#define dump_1d(...) 42
#define dump_2d(...) 42
#endif

// デバッグ用変数ダンプ関数
void dump_func() {
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&&... tail)
{
    DUMPOUT << head;
    if (sizeof...(Tail) == 0) {
        DUMPOUT << " ";
    }
    else {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}

// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec) {
    os << "{";
    for (int i = 0; i<vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}/*}}}*/

#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 FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i >= n;i--)
#define foreach(x,a) for(auto& (x) : (a) )
#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define INF 2147483647
#define INFLL 1000000000000000000LL
#define MOD 1000000007/*}}}*/

struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;/*{{{*/
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<vii> vvii;
typedef tuple<int,int,int> iii;
typedef set<int> si;
typedef complex<double> pnt;
typedef vector<pnt> vpnt;
typedef priority_queue<pii,vii,greater<pii> > spq;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*}}}*/

// global variables

ll res;

int main() {
  int n;cin>>n;
  ll a,b,p,q;
  cin>>a>>b;
  rep(i,n-1){
    cin>>p>>q;
    ll mult = max((a+p-1)/p, (b+q-1)/q);
    a = p*mult;
    b = q*mult;
  }

  std::cout << a+b << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<cstring>
#include<iostream>
#include<cstdio>
#include<queue>
#include<cmath>
#include<algorithm>
#include<set>
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define down(i,l,r) for (int i=l;i>=r;i--)
#define clr(x,y) memset(x,y,sizeof(x))
#define low(x) (x&(-x)) 
#define maxn 200500
#define inf 1000000000
#define mm 1000000007
#define ll long long
#define pb(x) push_back(x)
using namespace std;

ll read(){
    ll x=0,f=1; char ch=getchar();
    while (!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while (isdigit(ch)) {x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
struct data{int obj,pre,c;
}e[maxn*8];
int head[maxn],ans[maxn],vis[maxn*4],n,rt,au,av,tot;
vector <int> a[maxn],b[maxn];
void insert(int x,int y){
	e[++tot].obj=y; e[tot].pre=head[x]; head[x]=tot; 
	e[++tot].obj=x; e[tot].pre=head[y]; head[y]=tot;
}
bool jud(int u,int v){
	if (1<=u&&u<=2*n&&1<=v&&v<=2*n&&abs(u-v)==n) return 1;
	return 0;
}
void dfs(int u){
	while (head[u]){
		int j=head[u],v=e[j].obj;
		if (!vis[j>>1]){
			vis[j>>1]=1;
			head[u]=e[j].pre;
			if (jud(u,v)) ans[u]++,ans[v]--;
			dfs(v);
		}
		else head[u]=e[j].pre;
	}
}
int main(){
//	freopen("in.txt","r",stdin);
	n=read();
	int rta,rtb;
	rep(i,1,n) {
		int x=read(); 
		if (x!=-1) a[x].pb(i);
		else rta=i;
	}
	rep(i,1,n){
		int x=read();
		if (x!=-1) b[x].pb(i);
		else rtb=i;
	}
	rep(i,1,n) {
		if (a[i].size()%2!=b[i].size()%2) {
			puts("IMPOSSIBLE");
			return 0;
		}
	}
	tot=1;
	insert(rta,2*n+1); insert(rtb+n,2*n+1);
	rep(i,1,n) {
		for (int j=0;j<a[i].size();j++) insert(i,a[i][j]);
		if (a[i].size()%2==0) insert(i,n+i); 
	}
	rep(i,1,n) {
		for (int j=0;j<b[i].size();j++) insert(n+i,b[i][j]+n);
	}
	dfs(1);
	puts("POSSIBLE");
	rep(i,1,n) printf("%d ",ans[i]);
    return 0;
}

Measured memory_bytes: 34304
N = int(input())
s1 = input()
s2 = input()
S = [s1, s2]
MOD = 10**9+7

if N == 1:
    print(3)
    exit()


x = 0
ans = 1
while x <= N-1:
    # 縦の場合
    if S[0][x] == S[1][x]:
        if x == 0:
            ans *= 3
            x += 1
        else:
            # 手前のやつが縦かどうかに依存
            if S[0][x-1] == S[1][x-1]:
                ans *= 2
                x += 1
            else:
                #横二段の後に縦なので、横２段以外の１色
                x += 1
    # 横の場合
    else:
        if x == 0:
            ans *= 3*2
            x += 2
        else:
            # 手前のやつが縦かどうかに依存
            if S[0][x-1] == S[1][x-1]:
                ans *= 2*1
                x += 2
            else:
                ans *= 3
                x += 2
    ans %= MOD
        
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,cnt;
  cin >> n;
  cnt=0;
 vector<int>a(n);
 vector<int>b(n);
 for (int i=0;i<n;i++)
 cin >> a.at(i); 
for (int i=0;i<n;i++)
 cin >> b.at(i);
for(int i=0;i<n;i++){
    if(a.at(i)>b.at(i))
    cnt+=a.at(i)-b.at(i);

}
cout << cnt << endl;
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <stdio.h>
#define mod 1000000007

int main()
{   int n,m;
    scanf("%d%d",&n,&m);
    int a[m+1];
    a[m]=114514;
    for(int i=0;i<m;i++){
        scanf("%d",&a[i]);
    }int k=0;
    int dp[n+1];
    dp[0]=1;
    if(a[0]==1){
        dp[1]=0;
        k++;
    }else{
        dp[1]=1;
    }
    for(int i=2;i<=n;i++){
        if(i==a[k]){
            dp[i]=0;
            k++;
        }else{
            dp[i]=dp[i-1]+dp[i-2];
            dp[i]%=mod;
        }
    }
    printf("%lld",dp[n]);

    return 0;
}


Measured memory_bytes: 896
long A,B,C=1,D=6,E=19,F,M=998244353,m;b,c,N,s[4];
main(f){
	for(m=M-3;read(0,&c,1),c-10;s[c-97]++,f&=b!=c,b=c)
		m=!N|N%3?m:m*2%M,
		F=N++?(5*E-6*D+2*C-10*B+12*A)%M:65,A=B,B=C,C=D,D=E,E=F;
	printf("%d\n",!*s+!s[1]+!s[2]>1?:(A+(N%3|*s%3-s[2]%3?f:N>3?m+f:m)+M)%M);
}

Measured memory_bytes: 128
//AtCoder ABC074 B - Collecting Balls (Easy Version)
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
    ll N,K;
    cin>>N>>K;
    vector<ll> atbl(N);
    for(auto&& a:atbl){
        cin>>a;
    }
    ll ans=0;
    for(const auto& a:atbl){
        ans += (min(abs(a-0),abs(a-K))*2);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
/*
  第4回ユニリタプログラミングコンテスト～練習サイト～
  C言語用
  ファイル名 qA.c
  作成者 228 金子幸裕 2017/06/14 18:00
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

int main( void )
{
    int nc;

    scanf( "%d" , &nc );

    if ( nc < 1200 )
    {
        printf("ABC");
    }
    else
    {
        printf("ARC");
    }


    printf("\n");

    return ( 0 );

}


Measured memory_bytes: 128
import networkx as nx

N,M = map(int,input().split())
G = nx.Graph()
for i in range(M):
    A,B = map(int,input().split())
    G.add_edge(A,B)
print("Yes")
pre = nx.predecessor(G,1)
for i in range(2,N+1):
    print(pre[i][0])

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

#define rep(i,start,end) for(int i=start;i<(int)(end);i++)
#define rrep(i,start,end) for(int i=start-1;i>=(int)(end);i--)
#define each(it,v) for(auto &it : v)
#define all(v) (v).begin(),(v).end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using Pii = pair<int,int>;
using Pll = pair<ll,ll>;
using vpii = vector<Pii>;
using vpll = vector<Pll>;

const ll mod=1e9+7;
const int intINF=INT_MAX;
const ll  longINF=LONG_LONG_MAX;

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

        int a[3][100];

        rep(i,0,3)
        {
                rep(j,0,100)
                {
                        a[i][j]=(j+1)*pow(100,i);
                }
        }
        a[0][99]=101;
        a[1][99]=10100;
        a[2][99]=1010000;
/*
        rep(i,0,3)
        {
                rep(j,0,100)
                {
                        cout<<a[i][j]<<" ";
                }
                cout<<endl;
        }*/
        cout<<a[d][n-1]<<endl;

}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

	char mark[9];
	int num[9], r_num[9], b_num[9], g_num[9], set, i, j;
	

	scanf("%d", &set);	/* ???????????°?????\??? */
	int ans[set];

	for(i = 0 ; i < 9 ; i++){	/* ????????????????????? */
		r_num[i] = 0;
		g_num[i] = 0;
		b_num[i] = 0;
	}

	for(i = 0 ; i < set ; i++){
		ans[i] = 0;
	}

	for(i = 0 ; i < set ; i++){	/* ???????????°?????°????????? */

	for(j = 0 ; j < 9 ; j++){
		scanf("%d", &num[j]);
	}
		for(j = 0 ; j < 9 ; j++){
			if(j == 9){
				scanf("%c", &mark[j]);
			}
		else{
			scanf(" %c", &mark[j]);
		}
	}

	for(j = 0 ; j < 9 ; j++){		/* ????????¨?????????????????? */
		if(mark[j] == 'R'){
			r_num[j] = num[j];
	}
			else if(mark[j] == 'G'){
				g_num[j] = num[j];
			}
			else if(mark[j] == 'B'){
				b_num[j] = num[j];
			}
		}

	sort(r_num);	/* ??????????????? */
	sort(g_num);	/* ??????????????? */
	sort(b_num);	/* ??????????????? */

		if(judge(r_num) == 1 && judge(g_num) == 1 && judge(b_num) == 1){	/* ???????????? */
			ans[i] = 1;
			}
	else{

		ans[i] = 0;
	}

		for(j = 0 ; j < 9 ; j++){	/* ????????????????????? */
			r_num[j] = 0;
			g_num[j] = 0;
			b_num[j] = 0;
		}
	}

		for(i = 0 ; i < set ; i++){
			printf("%d\n", ans[i]);
		}

	return 0;
}

void sort(int num[]){

	int p, q, tmp;

	for(p = 0; p < 8; p++){
		for(q = p + 1; q < 9; q++){
			if(num[p] > num[q]){
				tmp = num[p];
				num[p] = num[q];
				num[q] = tmp;
				}
			}
		}   
	}

int judge(int num[]){

	int cnt = 0;
	int i, j, k;

	for(i = 0; i < 9; i++){
		if(num[i] == 0){
			cnt++;			/* ???????????????0?????°??????????????? */
		}
	}
			if(cnt % 3 != 0){		/* 0?????°???3????????°??§???????????°0????????? */
		return 0;
	}

	for(i = cnt; i < 9; i++){	/* ???????????¶?????????????????????????????? */
		if(num[i] != 0){
			for(j = cnt; j < 9; j++){
				if(num[j] != 0 && j != i){
					if(num[i] == num[j]){
						for(k = cnt; k < 9; k++){
							if(num[k] != 0 && (k != i && k != j)){
								if(num[i] == num[k]){
									num[i] = 0;
									num[j] = 0;
									num[k] = 0;
								}
							}
						}
					}

					else if(num[j] - num[i] == 1){
						for(k = cnt; k < 9; k++){
							if(num[k] != 0 && (k != i && k != j)){
								if(num[k] - num[j] == 1){
									num[i] = 0;
									num[j] = 0;
									num[k] = 0;
								}
							}
						}
					}
				}
			}
		}
	}
	cnt = 0;
	for(i = 0; i < 9; i++){
		if(num[i] == 0){
			cnt++;
		}
	}
			if(cnt == 9){
				return 1;
			}
		else
	{
		return 0;
	}

}

Measured memory_bytes: 596
from collections import deque

N, Q = map(int, input().split())

G=[[] for i in range(N)]
A =[0]*N

for i in range(N-1):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

for i in range(Q):
    p, x = map(int, input().split())
    A[p-1] += x

queue = deque([0])
visited= [0]*N
while queue:
    a = queue.popleft()
    visited[0] = 1
    for i in G[a]:
        if visited[i] == 0:
            A[i] += A[a]
            visited[a] = 1
            queue.append(i)

print(*A)

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

int main(){
	string s; cin>>s;
	string sr=s;
	reverse(sr.begin(),sr.end());
	if(s.size()==2) cout<<s<<endl;
	else cout<<sr<<endl;
}

Measured memory_bytes: 3600
n = input()
n = int(n)

BUILDS = 4
FLOORS = 3
ROOMS = 10

house = [[[0 for x in range(ROOMS)] for y in range(FLOORS)] for z in range(BUILDS)]

for i in range(n):
    a = input()
    b, f, r, v = a.split(' ')
    house[int(b) - 1][int(f) - 1][int(r) - 1] += int(v)

for i in range(BUILDS):
    for j in range(FLOORS):
        floor = ''
        for k in range(ROOMS):
            floor += ' {}'.format(house[i][j][k])
        print(floor)
    
    if i < BUILDS - 1:
        print('#' * 20)


Measured memory_bytes: 5608
import java.util.*;
import java.util.regex.Pattern;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		int K = sc.nextInt();

		String target = S.substring(K-1,K);

		S = S.replaceAll(target, "@");
		S = S.replaceAll("[^@]", "*");
		S = S.replaceAll("@", target);

		System.out.println(S);

	}


}


Measured memory_bytes: 23764
h, w, k = map(int, input().split())
matrix = [list(input()) for i in range(h)]
ans = 0
for paint_h in range(1 << h):
    for paint_w in range(1 << w):
        cnt = 0
        for i in range(h):
            for j in range(w):
                if (paint_h >> i) & 1 == 0 and (paint_w >> j) & 1 == 0:
                    if matrix[i][j] == "#":
                        cnt += 1
        if cnt == k:
            ans += 1

print(ans)

Measured memory_bytes: 73664
import java.io.*;
import java.util.*;
import java.util.function.*;

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Supplier<String> sc) {
		int N = Integer.parseInt(sc.get());
		long K = Long.parseLong(sc.get());
		int[] A = new int[N];
		Arrays.setAll(A, $ -> Integer.parseInt(sc.get()));
		int[] F = new int[N];
		Arrays.setAll(F, $ -> Integer.parseInt(sc.get()));
		Arrays.sort(A);
		Arrays.sort(F);

		long notrain = -1;
		for (int i = 0; i < A.length; i++) {
			long member = A[i];
			long food = F[F.length - 1 - i];
			if (notrain < member * food) {
				notrain = member * food;
			}
		}

		long ng = -1;
		long ok = notrain;
		while (Math.abs(ok - ng) > 1) {
			long mid = (ok + ng) / 2;
			if (canTrain(K, mid, A, F)) ok = mid;
			else ng = mid;
		}

		System.out.println(ok);
	}

	static long ceilDiv(long a, long div){
		return -Math.floorDiv(-a, div);
	}

	boolean canTrain(long K, long max, int[] A, int[] F){
		for (int i = 0; i < A.length; i++) {
			long member = A[i];
			long food = F[F.length - 1 - i];
			long time = member * food;
			if (max >= time) continue;
			K -= ceilDiv(time - max, food);
			if (K < 0) return false;
		}
		return K >= 0;
	}
}

class Main {
	public static void main(String... args) {
		System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		Solver.INSTANCE.solve(new Supplier<String>() {
			StringTokenizer line;

			public String get() {
				while (line == null || !line.hasMoreTokens()) try {
					line = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
				return line.nextToken();
			}
		});
		System.out.flush();
	}
}

Measured memory_bytes: 53456
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		int H=scn.nextInt();
		int W=scn.nextInt();
		int h=scn.nextInt();
		int w=scn.nextInt();
		System.out.println(H*W+h*w-H*w-W*h);
	}

}


Measured memory_bytes: 23892
a,b,c,d = list(map(int,input().split()))
s = max([abs(a-b),abs(a-c),abs(b-c)])
ac = abs(a-c)
ab = abs(a-b)
bc = abs(b-c)
if  ac <= d or (ab <= d and bc <= d ):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define REP(i,n) for (int i = 0; i < n; ++ i)
#define FOR(i,a,b) for (int i = a; i <= b; ++ i)
#define FORD(i,b,a) for (int i = b; i >= a; -- i)
#define debug(x) cerr << #x << ": " << x << "\n"
#define task "0"
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> li;
typedef vector<int> vi;

const int N = 2e3 + 5;
int n, k, q, a[N], res;
vi tmp1, tmp2, v;
void trans() {
	if ((int) tmp1.size() >= k) {
		sort(tmp1.begin(), tmp1.end());
		REP(i, (int) tmp1.size() - k + 1) tmp2.pb(tmp1[i]);
	}
	tmp1.clear();
}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	//freopen(task".inp", "r", stdin);
	//freopen(task".out", "w", stdout);
	cin >> n >> k >> q;
	FOR(i, 1, n) {
		cin >> a[i];
		v.pb(a[i]);
	}
	sort(v.begin(), v.end());
	res = v.back() - v[0];

	REP(i, n) if (i == 0 || v[i] != v[i-1]) {
		int bound = v[i];

		tmp1.clear(); tmp2.clear();
		FOR(j, 1, n) {
			if (a[j] >= bound) tmp1.push_back(a[j]);
			else trans();
		}
		trans();

		if ((int) tmp2.size() >= q) {
			sort(tmp2.begin(), tmp2.end());
			res = min(res, tmp2[q-1] - tmp2[0]);
		} else break;
	}
	cout << res;
}


Measured memory_bytes: 256
from collections import deque

N, M = map(int, input().split())
d = [set() for _ in range(N+1)]
for _ in range(M):
    a, b = map(int, input().split())
    d[a].add(b)
    d[b].add(a)

queue=deque([1])
vs = set([1])
parents = [0] * (N+1)
while queue:
    v = queue.popleft()
    for u in d[v]:
        if u in vs:
            continue
        parents[u] = v
        vs.add(u)
        queue.append(u)
print("Yes")
for x in parents[2:]:
    print(x)


Measured memory_bytes: 128380
#include<iostream>
#include<string>
#include<queue>
#include<vector>
using namespace std;
const long long INF=200000000000000000LL;
typedef pair<int,int> P;
int main(){
	int N,A,B,ans=0;
	cin>>N;
	for(int i=0;i<N;++i){
		cin>>A>>B;
		ans+=B-A+1;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
g = list(map(lambda x: int(x)-1,input().split()))

check = [-1] * n
now = 0
check[now] = 0
cnt = 0
while 1:
    cnt += 1
    now = g[now]
    if check[now] != -1:
        sa = cnt - check[now]
        cnt = cnt + (k - cnt)//sa *sa
        if cnt == k:
                print(now+1)
                exit()
        while 1:
            cnt += 1
            now = g[now]
            if cnt == k:
                print(now+1)
                exit()
    else:
        check[now] = cnt
    if cnt == k:
        print(now+1)
        exit()

Measured memory_bytes: 91848
#! /usr/bin/env python3
# # -*- coding: utf-8 -*-


class Node:
    def __init__(self, val, left, right):
        self.val = val
        self.left = left
        self.right = right

    def __iter__(self):
        yield from self.postorder()

    def postorder(self):
        yield from self.left
        yield from self.right
        yield self


def reconstruct(preorder, inorder):
    if len(preorder) == 0:
        return []

    root_val = preorder[0]
    root_index = inorder.index(root_val)
    inorder_left = inorder[:root_index]
    inorder_right = inorder[root_index + 1 :]
    preorder_left = [x for x in preorder if x in inorder_left]
    preorder_right = [x for x in preorder if x in inorder_right]

    return Node(
        root_val,
        reconstruct(preorder_left, inorder_left),
        reconstruct(preorder_right, inorder_right),
    )


def main():
    n = int(input())
    preorder = [int(x) for x in input().split()]
    inorder = [int(x) for x in input().split()]

    print(*[node.val for node in reconstruct(preorder, inorder).postorder()])


main()



Measured memory_bytes: 5628
n = int(input())
H = list(map(int, input().split()))
TMP = []
ans = 0
for i in range(n-1):
  if H[i] >= H[i+1]:
    TMP.append(1)
  else:
    TMP.append(-1)
tmp = 0
for i in range(n-1):
  if TMP[i] == 1:
    tmp += 1
  else:
    ans = max(ans, tmp)
    tmp = 0
ans = max(ans, tmp)
print(ans)
    

Measured memory_bytes: 14252
#include <stdio.h>

#define KI_MAX 212345

int ki[KI_MAX];

void ki_init(void) {
	int i;
	for (i = 0; i < KI_MAX; i++) {
		ki[i] = -1;
	}
}

int ki_root(int node) {
	if (ki[node] < 0) return node;
	return ki[node] = ki_root(ki[node]);
}

int ki_size(int node) {
	return -ki[ki_root(node)];
}

void ki_merge(int a, int b) {
	int ra = ki_root(a);
	int rb = ki_root(b);
	if (ra != rb) {
		int sa = ki_root(ra);
		int sb = ki_root(rb);
		if (sa >= sb) {
			ki[ra] += ki[rb];
			ki[rb] = ra;
		} else {
			ki[rb] += ki[ra];
			ki[ra] = rb;
		}
	}
}

int main(void) {
	int N, Q;
	int i;
	ki_init();
	if (scanf("%d%d", &N, &Q) != 2) return 1;
	for (i = 0; i < Q; i++) {
		int t, u, v;
		if (scanf("%d%d%d", &t, &u, &v) != 3) return 1;
		if (t == 0) {
			ki_merge(u, v);
		} else if (t == 1) {
			printf("%d\n", ki_root(u) == ki_root(v));
		}
	}
	return 0;
}


Measured memory_bytes: 2556
#include <iostream>
#include <string>
#include <vector>
#include <queue>

using namespace std;

vector<int> g[500005];
bool nonRoot[500005] = {false};
int w[500005] = {0};

int main() {
  string s;
  cin >> s;
  int n = s.size();
  for (int i = 0; i < n; i++) {
    if (s[i] == '<') {
      g[i].push_back(i + 1);
      nonRoot[i + 1] = true;
    } else {
      g[i + 1].push_back(i);
      nonRoot[i] = true;
    }
  }
  /*
  for (int i = 0; i <= n; i++) {
    cerr << "vertex " << i << ": ";
    for (int j = 0; j < g[i].size(); j++) {
      cerr << g[i][j] << ", ";
    }
    cerr << endl;
  }
  for (int i = 0; i <= n; i++) {
    cerr << "root " << i << " " << !nonRoot[i] << endl;
  }
  */

  queue<int> q;
  for (int i = 0; i <= n; i++) {
    if (!nonRoot[i]) {
      q.push(i);
    }
  }
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int i = 0; i < g[v].size(); i++) {
      int u = g[v][i];
      w[u] = max(w[u], w[v] + 1);
      q.push(u);
    }
  }
  long long sum = 0;
  for (int i = 0; i <= n; i++) sum += (long long)w[i];
  cout << sum << endl;

  return 0;
}



Measured memory_bytes: 30468
#include <stdio.h>

int hantei(int);

int main(){
  int n,m,i,v = 0;

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    scanf("%d",&m);
    if(hantei(m) == 1) v++;
  }

  printf("%d\n",v);

  return 0;
}

int hantei(int m){
  int j;
  
  if(m == 2 || m == 3) return 1;
  else if(m%2 == 0 || m%3 == 0) return 0;
  
    for(j = 5; j*j <= m; j++){
      if(m%j == 0 || m%(j+2) == 0) return 0;
    }

    return 1;
}



Measured memory_bytes: 2056
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int n, m, root, a[MAXN], b[MAXN], f[MAXN], pos[MAXN], fa[MAXN];
vector <int> e[MAXN], t[MAXN];
long long dp[MAXN], sum[MAXN];
void work(int pos) {
	if (t[pos].size() == 0) {
		dp[pos] = a[pos] + b[pos];
		sum[pos] = b[pos];
		return;
	}
	sum[pos] = b[pos];
	for (unsigned i = 0; i < t[pos].size(); i++) {
		work(t[pos][i]);
		sum[pos] += sum[t[pos][i]];
	}
	dp[pos] = 1e18;
	for (unsigned i = 0; i < t[pos].size(); i++)
		chkmin(dp[pos], max(dp[t[pos][i]], 1ll * a[pos]) + sum[pos] - sum[t[pos][i]]);
}
bool cmp(int x, int y) {
	return a[x] < a[y];
}
int F(int x) {
	if (f[x] == x) return x;
	else return f[x] = F(f[x]);
}
int main() {
	read(n), read(m);
	for (int i = 1; i <= n; i++) {
		read(a[i]), read(b[i]);
		a[i] = max(a[i] - b[i], 0);
		pos[i] = i;
	}
	sort(pos + 1, pos + n + 1, cmp);
	for (int i = 1; i <= m; i++) {
		int x, y;
		read(x), read(y);
		e[x].push_back(y);
		e[y].push_back(x);
	}
	memset(fa, -1, sizeof(fa));
	for (int i = 1; i <= n; i++) {
		int tmp = pos[i];
		f[tmp] = tmp;
		for (unsigned j = 0; j < e[tmp].size(); j++)
			if (fa[F(e[tmp][j])] == 0) fa[F(e[tmp][j])] = tmp, f[F(e[tmp][j])] = tmp;
		fa[tmp] = 0;
	}
	for (int i = 1; i <= n; i++)
		if (fa[i]) t[fa[i]].push_back(i);
		else root = i;
	work(root);
	writeln(dp[root]);
	return 0;
}

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

int root[100010]; //root[i]=i's parent
int element[100010]; //element[i]=i's group's element
//element[find(i)] is better
 
void init(int n){
  for(int i=0;i<n;i++) root[i]=i,element[i]=1;
}//reset
int find(int x){
  if(root[x]==x){
    return x;
  }
  else{
    return root[x]=find(root[x]);
  }
}//search x's parent
bool same(int x,int y){
  return find(x)==find(y);
}
void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y) return;
  root[x]=y;
  element[y]+=element[x];
}//x"->"y

int main(){
  int n,m;
  cin>>n>>m;
  init(n);
  int x,y,z;
  for(int i=0;i<m;i++){
    cin>>x>>y>>z;
    x--;
    y--;
    unite(x,y);
  }
  int ans=0;
  for(int i=0;i<n;i++){
    if(element[find(i)]>0){
      ans++;
      element[find(i)]=0;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;
#define reverse(s) reverse(s.begin(),s.end())
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
int main(){
    int x[5];
    rep(i,5){
        cin >> x[i];
    }

    rep(i,5){
        if(x[i]==0){
            cout << i+1 << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
  int N,Q; cin>>N>>Q;
  string str; cin>>str;
  
  vector<int> s(N+1,0);
  for(int i=0;i<N;i++){
      if(i+1<N && str[i]=='A' && str[i+1]=='C') s[i+1]=s[i]+1;
      else s[i+1]=s[i];
  }
  
  for(int i=0;i<Q;i++){
      int l,r; cin>>l>>r;
      l--,r--;
      cout<<s[r]-s[l]<<endl;
  }
}

Measured memory_bytes: 1408
N,X,Y = map(int,input().split())
a = [0]*(N-1)
for i in range(1,N):
  for j in range(i+1,N+1):
    ans = min(j-i,abs(X-i)+1+abs(Y-j),abs(X-j)+1+abs(Y-i))
    a[ans -1] += 1
for item in a:
  print(item)

Measured memory_bytes: 9152
#include <stdio.h>

int main(){
  int x,y,xy,i;
  scanf("%d %d",&x,&y);

  if(x < y){
    i = x;
    x = y;
    y = i;
  }

  while(1){
    if(x % y == 0)break;
    xy = x % y;
    x = y;
    y = xy;
  }
  printf("%d\n",y);
}


Measured memory_bytes: 2072
#include <bits/stdc++.h> 
#define rep(i,N)  for(int i=0; i<N; i++)
#define ol(a) cout << a << endl;
#define PI 3.14159265359
using namespace std;

int main(){
  int64_t n;  cin >> n;
  vector<int> tisa;
  string ans;
  deque<char> ww;
  //+96
  int64_t x,b;
  x = n; //initial
  char s;
  while(x > 0){
    b = x % 26;
    if(b==0){
      s = 'z';
    }
    else{
      s = char(b+96);
    }
    ww.push_front(s);
    x = x / 26;
    if(b==0){
      x--;
    }
  }
  char p;
  while(!ww.empty()){
    p = ww.front();
    ans += p;
    ww.pop_front();
  }
  ol(ans)
      
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

bool ch[100010];
vector<P> G[100010];
bool used[100010];
vector<int> ans;
bool isOK = true;

int dfs(int v,int num){
	used[v] = true;
	int sum = ch[v];
	for(auto to : G[v]){
		if(used[to.first]) continue;
		sum += dfs(to.first,to.second);
	}
	if(sum % 2){
		if(num == -1) isOK = false;
		else ans.push_back(num);
	}
	return sum % 2;
}

signed main(){
	int n,m,a[100010],b[100010],l[200010],r[200010];
	cin >> n >> m;
	vector<P> vec;
	for(int i = 0;i < n;i++){
		cin >> a[i] >> b[i];
		vec.emplace_back(a[i],b[i]);
	}
	sort(all(vec));
	a[0] = b[0] = 0;
	a[n + 1] = INF;
	b[n + 1] = 0;
	for(int i = 0;i < n;i++){
		a[i + 1] = vec[i].first;
		b[i + 1] = vec[i].second;
	}
	for(int i = 0;i <= n;i++){
		ch[i] = (b[i] != b[i + 1]);
	}
	for(int i = 0;i < m;i++){
		cin >> l[i] >> r[i];
		l[i] = lower_bound(a,a + n + 2,l[i]) - a - 1;
		r[i] = upper_bound(a,a + n + 2,r[i]) - a - 1;
		G[l[i]].emplace_back(r[i],i);
		G[r[i]].emplace_back(l[i],i);
	}
	for(int i = 0;i < n;i++){
		if(used[i]) continue;
		dfs(i,-1);
	}
	if(!isOK) cout << -1 << endl;
	else{
		cout << ans.size() << endl;
		if(ans.size()){
			sort(all(ans));
			for(int i = 0;i < ans.size();i++) cout << (i ? " " : "") << ans[i] + 1;
		}
		cout << endl;
	}
	

}

Measured memory_bytes: 24176
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int P_MAX = 500000;

vector<int> table(P_MAX, 0); // ずらしテーブル

void make_table(vector<int> p, int m) {
    int j = 0;
    for(int i=1;i<m;++i) {
        table[i] = j;
        if(p[i] == p[j]) {
            ++j;
        } else {
            j = 0;
        }
    }
}

vector<int> kmp(vector<int> s, vector<int> p, int n, int m, int start=0) {
    int i = start, j = 0;
    vector<int> ret;
    while(i < n) {
        if(s[i] == p[j]) {
            if(j == m-1) {
                ret.push_back(i-j);
                j = table[j];
            } else {
                ++i;
                ++j;
            }
        } else if(j == 0) {
            ++i;
        } else {
            j = table[j];
        }
    }
    return ret;
}
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(2*n), b(n), a_diff, b_diff;
    for(int i=0;i<n;++i) {
        cin >> a[i];
        a[i+n] = a[i];
    }
    for(int i=1;i<2*n;++i) {
        a_diff.push_back(a[i-1]^a[i]);
    }
    for(int i=0;i<n;++i) {
        cin >> b[i];
        if(i) {
            b_diff.push_back(b[i-1]^b[i]);
        }
    }
    make_table(b_diff, n-1);
    
    vector<int> vk = kmp(a_diff, b_diff, 2*n-1, n-1);
    for(int k: vk) {
        if(k >= n) break;
        cout << k << " " << (a[k]^b[0]) << endl;
    }
}


Measured memory_bytes: 12884
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  string s;
  string ans = "";
  cin >> s;

  if (s == "Sunny") {
    ans = "Cloudy";
  } else if (s == "Cloudy") {
    ans = "Rainy";
  } else {
    ans = "Sunny";
  }
  cout << ans << endl;
  return 0;
}

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

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

int N,Q;
string S;
vector<set<int>> pls;
const int INF = 1 << 30;

void solve() {
	pls.assign(26, set<int>({ INF }));
	rep(i, N) pls[S[i] - 'a'].insert(i);

	while (Q--) {
		int type;
		cin >> type;
		if (type == 1) {
			int ind; char nc; cin >> ind >> nc; --ind;
			auto pc = S[ind];
			S[ind] = nc;
			pls[pc - 'a'].erase(ind);
			pls[nc - 'a'].insert(ind);
		}
		else {
			int l, r; cin >> l >> r; --l;
			int res = 0;
			rep(c, 26) {
				if (pls[c].empty()) continue;
				int lid = *pls[c].lower_bound(l);
				int rid = *pls[c].lower_bound(r);
				if (rid > lid) ++res;
			}
			cout << res << endl;
		}
	}
}

int main() {

	cin >> N >> S >> Q;
	solve();

}


Measured memory_bytes: 24196
N = int(input())
S = input()

A1, A2 = [0 for _ in range(N)], [0 for _ in range(N)]
for i, s in enumerate(S):
  if i == 0:
    if s == '(': A1[i] = 1
    else: A2[i] = 1
  else:
    if s == '(':
      A1[i] = A1[i-1] + 1
      A2[i] = A2[i-1] 
    else:
      A1[i] = A1[i-1] 
      A2[i] = A2[i-1] + 1

A3, A4 = [0 for _ in range(N)], [0 for _ in range(N)]
for i in range(N-1, -1, -1):
  if i == N-1:
    if S[i] == '(': A3[i] = 1
    else: A4[i] = 1
  else:
    if S[i] == '(':
      A3[i] = A3[i+1] + 1
      A4[i] = A4[i+1] 
    else:
      A3[i] = A3[i+1] 
      A4[i] = A4[i+1] + 1

v1 = max(max([a2-a1 for a1, a2 in zip(A1,A2)]),0)
v2 = max(max([a3-a4 for a3, a4 in zip(A3,A4)]),0)
print('('*v1+S+')'*v2)

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

char b1[5]={'.' , ',' , '!' , '?' , ' '};
char b2[3]={'a' , 'b' , 'c'};
char b3[3]={'d' , 'e' , 'f'};
char b4[3]={'g' , 'h' , 'i'};
char b5[3]={'j' , 'k' , 'l'};
char b6[3]={'m' , 'n' , 'o'};
char b7[4]={'p' , 'q' , 'r' , 's'};
char b8[3]={'t' , 'u' , 'v'};
char b9[4]={'w' , 'x' , 'y' , 'z'};

int main()
{
	int n;
	cin>>n;
	while(n--)
	{
		string in,out;
		cin>>in;
		int cnt=0;
		for(int i=0;i<in.size();i++)
		{
			if(in[i]==0&&cnt==0) continue;
			else if(in[i]!='0') cnt++;
			else
			{
				switch(in[i-1]){
					case '1':
						out+=b1[(cnt-1)%5];
						break;
					case '2':
						out+=b2[(cnt-1)%3];
						break;
					case '3':
						out+=b3[(cnt-1)%3];
						break;
					case '4':
						out+=b4[(cnt-1)%3];
						break;
					case '5':
						out+=b5[(cnt-1)%3];
						break;
					case '6':
						out+=b6[(cnt-1)%3];
						break;
					case '7':
						out+=b7[(cnt-1)%4];
						break;
					case '8':
						out+=b8[(cnt-1)%3];
						break;
					case '9':
						out+=b9[(cnt-1)%4];
						break;
				}
				cnt=0;
			}
		}
		cout<<out<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

int main() {
	int n, **ms;
	while (cin >> n && n) {
		ms = new int*[n];
		for (int i = 0; i < n; i++)
			ms[i] = new int[n];
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				ms[i][j] = 0;

		int x = n / 2;
		int y = x + 1;
		ms[y][x] = 1;
		for (int i = 2; i <= n * n; i++) {
			x++; y++;
			while (1) {
				if (n <= x)
					x = 0;
				else if (x < 0)
					x = n - 1;
				else if (n <= y)
					y = 0;
				else if (y < 0)
					y = n - 1;
				else if (ms[y][x] != 0) {
					x--;
					y++;
				}
				else {
					ms[y][x] = i;
					break;
				}
			}
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++)
				printf("%4d", ms[i][j]);
//				cout << setprecision(2) << ms[i][j];
			cout << endl;
		}

		for (int i = 0; i < n; i++)
			delete[] ms[i];
		delete[] ms;
	}
	return 0;
}

Measured memory_bytes: 1220
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>

using namespace std;
int main(int argc, const char * argv[]) {
    
    int a, b, c;
    cin >> a >> b >> c;

    int m = max(a, max(b, c));
    cout << a+ b+ c - m + m*10  << endl;
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = Array.new
b = Array.new
ab = Array.new
ans = 0

n.times do
  s = gets.chomp.gsub(/AB/, '!')
  ans += s.count('!')
  if s[0] == 'B' and s[-1] == 'A'
    ab << s
  elsif s[0] == 'B'
    b << s
  elsif s[-1] == 'A'
    a << s
  end
end

as = a.size
bs = b.size
abs = ab.size

if as == 0 and bs == 0
  if abs == 0
    puts ans
  else
    ans += abs - 1
    puts ans
  end
elsif as == 0 or bs == 0
  if abs == 0
    puts ans
  else
    if as == 0
      if abs <= bs
        ans += abs
      else
        ans += abs
      end
    else
      if abs <= as
        ans += abs
      else
        ans += abs
      end
    end
    puts ans
  end
else
  if abs == 0
    if as <= bs
      ans += as
    else
      ans += bs
    end
  else
    if as == bs
      if as == abs
        ans += as * 2
      else
        ans += as
        ans += abs
      end
    elsif as < bs
      ans += as
      t = bs - as
      if t == abs
        ans += t
      elsif t < abs
        ans += abs
      else
        ans += abs
      end
    elsif as > bs
      ans += bs
      t = as - bs
      if t == abs
        ans += t
      elsif t < abs
        ans += abs
      else
        ans += abs
      end
    end
  end
  puts ans
end


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

public class Hello
{
    public static void Main()
    {
        hoge();
        System.Console.ReadLine();
    }

    public static void hoge()
    {
        var vars = System.Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        var n = vars[0];
        var k = vars[1];

        var a = System.Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

        if(n == 2)
        {
            if(a[1] > a[0])
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
            return;
        }

        var top = a[0];

        for(int i = 1; i <= n - k; i++)
        {
            var top2 = a[i];
            var bottom2 = a[k - 1 + i];
            if(bottom2 > top)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
            top = top2;
        }
    }
}

Measured memory_bytes: 46936
#include<iostream>
using namespace std;
int main() {
  int N;
  cin >> N;
  int C[N], S[N], F[N];
  for (int i = 0;i < N - 1;++ i) cin >> C[i] >> S[i] >> F[i];
  for (int i = 0;i < N;++ i) {
    int t = 0;
    for (int j = i;j < N - 1;++ j) t = max(S[j], t + (F[j] - t % F[j]) % F[j]) + C[j];
    cout << t << endl;
  }
  return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
dd = defaultdict(bool)
n = int(input())
w = [input() for _ in range(n)]
pre = w[0][0]
for s in w:
    if dd[s] or (pre[len(pre) - 1] != s[0]):
        print("No")
        exit()
    dd[s] = True
    pre = s
print("Yes")

Measured memory_bytes: 3316