akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header
int calc(int t){
	if(t%2 == 0) return t/2;
	else return 3*t+1;
}
int main() {
	int x, y, z;
	cin >> x >> y >> z;
	x-=z;
	cout << x/(y+z) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int h,n;
  cin>>h>>n;
  vector<int> a(n);
  int s=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
  s+=a[i];
  }
if(s>=h){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}
  return 0;
}


Measured memory_bytes: 640
N,Q=map(int,input().split())
S=input()
AC=[0]*N
AC_cnt=0
for i in range(1,N):
    if S[i-1]=='A' and S[i]=='C':
        AC_cnt+=1
    AC[i]=AC_cnt
for _ in range(Q):
    l,r=map(int,input().split())
    ans=AC[r-1]-AC[l-1]
    print(ans)

Measured memory_bytes: 6084
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int N; cin >> N;
    vector<int>l(N);
    vector<int>r(N);
    int ans = 0;
    rep(i, N) {
        cin >> l[i] >> r[i];
        ans += r[i] - l[i] + 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3648
from itertools import groupby
import sys

N, K = map(int, input().split())
S = input()

S = [[i, len(list(j))] for i, j in groupby(S)]

if len(S) // 2 <= K:
    if len(S) % 2 == 1 and S[-1][0] == "0":
        if len(S) == 1:
            print(sum([j for i, j in S]))
            sys.exit()
            
    else:
        print(sum([j for i, j in S]))
        sys.exit()

ans = 0
cnt = 0
lidx = -1
for i, j in S:
    lidx += 1
    if cnt == K and i == "0":
        break
    ans += j
    if i == "0":
        cnt += 1
sidx = 0
mans = ans
for i in range(lidx,len(S)):
    ans += S[i][1]
    if i == len(S)-1 or S[i][0] == "1":
        while True:
            ans -= S[sidx][1]
            sidx += 1
            if S[sidx][0] == "1":
                break
        mans = max(mans, ans)

print(mans)


        
        

Measured memory_bytes: 17796
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N = get_int
P = get_ints

min = P[0]
count = 1

P[1..].each do |p|
  if p <= min
    min = p
    count += 1
  end
end

puts count


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

class Node {
public:    
  int key;
  Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int key) {
  Node *x, *y, *z;

  z = new Node;
  z->key = key;
  z->left = z->right = NIL;
  y = NIL;
  x = root;

  while (x != NIL) {
    y = x;
    if (z->key < y->key) x = x->left;
    else x = x->right;
  }

  z->parent = y;
  if (y == NIL) root = z;
  else if (z->key < y->key) y->left = z;
  else y->right = z;
}

void preorder(Node *node) {
  if (node == NIL) return;
  cout << " " << node->key;
  preorder(node->left);
  preorder(node->right);
}

void inorder(Node *node) {
  if (node == NIL) return;
  inorder(node->left);
  cout << " " << node->key;
  inorder(node->right);
}

void print() {
  inorder(root);
  cout << endl;
  preorder(root);
  cout << endl;
};

bool find(int key) {
  Node *x = root;

  while (x != NIL) {
    if (key < x->key) x = x->left;
    else if (key > x->key)  x = x->right;
    else return true;
  }
  
  return false;
}

int main() {
  int i, m, key;
  string command;

  cin >> m;
  for (i = 0; i < m; i++) {
    cin >> command;
    if (command[0] == 'i') {
      cin >> key;
      insert(key);
    } else if (command[0] == 'f') {
      cin >> key;
      if (find(key)) cout << "yes" << endl;
      else cout << "no" << endl;
    } else {
      print();
    }
  }
    
  return 0;
}



Measured memory_bytes: 21848
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
main(){
    int K,S,cnt = 0;
    cin >> K >> S;
    for(int i = 0;i <= K;i++){
        for(int j = 0;j <= K;j++){
            if(S-i-j <= K && S-i-j >= 0)cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
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 fi first
#define sc second
#define rep(i,x) for(int i=0;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())
#define mod 1000000007
int n,m,a[305][305],b[305][305],c[305];
int main(){
	cin >> n >> m;
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){
		cin >> a[i][j];
	}
	int lb = 0,ub = n;
	while(ub-lb>1){
		int mid = (lb+ub)/2;
		vector<int>pos[305];
		bool used[305]={};
		queue<int>que;
		for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){
			b[i][j]=a[i][j]; c[i] = 1;
			if(j==1){
				pos[a[i][j]].pb(i);
				if(pos[a[i][j]].size() == mid+1){
					que.push(a[i][j]);
				}
			}
		}
		while(!que.empty()){
			int q = que.front(); que.pop();
			used[q] = 1;
			for(int i=0;i<pos[q].size();i++){
				int x = pos[q][i];
				for(int j=c[x];j<=m;j++){
					if(!used[a[x][j]]){
						pos[a[x][j]].pb(x);
						if(pos[a[x][j]].size() == mid+1) que.push(a[x][j]);
						c[x] = j+1; break;
					}
				}
			}
			pos[q].clear();
		}
		for(int i=1;i<=m;i++) if(pos[i].size()){
			ub = mid; goto ok;
		}
		lb = mid; ok:;
	}
	cout << ub << endl;
}

Measured memory_bytes: 1632
n,m,c=map(int,input().split())
hogeA=list(map(int,input().split()))
ans=0

for i in range(n):
  hogeB=list(map(int,input().split()))
  kei=0
  for j in range(m):
    kei+=hogeA[j]*hogeB[j]
  if(kei+c>0):
    ans+=1

print(ans)

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

using namespace std;

struct expand_type {
    template <typename... T>
    expand_type (T&&...) {}
};
template <typename... ArgTypes>
void print (ArgTypes... args) {
    expand_type {0, (cerr << args << ", ", 0)...};
    cerr << "\b\b \n";
}
#define printv(x) cerr << "["; for(auto i : (x)) cerr << i << ", "; cerr << "\b\b]\n";
#define __lcm(a,b) a * b / __gcd(a, b)

typedef unsigned long long ull;
typedef long double ld;

int main () {
    std::ios::sync_with_stdio (false);
    cin.tie (nullptr);
    cout.tie (nullptr);
    ld a, b;
    cin >> a >> b;
    cout << (ull)floor(a*b) << endl;
    return 0;
}


Measured memory_bytes: 3744
s = input()

flag = True
if s[0] != "A":
    flag = False

if s[2:-1].count("C") != 1:
    flag = False

for i in s[1:]:
    if i == "C":
        continue
    if i.isupper():
        flag = False

if flag:
    print("AC")
else:
    print("WA")

Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include "bits/stdc++.h"
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <list>
#define REP(i,a,b) for(i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define SQR(X)  ( (X)*(X) )
#define CUBE(X) ( (X)*(X)*(X) )
 
// #define int ll
 
using namespace std;
 
bool test = 0;
 
/* ?????????????????¬??¨ */
 
int main(){
  int i,j,k,l;
  int n;
  while(cin >> n) {
    if(n == 0) return 0;
    map<int,int> m;
    rep(i,n) {
      int a; cin >> a;
      if( m.count(a) == 0 ) m[a] = 1;
      else m[a]++;
    }
    auto itr = m.begin();
    for(; itr != m.end(); ++itr) {
      // cout << itr->first;
      // cout << ":" << itr->second << endl;
      if(itr->second*2 > n) break;
    }
    if(itr == m.end() ) puts("NO COLOR");
    else printf("%d\n",itr->first);
  }
  return 0;
}

Measured memory_bytes: 4568
#include<bits/stdc++.h>
using namespace std;
char s[100010],ss[100010];
int main()
{
	scanf("%s",s+1);
	int len=strlen(s+1);
	for(int i=1;i<=len;i++)
		ss[i]=s[len-i+1];
	for(int i=1;i<=len;i++)
		if(ss[i]=='b')ss[i]='d';
		else if(ss[i]=='d')ss[i]='b';
		else if(ss[i]=='p')ss[i]='q';
		else if(ss[i]=='q')ss[i]='p';
	for(int i=1;i<=len;i++)
		if(s[i]!=ss[i])return puts("No"),0;
	puts("Yes");
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
//#include <mylib.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)
//1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;
int n;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int m;
    cin >> n >> m;
    int road[n];
    int input;
    
    rep(i, n){
        road[i] = 0;
    }
    
    rep(i, m*2){
        cin >> input;
        road[input - 1]++;
        //rep(i, n){
        //  cout << road[i] << endl;
        //}
        //cout << endl;
    }
    
    rep(i, n){
        cout << road[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
def z_algo(S):
    N = len(S)
    A = [0]*N
    i = 1; j = 0
    A[0] = l = len(S)
    while i < l:
        while i+j < l and S[j] == S[i+j]:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while l-i > k < j - A[k]:
            A[i+k] = A[k]
            k += 1
        i += k; j -= k
    return A


N = int(input())
S = input()

ans = 0
for i in range(N):
    T = S[i:]
    Ai = z_algo(T)
    for j in range(len(Ai)):
        if Ai[j] <= j:
            ans = max(ans, Ai[j])

print(ans)


Measured memory_bytes: 49628
N = int(input())
MOD = 10**9+7

dp = [[[0]*4 for _ in range(4)] for _ in range(4)]
A,G,C,T = 0,1,2,3
for i in range(4):
    for j in range(4):
        for k in range(4):
            if (i,j,k) in [(A,G,C), (A,C,G), (G,A,C)]: continue
            dp[i][j][k] = 1

for _ in range(N-3):
    dp2 = [[[0]*4 for _ in range(4)] for _ in range(4)]
    for i in range(4):
        for j in range(4):
            for k in range(4):
                if (i,j,k) in [(A,G,C), (A,C,G), (G,A,C)]: continue
                for l in range(4):
                    if (j,k,l) in [(A,G,C), (A,C,G), (G,A,C)]: continue
                    if (i,k,l) == (A,G,C) or (i,j,l) == (A,G,C): continue
                    dp2[j][k][l] += dp[i][j][k]
                    dp2[j][k][l] %= MOD
    dp = dp2

ans = 0
for row in dp:
    for row2 in row:
        ans += sum(row2)
print(ans%MOD)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
int main()
{
    int n,k;
    cin>>n>>k;
    ll a[n];
    ll pro=1;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(i<k)
        {
            pro=pro*1LL*a[i];
        }
    }
    int lst=0;
    for(int i=k;i<n;i++)
    {
        //ll pro1=(pro/a[lst])*1LL*a[i];
        if(a[lst]>=a[i]) cout<<"No\n";
        else cout<<"Yes\n";
        //pro=pro1;
        lst++;

    }


}

Measured memory_bytes: 5152
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long int;
 
#define REP(i,n) for(ll i=0;i<(ll)(n);i++) //REP(i, 5) cout<<i;
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define MOD 1000000007 //10^9+7
//#define MOD 1
 
ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
const int MAX = 1000;
 
ll table[MAX][MAX];
 
// テーブルを作る前処理
void COMinit() {
    table[0][0] = table[0][1] = 1;
    FOR(i, 1, MAX-1){
      FOR(j, 0, i+1){
        if(j==0) table[i][j] = 1;
        else if(j == i+1) table[i][j] = 1;
        else table[i][j] = table[i-1][j-1]+table[i-1][j];
      }
    }
}
 
// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return table[n-1][k];
}

void sosuu(ll n, vector<ll> &v){

  vector<ll> num(n, 0);

  FOR(i, 1, sqrt(n)){
    if(num[i]==0){
      FOR(j, 0, n/i){
        num[i+(j*i)] = 1;
      }
    }
  }
  REP(i, n){
    if(num[i]==0) v.push_back(i+1);
  }
}

ll SORT(int n, vector<pair<ll, ll>> &v, int start){
  sort(v.begin()+start, v.end());
  return v[n-1].first;
}


int main(void){
 
  ll n;
  cin>>n;

  vector<ll> v(n);
  REP(i, n){
    ll x;
    cin>>x;
    v[i] = x;
  }

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

  if(n%2==0){
    REP(i, n){
      if(v[i]!=(i/2)*2+1){
        cout<<"0"<<endl;
        return 0;
      }
    }
  }else{
    REP(i, n){
      if(i==0){
        if(v[0]!=0){
          cout<<"0"<<endl;
          return 0;
        }
      }else{
        if(v[i]!=i+i%2){
          cout<<"0"<<endl;
          return 0;
        }
      }
    }
  }

  ll ans=1, piv;
  piv = n/2;
  //cout<<piv<<endl;
  REP(i, piv){
    ans *= 2;
    ans = ans%MOD;
   // cout<<ans<<endl;
  }
  cout<<ans<<endl;
  return 0;

}

Measured memory_bytes: 1024
# A - Addition and Subtraction Easy


# A op B という式の値を計算したい
# op ⇔ + or -

# A op B とstr型で標準入力する
A, op, B = map(str, input().split(maxsplit=3))
# print(A, op, B)

# A B を int型 に変換
A = int(A)
B = int(B)

# op が　+ の場合 A + B
# それ以外の時は   A -B

if op == "+":
    answer = A + B
else:
    answer = A - B

# 結果を出力
print(answer)


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

int main() {
	cin.tie(0)->sync_with_stdio(false);

	int r, g, b; cin >> r >> g >> b;
	int k; cin >> k;

	bool ok = true;
	if (r >= g) {
		while (true) {
			g *= 2;
			k--;
			if (r < g)
				break ;
		}
	}

	if (k < 0) ok = false;
	else {
		if (g >= b) {
			while (true) {
				b *= 2;
				k--;
				if (g < b)
					break ;
			}
		}
	}

	if (k < 0) ok = false;

	if (ok) cout << "Yes" << '\n';
	else cout << "No" << '\n';
	return 0;
}

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

int main() {
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	int d = x - y;
	int t = 0;
	if (y - x >= 0) {
	    d = y - x;
	    t = 1;
	}
	int price = 0;
	if (t == 0) {
	    if (a <= c * 2) price = a * d;
	    else price = d * c * 2;
	} else {
	    if (b <= c * 2) price = b * d;
	    else price = d * c * 2;
	}
	if (a + b <= c * 2) price = price + (a + b) * (x + y - d) / 2;
	else price = price + (c * 2) * (x + y - d) / 2;
	cout << price;
}


Measured memory_bytes: 256
import java.util.*;

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

    if(N>K){
    System.out.println(X*K+Y*(N-K));    
    }else{
    System.out.println(X*N);
    }
}
}

Measured memory_bytes: 35892
N, M = map(int, input().split())
left = 0
right = N
for i in range(M):
    L, R = map(int, input().split())
    if left < L:
        left = L
    if right > R:
        right = R
ans = right - left + 1
if ans < 0:
    print(0)
else:
    print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

ll N,L;
ll x[100010];
ll r[40][100010];

ll bin_search(ll idx){
    ll low=idx, high=N;
    while(high-low>1){
        ll mid=(low+high)/2;
        if(x[mid]-x[idx]<=L){
            low=mid;
        }else{
            high=mid;
        }
    }
    return low;
}

bool judge(ll days, ll a, ll b){
    REP(i,32)if((days>>i)&1){
        a = r[i][a];
    }
    if(a>=b)return true;
    return false;
}

int main(){
    
    cin>>N;
    REP(i,N)cin>>x[i];
    cin>>L;
    
    REP(i,N)r[0][i]=bin_search(i);

    for(int i=0;i<32;i++){
        REP(j,N)r[i+1][j] = r[i][r[i][j]];
    }
    
    int Q; cin>>Q;
    REP(kai,Q){
        ll a,b; cin>>a>>b;
        a--; b--;
        if(a>b)swap(a,b);
        ll low=0, high=N;
        while(high-low>1){
            ll mid=(low+high)/2;
            if(judge(mid,a,b)){
                high=mid;
            }else{
                low=mid;
            }
        }
        cout<<high<<endl;
    }
    
    return 0;
}


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

template<typename T> inline void fastin(T& num) {
  T c;
  num = 0;
  c = getchar_unlocked();
  for (; (c > 47 && c < 58); c = getchar_unlocked()) num = (num << 3) + (num << 1) + c - 48;
}

int main() {
  int num, input, index;
  fastin(num);
  index = 1;
  for (int i = 0; i < num; i++) {
    fastin(input);
    if (input == index) index++;
  }
  if (index == 1) cout << -1 << endl;
  else cout << num - index + 1 << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
m = sum(a[:1])
n = sum(a[1:])
ans = [abs(m-n)]
for i in range(1, N-1):
    m += a[i]
    n -= a[i]
    ans.append(abs(m-n))
print(min(ans))

Measured memory_bytes: 24832
import sys
from collections import Counter

lines = 1
inp = list()

for _ in range(lines):
    inp.append(sys.stdin.readline().strip())


nk = inp[0].split()
n = int(nk[0])
k = int(nk[1])

# def sigma(_m, _n, func, s=0):
#     if _m > _n:
#         return s
#     return sigma(_m+1, n, func, s + func(_m))
#
#
# sigma = sigma(1, k-2, lambda x: x)

i = 1
sigma = 0
while i <= k - 2:
    sigma += i
    i += 1


result = 0
i = k


while k <= i <= n + 1:
    sigma += i - 1
    result += i * n - 2 * sigma + 1
    i += 1


print(result % (10 ** 9 + 7))


Measured memory_bytes: 9420
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    h = II()
    r = h
    ans = [1]
    while r > 0:
        r = r // 2
        if r > 0:
            ans.append(ans[-1] * 2)
    print(sum(ans))



if __name__ == '__main__':
    main()

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

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	int odd=0,even=0;
	for(int i=0;i<n;i++)
	{
		cin >> a[i];
		if(a[i]%2==0)
		{
			even++;
		}
		else
			odd++;
	}
	cout << ((odd==0 or even==0) ? 0:(odd%2==0 ? n-2:n-1)) << endl;
}


Measured memory_bytes: 3624
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i) 
const int N = 200005 ;
using namespace std ;

