akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define mod 1000000007
#define F first
#define S second
#define mk make_pair
#define B(v) v.begin(), v.end()

int n,k;
char a[53][53];

int f(int ii,int jj)
{
	int co=0;
	for(int i=ii-1;i<=ii+1;i++)
	{
		for(int j=jj-1;j<=jj+1;j++)
		{
			
				if(a[i][j]=='#')
				{
					co++;
				}
			
		}
	}
	return co;
}


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

	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=k;j++)
		{
			if(a[i][j]=='#')
			{
				cout<<'#';
			}
			else
			{
				cout<<f(i,j);
			}
		}
		cout<<endl;
	}
}

Measured memory_bytes: 256
using namespace std;
#include <bits/stdc++.h>
#define frr(i, r, l) for(int i = r; i >= l; --i)
#define fr(i, l, r) for(int i = l; i < r; ++i)
#define forit(it, type, var) for(type::iterator it = var.begin(); it != var.end(); it++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define MEMS(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define m_p make_pair
#define pb push_back
#define ll long long
#define ld long double
typedef pair<ll, ll> iPair; 
priority_queue< ll, vector <ll> , greater<ll>>pq1,pq2;
#define maxN 1000000000000000000
ll power(ll a,ll b){ll res=1;while(b>0){res*=a;b--;}return res;}
int main()
{
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k,ar1[200005],ar2[200005],visit[200005]={0};
    vector<ll>v[5005];
    cin>>n>>k;

    fr(i,1,n+1)
    {
        cin>>ar1[i];
    }
    fr(i,1,n+1)
    {
        cin>>ar2[i];
    }
    ll p=0,g;
    fr(i,1,n+1)
    {
        ll j=i;
        ll ct=0;
        while(visit[ar1[j]]==0)
        {
            ct++;
            g=ar1[j];
            visit[g]=1;
            v[p].pb(ar2[g]);
            j=g;
        }
        if(ct>0)
        p++;
    }
    
    ll sum,st,q,ans,ansf=-maxN;
    fr(i,0,p)
    {
        fr(l,0,v[i].size())
        {
            sum=0;
            fr(j,0,v[i].size())
            {
                sum+=v[i][j];
            }
            if(k<=v[i].size())
            {
                
                ans=0;
                st=-maxN;
                fr(j,l,l+k)
                {
                    q=j%v[i].size();
                    ans+=v[i][q];
                    st=max(st,ans);
                }
                ansf=max(ansf,st);
            }
            else
            {
                
                ll st1=k-v[i].size();
                ll st2=st1/v[i].size();
                ans=0;
                if(sum>0)
                {
                    ans+=st2*sum;
                }
                st2=k%v[i].size();
                ll temp=0;
                st=-maxN;
                fr(j,l,l+st2)
                {
                    q=j%v[i].size();
                    temp+=v[i][q];
                    st=max(st,temp);
                }
                
                st1=sum+st;
                ll tmp=0;
                fr(j,l,l+v[i].size())
                {
                    q=j%v[i].size();
                    tmp+=v[i][q];
                    st1=max(st1,tmp);
                }
                ans+=st1;
                
                ansf=max(ansf,ans);
            }
        
        }
    }
    cout<<ansf<<endl;
    return 0;
}



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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K; cin >> N >> K;
    vector<ll> A(N);
    for (int i=0;i<N;++i) cin >> A[i];
    sort(A.begin(),A.end());
    ll ub=1e18,lb=-ub; ++ub,--lb;
    while(ub-lb>1){
        ll mid=(ub+lb)>>1LL,cnt=0;
        for (int i=0;i<N;++i){
            if (A[i]==0){
                if (0<=mid) cnt+=N-1;
                continue;
            }
            if (A[i]>0) cnt+=upper_bound(A.begin(),A.end(),mid/A[i]+(mid<0&&mid%A[i]!=0?-1:0))-A.begin();
            else cnt+=A.end()-lower_bound(A.begin(),A.end(),mid/A[i]+(mid<0&&mid%A[i]!=0?1:0));
            if (A[i]*A[i]<=mid) --cnt;
        }
        cnt/=2;
        (K<=cnt?ub:lb)=mid;
    }
    cout << ub << endl;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
#define N 100000
int height(int);
struct Node{
  int parent;
  int left;
  int right;
};
struct Node T[N];
int H[N];
int main(){
  
  int n,j,p,i,d,s,t,a,id,b,k,l,r,re,re1,sum,ty,MAX=0;
  
  scanf("%d",&n);
  
  

  for(i=0;i<n;i++){
    T[i].right=T[i].left=T[i].parent=-1;
  }
  
  for(i=0;i<n;i++){
    scanf("%d",&id);
    scanf("%d%d",&l,&r);
    T[id].left=l;
    T[l].parent=id;
    T[id].right=r;
    T[r].parent=id;
    
  }
  printf("Preorder\n");
  for(i=0;i<n;i++){
    if(T[i].parent==-1)
      preorder(i);
  }
  printf("\n");
 printf("Inorder\n");
  for(i=0;i<n;i++){
    if(T[i].parent==-1)
      inorder(i);
  }
  printf("\n");
  printf("Postorder\n");
  for(i=0;i<n;i++){
    if(T[i].parent==-1)
      postorder(i);
  }
  printf("\n");
  
  
  return 0;
}


