akhauriyash/Code-Regression huggingface dataset:
program main;
var
    s1, s2 : string;
    pass : boolean;
begin
    pass := true;
    readln(s1);
    readln(s2);
    if length(s1) > 10
        then pass := false;
    if length(s2) - length(s1) <> 1
        then pass := false;
    s2 := copy(s2, 1, length(s2)-1);
    if s1 <> s2 
        then pass := false;
    if pass
        then writeln('Yes')
        else writeln('No');
end.


Measured memory_bytes: 1384
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;

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

    int N, M, R;
    cin >> N >> M >> R;
    vector<ll> r(R);
    rep(i, R) {
        cin >> r[i];
        r[i]--;
    }

    vector<vector<ll>> dist(N, vector<ll>(N, INF));
    rep(i, M) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        dist[a][b] = c;
        dist[b][a] = c;
    }

    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    sort(all(r));

    ll ans = INF;

    do {
        ll tmp = 0;
        rep(i, R - 1) { tmp += dist[r[i]][r[i + 1]]; }

        ans = min(ans, tmp);

    } while (next_permutation(all(r)));

    cout << ans << endl;
}

Measured memory_bytes: 3636
aa, bb = map(int, input().split())
A = max(aa, bb)
B = min(aa, bb)


def get_max(a, b):
    while True:
        c = a % b
        if c == 0:
            return b
        a = b
        b = c


def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct


B = get_max(A, B)
factors = factorize(B)

if len(factors) == 0:
    print(1)
else:
    count = 1
    for i in range(0, len(factors) - 1):
        if factors[i] != factors[i + 1]:
            count += 1
    print(count + 1)

Measured memory_bytes: 3064
N,Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for _ in range(Q)]

ac_cnt = [0]
for i in range(1,N):
    ac_cnt.append(ac_cnt[i-1]+1 if S[i-1:i+1] == 'AC' else ac_cnt[i-1])

for lr in LR:
    print(ac_cnt[lr[1]-1] - ac_cnt[lr[0]-1])


Measured memory_bytes: 30664
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define pb(a) push_back(a)
using namespace std;
typedef long long ll;

int gcd(int a, int b)
{
    if (a < b)
    {
        int tmp = a;
        a = b;
        b = tmp;
    }

    if (a % b == 0)
    {
        return b;
    }
    else
    {
        return gcd(b, a % b);
    }
}

int main()
{
    int N;
    cin >> N;
    vector<int> data(N);
    REP(i, N)
    {
        int a;
        cin >> a;
        data.at(i) = a;
    }

    vector<int> l(N);
    vector<int> r(N);
    l.at(0) = data.at(0);
    r.at(N - 1) = data.at(N - 1);
    FOR(i, 1, N)
    {
        l.at(i) = gcd(l.at(i - 1), data.at(i));
    }

    FORR(i, N - 2, 0)
    {
        r.at(i) = gcd(r.at(i + 1), data.at(i));
    }

    int ans = 1;
    ans = max(ans, r.at(1));
    ans = max(ans, l.at(N - 2));
    FOR(i, 1, N - 1)
    {
        ans = max(ans, gcd(l.at(i - 1), r.at(i + 1)));
    }

    cout << ans << endl;
}

Measured memory_bytes: 1408
#!/usr/bin/env python3

import sys


def LI():
    return list(map(int, sys.stdin.buffer.readline().split()))


def I():
    return int(sys.stdin.buffer.readline())


def LS():
    return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()


def S():
    return sys.stdin.buffer.readline().rstrip().decode('utf-8')


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


def SRL(n):
    return [list(S()) for i in range(n)]


def MSRL(n):
    return [[int(j) for j in list(S())] for i in range(n)]

# ----------------------------------------------------------------


def main():
    l = I()
    print((l / 3)**3)


main()


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

int main(){
  long long h, w;
  cin >> h >> w;
  if (h % 3 == 0 || w % 3 == 0) {
    cout << "0" << endl;
    return 0;
  }
  long long m = min(h, w);
  for (long long i = 1; i < h; i++) {
    long long t = i * w;
    long long u = (h - i) * (w / 2);
    long long v = (h - i) * (w - w / 2);
    long long d = max(t, max(u, v)) - min(t, min(u, v));
    m = min(m, d);
  }
  for (long long i = 1; i < w; i++) {
    long long t = i * h;
    long long u = (w - i) * (h / 2);
    long long v = (w - i) * (h - h / 2);
    long long d = max(t, max(u, v)) - min(t, min(u, v));
    m = min(m, d);
  }
  cout << m << endl;
  return 0;
}


Measured memory_bytes: 256
s = int(input())
a = [s]

for _ in range(1,1000):
    if s % 2 != 0:
        a.append(int(3*s+1))
        s = int(3*s+1)
    else:
        a.append(int(s/2))
        s = int(s/2)

cnt = 0
ans = []

for i,j in zip(a,a[1:]):
    ans.append(i)
    if j in ans:
        ans.append(j)
        print(len(ans))
        break

Measured memory_bytes: 9180
import java.util.*;

public class Main {
    public static void main(String args[] ) throws Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        int reds = 0;
        int idx = 0;

        while (idx < s.length()) {
            if (s.charAt(idx++) == '0') reds++;
        }
        System.out.println(Math.min(reds, s.length()-reds) * 2);
    }
}

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

