akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
/* Written by Nishant Mittal aka nishantwrp */
#define FAST std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define modnum 1000000007
#define mp make_pair
#define pb push_back
#define PB pop_back
#define sl(a) (int)a.length()
#define sz(a) (int)a.size()
#define lcase(a) (char)tolower(a)
#define ucase(a) (char)toupper(a)
#define precise(a) fixed<<setprecision(a)<<
#define F first
#define S second
#define I insert
#define pii pair<int,int>
#define trav(a, x) for(auto& a : x)
#define rep(n) for(int i = 0;i<n;i++)
#define time cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.I(tmp);commands}
#define display(x) trav(a,x) cout<<a<<" "; cout<<endl;
#define ingrid(data,n,commands) for(int i = 0; i<n; i++){cin>>data[i];commands}
#define section(a,b,w) set_intersection(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define union(a,b,w) set_union(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define copy(a,w) copy(a.begin(), a.end(),back_inserter(w));
#define all(data) data.begin(), data.end()
#define PI 3.14159265358979323844
#define endl '\n'

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

// Graph DFS
const int fx[]={+1,-1,+0,+0};
const int fy[]={+0,+0,+1,-1};

//Returns index of first element not less than key and more than key respectively
#define lb(data,key) lower_bound(all(data),key) - data.begin();
#define up(data,key) upper_bound(all(data),key) - data.begin();
#define fnd(data,key) find(all(data),key) - data.begin();
/* Long Long Int */
#define int long long int
/*

███╗   ██╗██╗███████╗██╗  ██╗ █████╗ ███╗   ██╗████████╗██╗    ██╗██████╗ ██████╗ 
████╗  ██║██║██╔════╝██║  ██║██╔══██╗████╗  ██║╚══██╔══╝██║    ██║██╔══██╗██╔══██╗
██╔██╗ ██║██║███████╗███████║███████║██╔██╗ ██║   ██║   ██║ █╗ ██║██████╔╝██████╔╝
██║╚██╗██║██║╚════██║██╔══██║██╔══██║██║╚██╗██║   ██║   ██║███╗██║██╔══██╗██╔═══╝ 
██║ ╚████║██║███████║██║  ██║██║  ██║██║ ╚████║   ██║   ╚███╔███╔╝██║  ██║██║     
╚═╝  ╚═══╝╚═╝╚══════╝╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═══╝   ╚═╝    ╚══╝╚══╝ ╚═╝  ╚═╝╚═╝     
                                                                                                       
*/
int ans = 0;


signed main()
{
FAST
int n;
cin>>n;
vector <int> data;
invect(data,n+1,)
vector <int> hero;
invect(hero,n,)
hero.pb(0);
rep(n) {
  if (hero[i] >= data[i])
  {
    ans += data[i];
    hero[i] -= data[i];
    if (hero[i] >= data[i+1])
    {
      ans += data[i+1];
      data[i+1] = 0;
    } else {
      ans += hero[i];
      data[i+1] -= hero[i];
    }
  } else {
    ans += hero[i];
  }
}
cout<<ans;
return 0;
}

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

using namespace std;
using namespace __gnu_pbds;

const int MAX_N = 1e5 + 5;
const int MAX_L = 20; // ~ Log N
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define rep(i,n) for (i = 0; i < n; ++i)
#define REP(i,k,n) for (i = k; i <= n; ++i)
#define REPR(i,k,n) for (i = k; i >= n; --i)

#define LSOne(S) (S & (-S))
#define isBitSet(S, i) ((S >> i) & 1)

int H, W, M;
vii v;
int row[300001], col[300001];
void solve() {
    cin >> H >> W >> M;
    int i;

    rep(i, M) {
        int h, w;
        cin >> h >> w;
        row[h] += 1;
        col[w] += 1;
        v.push_back(make_pair(h, w));
    }
    int r = 0, w = 0, rCnt, wCnt;
    for (i = 1; i <= H; i++) {
        if (row[i] > r) {
            rCnt = 0;
            r = row[i];
        }
        if (row[i] == r) {
            rCnt++;
        }
    }
    for (i = 1; i <= W; i++) {
        if (col[i] > w) {
            wCnt = 0;
            w = col[i];
        }
        if (col[i] == w) {
            wCnt++;
        }
    }
    int target = rCnt * wCnt;
//    cout << rCnt << ' ' << wCnt << endl;
//    cout << r << ' ' << w << endl;
    for (i = 0; i < v.size(); i++) {
        if (row[v[i].first] == r && col[v[i].second] == w) {
            target--;
        }
    }
    if (target == 0) {
        cout << r + w - 1;
    } else {
        cout << r + w;
    }
}

//#define LOCAL 1

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

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    solve();

    return 0;
}

Measured memory_bytes: 9756
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;