int preorder(int x){
  if(x!=-1){
    printf(" %d",x);
    preorder(T[x].left);
    preorder(T[x].right);
  }
}

int inorder(int x){
  if(x!=-1){
    inorder(T[x].left);
    printf(" %d",x);
    inorder(T[x].right);
  }
}

int postorder(int x){
  if(x!=-1){
    postorder(T[x].left);
    postorder(T[x].right);
    printf(" %d",x);
  }
}

Measured memory_bytes: 620
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <ctime>
#include <string>
#include <map>
using namespace std;

int main(void){
	map<string, int> table;
	string word, frequent, longest;
	int N = 0;
	while(cin >> word){
		table[word] += 1;
		if(table[word] > N){
			N = table[word];
			frequent = word;
		}

		if(word.size() > longest.size()){
			longest = word;
		}
	}

	cout << frequent << " " << longest << endl;
	
    return 0;
}

Measured memory_bytes: 1196
#include<iostream>
using namespace std;
 
int main(){
    int n, a, b;
    int sa, sb;
     
    while(1){
        cin >> n;
        if(n==0) break;
        sa=0; sb=0;
         
        for(int i=0;i<n;i++){
            cin >> a >> b;
            if(a>b) sa += (a+b);
            else if(a<b) sb += (a+b);
            else{
                sa += a;
                sb += b;
            }
        }
         
        cout << sa << " " << sb << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
    using namespace std;
    #define ll long long int
    #define pb push_back
    #define mk make_pair
    #define ft first
    #define sc second
    #define ppb pop_back
    #define sz size
    #define forn(i,a,n) for(i=a;i<n;i++)
    #define M 1000000007
    #define inf 2e18
    
    int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    map<ll,ll> m;
    for(ll i=1;i<=9;i++){
        for(ll j=i;j<=9;j++){
            m[i*j]=1;
        }
    }
    ll c;
    cin>>c;
    if(m[c]==1)cout<<"Yes\n";
    else
        cout<<"No\n";

    return 0;
    } 

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

#define ipr pair<int, int>
#define pb push_back
#define ff first
#define ss second
#define fr(i, j, k) for (int i = j; i < k; i++)
#define rf(i, j, k) for (int i = j; i >= k; i--)
#define ll unsigned long long
#define int long long
#define ld long double
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mp make_pair
#define cnt_ones(x) __builtin_popcountll(x)

#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

const int Maxn = (int)1e6+1;
const ld pi = acos(-1);
int mod = (int)1e9 + 7;
const int inf = (int)1e18;

template <class T>
ostream &operator<<(ostream &out, vector<T> &A) {
    fr(i, 0, (int)A.size()) out << A[i] << " ";
    return out;
}

template <class T1, class T2>
ostream &operator<<(ostream &out, map<T1, T2> &A) {
    for (auto x : A) cout << x.ff << " # " << x.ss << endl;
    return out;
}


int32_t main() {
    IOS
    int n,d,cnt=0;    cin>>n>>d;
    while(n--){
        int x,y;    cin>>x>>y;
        double temp = sqrt(x*x+y*y);
        if(temp <= d)   cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3680
targ = input().split(' ')
mostfre = {}
ansfre = ""
longest = [0,""]
for t in targ:
    if len(t) > longest[0]:
        longest[0],longest[1] = len(t),t
    mostfre[t] = mostfre.get(t,0) + 1
temp = 0
for k,v in mostfre.items():
    if v > temp:
        temp = v
        ansfre = k
print(ansfre + ' ' + longest[1])

Measured memory_bytes: 7368
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

k,a,b=nii()

num=1
if b-a<=1:
  print(num+k)
  exit()

if num<a:
  k-=a-num
  num+=a-num

cnt=k//2
if k%2==0:
  num+=(b-a)*cnt
else:
  num+=(b-a)*cnt+1

print(num)

Measured memory_bytes: 9080
n = gets.to_i
as = gets.split.map(&:to_i)

odd = []
even = []
as.length.times do |i|
    odd.push(as[i]) if i % 2 == 1
    even.push(as[i]) if i % 2 == 0
end

if n % 2 == 1
    puts (even.reverse + odd).join(' ')
else
    puts (odd.reverse + even).join(' ')
end

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

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

using namespace std;

const int INF=1<<29;

int main(){
	string s; cin>>s;
	int n=s.length();

	int dp[200001][2]={}; // dp[i][j] = (s[0,i) について, 分割した一番右の文字列が長さ j+1 であるような最大分割数)
	for(int i=1;i<=n;i++){
		// 1 文字で分割
		dp[i][0]=dp[i-1][1]+1;
		if(i>=2 && s[i-1]!=s[i-2]) dp[i][0]=max(dp[i][0],dp[i-1][0]+1);

		// 2 文字で分割
		dp[i][1]=-INF;
		if(i>=2) dp[i][1]=dp[i-2][0]+1;
		if(i>=4 && s.substr(i-2,2)!=s.substr(i-4,2)) dp[i][1]=max(dp[i][1],dp[i-2][1]+1);
	}

	printf("%d\n",max(dp[n][0],dp[n][1]));

	return 0;
}


Measured memory_bytes: 2180
a = input()
kazu = 0
a = [int(i) for i in a]
if a[0]==0:
    check = [ 0 if i%2==0 else 1 for i in range(len(a))]
else:
    check = [ 1 if i%2==0 else 0 for i in range(len(a))]
for i in range(len(a)):
    if a[i]!=check[i]:
        kazu+=1
print(kazu)

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

int main() {
	int d;cin>>d;
  if(d==22)cout<<"Christmas Eve Eve Eve";
  if(d==23)cout<<"Christmas Eve Eve";
  if(d==24)cout<<"Christmas Eve";
  if(d==25)cout<<"Christmas";
}

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

#define  int    long long int
 #define    sp(x)                 setprecision(x)
#define    bp(x)           __builtin_popcount(x)
 #define  ld         long double
 #define  f(i,j,n)            for(int i = j; i <= n; i++)
#define  r(i,n,j)       for(int i = n; i >= j; i--)
 #define  all(container)       container.begin() , container.end()
#define  sz(container)   (int)container.size()
 #define  ff         first
#define  ss    second
 #define  pii      pair <int , int>
#define  sp(x)       setprecision(x)
 #define  endl    "\n"
#define  mod  1000000007
 #define  pb    push_back
#define  mp    make_pair
 #define  T     int ttt; cin >> ttt; while(ttt--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);

int32_t main()
{
    fast
    int n,k;
    cin>>n>>k;
    int a[n+1],b[n+2];
    f(i,1,n)
        cin>>a[i];
    while(k--)
    {
        f(i,0,n+1)
            b[i]=0;
        f(i,1,n)
        {
            int x=max(1LL,i-a[i]);
            b[x]++;
            x=min(n+1,i+a[i]+1);
            b[x]--;
        }
        f(i,1,n)
            b[i]+=b[i-1];
        int c=1;
        f(i,1,n)
        {
            a[i]=b[i];
            if(a[i]<n)
                c=0;
        }
        if(c)
            break;
    }
    f(i,1,n)
        cout<<a[i]<<" ";
}

Measured memory_bytes: 6740
process.stdin.resume();
process.stdin.setEncoding('utf8');
 
// inputに入力データ全体が入る
function Main(input) {
  // 1行目がline1, 2行目がline2, …に入る
  var arg   = input.split("\n");
  var line0 = arg[0].split(" ");
  //var line1 = arg[1].split(" ");
  //var line2 = tmp[2].split(" ");
  //var line3 = tmp[3].split(" ");

  var input1 = Number(line0[0]);
  //var input2 = Number(line0[1]);
  //var input3 = Number(line0[2]);
  var n = String(input1);
//  var a = input2;
  //var b = input3;

  var ans = "initial_answer";
  //console.log( "[INPUT] "+ n +" "+ a +" "+ b + "");
  
  // LOGIC //
  ans = "No";
  var len = n.length;
  var fx = 0;
  for(var i=0; i<len; i++){
    fx += Number(n[i]);
    //console.log("fx: " + fx);
  }
  if(Number(n) % fx === 0) ans = "Yes";
  //console.log( "[INPUT] "+ n +" "+ fx +" "+ ans + "");

  console.log(ans);


  


}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7500
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin >> A>>B;
  C=max(A,B);
  D=min(A,B);
  if((C-D)%2!=0)cout<<"IMPOSSIBLE"<<endl;
  else cout << D+(C-D)/2 <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Rep(i,j,n) for(int i=j; i<n; i++)
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100//000000000
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
#define T tuple<int,int,int> 
using namespace std;
 
int main(){
  ll n,m; cin >> n >> m;
  ll ans=0;
  if(n==1 && m==1) ans=1;
  else if(n==1 || m==1) ans=max(n,m)-2;
  else ans=max((ll)0,n*m-n-m-n-m+4);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
#include<stdlib.h>
int main()
{
	int sec=0, h=0, m=0, s=0;
	scanf("%d",&sec);

    h = (sec/3600); 
	
	m = (sec -(3600*h))/60;
	
	s = (sec -(3600*h)-(m*60));
	
	printf("%d:%d:%d\n",h,m,s);
	
	return 0;
}


Measured memory_bytes: 2112
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int main(){
 int n,k;cin>>n>>k;
 int ans=(n-k);
 if(ans<0) ans=0;
 if(k==1) ans=0;
 cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
#define ll long long
using namespace std;

int main()
{
    int n;
    cin >> n;
    int flag = 0;
    while(n > 0)
    {
    	int rem = n % 10;
    	if(rem == 7)
    		flag = 1;
    	n = n / 10;
    }
    if(flag == 1)
    	cout << "Yes" << endl;
    else
    	cout << "No" << endl;
}

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

int main() {
  int N, K;
  vector<ll> H;

  cin >> N >> K;

  ll x; 
  for (int i = 0; i < N; i++) {
    cin >> x;
    H.push_back(x);
  }

  sort(H.rbegin(), H.rend());

  for (int i = 0; i < K && i < H.size(); i++) {
    H[i] = -1; //death
  }

  ll cnt = 0;
  for (int i = 0; i < H.size(); i++) {
    if (H[i] != -1) {
      cnt += H[i];
    }
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 2420
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
    a[i] -= i + 1
a.sort()
b1 = a[n // 2]
b2 = a[(n // 2 ) - 1]
r1=0
r2=0
for i in range(n):
    r1+=abs(a[i]-b1)
    r2+=abs(a[i]-b2)
print(min(r1,r2))

Measured memory_bytes: 26020
use std::io::prelude::*;

fn main() {
    let mut input_str = String::new();
    std::io::stdin().read_to_string(&mut input_str).unwrap();

    let input_parts = input_str.split_whitespace().collect::<Vec<_>>();
    let mut input_parts_it = input_parts.iter().cloned();
    let mut next = || input_parts_it.next().unwrap();

    let h: usize = next().parse().unwrap();
    let w: usize = next().parse().unwrap();
    let a_map: Vec<i32> = (0..(w * h)).map(|_| next().parse().unwrap()).collect();
    let b_map: Vec<i32> = (0..(w * h)).map(|_| next().parse().unwrap()).collect();

    let idx = |x: usize, y: usize| x + y * w;

    let mut costs: Vec<Vec<i32>> = vec![Vec::new(); a_map.len()];

    let mut buf = Vec::new();

    for y in 0..h {
        for x in 0..w {
            buf.clear();

            if x == 0 && y == 0 {
                buf.push(0);
            }
            if x > 0 {
                buf.extend(costs[idx(x - 1, y)].iter().cloned());
            }
            if y > 0 {
                buf.extend(costs[idx(x, y - 1)].iter().cloned());
            }

            let (a, b) = (a_map[idx(x, y)], b_map[idx(x, y)]);

            let out_cost = &mut costs[idx(x, y)];
            out_cost.reserve(buf.len() * 2);
            out_cost.extend(buf.iter().map(|&x| x + (a - b)));
            out_cost.extend(buf.iter().map(|&x| x + (b - a)));
            out_cost.sort();
            out_cost.dedup();
        }
    }

    let goal = costs.last().unwrap();

    let best = goal.iter().map(|&cost| cost.abs()).min().unwrap();

    println!("{}", best);
}


Measured memory_bytes: 766204
Signal.trap(:INT){
  exit(0)
}

while come = gets
	a = ["aa","bb"]
	siz = 1 #keta
	a = come.split(" ")

	sum = a[0].to_i + a[1].to_i 

	for i in (1..10)
		 if siz > sum
	 		puts i-1
	 		break
	 	end
	 	siz *= 10
	end

end

Measured memory_bytes: 6100
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define all(x) (x).begin(),(x).end()

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i,N)cin >> A[i];
    int count = 1;
    int now = 0;
    REP(i,N){
        if(count == A[i]){
            count++;
            now++;
        }
    }
    if(now != 0){
        cout <<N-now<< "\n";
    }else{
        cout <<-1<< "\n";
    }
}

Measured memory_bytes: 1024
<?php
$in = explode(" ",trim(fgets(STDIN)));
$a = $in[0];
$b = $in[1];
$c = $in[2];
if($c > $b)
{
    if($b > $a)
    {
        echo "Yes\n";
    }
    else {
        echo "No\n";
    }
}
else {
    echo "No\n";
}

Measured memory_bytes: 15196
a,b,c=map(int,input().split())
ans=0
while a%2==0 and b%2==0 and c%2==0:
  d,e,f=0,0,0
  d=(b+c)//2
  e=(a+c)//2
  f=(a+b)//2
  a,b,c=d,e,f
  ans+=1
  if ans==100000:
    ans=(-1)
    break
print(ans)


Measured memory_bytes: 9184
#include <iostream>
#include <string>

using namespace std;

int main() {
    string s;   cin >> s;
    int len = s.length();
    int *ans = new int[len];
    for (int i = 0; i < len; ) {
        int r = 0, l = 0;
        while (i < len && s[i] == 'R') {
            ans[i] = 0;
            i++;
            r++;
        }
        int j = i;
        while (j < len && s[j] == 'L') {
            ans[j] = 0;
            j++;
            l++;
        }
        ans[i-1] = (r+1)/2 + l/2;
        ans[i] = r/2 + (l+1)/2;
        i = j;
    }

    for (int i = 0; i < len; i++)
        cout << ans[i] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 1088
#include<iostream> 
using namespace std; 
  
int main ()
{
  int a,b,sum;
  cin>>a>>b;
  sum=a+b;
  if (sum>=24)
  {
      sum=sum-24;
      cout<<sum<<"\n";
  }
  else  
  {
      cout<<sum<<"\n";
  }
    return 0;
}

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

int A[1001][1001];
int n;
int arr[1001];

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
		
	queue <pair<int,int>> que;
	int cnt = 0;
	int res = 1;

	cin >> n;

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

	memset(arr,0,sizeof(arr));
	
	for(int i=1;i<=n;i++)
	{
		int turn = arr[i];
		int j = A[i][turn];
		int turn2 = arr[j];
		if(A[j][turn2]==i && i<j)
		{
			//cout << i << ' ' << j << '\n';
			que.push(make_pair(i,j));
		}
	}	

	while(1)
	{
		if(que.empty())
		{
			cout << -1 << '\n';
			return 0;
		}

		int s = que.size();
		while(s--)
		{
			int x = que.front().first;
			int y = que.front().second;
			que.pop();
			arr[x]++;
			arr[y]++;
			cnt++;
			for(int i=1;i<=n;i++)
			{
				int turn = arr[x];
				int turn2 = arr[i];
				//cout << x << ' ' << i << ' ' << turn << ' ' << turn2 << ' ' << A[i][turn2] << ' ' << A[x][turn] << '\n';
				if((A[x][turn]==i && A[i][turn2]==x))
				{
					//cout << i << ' ' << x << '\n';
					que.push(make_pair(i,x));
				}
			}
			for(int i=1;i<=n;i++)
			{
				int turn = arr[y];
				int turn2 = arr[i];
				if((A[y][turn]==i && A[i][turn2]==y))
				{
					que.push(make_pair(i,y));
				}
			}			
		}
		if(cnt==n*(n-1)/2)
		{
			break;
		}
		res++;
	}

	cout << res << '\n';
	return 0;	
}

Measured memory_bytes: 4224
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

#define sz(x) (int)(x.size())
#define fr(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define mp make_pair
typedef pair<int, int> pii;
////////////////////////

int const N = 541;
int const M = N * N;

int n, ans[M], cnt[N], x[N], g[M];
vector<pii> a;

void bad(){
	cout << "No" << endl;
	exit(0);
}

void print(){
	cout << "Yes" << endl;
	fr(i, 0, n*n){
		cout << ans[i] << " ";
	}
}

void tryPlace(int p, int v){
	if(p >= n * n) bad();
	if(ans[p] != 0) bad();
	ans[p] = v;
	++cnt[v];
}

void solve(){
	cin >> n;
	fr(i, 0, n){
		cin >> x[i];
		--x[i];
		g[x[i]] = 1;
		tryPlace(x[i], i+1);
		a.pb(mp(x[i], i+1));
	}

	sort(a.begin(), a.end());
	int p = 0;
	fr(i, 0, n){
		int rem = a[i].second - 1;
		while(rem > 0){
			--rem;
			while(ans[p] != 0) ++p;
			if(p > a[i].first) bad();
			tryPlace(p, a[i].second);
		}
	}
	vector<int> st;
	p = 0;
	while(p < n * n){
		if(ans[p] == 0){
			if(sz(st) == 0) bad();
			tryPlace(p, st.back());
			if(cnt[st.back()] == n) st.pop_back();
		}else{
			if(g[p] && cnt[ans[p]] < n) st.pb(ans[p]);
		}
		++p;
	}
	fr(i, 1, n+1) if(cnt[i] != n) bad();
	print();
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();


	return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  VEC<int> C(N);
  VEC<VEC<int>> A(N, VEC<int>(M, 0));
  REP(i, 0, N) {
    cin >> C[i];
    REP(j, 0, M) { cin >> A[i][j]; }
  }
  LL mi = LLONG_MAX;
  REP(bit, 0, 1 << N) {
    VEC<int> U(M, 0);
    LL cand = 0;
    REP(i, 0, N) {
      if ((bit >> i) & 1) {
        cand += C[i];
        REP(j, 0, M) { U[j] += A[i][j]; }
      }
    }
    bool all = 1;
    REP(i, 0, M) {
      if (U[i] < X) {
        all = 0;
        break;
      }
    }
    if (all) mi = min(mi, cand);
  }
  if (mi == LLONG_MAX) {
    cout << -1 << endl;
  } else {
    cout << mi << endl;
  }

  return 0;
}


Measured memory_bytes: 3636
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

const ll INF = 1LL << 50;

int main() {
  ll n, m, k;
  cin >> n >> m >> k;

  rep(i, n + 1) rep(j, m + 1) {
    ll bn = i * m + j * n - 2 * i * j;
    if (bn == k) {
      puts("Yes");
      return 0;
    }
  }

  puts("No");
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n,w;
	cin>>n>>w;
	int wt[n+1],val[n+1];
	for(int i=0;i<n;i++)
		cin>>wt[i]>>val[i];
	ll dp[w+1][n+1];
	for(int i=0;i<=w;i++)
	{
		for(int j=0;j<=n;j++)
		{
			if(i==0 || j==0)
				dp[i][j]=0;
			else if(i-wt[j-1]<0)
				dp[i][j]=dp[i][j-1];
			else
				dp[i][j]=max(dp[i][j-1],val[j-1]+dp[i-wt[j-1]][j-1]);
		}
	}
	cout<<dp[w][n]<<"\n";
}

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

int main() {
    int N;
    cin >> N;
    string S, T;
    cin >> S >> T;

    string ans = S + T;
    int i = 0;
    int j = 0;
    while(i < N*2){
        ans[i] = S[j];
        i++;
        ans[i] = T[j];
        i++;
        j++;
    }
    cout << ans << endl;
}

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

int main(){
  int cnt=0,x,n,j;

  std::cin>>n;

  for(int i=0;i<n;i++){
    std::cin>>x;
    //in the case of x=2
    if(x==2){
      cnt++;
    }

    j=2;

    while(x%j!=0){
      if(j>sqrt(x)){
	cnt++;
	break;
      }

      j++;
    }

  }
  std::cout<<cnt<<"\n";

  return 0;
}



Measured memory_bytes: 3068
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <cstring>
#include <queue>
#include <sys/time.h>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rev(i,n) for(int i=(int)n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SS stringstream
#define bitcount(b) __builtin_popcount(b)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)

#define delete(a,n) a.erase(remove(all(a),n),a.end())
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ( (a)/__gcd((a),(b))*(b) )

template<typename T, typename S> vector<T>& operator<<(vector<T>& a, S b) { a.push_back(b); return a; }
template<typename T> void operator>>(vector<T>& a, int b) {while(b--)if(!a.empty())a.pop_back();}
bool isprime(int n){ if(n<2)return false;  for(int i=2;i*i<=n;i++)if(n%i==0)return false;  return true;} 
ll b_pow(ll x,ll n){return n ? b_pow(x*x,n/2)*(n%2?x:1) : 1ll;}
string itos(int n){stringstream ss;ss << n;return ss.str();}
long long v[6],t[6];
/*
#include <ctime>
#define OFFSET (1311436118)
#define RND(a,b) (int)( (unsigned int)xorshift128()%((b)-(a)+1) + (a))

// V[hÍSvfÌzñBÇÁ©ÅêxKÉè`·é±ÆB
unsigned int seed128[4];

// V[hð^¦éÖ
inline void init_xorshift(unsigned int s){
	for (unsigned int i=0;i<4;++i) seed128[i]=s=1812433253U*(s^(s>>30))+i;
}

// 32bitÌ®ð¶¬
inline unsigned int xorshift128(){
	unsigned int *a = seed128;
	unsigned int  t = (a[0]^(a[0]<<11));
	a[0]=a[1]; a[1]=a[2]; a[2]=a[3];
	return( a[3]=(a[3]^(a[3]>>19))^(t^(t>>8)) );
}


int init(int seed){
	timeval a;
	gettimeofday(&a,NULL);
	if(seed == -1)seed = (time(NULL)-OFFSET)*10000+a.tv_usec / 100;
	init_xorshift(seed);
	return seed;
}

int ppp = 0;
int naive(){
	int poge = 0;
	long long w = *min_element(t,t+3);
	for(int i = 0 ; i <= w ; i++){
		rep(j,3)v[j] = t[j];
		rep(j,3) v[j] -= i;
		int tmp = i + (v[0]/3) + (v[1]/3) + (v[2]/3);
		if(poge < tmp){
			poge = tmp;
			ppp = i;
		}
		
	}
	return poge;
}
*/
int naive2(){
	int poge = 0;
	int w = *min_element(t,t+3);
	for(int i = 0 ; i <= min(3,w) ; i++){
		rep(j,3)v[j] = t[j];
		rep(j,3) v[j] -= i;
		int tmp = i + (v[0]/3) + (v[1]/3) + (v[2]/3);
		if(poge < tmp){
			poge = tmp;
		}
		
	}
	return poge;
}
int main(){
	while(cin >> v[0] >> v[1] >> v[2] >> v[3] >> v[4] >> v[5]){
		if(v[0] == 0 && v[1] == 0 && v[2] == 0 && v[3] == 0 && v[4] == 0 && v[5] == 0) return 0;

		v[0] += v[3];
		v[1] += v[4];
		v[2] += v[5];
		v[3] = v[4] = v[5] = 0;
		rep(j,3)t[j] = v[j];
		long long i = *min_element(v,v+3);
		rep(j,3) v[j] -= i;
		int ans = i + (v[0]/3) + (v[1]/3) + (v[2]/3);
		ans = max(ans,naive2());
		cout << ans << endl;
		/*if(naive() != ans){
			cout << naive() << " " << ans << endl;
			cout << ppp << " " << *min_element(t,t+3) << endl;
		}*/
	}
}

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

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int D = cin.nextInt();
        int X = cin.nextInt();
        for (int i = 0; i < N; i++)
        {
            int a = cin.nextInt();
            int cur = 1;
            while (true)
            {
                if (cur <= D)
                {
                    X++;
                    cur += a;
                }
                else
                {
                    break;
                }
            }
        }

        Console.WriteLine(X);
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }


    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}

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

int main(){
  int n;
  cin >> n;
  map<string, int> M;
  rep(i,n) {
    string s;
    cin >> s;
    M[s]++;
  }
  int maxv = 0;
  for( auto&x: M){
    int v = x.second;
    if(v>maxv) maxv = v;
  }
  for(auto itr = M.begin(); itr != M.end();itr++){
    if(itr->second==maxv) cout << itr->first << endl;
  }
  return 0;
}


Measured memory_bytes: 19224
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int n;
	cin >> n;
	vector<P> a(n);
	ll T,A;
	for(int i = 0; i < n; i++) {
		cin >> T >> A;
		a[i] = mp(T,A); 
	}
	ll z = 1,B = 1;
	for(int i = 0; i < n; i++) {
		ll x = max((a[i].fs + z - 1)/a[i].fs,(a[i].sc + B - 1)/a[i].sc);
		z = x * a[i].fs;
		B = x * a[i].sc;
	}
	cout << z+B << endl;
	// for(int i = 1; i < n; i++) {
	// 	ll lb = 0;
	// 	ll ub = (1<<19) - 1;
	// 	while(ub - lb > 1){
	// 		ll mid = (lb + ub)/2;
	// 		if ((a[i - 1].fs <= a[i].fs * mid) && (a[i - 1].sc <= a[i].sc * mid)){
	// 			ub = mid;
	// 		}
	// 		else{
	// 			lb = mid;
	// 		}

	// 		// cout << a[i].fs << ' ' << a[i].sc << endl;
	// 		// cout << mid <<endl;
	// 	} 
	// 	a[i].fs*= ub;
	// 	a[i].sc *= ub;
	// 	// cout << a[i].fs << ' ' << a[i].sc << endl;
	// }
	// cout << a[n - 1].fs + a[n - 1].sc << endl;
	return 0;
}

Measured memory_bytes: 256
#include <math.h>
#include <assert.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <array>
#include <random>
#include <chrono>
#include <climits>
#include <bitset>
using namespace std ;
#define int long long
#define ii pair<int,int>
#define FAST_IO ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
//const int N = 3e5+7 ;
//const int INF = 1e18 ;
//const int MOD = 1e9 + 7 ;

void solve(){
	int c ;
	cin >> c ;
	if(c>=30){
		cout <<"Yes\n" ;
		return ;
	}
	cout << "No" << endl ;
}

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


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

using namespace std;

int main() {
	int n;
	cin >> n;
	pair <int, int> a[n];
	long long ans = 0;
	for(int i=0; i<n; i++) cin >> a[i].first, a[i].second = i;
	sort(a, a+n);
	for(int i=0; i<n; i++) ans += abs(i - a[i].second)%2;
	cout << ans/2 << endl;
	return 0;
}

Measured memory_bytes: 1024
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <vector>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> II;
typedef pair<LL, II> III;
typedef priority_queue<III, vector<III>, greater<>> Queue;
static const LL INF = 1LL << 60;

LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
LL lcm(LL a, LL b) { return (a / gcd(a, b)) * b; }

#if 0
	auto possible = [&](LL t) {

		return false;
	};
	LL left = 1, right = 1000000000;
	while (right - left > 1) {
		LL mid = (left + right) / 2;
		if (possible(mid)) {
			left = mid;
		} else {
			right = mid;
		}
	}
#endif

void solve(double D, double T, double S) {
	double t = D / S;
	bool ans = t <= (T + 1e-10);
	cout << (ans ? "Yes" : "No") << endl;
}

int main() {
    long long D;
	scanf("%lld", &D);
	long long T;
	scanf("%lld", &T);
	long long S;
	scanf("%lld", &S);
	solve(D, T, S);
	return 0;
}


Measured memory_bytes: 3760
import java.util.Scanner;

/**
 * PrintRectangle
 */
public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int H = sc.nextInt();
            int W = sc.nextInt();
            if (H == 0 && W == 0) {
                break;
            }

            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    System.out.print("#");
                }
                System.out.println();
            }
            System.out.println();
        }

        sc.close();
    }
}