int main(){
    int n, ans, v[20], c[20];
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> v[i];
    for (int i = 0; i < n; ++i) cin >> c[i];
    ans = 0;
    for (int i = 0; i < n; ++i) ans += max(0, v[i] - c[i]);
    cout << ans;
}

Measured memory_bytes: 256
using System;

class Program
{
  static void Main()
  {
    int n = int.Parse(Console.ReadLine());
    int[,,] oh = new int[4, 3, 10];
    string[] data;
    int i, j, k;
    int b, f, r, v;

    for (i = 0; i < 4; i++)
      for (j = 0; j < 3; j++)
        for (k = 0; k < 10; k++)
          oh[i, j, k] = 0;


    for (i = 0; i < n; i++)
    {
      data = Console.ReadLine().Split(' ');
      b = int.Parse(data[0]) - 1;
      f = int.Parse(data[1]) - 1;
      r = int.Parse(data[2]) - 1;
      v = int.Parse(data[3]);
      oh[b, f, r] += v;
    }

    for (i = 0; i < 4; i++)
    {
      for (j = 0; j < 3; j++)
      {
        for (k = 0; k < 10; k++)
          Console.Write(" {0}", oh[i, j, k]);
        Console.WriteLine();
      }
      if (i < 3) Console.WriteLine("####################");
    }
  }
}

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

#define pii  pair<int, int>
#define vi vector<int >
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define x first
#define y second
#define sz(x) (x).size()
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal

#define ll long long
#define ld long double

const ld EPS = 10e-9;
const int INF = 1e9 + 5;
const long long INFLL = (ll)INF * (ll)INF;
const ll MOD = 1e9 + 7;
const ld PI = 3.14159265358979323846;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "[";
    for (int i = 0; i < (int)v.size(); ++i) {
        os << v[i];
        if (i != (int)v.size() - 1)
            os << ", ";
    }
    os << "]\n";
    return os;
}

template <typename T>
ostream& operator<<(ostream& os, const set<T>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it;
        if (it != *v.rbegin())
            os << ", ";
    }
    os << "}\n";
    return os;
}

template <typename T>
ostream& operator<<(ostream& os, const unordered_set<T>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it;
        if (it != *v.rbegin())
            os << ", ";
    }
    os << "}\n";
    return os;
}

template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it.first << " : "
           << it.second;

        if( it != *v.rbegin())
            os  << ", ";
    }

    os << "}\n";
    return os;
}

template <typename T, typename S>
ostream& operator<<(ostream& os, const unordered_map<T, S>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it.first << " : "
           << it.second;

        if( it != *v.rbegin())
            os  << ", ";
    }

    os << "}\n";
    return os;
}

template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v)
{
    os << "(";
    os << v.first << ", "
       << v.second << ")";
    os << "\n";
    return os;
}

#define DEBUG

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


// __gcd(x, y)

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

    string s, t;
    cin >> s >> t;

    if(s == t.substr(0, s.size()))
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }

    return 0;
}


Measured memory_bytes: 3608
use std::io;

fn read_int() -> i32
{
    let mut s = String::new();
    io::stdin().read_line(&mut s)
        .expect("read_line() failed");
    let res:i32 = s.trim().parse()
        .expect("read_int(): not a number");;
    res
}