int main(){
	int n;
	int cnt=0,ex1=0;
	
	cin >> n;
	vector<int> v(n);
	
	for(int i=0;i<n;i++){
		cin >> v[i];
		if(v[i]==1)ex1=1;
	}
	
	if(ex1 == 0){
		cout << -1 << endl;
		return 0;
	}
	
	int temp = 0;
	
	for(int j=1;j<n;j++){
		for(int i=temp;i<v.size();i++){
			if(v[i] != j){
				cnt++;
			}else if(v[i] == j){
				temp = i+1;
				break;
			}
			
			if(i== v.size()-1)temp = -1;
		}
		if(temp == -1)break;
	}
	
	cout << cnt << endl;
	
		
	
	
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	string s; cin >> s;
	for (int i = 0; i < 12; i++) {
		cout << s[i];
		if (i == 3) cout << " ";
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  
  int a;
  char s[10];
  
  scanf("%d", &a);
  scanf("%s", s);
  
  if(a >= 3200){
    printf("%s",s);
  }
  else if(a < 3200){
    printf("red");
  }
  
  return 0;
}


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

using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> d(N);
  for(int i=0;i<N;++i){
   cin >> d.at(i);
  }
 int S=0;
  for(int i=0;i<N;++i){
    for(int j=i+1;j<N;++j){
    S+=d.at(i)*d.at(j);
    }
  }
  cout<<S<<endl; 
}

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