Measured memory_bytes: 32948
/*Author - Shubham Gupta (@shubham107)*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;      typedef vector<int> vi;
typedef vector<vl> vvl;     typedef vector<vi> vvi;
typedef pair<ll, ll> pll;   typedef pair<int, int> pii;
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define INF ll(1e18)
#ifdef SHUBHAM107
#include "../trace.h"
#else
#define trace(args...)
#endif
void solve() {
    int l, r, d, cnt = 0;
    cin >> l >> r >> d;
    for(int i = l; i <= r; i++) {
        if(i % d == 0)
            cnt++;
    }
    cout << cnt;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef SHUBHAM107
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("err.txt", "w", stderr);
#endif
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}


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

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> P(N);
    for (auto& p : P) {
        cin >> p;
    }
    set<int> range_set;
    int down_cnt = 0;
    for (int i = 0; i < K; i++) {
        range_set.insert(P.at(i));
        if (i > 0 and P.at(i - 1) > P.at(i)) {
            down_cnt++;
        }
    }
    int ans = 0;
    bool has_no_down = false;
    if (down_cnt == 0) {
        has_no_down = true;
    } else {
        ans++;
    }
    for (int i = K; i < N; i++) {
        int last_min = *range_set.begin();

        range_set.erase(P.at(i - K));
        range_set.insert(P.at(i));

        int new_max = *range_set.rbegin();

        if (P.at(i - K) > P.at(i - K + 1)) down_cnt--;
        if (P.at(i - 1) > P.at(i)) down_cnt++;

        if (down_cnt == 0) {
            has_no_down = true;
            continue;
        } else if (last_min == P.at(i - K) and new_max == P.at(i)) {
            continue;
        }
        ans++;
    }
    if (has_no_down) ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
int n;
string s[2];
long long dp[60][3][3];
const long long MOD=1000000007LL;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>s[0]>>s[1];
	if(s[0][0]!=s[1][0]){
		for(int i=0;i<3;i++){
			for(int j=0;j<3;j++)if(i!=j){
				dp[2][i][j]=1LL;
			}
		}
	}
	else{
		for(int i=0;i<3;i++){
			dp[1][i][i]=1LL;
		}
	}
	for(int i=1;i<n;i++){
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				if(s[0][i]==s[1][i]){
					for(int z=0;z<3;z++)if(z!=j&&z!=k){
						dp[i+1][z][z]+=dp[i][j][k];
					}
				}
				else{
					for(int z=0;z<3;z++)if(z!=j){
						for(int c=0;c<3;c++)if(c!=k&&c!=z){
							dp[i+2][z][c]+=dp[i][j][k];
						}
					}
				}
			}
		}
	} 
	long long res=0;
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			res+=dp[n][i][j];
		}
	}
	cout<<res%MOD<<endl;
	return 0;
}
/*
52
RvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn
RLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn
*/

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdlib.h>
using namespace std;