fn main()
{
    let n = read_int();
    let a = read_int();

    println!("{}", n*n - a);
}


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

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  vector<pair<ll, ll>> P(M);
  rep(i, M) {
    int B, C;
    cin >> B >> C;
    P[i].first = C;
    P[i].second = B;
  }
  sort(A.begin(), A.end());
  sort(P.begin(), P.end());
  reverse(P.begin(), P.end());
  ll itr = 0;
  bool end = false;
  rep(i, M) {
    for (ll j = itr; j < P[i].second + itr; j++) {
      if (A[j] > P[i].first) {
        end = true;
        break;
      }
      A[j] = P[i].first;
    }
    if (end) break;
    itr += P[i].second;
  }
  ll ans = 0;
  rep(i, N) {
    ans += A[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
s = input()
ints = [int(a) for a in s]

cnt = 0
for a in s[1:]:
    if a == '9':
        cnt += 1
        
if cnt == len(s)-1:
    print(sum(ints))
else:
    print(int(s[0])-1 + 9*(len(s)-1))

Measured memory_bytes: 3060
# include <bits/stdc++.h>
#define flash ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define endl '\n'
#define ll long long int
#include <tr1/unordered_map>
#define ld long double
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define f(i,a,b)  for(long long i=a;i<b;i++)
#define all(c) (c).begin(),(c).end()
#include <map>
using namespace std;

int main()
{




     flash;
     ///////////////////////////////////////////////////////////////////////////////////////
ll n;
cin>>n;
if(n%1000==0)
{
  cout<<0;
}
else
{
  cout<<1000-(n%1000);
}


    ///////////////////////////////////////////////////////////////////////////////////////

     return 0;

}


Measured memory_bytes: 3644
#include <stdio.h>

int main() {
    int i, j, k, N, ans = 0;
    int a, b, c;
    
    scanf("%d", &N);

    int tri[N];
    for(i=0; i < N; i++) {
        scanf("%d", &tri[i]);
    }

    for(i=0; i < N-2; i++) {
        for(j=i+1; j < N-1; j++) {
            for(k=j+1; k < N; k++) {
                a = tri[i];
                b = tri[j];
                c = tri[k];
                
                if(a+b>c && b+c>a && c+a>b && a != b && b != c && c != a) {
                    ans++;
                }
            }
        }
    }

    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1732
/*================================================================
*   Copyright (C) 2020 Sangfor Ltd. All rights reserved.
*
*   文件名称：B.cpp
*   创 建 者：sigmoidguo
*   创建日期：2020年07月17日
*   描    述：
*
================================================================*/

#include<iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    int ac = 0, wa = 0, tle = 0, re = 0;
    for(int i = 0; i < n; i++) {
        string s;
        cin >> s;
        if(s == "AC") ac++;
        if(s == "WA") wa++;
        if(s == "TLE") tle++;
        if(s == "RE") re++;
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
    return 0;
}

Measured memory_bytes: 3624
//love yjl forever
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int INF=0x3f3f3f3f;
int n;
int main()
{
/*	freopen("","r",stdin);
	freopen("","w",stdout);*/
	int i;
	int a,b,c;
	cin>>a>>b;
	cout<<a*b<<endl;
}

Measured memory_bytes: 3624
n, k = [int(i) for i in input().split(" ")]
t = []
d = []

for i in range(0, n):
    x, y = [int(i) for i in input().split(" ")]
    t.append(x)
    d.append(y)

dt = zip(d, t)
dt = sorted(dt, key = lambda k:k[0], reverse=True)
t_max = [False for i in range(0, n + 1)]
d_max = []
d_non_max = []

for i in range(0, n):
    if t_max[dt[i][1]]:
        d_non_max.append(dt[i][0])
    else:
        t_max[dt[i][1]] = True
        d_max.append(dt[i][0])
        
p = [0 for i in range(0, len(d_max) + 1)]
sum_max = 0
sum_non_max = sum(d_non_max[0:min(len(d_non_max), k)])

for i in range(1, len(p)):
    sum_max += d_max[i - 1]
    if k - i >= 0 and k - i < len(d_non_max):
        sum_non_max -= d_non_max[k - i]
    if k - i >= 0 and k - i - 1 < len(d_non_max):
        p[i] = sum_max + sum_non_max + i * i
    else:
        p[i] = 0
        
print(max(p))

Measured memory_bytes: 22176
def libra(l,r):
    if l>r:
        return "Left"
    elif l==r:
        return "Balanced"
    else:
        return "Right"
def sum(a,b):
    return a+b
    
a,b,c,d=[int(_) for _ in input().split()]
print(libra(sum(a,b),sum(c,d)))

Measured memory_bytes: 38384
/*******************************************
* AUTHOR : Adnan Masroor :-)
* NICK : adnanlari
* COLLEGE : NIT Durgapur
********************************************/

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
ll MOD=1000000007,BMOD=100000000700000;

ll C(ll x)
{
	if(x==0 || x==1)
		return 0;
	return ((x*(x-1))/2);
}

int main()
{
	ios::sync_with_stdio(false); 
	cin.tie(NULL);
	cout.tie(NULL);
	/*#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        #endif*/
	//the main code starts here
    
	ll n,total=0;
	cin>>n;
	ll a[n+1]={0},b[n+1]={0},x[n];
	for(int i=0;i<n;i++)
	{
		cin>>x[i];
		a[x[i]]++;
	}
	for(int i=1;i<=n;i++)
	{
		b[i]=C(a[i]);
		total+=b[i];
		//cout<<a[i]<<" "<<b[i]<<"\n";
	}
	for(int i=0;i<n;i++)
	{
		cout<<(total-a[x[i]]+1)<<"\n";
	}




	return 0;
}

Measured memory_bytes: 7296
#include<cstdio>
const int MaxN=300010;
int N,T[MaxN];
long long ST,f[MaxN][2],g[MaxN];
long long max(long long a,long long b){return a>b?a:b;}
void cmax(long long&a,long long b){b>a?a=b:1;}
struct Point{
	int x;long long y;
	long long val(int k){return y-1ll*k*x;}
}S[MaxN],*tp;
int sgn(long long x){return x<0?-1:x?1:0;}
void ins(Point p,bool ty){
	while(tp-S>1&&sgn((p.y-tp[-1].y)*(tp[-1].x-tp[-2].x)-(tp[-1].y-tp[-2].y)*(p.x-tp[-1].x))!=(ty?1:-1))--tp;
	*tp++=p;
}
void ins_l(int i){ins((Point){i,f[i][0]+i*(i-1ll)/2},0);}
void ins_r(int i){ins((Point){i+1,f[i+1][1]+(i+1)*(i+2ll)/2},1);}
void pops(int k){
	while(tp-S>1&&tp[-1].val(k)<=tp[-2].val(k))--tp;
}
long long tmp[MaxN];
void dc(int l,int r){
	if(r-l==1){
		cmax(g[l],f[l][0]+f[l+1][1]+1);
		return;
	}
	int mid=l+r>>1;
	long long mv=0;
	tp=S;
	for(int i=l;i<mid;i++)ins_l(i);
	for(int i=mid;i<r;i++){
		pops(i+1);
		tmp[i]=tp[-1].val(i+1)+(i+1)*(i+2ll)/2+f[i+1][1];
	}
	for(int i=r;i-->mid;)cmax(mv,tmp[i]),cmax(g[i],mv);
	tp=S;mv=0;
	for(int i=r;i-->mid;)ins_r(i);
	for(int i=mid;i-->l;){
		pops(i);
		tmp[i]=tp[-1].val(i)+i*(i-1ll)/2+f[i][0];
	}
	for(int i=l;i<mid;i++)cmax(mv,tmp[i]),cmax(g[i],mv);
	dc(l,mid);
	dc(mid,r);
}
int main(){
	scanf("%d",&N);
	for(int i=0;i<N;i++)scanf("%d",T+i),ST+=T[i];
	f[0][0]=0;
	tp=S;
	for(int i=0;i<N;i++){
		ins_l(i);pops(i+1);
		f[i+1][0]=max(f[i][0]+T[i],tp[-1].val(i+1)+(i+1)*(i+2ll)/2);
	}
	f[N][1]=0;
	tp=S;
	for(int i=N;i--;){
		ins_r(i);pops(i);
		f[i][1]=max(f[i+1][1]+T[i],tp[-1].val(i)+i*(i-1ll)/2);
	}
	dc(0,N);
	int M;scanf("%d",&M);
	while(M--){
		int P,X;scanf("%d%d",&P,&X);--P;
		printf("%lld\n",max(f[P][0]+f[P+1][1]+T[P]-ST,g[P]-ST+T[P]-X));
	}
}

Measured memory_bytes: 15744
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){
    string a, b, c;
    cin >> a >> b >> c;
    cout << (char)toupper(a[0]) << (char)toupper(b[0]) << (char)toupper(c[0]) << endl;
    return 0;
}

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

using namespace std;

int main(){
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif

	int s, w;

	scanf("%d %d", &s, &w);

	if (w >= s){
		printf("unsafe\n");
	} else{
		printf("safe\n");
	}

	return 0;
}

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

long long N;
string S[305];


bool check(long long a, long long b){
	char tmp[305][305];
	for(long long i = 0; i < N; i++){
		for(long long j = 0; j < N; j++){
			tmp[(i + a)%N][(j + b)%N] = S[i][j];
		}
	}

	for(long long i = 0; i < N; i++){
		for(long long j = 0; j < N; j++){
			if(tmp[i][j] != tmp[j][i])
				return false;
		}
	}
	return true;
}

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

	long long ans = 0;
	for(long long a = 0; a < N; a++){
		if(check(a, 0))
			ans += N - a;
	}

	for(long long b = 1; b < N; b++){
		if(check(0, b))
			ans += N - b;
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define pt pop_front
#define pk pop_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
template<class T> T count_bit(T p){
  if(typeid(p)==typeid(int))return __builtin_popcount(p);
  else if(typeid(p)==typeid(long))return __builtin_popcountl(p);
  else return __builtin_popcountll(p);
}
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;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(double p){printf("%.10f\n",p);}
template<class T>inline                             void outs(T p){for_each(all(p),out<decltype(p[0])>);}

inline void solve(void){
  long N;
  in(N);
  vector<long>p(N);
  ins(p);
  long cnt=0;
  rep(i,N)if(p[i]!=i+1)cnt++;
  if(cnt<=2)out("YES");
  else out("NO");
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
local mod = 1000000007
local mfl = math.floor

local function bmul(x, y)
  local x0, y0 = x % 31623, y % 31623
  local x1, y1 = mfl(x / 31623), mfl(y / 31623)
  return (x1 * y1 * 14122 + (x1 * y0 + x0 * y1) * 31623 + x0 * y0) % mod
end

local function badd(x, y)
  return (x + y) % mod
end

local n, c = io.read("*n", "*n")
local a, b = {}, {}
for i = 1, n do
  a[i] = io.read("*n")
end
for i = 1, n do
  b[i] = io.read("*n")
end
local dp1, dp2 = {1}, {0}
for i = 2, c + 1 do
  dp1[i] = 0
  dp2[i] = 0
end
for i = 1, n do
  local t = {}
  local ai, bi = a[i], b[i]
  for j = ai, bi do
    t[j + 1 - ai] = 1
  end
  local dpadd = {}
  for j = 1, c + 1 do
    dpadd[j] = 0
  end
  for j = 1, c + 1 do
    local tmp = 0
    for k = ai, bi do
      tmp = badd(tmp, t[k + 1 - ai])
      t[k + 1 - ai] = bmul(t[k + 1 - ai], k)
    end
    dpadd[j] = tmp
  end
  local dpsrc = i % 2 == 1 and dp1 or dp2
  local dpdst = i % 2 == 1 and dp2 or dp1
  for j = 1, c + 1 do
    dpdst[j] = 0
  end
  for j = c + 1, 1, -1 do
    local dpj = dpsrc[j]
    for k = 1, c - j + 2 do
      local dst = j + k - 1
      dpdst[dst] = badd(dpdst[dst], bmul(dpj, dpadd[k]))
    end
  end
end
if n % 2 == 0 then
  print(dp1[c + 1])
else
  print(dp2[c + 1])
end


Measured memory_bytes: 512
import sys
from collections import Counter
from collections import deque
import math
import fractions
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

h,w=mp()
g=[lmp() for i in range(h)]
step=[]
for i in range(h):
    if i%2==0:
        for k in range(w):
            step.append([i,k])
    else:
        for k in range(w):
            step.append([i,w-k-1])
ans=[]
for i in range(len(step)-1):
    if g[step[i][0]][step[i][1]]%2==1:
        g[step[i][0]][step[i][1]]-=1
        g[step[i+1][0]][step[i+1][1]]+=1
        ans.append([step[i][0]+1,step[i][1]+1,step[i+1][0]+1,step[i+1][1]+1])
print(len(ans))
for a in ans:
    print(*a)

Measured memory_bytes: 121176
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
void cal(int *ar,int n)
{
    int blocks[10]={0},temp[n];
    int i,j,t;
    for(i=0;i<n;i++)
    {
        for(j=0,t=1;j+1!=ar[i];j++)
        {
            if(blocks[j]==0)
                t++;
        }
        temp[i]=t;
        blocks[j]=1;
    }
    for(i=0;i<n;i++)
        ar[i]=temp[i];
}
int main()
{
    int ar[10]={1},ar1[10],ar2[10];
    int i,n,sum=0,t;
    for(i=1;i<10;i++)
        ar[i]=ar[i-1]*i;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&ar1[i]);
    for(i=0;i<n;i++)
        scanf("%d",&ar2[i]);
    cal(ar1,n);cal(ar2,n);
    for(i=0,ar[0]=0;i<n;i++)
        sum+=(ar1[i]-ar2[i])*ar[n-i-1];
    if(sum<0)
        sum=-sum;
    printf("%d\n",sum);
    return 0;
}


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

int main() {
    int t, sum = 0;
    for (int i = 0; i < 4; i++) {
        std::scanf("%d", &t);
        sum += t;
    }
    std::printf("%d\n%d\n", sum / 60, sum % 60);
    return  0;
}



Measured memory_bytes: 3204
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int a[10001],ans=0,bns=0,n;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=2*n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a+1,a+1+2*n);
    for(int i=1;i<=2*n;i+=2)
    {
        bns+=a[i];
    } 
    printf("%d\n",bns);
    return 0;
}

Measured memory_bytes: 256
i;k;t;main(n){
        int c[501],f[500],s[500];
        for(scanf("%d",&n);k<n-1;k++)scanf("%d%d%d",&c[k],&s[k],&f[k]);
        
        for(;i<n-1;i++){
            t=0;
            for(int j=i;j<n-1;j++){
                if(t<=s[j]){
                    t=s[j]+c[j];
                }else{
                    t=s[j]+c[j]+ceil( ((double)t-(double)s[j])/(double)f[j] )*f[j];
                    
                }
            }
            printf("%d\n",t);
        }
        printf("0");
    }

Measured memory_bytes: 1632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll a,b,c,d,n,ans=0;
void Main(){cin>>a>>b>>c>>d;
if(a+1==c&&d==1) cout<<1<<endl;
else cout<<0<<endl;
}
main(){
    Main();
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>


using namespace std;


int main() {

	string key = "keyence", S;
	bool ans = false;

	cin >> S;

	int i = 0, j = 0;

	for (i = 0; i <= S.size(); i++) {
		for (j = i; j <= S.size(); j++) {
			if (S.substr(0, i) + S.substr(j, S.size()) == key) {
				ans = true;
				break;
			}
		}
	}

	if (ans) {
		cout << "YES";
	}
	else{
		cout << "NO";
	}

	return 0;
}


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

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.setf(ios::fixed);
	cout.precision(4);
	
	int n, p;
	string s;
	
	cin >> n;
	
	vector <pair<pair<string, int>, int>> book;
	
	for (int i = 0; i < n; i++) {
	    cin >> s >> p;
        book.push_back(make_pair(make_pair(s, p*(-1)), i + 1));
	}
	
	sort(book.begin(), book.end());
	
	for (int i = 0; i < n; i++) cout << book[i].second << '\n';

	return 0;
}

Measured memory_bytes: 256
import sys

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    modDict = dict()
    modDictTotal = [0] * M
    numCount = dict()
    X = [int(x) for x in input().split()]
    used = [False] * M
    for x in X:
        modDictTotal[x % M] += 1
        if x % M in modDict: modDict[x % M] |= {x}
        else: modDict[x % M] = {x}
        if x in numCount: numCount[x] += 1
        else: numCount[x] = 1

    pairs = 0
    for key in modDict:
        if not used[key]:
            used[key] = True
            used[(M - key) % M] = True
            op = (M - key) % M
            if op != key:
                if modDictTotal[key] >= modDictTotal[op]:
                    pairs += modDictTotal[op]
                    left = modDictTotal[op]
                    for n in modDict[key]:
                        if numCount[n] % 2 == 1 and left > 0:
                            left -= 1
                            numCount[n] -= 1
                    for n in modDict[key]:
                        if left == 0: pairs += numCount[n] // 2
                        elif left > numCount[n]: 
                            left -= numCount[n]
                            numCount[n] = 0
                        else:
                            numCount[n] -= left
                            left = 0
                            pairs += numCount[n] // 2
                else:
                    pairs += modDictTotal[key]
                    left = modDictTotal[key]
                    for n in modDict[op]:
                        if numCount[n] % 2 == 1 and left > 0:
                            left -= 1
                            numCount[n] -= 1
                    for n in modDict[op]:
                        if left == 0: pairs += numCount[n] // 2
                        elif left > numCount[n]: 
                            left -= numCount[n]
                            numCount[n] = 0
                        else:
                            numCount[n] -= left
                            left = 0
                            pairs += numCount[n] // 2
            else: pairs += modDictTotal[key] // 2
    print(pairs)

    return 0

if __name__ == "__main__":
    solve()

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

int main()
{
  long H, W;

  cin >> H >> W;

  if (H == 1 || W == 1)
  {
    cout << 1 << endl;
  }
  else
  {
    cout << (H * W + 1) / 2 << endl;
  }
}

Measured memory_bytes: 256
#ifdef __GNUC__
#pragma GCC target("avx2")
#pragma GCC optimize ("O20")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC optimize("unroll-loops")
#define iss std::cin
#endif
#include "bits/stdc++.h"
#define rep(i, times) for(ll i = 0; i < (times); ++i)
#define p(x) (cout << x << "\n")
using ll = long long; using ld = long double; using namespace std;

#ifndef __GNUC__
string text =
R"X(5 2
3 1 2 5
2 2 3
1 0)X";
stringstream iss{text};
#endif