int main()
{
  int x, y;
  cin >> x >> y;

  if (y % 2 != 0 || x * 4 < y || y < x * 2)
  {
    cout << "No" << endl;
  }
  else
  {
    cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 3636
#16:41
h,w,k = map(int,input().split())
x1,y1,x2,y2 = map(lambda x:int(x)-1, input().split())
raw = []
for _ in range(h):
  raw.append(input())
inf = 10**6
seen = [[inf for _ in range(w)] for _ in range(h)]
seen[x1][y1] = 0
from heapq import heappush as push
from heapq import heappop as pop
now = [[0,x1,y1]]

while now:
  s,x,y = pop(now)
  if x == x2 and y == y2:
    print(s)
    exit()
  for i in range(1,k+1):
    if x-i == -1 or raw[x-i][y] == '@' or seen[x-i][y] < s+1:
      break
    if seen[x-i][y] != s+1:
      seen[x-i][y] = s+1
      push(now,[s+1,x-i,y])
  for i in range(1,k+1):
    if y-i == -1 or raw[x][y-i] == '@' or seen[x][y-i] < s+1:
      break
    if seen[x][y-i] != s+1:
      seen[x][y-i] = s+1
      push(now,[s+1,x,y-i])
  for i in range(1,k+1):
    if x+i == h or raw[x+i][y] == '@' or seen[x+i][y] < s+1:
      break
    if seen[x+i][y] != s+1:
      seen[x+i][y] = s+1
      push(now,[s+1,x+i,y])
  for i in range(1,k+1):
    if y+i == w or raw[x][y+i] == '@' or seen[x][y+i] < s+1:
      break
    if seen[x][y+i] != s+1:
      seen[x][y+i] = s+1
      push(now,[s+1,x,y+i])
print(-1)

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

int main() {
	int N;
	cin >> N;
	vector<int> d(N);
	for (int i = 0; i < N; i++) {
		cin >> d.at(i);
	}
	sort(d.begin(), d.end());
	reverse(d.begin(), d.end());
	int countN = 1;
	for (int i = 0; i < N-1; i++) {
		if (d.at(i) > d.at(i+1)) {
			countN++;
		}
	}
	cout << countN << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int N,x[50000],w[50000],num=0,L;
	scanf("%d",&L);
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%d %d",&x[i],&w[i]);
		num = num + (x[i]*w[i]);
	}
	if(num == 0){
		printf("0\n");
	}
	else{
		printf("1\n");
		if(num>0){
			printf("-1 %d\n",num);
		}
		else{
			num = -1*num;
			printf("1 %d\n",num);
		}
	}
	return 0;
}
	

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

using namespace std;

int main() {
  int A, B;
  cin >> A >> B;

  int ans = 0;
  for (int n = A; n <= B; ++n) {
    string strN = to_string(n);
    int size = strN.size();
    int mid = size / 2;
    bool ok = true;
    for (int i = 0; i < mid; ++i) {
      if (strN[i] != strN[size - i - 1]) {
        ok = false;
        break;
      }
    }
    if (ok) ++ans;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream> 
#include <vector>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
#include <queue>
#include <stack>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <cctype>
#include <climits>

using namespace std;
using ll = long long int;
using ii = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;



#define mp(a,b) make_pair(a,b)

const int MOD = 1000 * 1000 * 1000 + 7;

bool res() {
	int n;
	cin >> n;
	if (!cin) return false;

	vi v(n);
	for (int i = 0; i < n; ++i) cin >> v[i];

	vii primero, segundo;

	ll sol = 0;
	ll sumaseg;

	ll sumaSegElemsTot = 0; 
	for (int i = 1; i < n; ++i) {
		int cont = primero.size() - 1;
		int sumaElems = 0;
		vii segundosElementos;

		//Actualizamos los primeros elementos del Xlr
		while (cont >= 0 && primero[cont].first <= v[i]) {
			ii par = primero[cont];
			sumaElems += par.second;
			primero.pop_back();

			segundosElementos.push_back(par);
			--cont;
		}

		if(sumaElems > 0) primero.push_back(mp(v[i], sumaElems));
		//Primeros elementos Gucci

		cont = segundo.size() - 1;
		//int sumaElems2 = 0;
		int sum = 0;
		ii ultpar;

		//Actualizamos los segundos elementos de los pares que tienen como primer elemento al que acabamos de meter
		while (cont >= 0 && sum < sumaElems) {
			ultpar = segundo[cont];
			segundo.pop_back();
			sumaSegElemsTot -= ultpar.first * ultpar.second;

			if (sum + ultpar.second > sumaElems) {
				sum += ultpar.second;
				ultpar.second -= (ll)sumaElems - sum;
			}
			else {
				sum += ultpar.second;
				ultpar.second = 0;
			}
			--cont;
		}

		//METER EL ULTIMO PAR EN CASO DE SER NECESARIO
		//
		//
		//
		//
		if (ultpar.second > 0) segundo.push_back(ultpar);

		int sumaElems3 = 0;

		//Actualizamos los segundos valores de los pares que tienen como segundo valor el valor recién introducido
		while (cont >= 0 && segundo[cont].first <= v[i]) {
			ii par = segundo[cont];
			sumaElems3 += par.second;
			sumaSegElemsTot -= par.first * par.second;

			segundo.pop_back();
			--cont;
		}
		if (sumaElems3 > 0) segundo.push_back(mp(v[i], sumaElems3));
		sumaSegElemsTot += (ll)v[i] * sumaElems3;

		//Meter segundos elementos
		for (int i = segundosElementos.size() - 1; i >= 0; --i) {
			segundo.push_back(segundosElementos[i]);
			sumaSegElemsTot += (ll)segundosElementos[i].first * segundosElementos[i].second;
		}

		primero.push_back(make_pair(max(v[i], v[i - 1]), 1));
		segundo.push_back(make_pair(min(v[i], v[i - 1]), 1));

		//Actualizar sumaSegElemsTot
		sumaSegElemsTot += min(v[i], v[i - 1]);

		sol += sumaSegElemsTot;
	}

	cout << sol << '\n';

	return true;
}

int main() {
	while (res()) {}
	return 0;
}

Measured memory_bytes: 3948
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,a[100005],b[100005],sum;
signed main(){
	cin>>n;
	for(int i=1;i<=n+1;i++) cin>>a[i];
	for(int i=1;i<=n;i++) cin>>b[i];
	for(int i=1;i<=n;i++){
		if(b[i]<a[i]){a[i]-=b[i],sum+=b[i];continue;}
		if(b[i]>=a[i]) b[i]-=a[i],sum+=a[i],a[i]=0;
		if(b[i]>=a[i+1]) sum+=a[i+1],a[i+1]=0;
		else sum+=b[i],a[i+1]-=b[i];
	}
	cout<<sum;
}


Measured memory_bytes: 1792
using static System.Console;

class Program
{
  static void Main(string[] args)
  {
			string[] s = ReadLine().Split(' ');
			int A = int.Parse(s[0]), B = int.Parse(s[1]);
			if (B % A == 0) WriteLine(A + B);
			else WriteLine(B - A);
  }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
bitset<4000003> bs;
ll ans[4000003];
int main(){
	ios::sync_with_stdio(0);
	ll now;
	ll n;;
	cin>>n;
	bs[0]=1;
	rep(i,n){
		cin>>now;
		bs|=(bs<<now);
	}
	ll nn=0;
	forn(i,1,4000002){
		if(bs[i]){
			ans[nn++]=i;
		}
	}
	cout<<ans[(nn-1)/2];
	re 0;
}


Measured memory_bytes: 18048
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ull  unsigned long long
#define ll long long int
#define ull unsigned long long 
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(),v.rend() //reverse
#define vl vector< long long>v(n);
#define mii unordered_map<ll,ll>
double pi = 2*acos(0.0);
#define mod 1000000007

ll power(ll a,ll b){ ll res=1;while(b){if(b&1)res=res*a;b=b/2; a=(a*a); }return res;}

 int main()
 {
       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
       ll tst;
       tst=1;
       //cin>>tst;
       while(tst--)
       {
         ll a;
         cin>>a;
         cout<<power(a,2)+power(a,3)+a<<endl;
            
       }
 }

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(10);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

ll f(ll n){
    if(n%2)return 3*n+1;
    return n/2;
}

signed main(){
    ll N;
    cin >> N;
    vl h(N+1,0);
    FOR(i,0,N)cin >> h[i];
    ll ans = 0;
    while(1){
        ll l=0,r;
        while(h[l] == 0 && l < N)l++;
        if(l == N)break;
        r = l;
        while(h[r] != 0 && r <= N)r++;
        ans++;
        FOR(i,l,r){
            h[i]--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
from collections import Counter
# import math
MOD = 998244353

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def main():
    n = getN()
    nums = getList()
    cnt = Counter(nums)
    items = sorted(cnt.items(), key=lambda x: x[0])
    # print(items)
    if nums[0] != 0:
        print(0)
        return

    ans = 1
    prev = 1
    for i, item in enumerate(items):
        if i != item[0]:
            print(0)
            return
        if item[0] == 0 and item[1] != 1:
            print(0)
            return
        else:
            # a,b = max(item[1], prev), min(item[1], prev)
            ans *= (prev**item[1])
            prev = item[1]
            ans %= MOD


    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 67756
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define maxn 100010
#define mod 1000000007
#define inf 1000000000000000007
using namespace std;
typedef long long ll;
ll read()
{
    ll x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n;
ll A,B;
ll a[maxn];
ll f[maxn];
int las1[maxn],las2[maxn];
ll t[maxn*4];
void push_up(int k)
{
    t[k]=(t[k*2]+t[k*2+1])%mod;
}
void modi(int k,int l,int r,int x,ll y)
{
    if(l==r)
    {
        t[k]=y;
        return;
    }
    int mid=(l+r)/2;
    if(mid>=x)  modi(k*2,l,mid,x,y);
    else        modi(k*2+1,mid+1,r,x,y);
    push_up(k);
}
ll query(int k,int l,int r,int x,int y)
{
    if(x>y)  return 0;
    if(l>=x&&r<=y)  return t[k];
    int mid=(l+r)/2;
    ll res=0;
    if(mid>=x)   res+=query(k*2,l,mid,x,y);
    res%=mod;
    if(mid<y)    res+=query(k*2+1,mid+1,r,x,y);
    res%=mod;
    return res; 
}
int main()
{
    n=read();A=read();B=read();
    if(A<B)  swap(A,B);
    for(int i=1;i<=n;i++)  a[i]=read();
    las1[1]=las2[1]=1;
    for(int i=2;i<=n;i++)
    {
        if(a[i]-a[i-1]>=A)  las1[i]=las1[i-1];
        else las1[i]=i;
        if(a[i]-a[i-1]>=B)  las2[i]=las2[i-1];
        else las2[i]=i;
    }
    a[0]=-A;
    a[n+1]=a[n]+A;
    f[0]=1;
    modi(1,0,n,0,f[0]);
    int l=0;
    for(int i=1;i<=n+1;i++)
    {
        int r=upper_bound(a,a+i+1,a[i]-A)-a-1;
        if(i>=2&&a[i-1]-a[i-2]<B)  l=i-2;
        if(a[i]-a[i-1]>=A)  f[i]=f[i-1];
        f[i]+=query(1,0,n,l,min(i-2,r));
        f[i]%=mod;
        if(i<=n&&a[i+1]-a[i-1]>=B)  modi(1,0,n,i,f[i]);
    }
    printf("%lld\n",f[n+1]);
    return 0;
}

Measured memory_bytes: 5760
from itertools import combinations as comb

def main():
    N,K = map(int,input().split())
    
    Max = (N-1)*(N-2)//2  #中心を一つ決めてN-1個の中から2つを選ぶ
    if K>Max:
        print(-1)
    else:
        M = Max - K
        Edge = [(1,_) for _ in range(2, N+1)]
        Edge += list(comb(range(2,N+1),2))[:M]
        print(len(Edge))
        for i,j in Edge:
            print(i,j)
            
if __name__ == '__main__':
    main()

Measured memory_bytes: 3992
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[][] c = new int[3][3];

		for (int i = 0; i < c.length; i++) {
			for (int j = 0; j < c[i].length; j++) {
				c[i][j] = sc.nextInt();
			}
		}

		int[] a = new int[3];
		int[] b = new int[3];

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

		for (int i = 1; i < a.length; i++) {
			a[i] = c[i][0] - b[0];
		}

		boolean jdg = true;
		outer:
		for (int i = 0; i < c.length; i++) {
			for (int j = 0; j < c[i].length; j++) {
				if (!(jdg = (a[i] + b[j] == c[i][j])))
					break outer;
			}
		}

		System.out.println(jdg ? "Yes" : "No");

		sc.close();
	}
}


Measured memory_bytes: 21972
#include <stdio.h>

int main(void)
{
	char s[104];
	int i,count=0;

	scanf("%s",s);
	for(i=1;s[i+2] != '\0';i++,count++){
	}
	printf("%c%d%c\n",s[0],count+1,s[count+2]);
	return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n, k; cin >> n >> k;
    VI is(n);
    FOR(i, 0, k) {
        int d; cin >> d;
        FOR(j, 0, d) {
            int a; cin >> a;
            ++is[a - 1];
        }
    }

    int ans = 0;
    FOR(i, 0, n)if (is[i] == 0)++ans;
    cout << ans << "\n";
}


Measured memory_bytes: 3652
import sys
import random
from copy import copy
from math import floor, e

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def write_output(out):
    with open("my_sample3.out", mode="w") as f:
        for x in out:
            f.write(str(x + 1) + "\n")


def main():
    d = int(readline())
    c = list(map(int, readline().split()))
    s = [list(map(int, readline().split())) for _ in range(d)]

    sat_cur = 0
    last = [1] * 26
    out = [-1] * d

    for day in range(d):
        estimate = [0.0] * 26
        for cid in range(26):
            if s[day][cid] > 16000:
                estimate[cid] = last[cid] * c[cid] + c[cid] ** 1
        cur = estimate.index(max(estimate))
        out[day] = cur
        sat_cur += s[day][cur]
        last[cur] = 1
        for cid in range(26):
            if cid != cur:
                sat_cur -= last[cid] * c[cid]
                last[cid] += 1

    # print("begin", sat_cur)
    out_best = copy(out)
    sat_best = sat_cur
    num_of_try = 10000
    for i in range(1, num_of_try + 1):
        change_num = floor((num_of_try - i) / 5000)
        out_temp = copy(out_best)
        for j in range(change_num):
            #c_day = int(random.triangular(0, 365 - 0.01, 50))
            c_day = random.randint(0,364)
            c_cid = random.randint(0, 25)
            out_temp[c_day] = c_cid

        last = [1] * 26
        sat_temp = 0
        for day in range(d):
            cur = out_temp[day]
            sat_temp += s[day][cur]
            last[cur] = 1
            for cid in range(26):
                if cid != cur:
                    sat_temp -= last[cid] * c[cid]
                    last[cid] += 1
        if sat_temp > sat_best:
            # print(i, ":", sat_temp)
            out_best = out_temp
            sat_best = sat_temp

    for x in out_best:
        print(x + 1)

    #write_output(out_best)


if __name__ == '__main__':
    main()


Measured memory_bytes: 81716
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <iostream>
#include <stack>

using namespace std;

long n;
long ans = 0;

void check(long m){
    if(m > 1 && n / m == n % m){
        ans += m;
    }
}

int main(){
    scanf("%ld", &n);
    for(long i = 1; i*i <= n; ++i){
        if(i * i == n){
            check(i-1);
        }else if(n % i == 0){
            check(i-1);
            check(n/i-1);
        }
    }
    printf("%ld\n", ans);
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
ans = 1
b = 1
c = 1
p = 10**18
    
for i in range(N):
  if A[i] == 0:
    c = 0
    break
  else:
    ans *= A[i]
    if p < ans:
      b = -1
      ans = 0
if c == 0:
  print(c)
elif b == -1:
  print(b)
else:
  print(ans)
    
  

Measured memory_bytes: 21572
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod 1000000007
int32_t main()
{
	fast;
	int n, m;
	cin >> m >> n;
	int a[n];
	int su = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		su += a[i];
	}
	if (m < su)
	{
		cout << -1;
	}
	else
	{
		cout << m - su;
	}






}

Measured memory_bytes: 3688
// C - Grid Repainting 2
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, n, w, ans = 0, count = 0;
  vector<pair<string, pair<lli, lli>>> pr;
  cin >> h >> w;
  vs s(h);
  rep(i, 0, h)
  {
    cin >> s[i];
  }
  vlli dx = {0, 1, 0, -1};
  vlli dy = {1, 0, -1, 0};
  rep(i, 0, h)
  {
    rep(j, 0, w)
    {
      if (s[i][j] == '.')
      {
        continue;
      }
      rep(k, 0, 4)
      {
        a = i + dy[k];
        b = j + dx[k];
        if (a < 0 || a >= h)
          continue;
        if (b < 0 || b >= w)
          continue;
        if (s[a][b] == '#')
          count++;
      }
      if (count == 0)
      {
        cout << "No" << endl;
        return 0;
      }
      count = 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}
constexpr int INF = 1100000000;
constexpr long long LLINF = 1100000000000000000LL;
constexpr long long MOD = 1000000007;

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


int main()
{
  int N;
  cin >> N;
  vector<ll> A(N + 1), B(N);
  REP(i, N + 1) cin >> A[i];
  REP(i, N) cin >> B[i];

  ll ans = 0;
  REP(i, N) {
    REP(j, 2) {
      ll tmp = min(A[i + j], B[i]);
      ans += tmp;
      A[i + j] -= tmp;
      B[i] -= tmp;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
summer_vacation, amount_of_homework = map(int, input().split())
a = map(int, input().split())
homework_list = list(a)

total_days = 0

for i in homework_list:
    total_days += i

if summer_vacation >= total_days:
    print(summer_vacation - total_days)
else:
    print(-1)


Measured memory_bytes: 9848
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    string s;
    cin >> s;
    string x = s.substr(0,2);
    string y = s.substr(2,2);
    int xi;
    int yi;
    xi = stoi(x);
    yi = stoi(y);
    if(xi > 0 && xi <=12){
        if(yi > 0 && yi <= 12){
            cout << "AMBIGUOUS" << endl;
        }else{
            cout << "MMYY" << endl;
        }
    }else{
        if(yi > 0 && yi <= 12){
            cout << "YYMM" << endl;
        }else{
            cout << "NA" << endl;
        }
    }
}


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

long long p1[1005], p2[1005], p3[1005], p4[1005], p5[1005], p6[1005], p7[1005], p8[1005];

long long cal_sum(long long *A, int n) {
    long long res = 0;
    for (int i = 0; i < n; i++) {
        res += A[i];
    }
    return res;
}

int main() {
    int N, M;
    scanf("%d %d", &N, &M);
    long long x, y, z;
    for (int i = 0; i < N; i++) {
        scanf("%lld %lld %lld", &x, &y, &z);
        p1[i] = x + y + z;
        p2[i] = x + y - z;
        p3[i] = x - y + z;
        p4[i] = x - y - z;
        p5[i] = -x + y + z;
        p6[i] = -x + y - z;
        p7[i] = -x - y + z;
        p8[i] = -x - y - z;
    }
    sort(p1, p1 + N, greater<long long>());
    sort(p2, p2 + N, greater<long long>());
    sort(p3, p3 + N, greater<long long>());
    sort(p4, p4 + N, greater<long long>());
    sort(p5, p5 + N, greater<long long>());
    sort(p6, p6 + N, greater<long long>());
    sort(p7, p7 + N, greater<long long>());
    sort(p8, p8 + N, greater<long long>());
    long long ans = 0;
    ans = max(ans, cal_sum(p1, M));
    ans = max(ans, cal_sum(p2, M));
    ans = max(ans, cal_sum(p3, M));
    ans = max(ans, cal_sum(p4, M));
    ans = max(ans, cal_sum(p5, M));
    ans = max(ans, cal_sum(p6, M));
    ans = max(ans, cal_sum(p7, M));
    ans = max(ans, cal_sum(p8, M));
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
ab=[]
for m in range(M):
  [a,b]=[int(i) for i in input().split()]
  ab.append([a,b])
ab.sort(key=lambda x:x[1])
count=[]
count.append(ab[0][1]-1)
for i in range(1,M):
  if ab[i][0]<=count[-1]<ab[i][1]:
    pass
  elif ab[i][0]<=count[-1] and ab[i][1]-1==count[-1]:
    count.remove(count[-1])
    count.append(ab[i][1]-1)
  else:
    count.append(ab[i][1]-1)
print(len(count))

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e9+7)
ll N,A[101010];
ll mk[101010];
ll i, j,ans;
int main(){
    scanf("%lld",&N);
    fornum(i,0,N){
        scanf("%lld", &A[i]);
    }
    ans = 1;
    fornum(i,0,N){
        if(A[i]!=0){
            if(mk[A[i]-1]==mk[A[i]]){
                printf("0\n");
                return 0;
            }
            ans *= mk[A[i] - 1] - mk[A[i]];
            ans %= MOD;
        }
        mk[A[i]]++;
        if(mk[A[i]]>3){
            printf("0\n");
            return 0;
        }
    }
    j = 1;
    fornum(i,0,mk[0]){
        j *= 3-i;
    }
    printf("%lld", ans*j%MOD);
    return 0;
}

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

string s, t, a;

int main(){
	cin >> s >> t >> a;
	s[0] -= 32;
	t[0] -= 32;
	a[0] -= 32;
	cout << s[0] << t[0] << a[0] << endl;
	return 0;
}

Measured memory_bytes: 256
// Problem Link: 
// Tutorial Link: 

#include<bits/stdc++.h>
 
using namespace std;
 
#define LL long long
#define pb push_back
#define pLL pair<LL,LL>
#define ff first
#define ss second
#define rep(i,a,b) for(LL i=a;i<=b;++i)
#define repb(i,a,b) for(LL i=a;i>=b;--i)
#define ld double
#define mp make_pair
#define vLL vector<LL>
#define vpLL vector<pLL>
#define vld vector<ld>
#define pld pair<ld,ld>
#define vpld vector<pld>
#define SLL set<LL>
#define SpLL set<pLL>
#define FIO ios::sync_with_stdio(false)
#define mod 1000000007

LL n,k,p[1005];

int main()
{
	cin >> n >> k;
    rep(i,1,n) cin >>p[i];
    sort(p+1, p+n+1);
    LL ans = 0;
    rep(i,1,k) ans +=p[i];
    cout << ans <<endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define pi 3.141592653589793238

int main( )
{
     ll t,m,i,sum=0;
     cin>>t>>m;
     ll a[m+1];
     for(i=1;i<=m;i++)
     {
          cin>>a[i];sum+=a[i];
     }
     ll ans = t-sum;
     if(ans<0)cout<<-1<<endl;
     else cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  int p;
  int m=0,sum=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>p;
    sum+=p;
    m=max(m,p);
  }
  cout<<sum-m/2<<endl;
  return 0;
}


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

int main()
{
   ll a, b, c, d;
   cin >> a >> b >> c >> d;

   cout <<  max(max((b*c),(b*d)),max((a*d),(a*c)))<< endl;

}




Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll a[200003],c[200003];
int main()
{
   ll t,tc,m1=INT_MAX,m2=INT_MIN;
   cin>>t;
   tc=t;
   for(int i=0;i<t;i++)
   {
       cin>>a[i];
       c[i]=a[i];
   }
   sort(a,a+t);
   m1=a[t-2];
   m2=a[t-1];
   //cout<<m1<<" "<<m2<<endl;
   for(int i=0;i<t;i++)
   {
       if(c[i]<=m1)
        cout<<m2<<"\n";
       else
        cout<<m1<<"\n";
   }

   return 0;
}


Measured memory_bytes: 4736
import itertools
n,m,q=map(int, input().split())
S = []
for i in range(q):
    a,b,c,d=map(int, input().split())
    S.append([a,b,c,d])
tl=itertools.combinations_with_replacement(range(1,m+1),n)
ans = 0
for l in tl:
    t = 0
    for a,b,c,d in S:
        if l[b-1]-l[a-1] == c:
            t += d
    ans = max(ans,t)
print(ans)

Measured memory_bytes: 9192
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		StringBuilder sb = new StringBuilder(s);
		int n = scan.nextInt();
		for(int i = 0; i < n; i++) {
			String q = scan.next();
			if(q.equals("print")){
				int a = scan.nextInt();
				int b = scan.nextInt();
				System.out.println(sb.toString().substring(a, b + 1));
			}else if(q.equals("replace")) {
				int a = scan.nextInt();
				int b = scan.nextInt();
				String str = scan.next();
				sb.replace(a, b + 1, str);
			}else {
				int a = scan.nextInt();
				int b = scan.nextInt();
				if(a == 0) {
					StringBuilder sb1 = new StringBuilder(sb.substring(a, b + 1));
					sb1.reverse();
					if(b == s.length()) {
						sb = new StringBuilder(sb1.toString());
					}else {
						String t = sb.substring(b + 1, s.length());
						sb = new StringBuilder(sb1.toString() + t);
					}
				}else {
					StringBuilder sb1 = new StringBuilder(sb.substring(a, b + 1));
					sb1.reverse();
					String t = sb.substring(0, a);
					if(b == s.length() - 1) {
						sb = new StringBuilder(t + sb1.toString());
					}else {
						String t2 = sb.substring(b + 1, s.length());
						sb = new StringBuilder(t + sb1.toString() + t2);
					}
				}
			}
		}
		scan.close();
	}
}


Measured memory_bytes: 29316
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val hs = readLine()!!.split(' ').map { it.toInt() }
    var r = 0
    var h = 0
    hs.forEach {
        if (it >= h) {
            h = it
            r++
        }
    }
    println(r)
}

Measured memory_bytes: 38248
#include <bits/stdc++.h>
  using namespace std;
  //---------------------------------//
  void __print(int x) {cerr << x;}
  void __print(long x) {cerr << x;}
  void __print(long long x) {cerr << x;}
  void __print(unsigned x) {cerr << x;}
  void __print(unsigned long x) {cerr << x;}
  void __print(unsigned long long x) {cerr << x;}
  void __print(float x) {cerr << x;}
  void __print(double x) {cerr << x;}
  void __print(long double x) {cerr << x;}
  void __print(char x) {cerr << '\'' << x << '\'';}
  void __print(const char *x) {cerr << '\"' << x << '\"';}
  void __print(const string &x) {cerr << '\"' << x << '\"';}
  void __print(bool x) {cerr << (x ? "true" : "false");}

  template<typename T, typename V>
  void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
  template<typename T>
  void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
  void _print() {cerr << "]\n";}
  template <typename T, typename... V>
  void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
  #ifndef ONLINE_JUDGE
  #define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
  #else
  #define deb(x...)
  #endif
 //------------------------------//

  typedef long long int ll;
  typedef pair<int,int> pi;
  typedef pair<ll,ll> pll;
  typedef vector<int> vi;
  typedef vector<ll> vll;
  typedef vector<pi> vpi;
  typedef vector<pll> vpll;

  #define  ff           first
  #define  ss           second
  #define  pb           push_back
  #define  IOS          ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define  all(x)       (x).begin(), (x).end()
  #define  ps(x,y)      fixed<<setprecision(y)<<x
  #define  rep(i,a,b)   for(ll i=a ; i<b ; ++i)

  const ll MOD = 1e9 + 7;
  const ll INF = 1e18;
  const ll maxn = 1e6 + 4;


  void solve(){
     int n;
     cin >> n;
     ll ans = 1;
     string s1,s2;
     cin >> s1 >> s2;
     int lst = -1;
     for(int i=0;i<n;i++){
     	  if(s1[i] == s2[i]){
     	  	   if(lst==-1){
     	  	      ans = ans*3;
     	  	   }
				else if(lst==1){
					ans = (ans*2)%MOD;
				}
			lst = 1;	
     	  }
     	  else{
     	  	 if(lst == -1){
     	  	 	ans = ans*6;
     	  	 }
     	  	 else if(lst == 0){
     	  	 	ans = (ans*3)%MOD;
     	  	 }
     	  	 else{
     	  	 	ans = (ans*2)%MOD;
     	  	 }
     	  	 i++;
     	  	 lst = 0;
     	  }
     }
     cout << ans;
  }

  int main(){
    IOS
    	solve();
    cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
  }

// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying

Measured memory_bytes: 3780
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    int sum = 0;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        sum += v[i];
    }
    sort(v.begin(), v.end());

    int remain = sum - v[n - 1];
    cout << (v[n - 1] < remain ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#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)
int INF = 1e9 + 7;
int mod = 998244353;
long double PI = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998626034825342117;
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;
int main() {
    int N; cin >> N;
    vector<int>L(N);
    rep(i, N)cin >> L[i];
    long long ans = 0;
    rep(i, N) {
        rep(j, N) {
            rep(k, N) {
                if (L[i] != L[j] && L[j] != L[k] && L[i] != L[k] && L[i] + L[j] > L[k] && L[i] + L[k] > L[j] && L[j] + L[k] > L[i])ans++;
            }
        }
    }
    cout << ans/6 << endl;
}

Measured memory_bytes: 3628
n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
x = 0
for i in range(1, n, 2):
    x += a[i]

ans[0] = sum(a) - 2 * x
for i in range(1, n):
    ans[i] = 2 * a[i - 1] - ans[i - 1]

print(*ans)

Measured memory_bytes: 20624
#include <stdio.h>
 
int main (voif)
{
	int i,j;
	char n[100000] = {0};
	int x[1001] = {0};
	i = 0;
	j = 0;

	while(1) {
	scanf("%c",&n[i]);
	if(n[i] == '0' && n[i-1] == '\n'|| n[0] == '0') {break;}
 
	if(n[i] >= '1' && '9' >= n[i] && n[i] != '\n') {
	x[j] += n[i]-48;
	}
	if(n[i] == '\n') {
	j = j + 1;
	}

	i= i+1;
}

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


Measured memory_bytes: 2044
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

long MOD = 10^^9 + 7;

void main() {
    auto N = readln.chomp.to!int;
    int px = 0, py = 0, pt = 0;

    foreach (_; 0..N) {
        auto s = readln.split.map!(to!int);
        auto t = s[0];
        auto x = s[1];
        auto y = s[2];
        auto dt = t - pt;
        auto dx = abs(x - px);
        auto dy = abs(y - py);
        if (dt < dx + dy) {
            writeln("No");
            return;
        }
        if ((dt - dx - dy) % 2 != 0) {
            writeln("No");
            return;
        }
        pt = t;
        px = x;
        py = y;
    }

    writeln("Yes");
}


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

int n;
long long W,w[110],v[110];
long long dp[110][100100] = {0};
    
int main(){
    cin >> n >> W;
    for(int i = 0; i < n; i++) cin >> w[i] >> v[i];
    for(int i = 0; i < n; i++){
        for(int s = 0; s <= W; s++){
            if(s - w[i] >= 0) dp[i + 1][s] = max(dp[i][s], dp[i][s - w[i]] + v[i]);
            dp[i + 1][s] = max(dp[i][s],dp[i + 1][s]);
            }
        }
    cout << dp[n][W] << "\n";
    }

Measured memory_bytes: 79360
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

int a[50];
int b[50];
int c[50];
int d[50];
signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    int2(n, m);
    rep(i, n)scanf("%d %d", a+i, b+i);
    rep(i, m)scanf("%d %d", c+i, d+i);

    rep(i, n){
      ll res = 0, mi = 1234567890LL;
      rep(j, m){
        ll tmp = abs(a[i] - c[j]) + abs(b[i] - d[j]);
        if(tmp < mi){
          res = j;
          mi = tmp;
        }
        //pri2(i, j);
        //pri3(res, tmp, mi);
      }
      pri(res + 1);
    }

/*/

//*/ break;
  }
  return 0;
}


Measured memory_bytes: 256
x = [i for i in input()]
a,b=int(x[0]+x[1]),int(x[2]+x[3])
if (1<=a and a<=12) and (1<=b and b<=12):
  print("AMBIGUOUS")
elif 1<=a and a<=12:
  print("MMYY")
elif 1<=b and b<=12:
  print("YYMM")
else:
  print("NA")
  

Measured memory_bytes: 3060