int main()
{
	string s;

	cin >> s;

	vector<int> result(s.length());

	for (int i = 0; i < s.length(); i++) {
		result[i] = 0;
	}

	int Rstreek = 0;
	int Lstreek = 0;

	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'R') {
			Rstreek++;
			if (Lstreek != 0) {
				if (Lstreek % 2 == 0) {
					result[i - Lstreek] += Lstreek / 2;
					result[i - Lstreek-1] += Lstreek / 2;
				}
				else {
					result[i - Lstreek] += (Lstreek + 1) / 2;
					result[i - Lstreek - 1] += (Lstreek - 1) / 2;
				}
			}
			Lstreek = 0;
		}
		else if(s[i] == 'L'){
			Lstreek++;
			if (Rstreek != 0) {
				if (Rstreek % 2 == 0) {
					result[i] += Rstreek / 2;
					result[i - 1] += Rstreek / 2;
				}
				else {
					result[i] += (Rstreek - 1) / 2;
					result[i - 1] += (Rstreek + 1) / 2;
				}
			}
			Rstreek = 0;
		}
	}

	if (Lstreek % 2 == 0) {
		result[s.length() - Lstreek] += Lstreek / 2;
		result[s.length() - Lstreek - 1] += Lstreek / 2;
	}
	else {
		result[s.length() - Lstreek] += (Lstreek + 1) / 2;
		result[s.length() - Lstreek - 1] += (Lstreek - 1) / 2;
	}

	for (int i = 0; i < s.length(); i++) {
		cout << result[i] << " ";
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(){
   int a,b,c;
   scanf("%d %d %d",&a,&b,&c);
   if(a==b&&b==c&&c==a){
      printf("No");
   }else if(a==b||b==c||c==a){
      printf("Yes");
   }else{
      printf("No");
   }
   return 0;
}

Measured memory_bytes: 1700
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    string s;
    cin >> s;

    for (auto& c : s) {
        if (c == ',') {
            c = ' ';
        }
    }

    cout << s << '\n';

    return 0;
}