class Switches
{
	ll N{0}, M{0}, allS{0}, cnt{0};
	vector<vector<ll>> s;
	vector<ll> p;
	void inp( ) {
		iss >> N >> M;
		s.resize(M);
		rep(m, M) {
			ll K; iss >> K;	s[m].resize(K);
			rep(k, K) { iss >> s[m][k]; }
		}
		p.resize(M); rep(m, M) { iss >> p[m]; }
	}
	inline ll Non(ll m) {//m番目の電球につながっているスイッチでonのものの個数
		ll con{0};
		for (auto &p : s[m]) {// m番目の電球につながっているp番目のスイッチ
			if ((allS >> (p - 1)) & 1) ++con; //スイッチpがonかどうか
		}
		return con;
	}
	inline bool light(ll m) {//m番目の電球がつくか？
		return !((Non(m) & 1) ^ p[m]);
	}
	inline bool allonQ( ) {//全部の電球がつくか
		rep(m, M) { if (!light(m)) return false; }
		return true;
	}
	void changeSwitch( ) {
		for (ll b = 0; b < ll(1 << N); ++b) {
			allS = b;//スイッチの状態を変える
			if (allonQ( )) ++cnt;
		}
	}
public:
	void procedures( ) {
		inp( );
		changeSwitch( );
		p(cnt);
	}
};