int n, A, B, a[N] ; 
ll f[N] ;

int main() {
	scanf("%d%d%d", &n, &A, &B) ;
	rep(i, 1, n) scanf("%d", &a[i]) ;
	f[1] = B ;
	rep(i, 2, n) {
		f[i] = min(f[i - 1] + B, f[i - 1] + (ll) (a[i] - a[i - 1]) * A) ;
	}
	printf("%lld\n", f[n] - B) ;
	return 0 ; 
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;

vector<int> parent;

int find(int a){
  int x=a;
  while(x!=parent.at(x)){
    x=parent.at(x);
  }
  return parent.at(a)=x;
}

void unite(int a, int b){
  int x=find(a);
  int y=find(b);
  if(x!=y){
    parent.at(x)=y;
  }
}

int main(){
  int N,M;
  cin>>N>>M;
  vector<int> a(M),b(M);
  for(int i=0;i<M;i++){
    cin>>a.at(i)>>b.at(i);
    a.at(i)--;b.at(i)--;
  }

  int ans=0;
  for(int i=0;i<M;i++){
    parent.resize(N);
    for(int j=0;j<N;j++){
      parent.at(j)=j;
    }
    for(int j=0;j<M;j++){
      if(i==j){
        continue;
      }
      unite(a.at(j),b.at(j));
    }
    bool flag=false;
    for(int i=0;i<N;i++){
      if(find(0)!=find(i)){
        flag=true;
        break;
      }
    }

    if(flag){
      ans++;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sct(tc) scanf("%lld",&tc)
#define scl(n) scanf("%lld",&n)
#define scll(n,m) scanf("%lld%lld",&n,&m)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
int main()
{
   ll i,cnt=0,len;
   string s,t;
   cin >> s;
   cin >> t;
   len=s.length();
   for(i=0;i<len;i++)
   {
   	if(s[i]!=t[i])
   	cnt++;
   }
   printf("%lld\n",cnt);
}


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

#input
X, Y = map(int, input().split())

#output
import math

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

if (X + Y) % 3 == 0:
    k = (-X + 2*Y) //3
    l = (2*X -Y) //3
    if k < 0 or l <0:
        answer = 0
    else:
        answer = cmb(k+l, l) % (10**9 + 7)
else:
    answer = 0

print(answer)

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

using namespace std;

#define PB push_back
#define f first
#define s second

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

const int MOD = 1000000007;
const int INF = 1000000007;
const int MAXN = (int)3e5+1;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int k;
    cin >> k;
    int ans = 0;
    for(int a=1; a<=k; a++)
    {
        for(int b=1; b<=k; b++)
        {
            for(int c=1; c<=k; c++)
            {
                int d = __gcd(a, b);
                d = __gcd(d, c);
                ans += d;
            }
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3656
//From Naruto to Hokage
//#include <RJ>
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
mii m;
void solve(){
    ll n;
    cin>>n;
    vi v(n);
    rep(i,0,n-1){
        cin>>v[i];
        m[v[i]]++;
    }
    // sort(all(v));
    // rep(i,0,n-1){
    //     if((v[(i-1+n)%n]^v[(i+1)%n])!=v[i]){
    //         cout<<"No";
    //         return;
    //     }
    // }
    // ll a=v[0],b=v[1];
    ll f=1;
    ll c=v[0],d=v[1];
    ll i=2;
    m[v[0]]--;
    m[v[1]]--;
    while(i<n){
    if(m[c^d]){
        m[c^d]--;
        ll temp=c^d;
        c=d;
        d=temp;
    }
    else{
        f=0;
        break;
    }
    i++;
    }
    if(f==1){
        cout<<"Yes";
        return;
    }
    rep(i,0,n-1){
        m[v[i]]++;
    }
    // sort(all(v));
    // rep(i,0,n-1){
    //     if((v[(i-1+n)%n]^v[(i+1)%n])!=v[i]){
    //         cout<<"No";
    //         return;
    //     }
    // }
    // a=v[n-1],b=v[n-2];
    c=v[1],d=v[2];
    i=2;
    f=1;
    m[v[1]]--;
    m[v[2]]--;
    while(i<n){
    if(m[c^d]){
        m[c^d]--;
        ll temp=c^d;
        c=d;
        d=temp;
    }
    else{
        f=0;
        break;
    }
    i++;
    }
        if(f==1){
        cout<<"Yes";
        return;
    }
    rep(i,0,n-1){
        m[v[i]]++;
    }
    // sort(all(v));
    // rep(i,0,n-1){
    //     if((v[(i-1+n)%n]^v[(i+1)%n])!=v[i]){
    //         cout<<"No";
    //         return;
    //     }
    // }
    // a=v[n-1],b=v[n-2];
    c=v[0],d=v[2];
    i=2;
    f=1;
    m[v[0]]--;
    m[v[2]]--;
    while(i<n){
    if(m[c^d]){
        m[c^d]--;
        ll temp=c^d;
        c=d;
        d=temp;
    }
    else{
        f=0;
        break;
    }
    i++;
    }
        if(f==1){
        cout<<"Yes";
        return;
    }
    cout<<"No";
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 5760
#include <iostream>
using namespace std;
int main()
{
  int N, K;
  cin >> N >> K;
  char D[K];
  for (int i = 0; i < K; i++)
    cin >> D[i];
  int ans = N;
  while (true)
  {
    bool flag = true;
    string ans_s = to_string(ans);
    for (int i = 0; i < K; i++)
    {
      if (ans_s.find(D[i]) != -1)
        flag = false;
    }
    if (flag && N <= ans)
    {
      cout << ans << endl;
      return 0;
    }
    ans++;
  }
  return 0;
}

Measured memory_bytes: 256
// AOJ 2497 One
// 2018.3.18 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define DIV       1000
#define EPS       1e-10
#define EQ(a,b)   (fabs((a)-(b))<EPS)

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	if (c == '-') {	c = getchar_unlocked();
		do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

int quadeq(double *x1, double *x2, double a, double b, double c) // ax^2 + bx + c = 0
{
	double d;

	if (EQ(a, 0)) {	if (!EQ(b, 0)) { *x1 = -c/b; return 1; } return 0; }
	b /= a, c /= a;	if (EQ(c, 0)) { *x1 = -b; return 1; }
	b /= 2.0, d = b*b-c;
	if (EQ(d, 0)) { *x1 = -b; return 1; }
	if (d <= 0) return 0;
	d = sqrt(d), *x1 = -b-d, *x2 = -b+d;
	return 2;
}

double fa, fp; double f(double x)
{
	double v = 2 * fa * (x - fp);
	return sqrt(1+v*v);
}
double integral(double xmin, double xmax)
{
	int i;
	double h, h2, x, ans;
	h = (xmax-xmin)/DIV, h2 = 0.5*h, x = xmin;
	ans = 0, i = DIV; while (i--) ans += f(x) + 4*f(x+h2) + f(x+h), x += h;
	return ans*h/6;
}


typedef struct { int a, p, q; } T;
T t[52];
double xx[10000]; int sz;

int cmp(double *a, double *b) { if (EQ(*a, *b)) return 0; if (*a <= *b) return -1; return 1; }

int main()
{
	int  W, H, N, i, j, k, f;
	double a, b, c, x1, x2, x;
	double ans, y, max;

	W = in(), H = in(), N = in();
	for (i = 0; i < N; i++) t[i].a = in(), t[i].p = in(), t[i].q = in();

	ans = 0, xx[0] = 0, sz = 1;
	for (i = 0; i < N; i++) {
		x = sqrt((double)t[i].q/(-t[i].a));
		x1 = t[i].p - x, x2 = t[i].p + x;
		if (x1 > 0) xx[sz++] = x1;
		if (x2 < W) xx[sz++] = x2;

		for (j = i+1; j < N; j++) {
			a = t[i].a - t[j].a;
			b = -2*(t[i].a*t[i].p - t[j].a*t[j].p);
			c = t[i].a*t[i].p*t[i].p - t[j].a*t[j].p*t[j].p + t[i].q-t[j].q;
			k = quadeq(&x1, &x2, a, b, c);
			if (k  > 0 && x1 > 0 && x1 < W) xx[sz++] = x1;
			if (k == 2 && x2 > 0 && x2 < W) xx[sz++] = x2;
		}
	}
	xx[sz++] = W;
	qsort(xx, sz, sizeof(double), cmp);

	for (i = 1; i < sz; i++) {
		x1 = xx[i-1], x2 = xx[i];
		if (EQ(x1, x2)) continue;

		x = (x1+x2)/2, max = 0, f = -1;
		for (k = 0; k < N; k++) {
			y = t[k].a*(x-t[k].p)*(x-t[k].p) + t[k].q;
			if (y > max) f = k, max = y;
		}
		if (f >= 0) fa = t[f].a, fp = t[f].p, ans += integral(x1, x2);
	}
	printf("%.15lf\n", ans);
	return 0;
}


Measured memory_bytes: 2092
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>

using namespace std;

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

int main(){

	string str;
	int idx;
	char buf[64];
	map<string,set<int> > pages;
	while(~scanf("%s %d",buf,&idx)){
		pages[buf].insert(idx);
	}

	for(map<string,set<int> >::iterator it = pages.begin(); it != pages.end(); it++){
		printf("%s\n",it->first.c_str());

		int i=0;
		for(set<int>::iterator it2 = it->second.begin(); it2 != it->second.end(); it2++){

			printf("%d%s",*it2,i==it->second.size()-1 ? "\n" : " ");
			i++;
		}
	}
}

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

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

ii a[200001];

bool cmp(const ii &a, const ii &b)
{
	if(max(a.fi,a.se)!=max(b.fi,b.se)) return max(a.fi,a.se)<max(b.fi,b.se);
	return a.fi<b.fi;
}

bool cmp2(const ii &a, const ii &b)
{
	if(min(a.fi,a.se)!=min(b.fi,b.se)) return min(a.fi,a.se)<min(b.fi,b.se);
	return a.fi<b.fi;
}
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	vector<ll> x;
	for(int i=0;i<n;i++)
	{
		cin>>a[i].fi>>a[i].se;
		if(a[i].fi<a[i].se) swap(a[i].fi,a[i].se);
		x.pb(a[i].fi); x.pb(a[i].se);
	}
	sort(x.begin(),x.end());
	x.erase(unique(x.begin(),x.end()),x.end());
	ll ans = ll(2e18);
	deque<ii> vec(n);
	ll tmp = 0;
	for(int i=0;i<n;i++)
	{
		vec[i]=a[i];
		tmp=max(tmp,min(vec[i].fi,vec[i].se));
	}
	sort(vec.begin(),vec.end(),cmp);
	for(int i = 1; i < x.size(); i++)
	{
		ll bmin = x[0]; ll rrange = x.back() - x[i];
		if(max(vec.front().fi,vec.front().se)<x[i])
		{
			break;
		}
		ans=min(ans,rrange*(tmp-bmin));
	}
	ll mm = max(vec.front().fi,vec.front().se);
	ll rrange = x.back()-x[0];
	sort(vec.begin(),vec.end(),cmp2);
	for(int i=0;i<x.size();i++)
	{
		if(x[i]>mm) break;
		ll bmin=x[i];
		while(!vec.empty()&&min(vec.front().fi,vec.front().se)<x[i])
		{
			tmp=max(tmp,max(vec.front().fi,vec.front().se));
			vec.pop_front();
		}
		ans=min(ans,(tmp-bmin)*rrange);
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 10732
n,x=map(int,input().split())
p=[0]*51
b=[0]*51
p[0]=1
for i in range(50):
    p[i+1]=2*p[i]+1
    b[i+1]=2*b[i]+2
def dfs(n,x):
    if x<=n:
        return 0
    if n==0:
        return 1
    z=p[n]+b[n]
    if z//2==x:
        return p[n-1]
    elif z//2+1==x:
        return p[n-1]+1
    elif z//2+1<x:
        return p[n-1]+1+dfs(n-1,x-z//2-1)
    else:
        return dfs(n-1,x-1)
print(dfs(n,x))


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

vector< int > graph[300];

int v[210];
int o[210];

int now = 0;
int ncnt = 0;

int solve(int idx){

	if(v[idx] == 1) return false;
	v[idx] = 1;

	bool f = true;

	for(int i = 0;i < graph[idx].size();i++){
		f =  f && solve(graph[idx][i]);
	}

	v[idx] = 0;
	
	return f;
}

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

	for(int i = 0;i < n;i++){
		int a, b;
		string s;
		cin >> a >> s >> b;
		a--;
		b--;
		if(s == "lock"){
			graph[b+100].push_back(a);
		}else{
			graph[a].push_back(b+100);
		}
	}

	bool ok = true;
	for(int i = 0;i < 200;i++){
		now = i;
		ncnt = 0;
		ok = ok && solve(i);
	}
	
	if(ok){
		cout << 0 << endl;
	}else{
		cout << 1 << endl;
	}
	
	memset(v, -1, sizeof(v));
	memset(o, -1, sizeof(o));

	return 0;
}
	


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

using u8 = uint8_t;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
template <typename T> using C = std::stack<T>;
template <typename T> using D = std::deque<T>;
template <typename T> using Q = std::queue<T>;
template <typename T> using S = std::set<T>;
template <typename T> using V = std::vector<T>;
template <typename T, size_t N> using A = std::array<T, N>;
template <typename L, typename R> using P = std::pair<L, R>;
template <typename K, typename V> using M = std::map<K, V>;
using std::string;
using std::cin;
using std::cout;
using std::endl;

int main() {
  i32 x, a, b;
  scanf("%d%d%d", &x, &a, &b);
  if ((x - a) * (x - a) < (x - b) * (x - b))
    puts("A");
  else
    puts("B");
  return 0;
}


Measured memory_bytes: 256
s=input()
for i in range(2):
    for j in range(2):
        for k in range(2):
            t=int(s[0])
            ans=s[0]
            if i:
                t+=int(s[1])
                ans+='+'+s[1]
            else:
                t-=int(s[1])
                ans+='-'+s[1]
            if j:
                t+=int(s[2])
                ans+='+'+s[2]
            else:
                t-=int(s[2])
                ans+='-'+s[2]
            if k:
                t+=int(s[3])
                ans+='+'+s[3]
            else:
                t-=int(s[3])
                ans+='-'+s[3]
            if t==7:
                print(ans+'=7')
                exit()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;
using pl = pair<ll,ll>;
const ll INF = MOD*100;
vl dx = {0,1,0,-1};
vl dy = {1,0,-1,0};

signed main(){
	ll H,W; cin >> H>> W;
	pl s,g;
	cin >> s.first >> s.second;
	s.first--; s.second--;
	cin >> g.first >> g.second;
	g.first--; g.second--;
	vector<vector<char>> table(H,vector<char>(W));
	rep(i,0,H)rep(j,0,W)cin >> table[i][j];
	vvl dist(H+10,vl(W+10,INF));
	dist[s.first][s.second] = 0;
	deque<pl> q;
	q.push_front(s);
	while(!q.empty()){
		pl p= q.front(); q.pop_front();
		ll a,b; tie(a,b) = p;
		ll d = dist[a][b];
		//徒歩
		rep(i,0,4){
			ll x = a + dx[i];
			ll y = b + dy[i];
			if(x<0 || x>=H || y<0 || y>=W)continue;
			if(table[x][y] == '#')continue;
			if(dist[x][y] <= d)continue;
			dist[x][y] = d;
			q.emplace_front(x,y);
		}

		//魔法
		rep(i,max((ll)0,a-2),min(H,a+3)){
			rep(j,max((ll)0,b-2),min(W,b+3)){
				if(table[i][j] == '#')continue;
				if(dist[i][j] <= d + 1)continue;
				dist[i][j] = d + 1;
				q.emplace_back(i,j);
			}
		}
	}
	if(dist[g.first][g.second] == INF)cout << -1 << endl;
	else cout << dist[g.first][g.second] << endl;

	return 0;
}


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

int main()
{

    int a, b, c, d;

    cin >> a >> b >> c >> d;

    cout << min(a, b) + min(c,d) << endl;

    return 0;

}


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

int main()
{
    long long k;
    cin >> k;

    long long i = 0;
    long long val = 0;

    while (true) {
        i++;
        val = val * 10 + 7;
        long long rem = val % k;
        if (rem == 0) {
            break;
        }
        if (i > 2 * k) {
            i = -1;
            break;
        }
        val = rem;
    }
    cout << i << endl;

    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){
  int n,k;
  cin>>n>>k;
  int ans = 1;
 for(int i = 0; i < n; i++){
   if(ans<k){
     ans*=2;
   }
   else{
     ans+=k;
   }
 }
 cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.List;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			char[] s1 = in.nextString().toCharArray();
			char[] s2 = in.nextString().toCharArray();


			List<Integer> tmp = new ArrayList<>();
			for (int i = 0; i < n; i++) {
				if (s1[i] == s2[i]) {
					tmp.add(1);
				} else {
					tmp.add(2);
					i++;
				}
			}
			Integer[] a = tmp.toArray(new Integer[0]);
			int len = a.length;

			long ans = a[0] == 1 ? 3 : 6;
			for (int i = 1; i < len; i++) {
				if (a[i-1] == 1 && a[i] == 1) {
					ans *= 2;
					ans %= MOD;
				} else if (a[i-1] == 1 && a[i] == 2) {
					ans *= 2;
					ans %= MOD;
				} else if (a[i-1] == 2 && a[i] == 1) {
					ans *= 1;
					ans %= MOD;
				} else if (a[i-1] == 2 && a[i] == 2) {
					ans *= 3;
					ans %= MOD;
				}
			}
			out.println(ans % MOD);

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 21460
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}

template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	string s;
	cin >> s;
	int ans = 0;
	rep(i,3) {
		if (s[i] == '1')ans++;
	}
	print(ans);
}

Measured memory_bytes: 3592
R, C = map(int, input().split())
grid = [list(map(int, input().split())) for _ in range(R)]
for i in range(R):
    grid[i].append(sum(grid[i]))

total_RC = []
for c in range(C):
    sum_C = 0
    for r in range(R):
        sum_C += grid[r][c]
    total_RC.append(sum_C)
total_RC.append(sum(total_RC))
grid.append(total_RC)
[print(*g) for g in grid]


Measured memory_bytes: 6228
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int u32;
typedef pair<int, int> p;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int Inf = (1<<30);
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; }
int main() {
	int n;
	cin >> n;
	int m;
	cin >> m;
	int i;
	vector<int> imos(n + 1, 0);
	for (i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		imos[a]++;
		imos[b + 1]--;
	}
	int ans = 0;
	for (i = 1; i < n; i++) {
		imos[i] += imos[i - 1];
	}
	for (i = 0; i < n; i++) if (imos[i] == m)  ans++;
	cout << ans;
	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	int MOD = 1000000007;
	public void run() {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int n = s.length();
		long dp[][] = new long[n+1][4];
		dp[0][0]=1;
		for(int i=0; i<n; i++) {
			char c = s.charAt(i);

			if(c=='A'||c=='?') {
				dp[i+1][0] = (dp[i+1][0] + dp[i][0]) % MOD;
				dp[i+1][1] = (dp[i+1][1] + dp[i][1]) % MOD;
				dp[i+1][2] = (dp[i+1][2] + dp[i][2]) % MOD;
				dp[i+1][3] = (dp[i+1][3] + dp[i][3]) % MOD;

				dp[i+1][1] = (dp[i+1][1] + dp[i][0]) % MOD;

			}
			if(c=='B'||c=='?') {
				dp[i+1][0] = (dp[i+1][0] + dp[i][0]) % MOD;
				dp[i+1][1] = (dp[i+1][1] + dp[i][1]) % MOD;
				dp[i+1][2] = (dp[i+1][2] + dp[i][2]) % MOD;
				dp[i+1][3] = (dp[i+1][3] + dp[i][3]) % MOD;

				dp[i+1][2] = (dp[i+1][2] + dp[i][1]) % MOD;
			}
			if(c=='C'||c=='?') {
				dp[i+1][0] = (dp[i+1][0] + dp[i][0]) % MOD;
				dp[i+1][1] = (dp[i+1][1] + dp[i][1]) % MOD;
				dp[i+1][2] = (dp[i+1][2] + dp[i][2]) % MOD;
				dp[i+1][3] = (dp[i+1][3] + dp[i][3]) % MOD;

				dp[i+1][3] = (dp[i+1][3] + dp[i][2]) % MOD;
			}
		}
		System.out.println(dp[n][3]);
		sc.close();
	}


}


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

using namespace std;

#define ff first
#define ss second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<long long, long long> pl;

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const double EPS = 1e-6;
const int MAX_N = 55;

struct Matrix {
    long long** mat;
    int a, b;
    
    Matrix() { a = b = 0; }

    Matrix(int a, int b) {
        this->a = a, this->b = b;
        mat = new long long*[a];
        for (int i = 0; i < a; ++i) {
            mat[i] = new long long[b];
            for (int j = 0; j < b; ++j) mat[i][j] = 0;
        }
    }
    
    Matrix(vector<vector<int>> v) : Matrix(v.size(), v[0].size()) {
        for (int i = 0; i < a; ++i) for (int j = 0; j < b; ++j) mat[i][j] = v[i][j];
    }
    
    void print() {
        for (int i = 0; i < a; ++i) {
            for (int j = 0; j < b; ++j) cout << mat[i][j] << " ";
            cout << "\n";
        }
        cout << "------------\n";
    }
    
    Matrix operator+(const Matrix& m) {
        Matrix ret(a, b);
        for (int i = 0; i < a; ++i) for (int j = 0; j < b; ++j) ret.mat[i][j] = (mat[i][j] + m.mat[i][j]) % MOD;
        return ret;
    }
    
    Matrix operator*(const Matrix& m) {
        Matrix ret(a, m.b);
        for (int i = 0; i < a; ++i) for (int j = 0; j < b; ++j) for (int k = 0; k < m.b; ++k) 
            ret.mat[i][k] = (ret.mat[i][k] + mat[i][j] * m.mat[j][k] % MOD) % MOD;
        return ret;
    }

    Matrix operator^(ll pow) {
        Matrix ret(a, a), base(*this); 
        for (int i = 0; i < a; ++i) ret.mat[i][i] = 1;
        while (pow) {
            if (pow & 1) ret = ret * base;
            base = base * base;
            pow /= 2;
        }
        return ret;
    }
};

int N;
ll K;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> N >> K;
	Matrix adjMat(N, N);
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			cin >> adjMat.mat[i][j];
		}
	}
	
	adjMat = adjMat ^ K;

	ll total = 0;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			total = (total + adjMat.mat[i][j]) % MOD;
		}
	}

	cout << total << '\n';

	return 0;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define BiSearchRangeNum(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y)turn idx;
#define deg_to_rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad_to_deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)

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

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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  if (N % 2 == 1) {
    cout << "No" << endl;
    return 0;
  }

  bool flag = true;
  int half = N / 2;
  rep(i, 0, half) {
    if (S[i] != S[i + half]) {
      flag = false;
      break;
    }
  }

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


Measured memory_bytes: 256