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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

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

	int n, m;
	cin >> n >> m;

	int P[m], Q[m];
	map< int, vector<int> > mp;

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

		//mp[P[i]].emplace_back(Q[i]);
		mp[P[i]].push_back(Q[i]);
	}

	for(auto &p : mp){
		sort(p.second.begin(), p.second.end()//, [&](int a, int b){
		//	return a < b;
		//}
		);
	}

	for(int i = 0; i < m; i++){
		auto it = lower_bound(mp[P[i]].begin(), mp[P[i]].end(), Q[i]) - mp[P[i]].begin();
		//printf("%06d%06d\n", P[i], (int)it + 1);
		cout << setfill('0') << setw(6) << P[i];
		cout << setfill('0') << setw(6) << (int)it + 1 << endl;
	}

	// return 0;
}


Measured memory_bytes: 13184
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string N;
  cin >> N;
  if ((N[0] == N[1] && N[0] == N[2]) || (N[1] == N[2] && N[1] == N[3])) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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


int main() {
	int H, W;
	cin >> H >> W;
	char s[55][55];
	
	for (int i = 0; i < H+2; i++) {
		for (int j = 0; j < W+2; j++) {
			if(i==0 || j==0 || i==H+1 || j==W+1)
				s[i][j] = '.';
			else
				cin >> s[i][j];
		}
	}
	int dx[] = { -1,0,1,0 }, dy[] = { 0,1,0,-1 };

	bool F=true;
	for (int i = 1; i < H + 1; i++) {
		for (int j = 1; j < W + 1; j++) {
			bool flag = false;
			if (s[i][j] == '#') {
				for (int d = 0; d < 4; d++) {
					if (s[i + dx[d]][j + dy[d]] == '#')
						flag = true;
				}
				if (!flag) { F = false; break; }
			}
		}
		if(!F) break;
	}

	cout << (F?"Yes":"No") << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<string>
#include<cstring>
#include<utility>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<vector>
#include<iostream>
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define inf 0x7fffffff
using namespace std;
int a[30];//75=25*3=5*15=5*5*3
int p[30]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
int main()
{
	int i,j,k,n,m,x,y;
	scanf("%d",&n);
	for(i=2;i<=n;i++)
	{
		x=i;
		for(j=0;p[j]<=x&&j<25;j++)
		{
			while(x%p[j]==0)
			{
				a[j]++;
				x/=p[j];
			}
		}
	}
	int x3=0,x5=0,x15=0,x25=0,x75=0;
	for(i=0;i<25;i++)
	{
		if(a[i]>=2)
		{
			x3++;
		}
		if(a[i]>=4)
		{
			x5++;
		}
		if(a[i]>=14)
		{
			x15++;
		}
		if(a[i]>=24)
		{
			x25++;
		}
		if(a[i]>=74)
		{
			x75++;
		}
	}
	printf("%d",(x3-2)*x5*(x5-1)/2+(x3-1)*x25+x15*(x5-1)+x75);
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
#include <complex>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-10;

bool is_prime[1000001];

int compute_key_number(int num){
  int sum = 0;
  int last_prime = 0;
  for(int i=2;i<=num;i++){
    if(!is_prime[i]) continue;
    if(num % i == 0){
      sum += i;
      last_prime = i;
    }
  }
  return last_prime - (sum-last_prime);
}

int main(){
  memset(is_prime,true,sizeof(is_prime));

  is_prime[0] = false;
  is_prime[1] = false;

  for(int i=2;i*i<=1000000;i++){
    if(!is_prime[i]) continue;
    for(int j=i+i;j<=1000000;j+=i){
      is_prime[j] = false;
    }
  }

  int doors[2];
  while(~scanf("%d %d",doors,doors+1)){
    if(doors[0] == 0 && doors[1] == 0) break;
    printf("%c\n",compute_key_number(doors[0]) > compute_key_number(doors[1]) ? 'a' : 'b');
  }
}

Measured memory_bytes: 2172
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(ll i##_len=(n) ,i=i##_len-1;i>=0;--i)
#define repi(i,a,b) for(ll i=ll(a);i<=ll(b);++i)
#define ALL(f,x,...) ([&](decltype((x)) xxxx) { return (f)(begin(xxxx), end(xxxx), ## __VA_ARGS__); })(x)
#define lim 1000000007ll
#define Yes(flag) cout<<((flag)? "Yes":"No");
#define YES(flag) cout<<((flag)? "YES":"NO");
#define which(flag,msg1,msg2) cout<<((flag)? msg1:msg2);

#include<bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = std::pair<ll,ll>;
using namespace std;
template<class T>T 
chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>T 
chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template <class T> T 
gcd(T a, T b){if (a < b) {a ^= b;b ^= a;a ^= b;} return b ? gcd(b, a % b) : a;}
template <class T> T 
lcm(T a, T b){return a * b / gcd(a, b);}
vector<char> 
string_to_vector_char(const string& input){vector<char> out(input.length());rep(i,input.length()){out[i]=input[i];}return out;}
map<char,int> 
count_same_elements(const vector<char>& v){map<char,int>cmap; for_each(v.begin(),v.end(),[&cmap](int x){cmap[x]++;}); return cmap; }
template<class A,class B> vector<B> 
mapf(const vector<A>& v,const function<B(A)>& func){vector<B> v_(v.size());rep(i,v.size()){ v_[i]=func(v[i]); }return v_;}
template<class A,class B> vector<B> 
adjacent_map(const vector<A>& v,const function<B(A,A)>& func){vector<B> v_(v.size()-1);rep(i,v.size()-1){ v_[i]=func(v[i+1],v[i]); }return v_;}
template<class A> bool
all_of(const vector<A>& v){bool flag=true;rep(i,v.size()){ if(v[i]<1){flag=false;}; }return flag;}
template<class A> bool
any_of(const vector<A>& v){bool flag=false;rep(i,v.size()){ if(v[i]>0){flag=true; break;}; }return flag;}
template<class A> bool
none_of(const vector<A>& v){bool flag=true;rep(i,v.size()){ if(v[i]>0){flag=false;}; }return flag;}
template<class T>
void scan_vector(long long size,vector<T>& vector){
    vector.resize(size);
    for(long long i=0;i<size;++i){
        cin>>vector[i];
    }
}
// 約数列挙
template <class T>
vector< T > divisor(T n) {
    vector< T > ret;
    for(T i = 1; i * i <= n; i++) {
        if(n % i == 0) {
        ret.push_back(i);
        if(i * i != n) ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return (ret);
}

ll h,w;
vector<string> s;
void input(){
    cin>>h>>w;
    scan_vector(h,s);
}
void src(){
    vector<vector<int>> f(h); vector<int> kn(h,1);
    rep(i,h) f[i].resize(w,1);
    rep(i,h){
        if(all_of(s[i].begin(),s[i].end(),[](auto x){return x=='.';})){
            rep(j,w) f[i][j]=0;
            kn[i]=0;
        };
    }
    rep(i,w){
        bool fl=true;
        rep(j,h) if(s[j][i]=='#'){fl=false;break;}
        if(fl){
            rep(j,h) f[j][i]=false;
        }
    }
    rep(i,h){
        if(kn[i]){
        rep(j,w){
            if(f[i][j])
                cout<<s[i][j];
        }
        cout<<"\n";

        }
    }


}   

int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
 //   ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
#include <complex>

using namespace std;

using ll = long long int;


const int MAXN=2e5+7;
int N;

complex<int> arr[MAXN];

int comp1(const complex<int>& a,const complex<int>& b){
    return (a.real()+a.imag())<(b.real()+b.imag());
}

int main(){
    scanf("%d",&N);
    for(int i=0;i<N;i++) {
        int x,y;
        scanf("%d%d",&x,&y);
        arr[i]=complex<int>(x,y);
    }

    int ans=0;
    auto largest=max_element(arr,arr+N,comp1),least=min_element(arr,arr+N,comp1);
    auto temp=largest->imag()+largest->real()-least->real()-least->imag();
    ans=max(temp,ans);

    for(int i=0;i<N;i++) {
        int x=arr[i].real(),y=arr[i].imag();
        arr[i]=complex<int>(1000000001-x,y);
    }

    largest=max_element(arr,arr+N,comp1),least=min_element(arr,arr+N,comp1);
    temp=largest->imag()+largest->real()-least->real()-least->imag();
    ans=max(temp,ans);
    
    printf("%d\n",ans);


    return 0;
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(int, h, w);
  vector a(h, vector(w, 0));
  rep(i, h) rep(j, w) cin >> a[i][j];
  int r = 0, c = 0;
  vector<string> moves;
  while (true) {
    dbg(r, c);
    int nr = r, nc = c + ((r & 1) ? -1 : 1);
    if (nc < 0 || w <= nc) {
      ++nr;
      if (nr == h) break;
      nc = c;
    }
    if (a[r][c] & 1) {
      stringstream ss;
      ss << (r + 1) << " " << (c + 1) << " " << (nr + 1) << " " << (nc + 1);
      moves.push_back(ss.str());
      --a[r][c];
      ++a[nr][nc];
    }
    r = nr;
    c = nc;
  }
  out(moves.size());
  for (auto& m : moves) out(m);
}


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

using ll = long long;

//constant
const ll MOD = 1e+9 + 7;
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// view vector
template<typename T> void view(T e) { std::cout << e << std::endl; }
template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v : vv) { view(v); } }


// ***************************************

int main(void) {

	map<string, ll> MP;
	ll N;
	cin >> N;

	string key;
	REP(i, N) {
		cin >> key;
		MP[key]++;
	}

	ll max_v = 0;
	for (auto& kv : MP) {
		max_v = max(max_v, kv.second);
	}


	for (auto& kv : MP) {
		if (kv.second == max_v) {
			cout << kv.first << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int w,h,n;
    cin >> w >> h >> n;
    int x_min = 0,y_min = 0,x_max = w,y_max = h;
    vector<tuple<int,int,int> > v;
    for(int i = 0;i < n;i++)
    {
        int x,y,a;
        cin >> x >> y >> a;
        if(a == 1 && x > x_min)
        {
            x_min = x;
        }
        else if(a == 2 && x < x_max)
        {
            x_max = x;
        }
        else if(a == 3 && y > y_min)
        {
            y_min = y;
        }
        else if(a == 4 && y < y_max)
        {
            y_max = y;
        }
    }
    int ans = (x_max - x_min) * (y_max - y_min);
    if(x_max - x_min > 0 && y_max - y_min > 0)
    {
        cout << ans << "\n";
    }
    else
    {
        cout << "0\n";
    }

    return 0;
}

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

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }


const int MAX = 200000;
const ll INF = 1LL<<61;

int n, k;
long long a[MAX];

int main() {
    while (cin >> n >> k) {
        if (n == 0) break;
        memset(a, 0, sizeof(a));
        for (int i = 0; i < n; ++i) cin >> a[i+1];
        for (int i = 0; i <= n; ++i) a[i+1] += a[i];
        
        long long res = -INF;
        for (int i = 0; i + k <= n; ++i) {
            chmax(res, a[i+k] - a[i]);
        }
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 2732
from itertools import product

A = [list(map(int,input().split())) for i in range(3)]
n = int(input())
crd = [[False,False,False] for i in range(3)]
for _ in range(n):
    b = int(input())
    for i,j in product(range(3),range(3)):
        if b == A[i][j]:
            crd[i][j] = True

line = [[(0,0),(0,1),(0,2)],[(1,0),(1,1),(1,2)],[(2,0),(2,1),(2,2)],\
        [(0,0),(1,0),(2,0)],[(0,1),(1,1),(2,1)],[(0,2),(1,2),(2,2)],\
        [(0,0),(1,1),(2,2)],[(2,0),(1,1),(0,2)]]


for l in line:
    if crd[l[0][0]][l[0][1]] and crd[l[1][0]][l[1][1]] and crd[l[2][0]][l[2][1]]:
        print('Yes')
        exit()

print('No')


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

int main() {
  int k,n;cin>>k>>n;
  vector<int> a(n+1);
  rep(i,n)cin>>a[i];
  a[n]=a[0]+k;
  int ans=0;
  rep(i,n+1){
    ans=max(ans,a[i+1]-a[i]);
  }
  cout<<k-ans<<endl;
}

Measured memory_bytes: 4032
#include<stdio.h>
#define l(a,p,q) (a%400==0||(a%100&&a%4==0))?p:q
int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31},a,b,c,x,y,z,i,j,r;
 
int main()
{
    for(;scanf("%d%d%d%d%d%d",&a,&b,&c,&x,&y,&z),a!=-1;)
    {
        r=-c;
        i=a%4;
        d[2]=l(a,29,28);
        for(i=b;i<=(a==x?y-1:12);i++)
            r+=d[i];
        for(i=a+1;i<x;i++)
            r+=l(i,366,365);
        d[2]=l(x,29,28);
        for(i=(a==x?13:1);i<y;i++)
            r+=d[i];
        printf("%d\n",r+z);
    }
    return 0;
}

Measured memory_bytes: 596
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<fstream>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<complex>
#include<cstring>
#include<string>
#include<algorithm>
#include<assert.h>
#include<vector>
#include<stack>
#include <utility>
#include<set>
#include<bitset>
#include<queue>
#include<map>
#include<valarray>
#include<numeric>
#include<map>
//#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) ((v).begin()),((v).end())
#define rall(v) ((v).end()),((v).begin())
#define clr(v,idx) memset(v,idx,sizeof(v))
#define rep(i,x) for(int i=0;i<(int)x;i++)
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define pll pair<ll,ll>
//const int dx[] = {1,-1,0,0,1,-1,1,-1};
//const int dy[] = {0,0,1,-1,1,-1,-1,1};
//const int dxhorse[] = {-2,-2,-1,-1,1,1,2,2};
//const int dyhorse[] = {1,-1,2,-2,2,-2,1,-1};
void fast()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
}

int main()
{
	string s; cin >> s;
	string tmp = s.substr(4);
	string ans = "2018";
	ans.append(tmp);
	cout << ans;
}

Measured memory_bytes: 256
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N;
int A[100010], B[100010], C[100010];
int rec[100010];

signed main() {
    cin >> N;
    rep(i,0,N) cin >> A[i];
    rep(i,0,N) cin >> B[i];
    rep(i,0,N) cin >> C[i];
    sort(B, B+N);
    sort(C, C+N);

    int ans = 0;
    repr(i,N-1,0) {
        int idx = upper_bound(C, C+N, B[i]) - C;
        rec[i] = rec[i+1] + (N - idx);
    }
    rep(i,0,N) {
        int idx_b = upper_bound(B, B+N, A[i]) - B;
        ans += rec[idx_b];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <string>
#include <sstream>
#include <numeric>
#include <ios> // std::left, std::right

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

int main()
{
  int h, w, t, i, j;
  cin >> h >> w;
  bool b;

  vector<vector<char>> a;
  a = vector<vector<char>>(h, vector<char>(w, '0'));

  for (int i = 0; i < h; i++)
  {
    for (int j = 0; j < w; j++)
    {
      cin >> a[i][j];
    }
  }

  b = true;
  for (int i = 0; i < h; i++)
  {
    for (int j = 0; j < w; j++)
    {
      if (a[i][j] == '#')
      {
        b = false;
        break;
      }
    }
    if (b)
    {
      for (int j = 0; j < w; j++)
      {
        a[i][j] = '0';
      }
    }
    b = true;
  }

  b = true;

  for (int j = 0; j < w; j++)
  {
    for (int i = 0; i < h; i++)
    {
      if (a[i][j] == '#')
      {
        b = false;
        break;
      }
    }
    if (b)
    {
      for (int i = 0; i < h; i++)
      {
        a[i][j] = '0';
      }
    }
    b = true;
  }

  b = false;
  for (int i = 0; i < h; i++)
  {
    for (int j = 0; j < w; j++)
    {
      if (a[i][j] != '0')
      {
        cout << a[i][j];
        b = true;
      }
    }
    if (b)
      cout << '\n';
    b = false;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define MAXN 200000 + 5
#define ll long long
#define int long long
using namespace std;
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(arr) arr.begin() , arr.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i , a , n) for(int i = a ; i < n ; i++)
#define s(arr) sort(all(arr))
#define r(arr) reverse(all(arr))
#define rs(arr) s(arr) ; r(arr)
#define con continue
#define endl "\n"
 
//debug
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl

int rec(int h){
    if (h == 1)
        return 1;
    return 2 * rec(h / 2) + 1;
}

signed main(){
    FAST;
    int h;
    cin >> h;
    cout << rec(h) << endl;
    return 0;
}

Measured memory_bytes: 256
#input
H, N = map(int, input().split())
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = map(int, input().split())

#output
M = max(A)
inf = 10**10
dp = [inf]*(H+(M+1))
dp[0] = 0
for i in range(N):
    for j in range(A[i], H+M):
        dp[j] = min(dp[j], dp[j-A[i]] + B[i])

answer = min(dp[H:(H+M+1)])
print(answer)

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

using db = double;
using ll = long long;
using vi = vector <int>;
#define op operator
#define pb push_back

const int N = 1e3L + 11;
int dp[N][N];

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

	int W, n;
	int _ = 0;
	while(cin >> W && W) {
		cin >> n;
		_ ++;
		memset(dp, 0, sizeof dp);
		for(int i = 1; i <= n; i ++) {
			int v, w; char c;
			cin >> v >> c >> w;
			for(int j = 0; j <= W; j ++)
				dp[i][j] = dp[i - 1][j];
			for(int j = w; j <= W; j ++)
				dp[i][j] = max(dp[i][j], dp[i - 1][j - w] + v);
		}
		cout << "Case " << _ << ":\n";
		cout << *max_element(dp[n], dp[n] + W + 1) << '\n';
		cout << max_element(dp[n], dp[n] + W + 1) - dp[n] << '\n';
	}

	return 0;
}

Measured memory_bytes: 7164
import java.io.InputStream
import java.math.BigDecimal
import java.math.BigInteger

fun main(args: Array<String>) = input.run {
    val n = nextInt()
    val a = nextInt()
    val b = nextInt()
    if (a > b || n == 1 && a != b) {
        println(0)
    } else if (n == 1) {
        println(1)
    } else {
        println((n - 2).toLong() * (b - a) + 1)
    }
}

val input = FastScanner()

fun String.toBigInteger() = BigInteger(this)
fun String.toBigDecimal() = BigDecimal(this)

class FastScanner(private val input: InputStream = System.`in`) {
    private val sb = StringBuilder()
    private val buffer = ByteArray(4096)
    private var pos = 0
    private var size = 0

    fun nextString(): String? {
        var c = skipWhitespace()
        if (c < 0) return null

        return sb.run {
            setLength(0)

            do {
                append(c.toChar())
                c = read()
            } while (c > ' '.toInt())

            toString()
        }
    }

    fun nextLine(): String? {
        var c = read()
        if (c < 0) return null

        return sb.run {
            setLength(0)

            while (c >= 0 && c != '\n'.toInt()) {
                append(c.toChar())
                c = read()
            }

            toString()
        }
    }

    fun nextLong(): Long {
        var c = skipWhitespace()

        val sign = if (c == '-'.toInt()) {
            c = read()
            -1
        } else 1

        var ans = 0L

        while (c > ' '.toInt()) {
            ans = ans * 10 + c - '0'.toInt()
            c = read()
        }

        return sign * ans
    }

    fun nextInt() = nextLong().toInt()
    fun nextDouble() = nextString()?.toDouble() ?: 0.0
    fun nextBigInteger(): BigInteger = nextString()?.toBigInteger() ?: BigInteger.ZERO
    fun nextBigDecimal(): BigDecimal = nextString()?.toBigDecimal() ?: BigDecimal.ZERO

    fun nextStrings(n: Int) = Array<String>(n) { nextString() ?: "" }
    fun nextInts(n: Int) = IntArray(n) { nextInt() }
    fun nextLongs(n: Int) = LongArray(n) { nextLong() }
    fun nextDoubles(n: Int) = DoubleArray(n) { nextDouble() }
    fun nextBigIntegers(n: Int) = Array<BigInteger>(n) { nextBigInteger() }
    fun nextBigDecimals(n: Int) = Array<BigDecimal>(n) { nextBigDecimal() }

    fun nextStrings(n: Int, m: Int) = Array(n) { nextStrings(m) }
    fun nextInts(n: Int, m: Int) = Array(n) { nextInts(m) }
    fun nextLongs(n: Int, m: Int) = Array(n) { nextLongs(m) }
    fun nextDoubles(n: Int, m: Int) = Array(n) { nextDoubles(m) }
    fun nextBigIntegers(n: Int, m: Int) = Array(n) { nextBigIntegers(m) }
    fun nextBigDecimals(n: Int, m: Int) = Array(n) { nextBigDecimals(m) }

    private fun skipWhitespace(): Int {
        while (true) {
            val c = read()
            if (c > ' '.toInt() || c < 0) return c
        }
    }

    private fun read(): Int {
        while (pos >= size) {
            if (size < 0) return -1
            size = input.read(buffer, 0, buffer.size)
            pos = 0
        }
        return buffer[pos++].toInt()
    }
}


Measured memory_bytes: 29608
#include <iostream>
#include <iomanip>
#include <cmath>
#define ld long double
using namespace std;

int main() {
	ld a, b, x, pi=acos(-1.0);
	cin >> a >> b >> x;
	x /= a;
	ld ans;
	if(x*2>a*b){
		x=a*b-x;
		ans=atan2((x/a)*2.0, a);
	}
	else{
		ans=pi/2.0-atan2((x/b)*2.0, b);
	}
	cout << setprecision(15) << (ans*180.0)/pi << endl;
	return 0;
}

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

#define N 200000

int main(void)
{
    int sum = 0;
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        char c = s.at(i);
        sum += atoi( &c );
    }
    
    
    if ( sum % 9 == 0 ){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    
    return 0;
}


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

int gcd(int m, int n);
int lcm(int m,int n);

int main()
{
	int a[50], b[50];
	int set = 0;
	while( cin >> a[set] >> b[set])
		set++;

	for(int i = 0; i < set; i++)
		cout << gcd(a[i], b[i]) << " " << lcm(a[i], b[i]) << endl;

	return 0;
}

int gcd(int m, int n)
{
	int t;
	if(m < n){
		t = m;
		m = n;
		n = t;
	}
	t = m % n;
	while(t != 0){
		m = n;
		n = t;
		t = m % n;
	}
	return n;
}

int lcm(int m, int n)
{
	if(0 == m || 0 == n)
		return 0;
	return ((m / gcd(m, n)) * n);
}

Measured memory_bytes: 3100
#include<stdio.h>
#include<stdbool.h>
 
int main(void)
{
    bool ly[3000];
    bool flag;
    bool put;
    int i;
    int a, b;
 
    memset(ly, false, sizeof(ly));
 
    for (i = 1; i < 3001; ++i){
        if ((i % 4) == 0){
            if ((i % 100) == 0){
                if ((i % 400) == 0){
                    ly[i] = true;
                }
            }else {
                ly[i] = true;
            }
        }
    }
     
    put = false;
 
    while (1){
        scanf("%d %d", &a, &b);
 
        if (a == 0 && b == 0){
            break;
        }
 
        flag = false;
 
        if (put == true){
            printf("\n");
        }
 
        for (i = a; i <= b; ++i){
            if (ly[i] == true){
                printf("%d\n", i);
                flag = true;
            }
        }
 
        if (flag == false){
            printf("NA\n");
        }
         
        put = true;
         
    }
 
    return 0;  
 
}

Measured memory_bytes: 616
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    
    if (s.equals("Sunny")) {
      System.out.println("Cloudy");
    } else if (s.equals("Cloudy")) {
      System.out.println("Rainy");
    } else if (s.equals("Rainy")) {
      System.out.println("Sunny");
    }
  }
}

Measured memory_bytes: 21844
#include<iostream>
#include<cstdio>
#include<ctype.h>
#include<algorithm>
using namespace std;
typedef long long ll;
inline int read(){
	int x=0,f=0;char ch=getchar();
	while(!isdigit(ch))f|=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+(ch^48),ch=getchar();
	return f?-x:x;
}
struct OOO{
	ll x,y;
	bool operator <(OOO b)const{return x<b.x;}
}a[200007];
ll mxn[200007],mn[200007];
int main(){
	ll n=read(),mx=-1,mxx=-1,mi=2e9,mii=2e9;
	for(int i=1;i<=n;++i){
		a[i].x=read(),a[i].y=read();
		if(a[i].x>a[i].y)swap(a[i].x,a[i].y);
		mx=max(mx,a[i].y),mi=min(mi,a[i].y);
		mxx=max(mxx,a[i].x),mii=min(mii,a[i].x);
	}
	ll ans1=1ll*(mx-mi)*(mxx-mii),ans2=1e18;
	mi=mii;sort(a+1,a+n+1);
	mxn[1]=mn[1]=a[1].y;
	for(int i=2;i<=n;++i){
		mxn[i]=max(mxn[i-1],a[i].y),mn[i]=min(mn[i-1],a[i].y);
		ans2=min(ans2,1ll*max(mxn[i],a[n].x)-min(mn[i],a[i+1].x));
	}
	printf("%lld\n",min(ans1,ans2*(mx-mi)));
	return 0;
}

Measured memory_bytes: 6528
n = int(input())
s = input()
r = []
w = []
for i in range(n):
    if s[i] == 'W':
        w.append(i)
    else:
        r.append(i)
ans = 0
for i in w:
    if len(r) == 0:
        break
    if i > r[-1]:
        break
    r.pop()
    ans += 1
print(ans)


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

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

using namespace std;

int main(){
	int h,w; scanf("%d%d",&h,&w);
	static char B[2000][2001];
	rep(i,h) scanf("%s",B[i]);

	static int hor[2000][2000],ver[2000][2000];
	rep(i,h) rep(j,w) if(B[i][j]=='.') hor[i][j]=ver[i][j]=1;
	rep(i,h) rep(j,w-1) if(B[i][j+1]=='.') hor[i][j+1]=hor[i][j]+1;
	rep(i,h) for(int j=w-1;j>0;j--) if(B[i][j]=='.' && B[i][j-1]=='.') hor[i][j-1]=hor[i][j];
	rep(j,w) rep(i,h-1) if(B[i+1][j]=='.') ver[i+1][j]=ver[i][j]+1;
	rep(j,w) for(int i=h-1;i>0;i--) if(B[i][j]=='.' && B[i-1][j]=='.') ver[i-1][j]=ver[i][j];

	int ans=0;
	rep(i,h) rep(j,w) ans=max(ans,hor[i][j]+ver[i][j]-1);
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 35456
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

ps = []

n = 55555
isps = [True] * (n+1)

isps[0] = isps[1] = False
for i in range(2, n+1):
    if isps[i]:
        for j in range(i*i, n+1, i):
            isps[j] = False

for i in range(n+1):
    if isps[i] and i % 5 == 1:
        ps.append(i)

m = ni()

print(" ".join([str(_) for _ in ps[:m]]))


Measured memory_bytes: 3444
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include <string>
#include <math.h>
#include <queue>
#include <stack>
#define cinf(n,x,y) for(int i=0;i<(n);i++) cin >> x[i] >>y[i];
typedef long long int ll;
using namespace std;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }

int main(){
    ll a,b,c,d; cin >>a>>b>>c>>d;
    ll m=c/GCD(c,d)*d;
    cout << (b-a+1)-(b/c-(a-1)/c)-(b/d-(a-1)/d)+(b/m-(a-1)/m) << endl;
}

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

int main(){
  int N, x = 1000;
  cin >> N;
  if (N%1000 == 0) x = 0;
  cout << x - N%1000 << endl;
}

Measured memory_bytes: 3596
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define int ll
using pint = pair<int,int>;
using Graph = vector<vector<int>>;
void YN(bool flg) {cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg) {cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg) {cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) cout << n << '\n'
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 1e10; //10^10
const double PI = acos(-1.0L);
const int dx[4] = {1, 0, -1, 0} , dy[4] = {0, 1, 0, -1};
/*mod逆元*/long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
template< typename T >T mod_pow(T x, T n, T p=MOD) {T ret = 1;while(n > 0) {if(n & 1) (ret *= x) %= p;(x *= x) %= p;n >>= 1;}return ret;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n >>= 1; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}

//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    VI a(3); REP(i,3) cin >> a[i]; SORT(a);
    if(a[0]!=a[1]) out(a[0]);
    else out(a[2]);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

int main(){
  int n,m;
  char c;
  cin >> n >> c >> m;
  int ans;
  if(c=='+'){ans=n+m;}else{ans=n-m;}

  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

int main(void) {
    int N;
    multiset<double> v;
    cin >> N;
    for (int i=0;i<N;i++) {
        int x;
        cin >> x;
        v.insert(x);
    }
    while (v.size() > 1) {
        auto itr = v.begin();
        double next = *itr;
        itr = v.erase(itr);
        next += *itr;
        v.erase(itr);
        v.insert(next/2.0);
    }
    auto itr = v.begin();
    cout << fixed << setprecision(10) << *itr << 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 main(){
  int n,d;
  cin >> n >> d;
  vector<double> x(n),y(n);
  int ans=0;
  for(int i=0;i<n;i++){
    cin >> x.at(i) >> y.at(i);
  }
  for(int i=0;i<n;i++){
    double dis=sqrt(x.at(i)*x.at(i)+y.at(i)*y.at(i));
    if(dis<=d){
      ans++;
    }
  }
  cout << ans;
}


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

///////////////////////////////////////////
//const long long int INF = 1000000000000000000LL;
const long long int INF = 1000000;
using ll = long long int;
using vi = vector<int>;
using Vi = vector<long long int>;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
auto max(auto x,auto y){if(x>y){return x;}else{return y;}}
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return 1; } return 0; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return 1; } return 0; }
template<class T>T sqar(T x){ return x*x; }
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(    v[0])>()) //降順でVをソート
///////////////////////////////////////////

ll n,ma,mb;
vi a,b,c;
ll dp[50][401][401]; //dp[i][j][k] := i番目まででaがj,bがkとなる最小の値段
/*
 * dp[i][j][k] = min(dp[i-1][j][k],dp[i-1][j-a[i]][
 */
void cal(int num,int x,int y){
    // cout<<"num,x,y : "<<num<<" , "<<x<<" , "<<y<<" , "<<dp[num][x][y]<<endl;
    if(num>=n) {

    }else{
        if(dp[num][x][y]==INF){}else {
            chmin(dp[num + 1][x + a[num]][y + b[num]], dp[num][x][y] + c[num]);
            chmin(dp[num + 1][x][y], dp[num][x][y]);
            cal(num + 1, x, y);
            cal(num + 1, x + a[num], y + b[num]);
        }
    }
}

int main(){
    cin>>n>>ma>>mb;
    int aa,bb,cc;
    rep(i,50)rep(j,401)rep(k,401)dp[i][j][k]=INF;
    dp[0][0][0]=0;
    //ll key = 0;
    rep(i,n){
        cin>>aa>>bb>>cc;
        a.pb(aa);
        //key+=aa;
        b.pb(bb);
        c.pb(cc);
    }
    rep(i,n)rep(j,401)rep(k,401){
                if(dp[i][j][k]==INF)continue;
                chmin(dp[i+1][j][k],dp[i][j][k]);
                chmin(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i]);
            }
    ll ans = INF;
    for(int i =1;i<50;i++){
        if(ma*i>490 || mb*i>490){
            break;
        }else{
            if(ma*mb==mb*ma)chmin(ans,dp[n][ma*i][mb*i]);
        }
    }
    if(ans==INF){
        cout<<-1<<endl;
    }else{
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 63104
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX_N 100000
#define MAX_M 100000
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecbvecb vector<vector<bool>>
#define vecst vector<string>
#define vecch vector<char>
#define vecf vector<float>
#define vecvec vector<vector<int>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
const int INF = 1e9;
#define PI 3.141592653589793
// cout << setprecision(15) << std::fixed;


int main() {
  cout << setprecision(15) << std::fixed;
  int n;
  cin>>n;
  float X[n],Y[n],c=0,ans=0;
  for(int i=0;i<n;i++) cin>>X[i]>>Y[i];
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i==j) continue;
      ans+=sqrtf((X[i]-X[j])*(X[i]-X[j])+(Y[i]-Y[j])*(Y[i]-Y[j]));
      c+=1.0;
    }
  }
  cout<<ans/c*(n-1)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main(){
	ll n,a,b;
	cin>>n>>a>>b;
	if(n==1){
		if(a!=b){
			cout << 0;
		}
		else{
			cout << 1;
		}
		return 0;
	}
	ll mi=a*(n-1)+b;
	ll ma=a*1+b*(n-1);
	if(b<a){
		cout << 0;
		return 0;
	}
	cout << ma-mi+1;
}

Measured memory_bytes: 256
from collections import deque
import sys
sys.setrecursionlimit(10**7)
n=int(input())
d=[10**20 for i in range(n)] 
g=[[] for i in range(n)]
for _ in range(n-1):
    a,b,c = map(int,input().split())
    g[a-1].append([b-1,c])
    g[b-1].append([a-1,c])
q,k = map(int,input().split())
k-=1
f=[False for i in range(n)]
d[k]=0

def dfs(s,c):
    f[s]=True
    d[s]=c
    for sg in g[s]:
        if not f[sg[0]]:
            dfs(sg[0],c+sg[1])
dfs(k,0)

lq=[]
for _ in range(q):
    lq.append(list(map(int,input().split())))
for sq in lq:
    print(d[sq[0]-1]+d[sq[1]-1])


Measured memory_bytes: 205600
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
#define F first
#define S second
#define MK make_pair
const ll E=1e17+7;
const ll MOD=1000000007;



int main(){
    ll n;
    cin>>n;
    string s[2];
    cin>>s[0]>>s[1];
    vector<ll> a;
    for(int i=0;i<n;i++){
        if(s[0][i]==s[1][i]){a.push_back(0);}
        else{a.push_back(2); i++;}
    }
    ll ans=1;
    ans*=(a[0]==0?3:6);
    for(int i=1;i<a.size();i++){
        if(a[i]==0 && a[i-1]==0){ans*=2;}
        if(a[i]==0 && a[i-1]==2){ans*=1;}
        if(a[i]==2 && a[i-1]==0){ans*=2;}
        if(a[i]==2 && a[i-1]==2){ans*=3;}
        ans%=MOD;
    }
    cout<<ans<<endl;
    
    
    return 0;
}


Measured memory_bytes: 256
/*input
3
28 3
16 4
19 2
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

int main()
{
	int n;
	cin>>n;
	int SG=0;
	REP(i,n){
		ll a,k;
		cin>>a>>k;
		while(a%k){
			int tmp=1+a/k;
			if((a%k)%tmp==0) a=a/k*k;
			else a-=((a%k)/tmp+1)*tmp;
		}
		SG^=a/k;
	}
	if(SG) cout<<"Takahashi\n";
	else cout<<"Aoki\n";
	return 0;
}


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

using namespace std;

#define pb push_back
#define fo(i, n) for(int i = 1; i <= n; ++i)

typedef long long ll;
typedef long double ld;

const int N = 500200;
const int mod = 1e9 + 7;
int n;
string s;
int e[N];

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n >> s;
    s = '#' + s;
    for(int i = 1; i <= n; ++i)
        e[i] = e[i-1] + (s[i] == 'W');
    int w = 0, ans = n;
    for(int i = n; i >= 1; --i) {
        ans = min(ans, e[i-1] + w);
        w += (s[i] == 'E');
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1900
#include<bits/stdc++.h>
#define mx 5005
#define inf 100000000000005
using namespace std;

int n;
long long h, p, dp[mx];
pair<long long, long long> hp[mx];

int main(){
  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    scanf("%d%d", &h, &p);
    hp[i] = make_pair(h+p, p);
  }
  sort(hp, hp+n);
  fill(dp+1, dp+n+1, inf);
  for(int i = 0; i < n; i++) for(int j = i; j >= 0; j--)
    if(dp[j] + hp[i].second <= hp[i].first) dp[j+1] = min(dp[j+1], dp[j] + hp[i].second);
  int ans = lower_bound(dp, dp+n+1, inf) - dp - 1;
  printf("%d\n", ans);
}

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

int k, n;

bool decrement(std::vector<int>&, int);

int main()
{
	scanf("%d%d", &k, &n);
	if (~k & 1)
	{
		printf("%d", k / 2);
		for (int i{}; i < n - 1; i++)
			printf(" %d", k);
		putchar('\n');
		return 0;
	}
	if (k == 1)
	{
		for (int i{}; i < (n + 1) / 2; i++)
			printf("1%c", i==(n+1)/2-1?'\n':' ');
		return 0;
	}
	std::vector<int> ans(n, k / 2 + 1);
	int delta{n - 1};
	while (delta > 0)
	{
		decrement(ans, n - 1);
		delta -= 2;
	}
	while (!ans.back()) ans.pop_back();
	for (unsigned int i{}; i < ans.size(); i++)
		printf("%d%c", ans[i], i==ans.size()-1?'\n':' ');

	return 0;
}

bool decrement(std::vector<int>& ans, int index)
{
	if (ans[index])
	{
		ans[index]--;
		return ans[index] > 0;
	}
	
	bool positive{decrement(ans, index - 1)};
	if (positive)
		ans[index] = k;
	return positive;
}

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

typedef int number;

int c;
string str;

void debug(string str) {
//  cout << str << endl;
}

int minimum(vector<number> v, int n) {
  sort(v.begin(), v.end());

  int sum = 0;
  REP(i, n) {
    sum += v[i];
  }
  return sum;
}

/*
 * A -> "[" A* "]" | Num
 * Num -> Digit*
 */

number A();
number Num();

number A() {
  debug("A:" + str.substr(c));
  if (str[c] == '[') {
    c++; // read [
    int p;
    vector<number> children;
    while (p = c, (str[p] == '[' || isdigit(str[p]))) {
      number a = A();
      children.push_back(a);
    }
    c++; // read ]
    int len = children.size();
    return minimum(children, (1 + len) / 2);
  } else {
    number num = Num();
    return num;
  }
}

number Num() {
  debug("Num:" + str.substr(c));
  int val = 0;
  while (isdigit(str[c])) {
    val = val * 10 + (str[c] - '0');
    c++;
  }
  return (1 + val) / 2;
}

int main() {
  int n;
  cin >> n;
  REP(i, n) {
    cin >> str;
    c = 0;

    cout << A() << endl;
  }
}

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

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

Measured memory_bytes: 256
N, K = map(int, input().split())
S = input()
S = '1' + S + '1'
rev = []
for i in range(N+1):
    if S[i] != S[i+1]:
        rev.append(i)
l = len(rev)//2
a = [(rev[2*i], rev[2*i+1]) for i in range(l)]

a = [(0, 0)] + a + [(N, N)]
K = min(K, l)

m = -1
for i in range(l-K+1):
    x = a[i+K+1][0]-a[i][1]
    m = max(m, x)

print(m)

Measured memory_bytes: 45440
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

n = int(input())
s = [input() for i in range(n)]
for k in range(n):
    s[k]=sorted(list(s[k]))
s=sorted(s)

c = 1
count = 0

for x in range (n-1):
        if s[x]==s[x+1]:
            c += 1
        else:
            if c>= 2:
                count += cmb(c,2)
            c = 1
if c >=2:
    count += cmb(c,2)
print(count)


Measured memory_bytes: 25432
#include <iostream>
#include <vector>
#include <algorithm>
//#include <numeric>
using namespace std;

int gcd(int a, int b) {
    while(b != 0) {
        int c = a % b;
        a = b;
        b = c;
    }
    return a;
}

int main(void){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    if(N == 2){
        cout << max(A[0], A[1]) << endl;
        return 0;
    }
    
    vector<int> gcd_l(N), gcd_r(N);
    gcd_l[0] = A[0];
    gcd_r[N-1] = A[N-1];
    for(int i=1; i<N; i++){
        gcd_l[i]=gcd(gcd_l[i-1], A[i]);
        gcd_r[N-1-i]=gcd(gcd_r[N-i], A[N-1-i]);
    }
    int ans=max(gcd_l[N-2], gcd_r[1]);
    for(int i=1, v; i<N-1; i++){
        v = gcd(gcd_l[i-1], gcd_r[i+1]);
        if(v > ans) ans = v;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1408
#include <iostream>
using namespace std;
int main() {
    int a, b;
    cin >> a >> b;
    if(a >= 13){
        cout << b << endl;
    } else if (a >= 6){
        cout << b/2 << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n,q = map(int,input().split())
yoko = [-n]
yoko2 = [-n]
yokol = 1
tate = [-n]
tate2 = [-n]
tatel = 1
last = [n,n]
import bisect
ans = (n-2)**2
#print(ans)
for _ in range(q):
  a,c = map(int,input().split())
  if a == 1:
    b = bisect.bisect_left(yoko,-c)
    if b == yokol:
      yoko.append(-c)
      yoko2.append(-last[0])
      yokol += 1
      last[1] = c
      ans -= last[0]-2
    else:
      ans -= -yoko2[b] - 2
  if a == 2:
    b = bisect.bisect_left(tate,-c)
    if b == tatel:
      tate.append(-c)
      tate2.append(-last[1])
      tatel += 1
      last[0] = c
      ans -= last[1]-2
    else:
      ans -= -tate2[b] - 2
  #print(yoko)
  #print(yoko2)
  #print(tate)
  #print(tate2)
print(ans)

Measured memory_bytes: 100784