int main( ) {
	cin.tie(0);	ios::sync_with_stdio(0);
	class Switches a; a.procedures( );
}

Measured memory_bytes: 3504
h, n  = map(int, input().split())
dp = [None] * (h+10)
dat = []
for _ in range(n):
    a,b = map(int, input().split())
    dat.append([a,b])
dp[0] = 0
for i in range(h):
    if dp[i] is None:
        continue
    for j in range(len(dat)):
        a,b = dat[j]
        #print(i,dp[i],j,a,b)
        magic = b + dp[i]
        nextdp = i + a
        if nextdp > h:
            nextdp = h
        if dp[nextdp] is None:
            dp[nextdp] = magic
        else:
            dp[nextdp] = min(dp[nextdp], magic)
#print(dp[:200])
print(dp[h])


Measured memory_bytes: 43612
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n;
    cin>>n;

    ll ub = n;
    if (n % 2 == 0) {
        ub++;
        cout<<(n - 2) * n / 2<<endl;
    }
    else {
        cout<<((n - 2) * (n - 1) + n - 1) / 2<<endl;
    }
    rep(i, n) {
        ll x = i + 1;
        for (int y = x + 1; y <= n; ++y) {
            if (ub - x == y) continue;
            cout<<x<<" "<<y<<endl;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
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() {
  //input
  int N;
  long long int W;
  cin >> N >> W;
  long long int w[N];
  int v[N];
  int v_max = 0;
  for(int i=0; i<N; i++){cin >> w[i] >> v[i];}
  for(int i=0; i<N; i++){v_max = max(v_max, v[i]);}
  
  //main
  int INF = 1e9;
  long long memo[N+10][N*v_max+1];
  
  //DPtable
  for(int i = 0; i < N+1; i++){
    for(int j = 0; j < (N*v_max+1); j++){
      memo[i][j] = INF;
    }
  }
  memo[0][0] = 0;

  //memo[i+1]...k番目について v[i]...k番目について
  for(int i=0; i<N; i++){
    for(int sum_v=0; sum_v<(N*v_max+1); sum_v++){
      if(sum_v - v[i] >= 0){ chmin(memo[i+1][sum_v], memo[i][sum_v-v[i]]+w[i]);}
      chmin( memo[i+1][sum_v], memo[i][sum_v] );
    }
  }
  
  //output  
  
  //loopが進むとsum_vが上昇 = Wの条件だけ見れば最適化できる。 
  long long ans = 0;
  for(int sum_v=0; sum_v<(N*v_max+1); sum_v++){
    if(memo[N][sum_v] <= W) ans = sum_v;
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 81024
N, K= map(int, input().split())
A = list(map(int, input().split()))
x = {1:0}
point = 1
count = 0
while True:
  next_point = A[point-1]
  count +=1
  if next_point in x :
    flag=next_point
    break
  x[next_point] =count
  point = next_point
  
#print(count, x[flag])
c = count - x[flag]
f = x[flag]
#print(c)
if K <f:
    print([i for i in x if x[i] == K ][0])
else :
    dic = {j-f: i for i,j in x.items()}
    print(dic[(K-f) % c])

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

signed main() {
	vector<int> v(3);
	for (int i = 0; i < 3; ++i)cin >> v[i];
	sort(v.begin(), v.end());
	cout << v[0] + v[1] << endl;
}

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

MOD = 10**9+7
def pow(a, b):
    res = 1
    while b:
        if b & 1: res = res * a % MOD
        a = a**2 % MOD
        b >>= 1
    return res


def main():    
    X, Y = map(int, input().split())
    
    if (X+Y) % 3: print(0); sys.exit()
    
    n = (X+Y) // 3
    
    X -= n
    Y -= n
    
    if X < 0 or Y < 0: print(0); sys.exit()
    
    fac = [1] * (X+Y+1)
    for i in range(2, X+Y+1): fac[i] = fac[i-1] * i % MOD
    
    ans = (fac[X+Y] * pow(fac[X], MOD-2)) % MOD * pow(fac[Y], MOD-2)
    print(ans%MOD)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 29428
using System;

class Program {
    static int Main(string[] args) {
        string v = Console.ReadLine();
        int a = int.Parse(v.Split(' ')[0]);
        int b = int.Parse(v.Split(' ')[1]);

        string msg = "a == b";
        if (a < b) { msg = "a < b"; }
        else if (a > b) { msg = "a > b"; }

        Console.WriteLine(msg);
        return 0;
    }
}

Measured memory_bytes: 8884
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = a*b;
        if (c%2 == 0) {
        	System.out.println("Even");
        } else {
        	System.out.println("Odd");
        }
	}
}


Measured memory_bytes: 35548
until (given = gets.chomp) == "0 0"
  x, y = given.split.map(&:to_i)
  x, y = y, x if x < y
  count = 0
  until y.zero?
    x = x % y
    x, y = y, x
    count += 1
  end
  puts "#{x} #{count}"
end


Measured memory_bytes: 6856
#include<bits/stdc++.h>
const int MAXN = 100000+15;
typedef long long ll;
using namespace std;
int main(){
  int T;
  scanf("%d",&T);
  int nowx = 0,nowy = 0,nowt = 0;
  int flag = 0;
  while(T--){
    int t,x,y;
    scanf("%d %d %d",&t,&x,&y);
    if(abs(x+y-nowx-nowy)>(t-nowt)){
      flag = 1;
      break;
    }else if((t-nowt-abs(x+y-nowx-nowy))%2!=0){
      flag = 1;
      break;
    }
    nowx = x;nowy = y;nowt = t;
  }
  if(flag)
  cout<<"No"<<endl;
  else
  cout<<"Yes"<<endl;

}


Measured memory_bytes: 256
N,K = map(int, input().split())
S = input()

# いったんリストにする
S_list = list(S)

if S_list[K-1] == 'A':
    S_list[K - 1]='a'
elif S_list[K-1] == 'B':
    S_list[K - 1] = 'b'
elif S_list[K-1] == 'C':
    S_list[K - 1] = 'c'

# またリストから文字列へ戻す
S_changed = "".join(S_list)
print(S_changed)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

vector<P> v;

int main(void){
	int k,i,n[2],m=0,a[2];
	ll p,ans=0ll;
	cin >> n[0] >> n[1];
	for(k=0; k<2; ++k){
		a[k] = n[k]+1;
		m += n[k];
		for(i=0; i<n[k]; ++i){
			cin >> p;
			v.push_back(P(p,k));
		}
	}
	sort(v.begin(),v.end());
	for(i=0; i<m; ++i){
		p = v[i].first;
		k = v[i].second;
		ans += p*a[1-k];
		--a[k];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 6384
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		new Main().run();
	}
	void run(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int b = sc.nextInt();
			if(b == 0){
				//System.out.println("break");
				break;
			}
			int[] a = new int[b];
			int left,right,searchvalue;
			for(int i=0; i < a.length; i++){
				a[i] = sc.nextInt();
			}
			searchvalue = sc.nextInt();
			left = 0; right = a.length-1;
			solve(left, right, searchvalue, a, 0);
		}
	}

	void solve(int left, int right,int sv,int[] a, int cnt){
		int index = (left + right) / 2;
		//System.out.println("left:"+left+" right:"+right+" sv:"+sv+" a[index]:"+a[index]);
		if(a[index] == sv){
			System.out.println(++cnt);
		}else if(left > right){
			System.out.println(cnt);
			return;
		}else if(a[index] < sv){
			left = index;
			solve(++left, right, sv, a, ++cnt);
		}else if(a[index] > sv){
			right = index;
			solve(left, --right, sv, a, ++cnt);			
		}
		
		/*
		if(cnt == a.length-1){
			System.out.println(cnt);
			return;
		}
		if(a[(left + right) / 2] < sv){
			System.out.println("left:"+left+" right:"+right);
			if(left <= right){
				left = (left + right) / 2 + 1;
				solve(left, right,sv, a, ++cnt);
			}else{
				System.out.println(++cnt);
			}
		}else if(a[(left + right) / 2] > sv){
			System.out.println("left:"+left+" right:"+right);
			if(left < right){
				right = (left + right) / 2 - 1;
				solve(left, right,sv, a, ++cnt);
			}else{
				System.out.println(++cnt);
			}
		}else{
			System.out.println(++cnt);
		}
		*/
	}
}

Measured memory_bytes: 20472
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
static const int n=1000;

int lcs(string x,string y){
  int c[n+1][n+1];
  int m=x.size();
  int n=y.size();
  int maxl=0;
  x=' '+x;
  y=' '+y;
  for(int i=1;i<=m;i++)c[i][0]=0;
  for(int i=1;i<=n;i++)c[0][i]=0;

  for(int i=1;i<=m;i++){
    for(int j=1;j<=n;j++){
      if(x[i]==y[j]){
	c[i][j]=c[i-1][j-1]+1;
      }else {
	c[i][j]=max(c[i-1][j],c[i][j-1]);
      }
      maxl=max(maxl,c[i][j]);
    }
  }
  return maxl;
}

int main(){
  string s1,s2;
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s1>>s2;
    cout<<lcs(s1,s2)<<endl;
  }
  return 0;
}