Measured memory_bytes: 3640
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define dcml(n) fixed<<setprecision(n)
using namespace std;
int main(void){
    string s;cin>>s;
    ll N=s.size();
    ll cntp=0;REP(i,N)if(s[i]=='p')cntp++;
    cout<<N/2-cntp<<"\n";
}

Measured memory_bytes: 512
#include<stdio.h>

#define N 100

int main(){
  int m[N][N];
  int n, i, j, u, k, v;

  scanf("%d", &n);

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

  for(i = 0 ; i < n ; i++){
    scanf("%d %d", &u, &k);
    u--;
    for(j = 0 ; j < k ; j++){
      scanf("%d", &v);
	v--;
	m[u][v] = 1;
    }
  }

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

  return 0;
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define pb push_back
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<string> v(n);
  cin >> v[0];
  FOR(i, 1, n){
    cin >> v[i];
    if(v[i - 1].back() != v[i].front()){
      cout << "No" << endl;
      return 0;
    }
    REP(j, i){
      if(v[i] == v[j]){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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


int main(){
    int N;
    cin >> N;
    long long H[N];
    for(int i = 0; i < N; i++) {
        cin >> H[i];
    }

    H[0]--;

    for(int i = 0; i < N-1; i++) {
        if(H[i+1] - H[i] < 0){
            cout << "No" << endl;
            return 0;
        }else if(H[i+1] - H[i] > 0){
            H[i+1]--;
        }
    }
    
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
int asc(const void *a, const void *b)
{
    long *A = (long *)a;
    long *B = (long *)b;
    if (*A > *B)return 1;
    if (*A < *B)return -1;
    return 0;
}
int main()
{
    int n;
    scanf("%d", &n);
    int i;
    long long int a[100005];
    for (i = 0; i < n; i++)
        scanf("%lld", &a[i]);
    qsort(a, n, sizeof(long long int), asc);
    long long int sum = 0;
    for (i = 0; i < n - 1; i++)
        sum += a[i];
    int ans = 1;
    for (i = n - 1; i > 0; i--)
    {
        if (2 * sum < a[i])
            break;
        ans++;
        sum -= a[i - 1];
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1788
from sys import stdin
from sys import setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

def main():
    from builtins import int, map
    n = int(input())
    print(ceil(n / 1000) * 1000 - n)

if __name__ == '__main__':
    main()

Measured memory_bytes: 65212
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main(){
  int n, ans=1;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s.at(i);
  REP(i, n-1){
    if(s[i][0] != s[i-1][s[i-1].size()-1])ans=0;
  }
  sort(all(s));
  REP(i, n-1){
    if(s.at(i) == s.at(i-1))ans = 0;
  }
  if(ans) cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
const int INF = 1e9;

int main() {
  ll n, cnt = 0, ok = 0;
  cin >> n;
  vector<ll> a(n+1, 0), b(n+1, 0);
  rep(i, n+1) cin >> a[i];
  rep(i, n) cin >> b[i];
  rep(i, n+1) {
    if (a[i] >= b[i] + ok) {
      cnt += b[i] + ok;
      ok = 0;
    } else {
      cnt += a[i];
      if (a[i] - ok > 0) {
        ok = b[i] - (a[i] - ok);
      } else {
        ok = b[i];
      }
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 1792
import math
S = input().split(" ")

A = int(S[0])
B = int(S[1])
C = int(S[2])
X = int(S[3])
Y = int(S[4])

def calculate(a,b,c,x,y):


    base = min([x,y])

    values = []
    for index in range(base+1):
        tmp = 2 * C * index + a * (x - index) + b * (y - index)
        values.append(tmp)

    s2 = max([x,y]) * 2 * c
    values.append(s2)

    print(min(values))

calculate(A,B,C,X,Y)

Measured memory_bytes: 7048