Measured memory_bytes: 5124
#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 mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

void solve(long long N, vector<string> S){
	bool oldIsTwo = false;
	ll res = 1;
	for (ll i = 0; i < N;) {
		if (i != 0) {
			if (S[0][i] == S[1][i]) {
				if (oldIsTwo) {
					res = res * 1 % mod;
				} else {
					res = res * 2 % mod;
				}
				oldIsTwo = false;
				i++;
			} else {
				if (oldIsTwo) {
					res = res * 3 % mod;
				} else {
					res = res * 2 % mod;
				}
				oldIsTwo = true;
				i+=2;
			}
		} else {
			if (S[0][i] == S[1][i]) {
				res = res * 3 % mod;
				oldIsTwo = false;
				i++;
			} else {
				res = res * 6 % mod;
				oldIsTwo = true;
				i+=2;
			}
		}
	}
	cout << res << endl;
}

int main(){	
	vector<string> S(2-1+1);
	long long N;
	scanf("%lld",&N);
	for(int i = 0 ; i <= 2-1 ; i++){
		cin >> S[i];
	}
	solve(N, S);
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>


int main()
{
    long long a, b;
    char c;
    scanf("%lld %c %lld",&a, &c, &b);
    if(c=='+'){
        printf("%lld", a+b);
    }
    else if(c=='-'){
        printf("%lld", a-b);
    }
    return 0;
}


Measured memory_bytes: 128
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  ll n,cnt=0,dis=2;
  cin >> n;
  vector<ll> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  cnt += a[0]-1;
  for(int i=1;i<n;i++){
    if(a[i]==dis){
      dis++;
    }else{
      ll fd = dis;
      if(a[i]%dis==0){
        fd++;
      }
      if(a[i]<fd) continue;
      a[i] -= fd;
      cnt++;
      cnt += a[i]/dis;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int n, m, v, u, par[200005];
vector<int> G[200005];
queue<int> qu;
int main(){
	scanf("%d%d", &n, &m);
	rep(i,m){
		scanf("%d%d", &v, &u);
		G[v].push_back(u);
		G[u].push_back(v);
	}
	qu.push(1); par[1] = 1;
	while(!qu.empty()){
		u = qu.front(); qu.pop();
		for(int nx: G[u]) if(!par[nx]){
			qu.push(nx);
			par[nx] = u;
		}
	}
	puts("Yes");
	rep(i,n-1) printf("%d\n", par[i+2]);
}

Measured memory_bytes: 12968
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);i++)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;i--)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> void chmin(T& t, const U& u){if(t>u)t=u;}
template<typename T,typename U> void chmax(T& t, const U& u){if(t<u)t=u;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T mpow(T a, T n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n;cin>>n;
  vector<ll> v(n),sum(n+1,0);
  rep(i,0,n){
     cin>>v[i];
     sum[i+1]=sum[i]+v[i];
  }

   ll ans=LINF;
  rep(i,0,n){
     ans=min(ans,abs(2*sum[i+1]-sum[n]));
  }
  cout<<ans<<endl;
}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

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

int main(void){
  int n,k,ans;
  
  cin >> n >> k;
  ans=0;
  for (int i=0; i<n; i++){
    int h;
    cin >> h;
    if (h>=k) ans++;
  }
  cout << ans << endl;
  return 0;
}
  

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

int main() {
  
  int N , M ;
  cin >> N >> M ;
  if( N <= 2*M ) cout << 0 << endl;
  else cout << N - 2*M << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Thu May  7 01:30:29 2020

@author: shinba
"""
import collections

def conbination(n):
    return int(n*(n-1)/2)

N = int(input())
A = list(map(int,input().split()))

B = collections.Counter(A)

W = 0
for i in B.values():
    W += conbination(i)

for i in A:
    print(W-B[i]+1)



Measured memory_bytes: 26780
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

int main() {
	ll n,a,b;
	cin >> n >> a >> b;
	if (a > b)cout << 0 << endl;
	else if (n == 1) cout << (a == b ? 1 : 0) << endl;
	else cout << (n - 2) * (b - a) + 1 << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, a) for(auto &&i:(a))
#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 RREP(i, n) for(int i=(n)-1;i>=0;--i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

map<char,int> mp[101];

signed main() {
  INIT;
  VAR(int,n);
  VAR(string,a,b,c);
  REP(i,n){
    ++mp[i][a[i]];
    ++mp[i][b[i]];
    ++mp[i][c[i]];
  }

  int ans = 0;
  REP(i,n){
    vector<int> tmp;
    EACH(mi,mp[i]){
      tmp.push_back(mi.second);
    }
    sort(ALL(tmp));
    int sm=0;
    REP(i,tmp.size()-1){
      sm += tmp[i];
    }
    ans += sm;
  }
  OUT(ans)BR;
  
  return 0;
}


Measured memory_bytes: 256