akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    double x = 0;
    String u = null;
    double ans = 0;
    for(int i=0;i<n;i++){
      x = sc.nextDouble();
      u = sc.next();
      if(u.equals("JPY")){
        ans += x;
      } else {
        ans += x*380000;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=410,p=1e9+7;
int inc(int x,int y){x+=y;return x>=p?x-p:x;}
int dec(int x,int y){x-=y;return x<0?x+p:x;}
int mul(int x,int y){return (ll)x*y%p;}
int power(int x,int y){
	int ans=1;
	for (;y;y>>=1,x=mul(x,x))
		if (y&1) ans=mul(ans,x);
	return ans;
}
int n,m,a[N],b[N],dp[150][N][N];
//dp[i][j][k][l]表示吃了i次，a,b中上一次被吃掉的分别是a[j],b[k]的方案数
//其中c吃的l个还没有确定的方案数，l=3*i-cnt[j][k]
bool ina[N][N],inb[N][N];
int cnt[N][N],P[N][N],sum[N][N],fac[N],ifac[N];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++) scanf("%d",&b[i]);
	fac[0]=1;
	for (int i=1;i<=n;i++) fac[i]=mul(fac[i-1],i);
	ifac[n]=power(fac[n],p-2);
	for (int i=n;i;i--) ifac[i-1]=mul(ifac[i],i);
	for (int i=1;i<=n;i++){
		for (int j=1;j<=n;j++) ina[i][j]=ina[i-1][j],inb[i][j]=inb[i-1][j];
		ina[i][a[i]]=inb[i][b[i]]=1;
	}
	for (int i=0;i<=n;i++)
	for (int j=0;j<=n;j++)
	for (int k=1;k<=n;k++)	
		cnt[i][j]+=(ina[i][k]||inb[j][k]);
	for (int i=0;i<=n;i++){
		P[i][0]=1;
		for (int j=1;j<=i;j++) P[i][j]=mul(P[i][j-1],i-j+1);
	}
	m=n/3;
	dp[0][0][0]=1;
	for (int i=0;i<m;i++){
		for (int j=0;j<=n;j++)
		for (int k=0;k<=n;k++){
			int l=3*i-cnt[j][k];
			sum[j][k]=(l>=0?mul(dp[i][j][k],fac[l]):0);
			if (j) sum[j][k]=inc(sum[j][k],sum[j-1][k]);
			if (k) sum[j][k]=inc(sum[j][k],sum[j][k-1]);
			if (j&&k) sum[j][k]=dec(sum[j][k],sum[j-1][k-1]);
		}
		for (int j=1;j<=n;j++)
		for (int k=1;k<=n;k++)
		if (!ina[j-1][b[k]]&&!inb[k-1][a[j]]&&a[j]!=b[k]){
			int l=3*i-cnt[j-1][k-1];
			if (l>=0) dp[i+1][j][k]=inc(dp[i+1][j][k],mul(mul(sum[j-1][k-1],ifac[l]),P[n-3*i-1][2]));
		}
	}
	int ans=0;
	for (int j=1;j<=n;j++)
	for (int k=1;k<=n;k++){
		int l=n-cnt[j][k];
		ans=inc(ans,mul(dp[m][j][k],fac[l]));
	}
	printf("%d\n",ans);
	return 0;
}

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

int main(){
 
 int n;
 long long a;
 long long minValue = 1000000;
 long long maxValue = -1000000;
 long long sum = 0;
     
 cin >> n;
 
   for ( int i = 0; i < n; i++ ){
     cin >> a;
     if ( a < minValue ) minValue = a;
     if ( a > maxValue ) maxValue = a;
     sum += a;
   }
   
cout << minValue << " " << maxValue << " " << sum <<endl;
    
       
return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> xyz(N);
    REP(i, N) {
        int x, y, z;
        cin >> x >> y >> z;
        xyz[i] = {x, y, z};
    }
    int ans = 0;
    REP(bit, 1 << 3) {
        vector<pii> l;
        REP(i, N) {
            int s = 0;
            REP(j, 3) {
                int sign = -1;
                if ((bit >> j) & 1) {
                    sign *= -1;
                }
                s += sign * xyz[i][j];
            }
            l.push_back({s, i});
        }
        sort(RALL(l));

        int tmp = 0;
        vector<int> XYZ(3, 0);
        REP(k, M) {
            int i = l[k].second;
            int s = l[k].first;
            tmp += s;
            REP(j, 3) {
                int sign = -1;
                if ((bit >> j) & 1) {
                    sign *= -1;
                }
                XYZ[j] += sign * xyz[i][j];
            }
        }
        bool ok = true;
        REP(j, 3) {
            if (XYZ[j] < 0) ok = false;
        }
        if (ok) {
            chmax(ans, tmp);
        }
    }
    cout << ans << endl;
    return 0;
}



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

/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______      
 * |\  \|\  \  |\  ___ \  |\  ___ \     
 * \ \  \/  /|_\ \   __/| \ \   __/|    
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__  
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \ 
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;

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

	int N,A;
	cin>>N>>A;
	cout<<(N%500 <= A?"Yes":"No")<<'\n';
	return 0;
}


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

fn main() {
    let scan = io::stdin();
    for line in scan.lock().lines() {
        let uline = line.unwrap();
        let vec: Vec<&str> = uline.split_whitespace().collect(); 
        let md:i32 = vec[0].parse().unwrap_or(0);
        let fi:i32 = vec[1].parse().unwrap_or(0);
        let mu:i32 = vec[2].parse().unwrap_or(0);
        if md == -1 && fi == -1 && mu == -1 {
            break;
        } else if md == -1 || fi == -1 {
            println!("F");
        } else {
            let sum = md + fi;
            if sum >= 80 {
                println!("A");
            } else if sum >= 65 {
                println!("B");
            } else if sum >= 50 {
                println!("C");
            } else if sum >= 30 {
                if mu >= 50 {
                    println!("C");
                } else {
                    println!("D");
                }
            } else {
                println!("F");
            }
        }
    }
}



Measured memory_bytes: 5032
//
// author  : Abhishek
//
#include <bits/stdc++.h>
#include<chrono>

#define ll long long
#define db double
#define deb(x) cout<<#x<<": "<<x<<"\n"
#define all(x) x.begin(),x.end()
#define fo(i, n) for(i=0 ; i<n ; i++)
#define Fo(i, k, n) for(i=k ; i<n ; i++)

using namespace std;
using namespace chrono;

const ll MOD = 1000000007;
const ll N = 300005;  // array size
const ll inf = 10000000000000000;
const db PI = 3.14159265358979323846264338327950288419716939937510;

void print(vector<ll> v) {
    ll i;
    fo(i, v.size())cout << v[i] << " ";
    cout << "\n";
}

void print(vector<pair<ll, ll> > v) {
    ll i;
    fo(i, v.size()) {
        cout << v[i].first << " " << v[i].second << "\n";
    }
}

vector<ll> read(ll n) {
    ll i;
    vector<ll> arr(n, 0);
    fo(i, n)cin >> arr[i];
    return arr;
}

vector<ll> read(ll n, ll k) {
    ll i;
    vector<ll> arr(n + k, 0);
    Fo(i, k, n + k)cin >> arr[i];
    return arr;
}

bool isEven(ll n) {
    return n % 2 == 0;
}

bool isOdd(ll n) {
    return n % 2 != 0;
}


void solve() {
    ll t = 1;
//    cin >> (t);
    while (t--) {

        ll i, j, k, n, m, p, q, x, y, a, b, l, r;
        cin >> n;
        vector<ll> arr;
        arr = read(n);
        ll ans = 1;
        ll mn = arr[0];
        fo(i, n) {
            if (arr[i] < mn) {
                ans++;
            }
            mn = min(arr[i], mn);
        }
        cout << ans;
    }


}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif

    auto start = high_resolution_clock::now();

    solve();

    ll i, j, k, n, m, p, q, x, y, a, b, l, r;


    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop - start);
#ifndef ONLINE_JUDGE
    cerr << "Time: " << duration.count() / 1000.0 << endl;
#endif


    return 0;
}




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

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

int main() {
    int a, b, c;
    int x;
    int res = 0;

    cin >> a >> b >> c;
    cin >> x;

    rep(i, a+1){
        rep(j, b+1){
            rep(k, c+1){
                if(500*i+100*j+50*k  == x){
                    res ++;
                }
            }
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 256
N = int(input())
B = list( map(int, input().split(" ")) )

A = [0]*( len(B)+1)
A[0] = B[0]
for i in range(0, len(B)):
    if A[i] > B[i]:
        A[i] = B[i]
    A[i+1] = B[i]
print(sum(A))

Measured memory_bytes: 38384
#include<iostream>
#include<cstdio>
#include<complex>
#include<cmath>
using namespace std;

typedef complex<double> P;

inline double dot(P a, P b) {return real( conj(a)*b);}
inline double cross(P a, P b) {return imag( conj(a)*b);}

P IntersectionLL(P a1, P a2, P b1, P b2) {
  P a = a2 - a1; P b = b2 - b1;
  return a1 + a * cross(b, b1-a1) / cross(b, a);
}

int main() {
  int T; cin >> T;
  while( T--> 0 ) {
    P p[3];
    for(int i = 0; i < 3; i++) {
      double x, y; cin >> x >> y;
      p[i] = P(x, y);
    }

    P a = p[1] - p[0];
    P b = p[2] - p[0];

    P m1 = p[0] + a / 2.0;
    P m2 = p[0] + b / 2.0;

    P o = IntersectionLL( m1, m1 + a * P(0, 1), m2, m2 + b * P(0, 1) );

    printf("%.3f %.3f %.3f\n", o.real(), o.imag(), abs(o - p[0]) );
  }
}

Measured memory_bytes: 0
n, l = map(int, input().split())
a = list(map(int, input().split()))

flag = -1
for i in range(n - 1):
    if l <= a[i] + a[i + 1]:
        flag = i + 1
if flag == -1:
    print("Impossible")
    exit()

print("Possible")
for i in range(1, flag):
    print(i)
for i in range(flag + 1, n)[::-1]:
    print(i)
print(flag)
      

Measured memory_bytes: 63968
#include <stdio.h>

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


Measured memory_bytes: 2108
#include<bits/stdc++.h>
#define pb push_back
#define in insert
#define ff first
#define ss second
#define mp make_pair
#define int long long
#define uint unsigned long long
#define rep(i,x,m) for(int i=x;i<m;i++)
#define repr(i,x,m) for(int i=x;i>=m;i--)
#define MOD 1000000007
#define endl "\n"
using namespace std;
#define noob ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

void ram5564()
{
    int n,m,c;
    cin>>n>>m>>c;
    int a[n+2],b[m+2];
    map<pair<int,int>,int>mpp;
    int a1=1e9,a2=1e9;
    for(int i=1;i<=n;++i)
    {
        cin>>a[i];
        a1=min(a1,a[i]);

    }
    for(int i=1;i<=m;++i)
    {
        cin>>b[i];
        a2=min(a2,b[i]);
    }
    int ans=a1+a2;
    int dis,x,y;
    while(c--)
    {
        cin>>x>>y>>dis;
        if(mpp.find(mp(x,y))==mpp.end())
        {
            mpp[mp(x,y)]=dis;
        }
        else
        {
            mpp[mp(x,y)]=max(mpp[mp(x,y)],dis);
        }
    }
    for(auto x:mpp)
    {
        ans=min(a[x.ff.ff]+b[x.ff.ss]-x.ss,ans);

    }
cout<<ans;
}

signed main()
{
        noob
       
        int t=1;
        //cin>>t;
        while(t--)
        ram5564();
        return 0;
}

Measured memory_bytes: 8064
#include<stdio.h>
#define N 100000
#define M 50000
int main(void){
  int i,j,k,s_total,t_total,left,right,mid=0,count=0;
  int S[N],T[M];

  scanf("%d",&s_total);
  for(i=0;i<s_total;++i){
    scanf("%d",&S[i]);
  }

  scanf("%d",&t_total);
  for(j=0;j<t_total;++j){
    scanf("%d",&T[j]);
  }
  for(k=0;k<t_total;k++){
    left=0;
    right=s_total;
   while(left<right){
     mid=(left+right)/2;
      if(S[mid]==T[k]){
        count++;
        break;
      }
      else if(S[mid]>T[k]){
        right=mid;
      }
      else {
        left=mid+1;
      }
   }
  }
  printf("%d\n",count);
  return 0;
}




Measured memory_bytes: 2444
#include<stdio.h>
#include<math.h>
int main(void){
  int n,*a,sum,i,ans=0;
  double d=100,ave;
  scanf("%d",&n);
  a=(int)malloc(sizeof(int)*n);
  for(i=0;i<n;i++)scanf("%d",&a[i]);
  for(sum=0,i=0;i<n;i++)sum+=a[i];
  ave=(double)sum/n;
  for(i=0;i<n;i++){
    if(fabs(a[i]-ave)<d){
      d=fabs(a[i]-ave);
      ans=i;
    }
  }
  printf("%d",ans);
  return 0;
}

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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

const int MOD=998244353;
int D[3001][3001][2][2];

int mul(int a, int b)
{
	return 1LL*a*b%MOD;
}

int add(int a, int b)
{
	return a+b>=MOD ? a+b-MOD:a+b;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt","r",stdin));
	TEST(freopen("output.txt","w",stdout));
	TEST(freopen("debug.txt","w",stderr));
	int A, B, X, Y;
	cin>>A>>B>>X>>Y;
	D[A][B][0][0]=1;
	for(int i=A;i<=X;i++) for(int j=B;j<=Y;j++) if(i!=A || j!=B) {
		if(i>A) D[i][j][0][0]=mul(add(D[i-1][j][0][0],D[i-1][j][1][0]),j-1);
		else D[i][j][0][0]=mul(add(D[i][j-1][0][0],D[i][j-1][0][1]),i-1);
		D[i][j][1][0]=add(add(D[i][j-1][0][0],D[i][j-1][0][1]),mul(D[i][j-1][1][0],i));
		D[i][j][0][1]=add(add(D[i-1][j][0][0],D[i-1][j][1][0]),mul(D[i-1][j][0][1],j));
	}
	cout<<add(D[X][Y][0][0],add(D[X][Y][1][0],D[X][Y][0][1]))<<'\n';
	return 0;
}

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

using namespace std;

int n, h[100002], dp[100002];

int sol(int i){
    if(i==n-1) return 0;
    if(i>=n) return 1E9;

    int &ret = dp[i];
    if(~ret) return ret;

    return ret = min(abs(h[i+1]-h[i]) + sol(i+1),
                     abs(h[i+2]-h[i]) + sol(i+2));
}

int main()
{
    cin >> n;
    for(int i=0; i<n; i++)
        cin >> h[i];

    memset(dp, -1, sizeof dp);
    cout << sol(0);
}


Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_solve
{
    class Program
    {
        public const ulong mod = 1000000007;

        static void Main(string[] args)

        {
            var kn = Input3();
            var a = Input3();
            long[] d = new long[kn[1]];
            long ans = 0;

            for(long i = 0; i < kn[1]-1; i++)
            {
                d[i] = a[i + 1] - a[i];
            }

            d[kn[1]-1] = kn[0] - a[kn[1] - 1]+a[0];

            Array.Sort(d);
            ans = kn[0]-d[kn[1]-1];
            

            Console.WriteLine(ans);
                
                





        }

       
        static public long Input()
        {
            return long.Parse(Console.ReadLine());
        }

        static public string[] Input2()
        {
            return Console.ReadLine().Split();
        }

        static public long[] Input3()
        {
            string[] data = Console.ReadLine().Split();
            long[] res = new long[data.LongLength];
            for(long i = 0; i < data.LongLength; i++)
            {
                res[i] = long.Parse(data[i]);
            }
            return res;
        }
        public static long Choose(long n, long a)
        {
            long x = 1;
            long y = 1;
            for (long i = 0; i < a; i++)
            {
                x *= n - i;
                y *= i + 1;
            }
            return x / y;
        }

        public static long Gcd(long a, long b)
        {
            long x = Math.Max(a, b);
            long y = Math.Min(a, b);
            if (x % y == 0) return y;
            else return Gcd(y, x % y);
        }
    }
}


Measured memory_bytes: 35204
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <unordered_map>

using namespace std;

typedef long long LL;

string str;

int main() {
    cin >> str;
    bool flag = true;
    for (int i = 0;i < str.size();i ++) {
        if ((i % 2 == 0 && str[i] != 'h') || (i % 2 == 1 && str[i] != 'i')) {
            flag = false;
            break;
        }
    }
    if (flag && str.size() % 2 == 0 && str.size() != 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
def factorize(n):
    res = []
    i = 2
    while i * i <= n:
        cnt = 0
        while n % i == 0:
            cnt += 1
            n //= i
        if cnt > 0:
            res.append([i, cnt])
        i += 1
    if n != 1:
        res.append([n, 1])
    return res

n = int(input())
nlist = factorize(n)
ans = 0
for k, v in nlist:
    i = 1
    while v >= i:
        v -= i
        i += 1
    ans += i-1
print(ans)

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

int ctoi(char c) {
    int n = c - '0';
    return n;
}

int pow_int(int x, int n) {
    if (n == 0) {
        return 1;
    }else {
        int y = x;
        for (int i = 0; i < n-1; i++) {
            x *= y;
        }
        return x;
    }
}


int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    double sum = 0;
    rep(i, n) sum += a[i];
    int count = 0;
    rep(i, n) {
        if (a[i] >= sum / (4.0*m)) count ++;
    }
    if (count >= m) {
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
    int N; cin >> N;
    vector<int> a(N);
    rep(i,N)cin >> a[i];
    sort(all(a));
    int sum = 0;
    rep(i,N-1)sum += a[i];
    cout << ((sum > a[N-1]) ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3556
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n;
char s1[105],s2[105],s3[105];
int main()
{
	int ans=0;
	scanf("%d",&n);
	scanf("%s%s%s",s1+1,s2+1,s3+1);
	for(int i=1;i<=n;i++)
	{
		if(s1[i]==s2[i]&&s2[i]==s3[i])continue;
		if(s1[i]==s2[i]||s2[i]==s3[i]||s1[i]==s3[i])ans++;
		else ans+=2;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

const int MAXN = 1e6+5;
int N;
long long W, v[101], w[101], dp[101][MAXN]{0};

int main()
{
    cin >> N >> W;
    for(int i = 0; i < N; i++) cin >> w[i] >> v[i];
    int ans = 0;
    for(int i = 1; i <= N; i++) {
        dp[i][v[i-1]] = w[i-1];
        for(int j = 0; j < MAXN; j++) {
            if(dp[i][j] == 0)
                dp[i][j] = dp[i-1][j];
            if(dp[i-1][j] > 0 && dp[i][j] > 0)
                dp[i][j] = min(dp[i-1][j], dp[i][j]);
            if(j >= v[i-1] && dp[i-1][j-v[i-1]] > 0 && dp[i-1][j-v[i-1]]+w[i-1] <= W) {
                if(dp[i][j] != 0)
                    dp[i][j] = min(dp[i][j], dp[i-1][j-v[i-1]]+w[i-1]);
                else
                    dp[i][j] = dp[i-1][j-v[i-1]]+w[i-1];
            }
            if(dp[i][j] > 0 && dp[i][j] <= W)
                ans = max(j, ans);
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 784852
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <stack>
#include <set>
#include <map>
#include <math.h>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define rev(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = INT_MAX;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ O(logN)
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//



int main() {

    int n;
    cin >> n;
    vector <ll> a(n+1);
    rep(i,n) cin >> a[i];
    a[n] = INF;
    Sort(a);

    int ans = 0;
    int num = a[0];
    int cnt = 0;
    rep(i,n+1) {
        if (a[i] == num) {
            ++cnt;
        }
        else {
            if (num <= cnt) ans += cnt - num;
            else ans += cnt;
            num = a[i];
            cnt = 1;
        }
    }

    out(ans);

    return 0;
}








Measured memory_bytes: 1024
<?php
  fscanf(STDIN, "%s", $s);
  fscanf(STDIN, "%s", $t);
$arr1 = str_split($s);
$arr2 = str_split($t);
$n=strlen($s);
$ans = 0;
if($s == $t){
$ans = 0;
}else
for($i=0;$i<$n;++$i){
  if($arr1[$i]!=$arr2[$i]){
  $ans = ++$ans;
}
}
echo $ans;
?>

Measured memory_bytes: 41248
//Solution by Tima
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
#include <map>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <bitset>
#define f first
#define s second
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define vi vector <int>
#define ld long double
#define pii pair<int, int>
#define y1 sda
using namespace std;    
const int N = int(3e5), mod = int(1e9)  + 7; 

int n, a[N];

int cnta[N], cntb[N], ca, cb;

set <pair<int,int> > sa, sb;

vector <int> x, y;

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

	for(int i = 1; i <= n; i++){
		if(i & 1) {
			sa.erase(mp(-cnta[a[i]], a[i]));
			cnta[a[i]]++;
			sa.insert(mp(-cnta[a[i]], a[i]));
			ca++;
		}
		else {
			sb.erase(mp(-cntb[a[i]], a[i]));
			cntb[a[i]]++;
			sb.insert(mp(-cntb[a[i]], a[i]));
			cb++;
		}
	}

	int it = 0;


	for(int i = 0; i < 3; i++){
		if(sa.size() > 0){
			x.pb((*sa.begin()).s);
			sa.erase(sa.begin());
		}
		if(sb.size() > 0){
			y.pb((*sb.begin()).s);
			sb.erase(sb.begin());
		}
	}

	x.pb(1);
	y.pb(1);
	x.pb(2);
	y.pb(2);

	int ans = n;
	for(int i = 0; i < x.size(); i++){
		for(int j = 0; j < y.size(); j++){
			if(x[i] != y[j]){
				ans = min(ans, n - cnta[x[i]] - cntb[y[j]]);
			}
		}	
	}
	cout << ans;


return 0;
}

Measured memory_bytes: 6144
#include<iostream>
#include<cstdlib>
#include <vector>
using namespace std;
class Hapiness
{
public:
	int swim;
	int catBugs;
	int hw;
	Hapiness() : swim(0),catBugs(0),hw(0) {}
};
int main()
{
	int n;
	cin >> n;
	vector<Hapiness>vect(n);
	for(int i = 0;i < n;++i)
	{
		cin >> vect[i].swim;
		cin >> vect[i].catBugs;
		cin >> vect[i].hw;
	}
	int dp[n][3];
	dp[0][0] = vect[0].swim;
	dp[0][1] = vect[0].catBugs;
	dp[0][2] = vect[0].hw;
	for(int i = 1;i < n;++i)
	{
		int op1 = vect[i].swim + max(dp[i-1][1],dp[i-1][2]);
		int op2 = vect[i].catBugs + max(dp[i-1][0],dp[i-1][2]);
		int op3 = vect[i].hw + max(dp[i-1][0],dp[i-1][1]);
		dp[i][0] = op1;
		dp[i][1] = op2;
		dp[i][2] = op3;
	}
	cout << max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2])) << endl;
	return 0;
}

Measured memory_bytes: 2560
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(2147483647)


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
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)]
mod = 1000000007


n, m, q = LI()
L = LIR(m)
query = LIR(q)
dp = [[0] * (n + 1) for _ in range(n + 1)]
for l, r in L:
    dp[l][r] += 1


cumsum = [list(accumulate(l)) for l in dp]
cumsum = list(zip(*[list(accumulate(l)) for l in zip(*cumsum)]))
for l, r in query:
    print(cumsum[r][r] - cumsum[l - 1][r] - cumsum[r][l - 1] + cumsum[l - 1][l - 1])

Measured memory_bytes: 109532
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
using namespace std;



int main() {
	int n;
	cin >> n;
	vector<int>h(n);
	long int ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
		if (i >= 1) {
			if (h[i - 1] > h[i]) {
				ans += h[i - 1] - h[i];
			}
		}
		if (i == n - 1) {
			ans += h[i];
		}
	}
	cout << ans << endl;
}


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

int a[200];
int main(){
	int b[4];
	for(int i = 0;i < 4;i++)scanf("%d", &b[i]);
	for(int i = b[0];i < b[1];i++)a[i]++;
	for(int i = b[2];i < b[3];i++)a[i]++;
	int ans = 0;
	for(int i = 0;i < 110;i++)ans += (a[i] == 2);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

ll order2(ll n){
  ll ans=0;
  while(1){
    if(n%2!=0){
      break;
    }else{
      n/=2;
      ans++;
    }
  }
  return ans;
}

ll gcd(ll a,ll b){
  if(a<b){
    ll tmp=a; a=b; b=tmp;
  }
  ll r=a%b;
  while(r!=0){
    a=b;
    b=r;
    r=a%b;
  }
  return b;
}

int main(){
  ll m,n,bunki=0,bunki2=0;
  cin>>n>>m;
  ll a[n],b[n];
  cin>>a[0];
  a[0]/=2;
  b[0]=order2(a[0]);
  rep1(i,n){
    cin>>a[i];
    a[i]/=2;
    b[i]=order2(a[i]);
    if(b[i]!=b[0]){
      bunki=1;
    }
  }
  if(bunki){
    cout<<0;
  }else{
    ll lcm=a[0];
    rep1(i,n){
      lcm/=gcd(lcm,a[i]);
      lcm*=a[i];
      if(lcm>m){
        bunki2=1;
        break;
      }
    }
    if(bunki2==1){
      cout<<0;
    }else{
      cout<<setprecision(12)<<floor(((double)m+lcm)/2/lcm);
    }
  }
}


Measured memory_bytes: 1792
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>

using namespace std;
typedef long long ll;

int main()
{
  int x;
  cin >> x;
  
  ll sum = 0;
  for (int i = 0; i <= x; i++) {
    sum += i;
    if (x <= sum) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}


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

const int N = 200005;
const int MOD = 1000000007;

int n;
vector<int> edges[N];

int power(int x, int y) {
  int ret = 1;
  for (; y; y >>= 1) {
    if (y & 1) ret = 1LL * ret * x % MOD;
    x = 1LL * x * x % MOD;
  }

  return ret;
}

inline int inv(int x) {
  return power(x, MOD-2);
}

int fact[N];
int ifact[N];

int cnt[N];
int dp[N];
void dfs(int u, int p) {
  cnt[u] = 1;
  dp[u] = 1;
  for (int v: edges[u]) {
    if (v == p) continue;
    dfs(v, u );
    cnt[u] += cnt[v];
    dp[u] = 1LL * dp[u] * ifact[cnt[v]] % MOD * dp[v] % MOD;
  }

  dp[u] = 1LL * dp[u] * fact[cnt[u] - 1] % MOD;
}

int dp2[N];
int ans[N];
void dfs2(int u, int p, int r) {
  dp2[u] = r;

  int nr = 1;
  for (int v: edges[u]) {
    if (v == p) continue;
    nr = 1LL * nr * dp[v] % MOD * ifact[cnt[v]] % MOD;
  }

  r = 1LL * r * ifact[n - cnt[u]] % MOD;
  ans[u] = 1LL * r * nr % MOD * fact[n-1] % MOD;

  for (int v: edges[u]) {
    if (v == p) continue;
    dfs2(v, u, 1L * r * nr % MOD * inv(dp[v]) % MOD * fact[cnt[v]] % MOD * fact[n - cnt[v] - 1] % MOD);
  }
}

int solve() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    --u, --v;

    edges[u].push_back(v);
    edges[v].push_back(u);
  }

  fact[0] = 1; for (int i = 1; i < N; ++i) fact[i] = 1LL * fact[i-1] * i % MOD;
  ifact[N-1] = inv(fact[N-1]); for (int i = N-2; i >= 0; --i) ifact[i] = 1LL * ifact[i+1] * (i+1) % MOD;

  dfs(0, 0);
  dfs2(0, 0, 1);

  for (int i = 0; i < n; ++i) {
    // cerr << dp[i] << " " << dp2[i] << endl;
    printf("%d\n", ans[i]);
  }
  return 0;
}

int main() {
  int t = 1;
  // scanf("%d", &t);
  while (t--) solve();
  return 0;
}


Measured memory_bytes: 18548
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  string s; cin>>s;
  int n = s.size();
  if(n==1) return cout<<s<< endl,0;
  int ans = 9*(n-1);
  int ans2 = s[0] - '0';
  reps(i,n-1){
    if(s[i]!='9') break;
    ans2 += 9;
    if(i==n-1) return cout<<ans2<<endl,0;
  }
  rep(i,n){
    if(s[i]!='9'){
      if(i==0) ans += s[i]-'1';
      else ans += 8;
      return cout<<ans<<endl,0;
    }
  }
  cout << ans+9 << endl;


  return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
sa = gets.split.map(&:to_i).sort
sb = gets.split.map(&:to_i).sort
sc = gets.split.map(&:to_i).sort
index_c = []
index_b = []
sc.each do |c|
  l = (0..n-1).bsearch { |j| sb[j] >= c }
  l = n unless l
  index_c.push l
end
sb.each do |b|
  l = (0..n-1).bsearch { |j| sa[j] >= b }
  l = n unless l
  index_b.push l
end
sum_b = []
sum = 0
index_b.each do |ib|
  sum += ib
  sum_b.push sum
end
sum = 0
sc.each_index do |i|
  sum += sum_b[index_c[i] - 1] if index_c[i] > 0
end
puts sum


Measured memory_bytes: 34416
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;

typedef queue<int> Q;
int n, m;
void yamawake(int k);
Q que, rsh, sh, carda, cardb;
int main(){
  int k;
  cin >> n >> m;
  for(int i = 1; i <= 2 * n; i++){
    que.push(i);
  }
  for(int i = 0; i < m; i++){
    cin >> k;
    if(k == 0){
      yamawake(0);
      for(int j = 0; j < n; j++){
	int t = carda.front();
	carda.pop();
	que.push(t);
	t = cardb.front();
	cardb.pop();
	que.push(t);
      }
    }
    else{
      yamawake(k);
      for(int j = 0 ; j < 2 * n - k; j++){
	int t = cardb.front();
	cardb.pop();
	que.push(t);
      }
      for(int j = 0 ; j < k; j++){
	int t = carda.front();
	carda.pop();
	que.push(t);
      }
    }
  }
  for(int i = 0; i < 2 * n; i++){
    cout << que.front() << endl;
    que.pop();
  }
}

void yamawake(int k){
  int judge;
  if(k == 0) judge = n;
  else judge = k;
  for(int j = 0; j < judge; j++){
    int t = que.front();
    que.pop();
    carda.push(t);
  }
  for(int j = 0 ; j < 2 * n - judge; j++){
    int t = que.front();
    que.pop();
    cardb.push(t);
  }
}

Measured memory_bytes: 1220
N, K = [int(x) for x in input().split(" ")]
A = [0 for i in range(N)]

for k in range(K):
    d_i = int(input())
    holder_list = [int(x) for x in input().split(" ")]

    for hi in holder_list:
        A[hi-1] += 1

count_non_holder = 0
for a in A:
    if a == 0:
        count_non_holder += 1

print(count_non_holder)

Measured memory_bytes: 9192
#include<stdio.h>
int main()
{
	int a,b,c;
	while(~scanf("%d%d%d",&a,&b,&c))
	{
		if(a==5&&b==5&&c==7||a==5&&b==7&&c==5||a==7&&b==5&&c==5)
		   printf("YES\n");
		else printf("NO\n");   
	}
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int k = sc.nextInt();
		int l = sc.nextInt();
		int g = sc.nextInt();
		int p = sc.nextInt();
		long count=0;

		if(m-n>p ||k-n>p ||l-n>p ||g-n>p||k-m>p||l-m>p||g-m>p||l-k>p||g-k>p||g-l>p) {
			System.out.println(":(");
		}else {
			System.out.println("Yay!");
		}
	}
}




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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll INFLL = 9e18;
const int N = 1e6;
int _w;

ll n;
int a, b, c, d;
map<ll,ll> f;
ll table[N];

void calc_table() {
	table[0] = 0;
	for( int i = 1; i < N; ++i ) {
		table[i] = table[i-1] + d;
		if( i % 2 == 0 )
			table[i] = min(table[i], table[i/2] + a);
		if( i % 3 == 0 )
			table[i] = min(table[i], table[i/3] + b);
		if( i % 5 == 0 )
			table[i] = min(table[i], table[i/5] + c);
	}
}

ll dp( ll n ) {
	// if( n < N ) return table[n];
	if( f.count(n) ) return f[n];
	ll &now = f[n];
	if( n == 0 ) return now = 0;
	now = INFLL;
	
	if( n % 2 ) {
		now = min(now, dp(n-n%2) + n%2*d);
		if( n/2+1 != n )
			now = min(now, dp(n/2+1) + (2-n%2)*d + a);
	} else {
		now = min(now, dp(n/2) + a);
		if( n/2 <= INF )
			now = min(now, dp(n/2) + n/2*d);
	}
	if( n % 3 ) {
		now = min(now, dp(n-n%3) + n%3*d);
		if( n/3+1 != n )
			now = min(now, dp(n/3+1) + (3-n%3)*d + b);
	} else {
		now = min(now, dp(n/3) + b);
		if( n/3*2 <= INF )
			now = min(now, dp(n/3) + n/3*2*d);
	}
	if( n % 5 ) {
		now = min(now, dp(n-n%5) + n%5*d);
		if( n/5+1 != n )
			now = min(now, dp(n/5+1) + (5-n%5)*d + c);
	} else {
		now = min(now, dp(n/5) + c);
		if( n/5*4 <= INF )
			now = min(now, dp(n/5) + n/5*4*d);
	}
	if( n <= INF )
		now = min(now, n*d);
	return now;
}

int main() {
	int T;
	cin >> T;
	while( T-- ) {
		cin >> n >> a >> b >> c >> d;
		calc_table();
		f.clear();
		cout << dp(n) << endl;
	}
	return 0;
}


Measured memory_bytes: 16692
#include<stdio.h>
#include<stdlib.h>

typedef struct _matrix{
  int r;
  int c;
}Matrix;

void matrixChain(Matrix*);

int n;

int main(){
  int i;
  Matrix *matrix;

  scanf("%d",&n);
  matrix=(Matrix*)malloc(n*sizeof(Matrix));
  for(i=0;i<n;i++){
    scanf("%d",&matrix[i].r);
    scanf("%d",&matrix[i].c);
  }

  matrixChain(matrix);

  return 0;
}

void matrixChain(Matrix* M){
  int i,l,j,k;
  int q;
  int m[100][100];

  for(i=0;i<n;i++){
    m[i][i]=0;
  }
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      //printf("i:%d,j:%d\n",i,j);
      m[i][j]=9999999;
      for(k=i;k<=j-1;k++){
        //printf("i:%d,j:%d,k:%d\n",i,j,k);
        q=m[i][k]+m[k+1][j]+(M[i-1].r)*(M[k].r)*(M[j-1].c);
        //printf("m[%d][%d]:%d, m[%d][%d]:%d, M[%d].r:%d, M[%d].r:%d, M[%d].r:%d \n",i,k,m[i][k],k+1,j,m[k+1][j],i-1,M[i-1].r,k,M[k].r,j,M[j].r);
        //printf("%d=m[%d][%d]+m[%d][%d]+M[%d].r*M[%d].r*M[%d].r\n",q,i,k,k+1,j,i-1,k,j);
        if(q<m[i][j]) m[i][j]=q;
       //printf("%d\n----------------------\n",m[i][j]);
      }
    }
  }
  //printf("%d,%d\n",i,j);
  printf("%d\n",m[i-1][j]);
}



Measured memory_bytes: 2112
n = int(input())
V = list(map(int, input().split()))
from collections import Counter
even = Counter(V[0::2])
even["0"]=0
even = sorted(even.items(), key=lambda x:x[1], reverse=True)
odd = Counter(V[1::2])
odd["-1"]=0
odd = sorted(odd.items(), key=lambda x:x[1], reverse=True)
i=0
even_top2, odd_top2 = [], []
for (e, o) in zip(even, odd):
  i+=1
  even_top2.append(e)
  odd_top2.append(o)
  if i==2:
    break
if even_top2[0][0] != odd_top2[0][0]:
  notchange = even_top2[0][1] + odd_top2[0][1]
else:
  notchange = max(even_top2[0][1]+odd_top2[1][1], even_top2[1][1]+odd_top2[0][1])
print(n-notchange)

Measured memory_bytes: 25160
import collections

def prime_factorize(n):
    prime_factor_list = []
    while n%2 == 0:
        prime_factor_list.append(2)
        n //= 2
    f = 3
    while f*f <= n:
        if n%f == 0:
            prime_factor_list.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        prime_factor_list.append(n)
    
    prime_factor = collections.Counter(prime_factor_list)

    return prime_factor

n = int(input())
c = prime_factorize(n)
ans = 0
for i in c.values():
    tmp = 0
    for j in range(1, i+1):
        tmp += j
        if tmp > i:
            break
        ans += 1
print(ans)

Measured memory_bytes: 9464
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

/*
ab
ab
->2倍

ab
ac
->2倍

ab
cb
->1倍

ab
cd
->3倍
*/

void solve(){
    int n;
    cin >> n;
    string s,t;
    cin >> s >> t;
    ll ans;
    if(s[0]==t[0]) ans = 3;
    else ans = 6;
    for(int i=1; i<n; i++){
        char c1,c2,c3,c4;
        c1 = s[i-1];
        c2 = t[i-1];
        c3 = s[i];
        c4 = t[i];
        if(c1==c2) ans = ans * 2 % MOD;
        if(c1!=c2&c3!=c4&&c1!=c3) ans = ans * 3 % MOD;
    }
    cout << ans << endl;
}

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



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

int main() {
	int A, B, X;
	cin >> A >> B >> X;
	if (A > X) {
		cout << "NO" << endl;
		return 0;
	}
	else {
		if (A == X) {
			cout << "YES" << endl;
		}
		else {
			if (A + B < X) {
				cout << "NO" << endl;
				return 0;
			}
			else {
				cout << "YES" << endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
static const int INF (1<<30);


int main() {
  int N;
  cin >> N;
  vector<int> x(N), y(N), h(N);
  int xmax, ymax, hmax = 0;
  rep(i, N) {
    cin >> x[i] >> y[i] >> h[i];
    if (h[i] >= hmax) {
      xmax = x[i];
      ymax = y[i];
      hmax = h[i];
    }
  }

  for (int cx = 0; cx <= 100; cx++) {
    for (int cy = 0; cy <= 100; cy++) {
      int ch = abs(xmax-cx) + abs(ymax-cy) + hmax;
      bool good = true;
      rep(i, N) {
        int tmp_h = max(ch-abs(x[i]-cx)-abs(y[i]-cy), 0);
        if (tmp_h != h[i]) {
          good = false;
          break;
        }
      }

      if (good) {
        cout << cx << " ";
        cout << cy << " ";
        cout << ch << endl;
        return 0;
      }
    }
  }


  return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    lli l=0, r=0;
    lli n;
    cin>>n;
    vi a(n);
    rep(i,n){
        cin>>a[i];
        r+=a[i];
    }
    lli ans;
    l=a[0];
    r-=a[0];
    ans=abs(l-r);
    rep(i,n-1){
        l+=a[i+1];
        r-=a[i+1];
            ans=min(ans, abs(l-r));
    }
    out(ans);
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define F(n) for(int i=0;i<n;++i)

int main()
{
    int n;
    string s;
    cin >> n >> s;
    bool f=true;
    if(n%2==0)
        F(n/2){
            if(s[i]!=s[n/2+i]) f= false;
        }
    if(f && n%2==0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, i, mini = 0, maxi = 0;
    scanf("%d", &n);
    int a[n], b = 0, c = 0;
    for (i=0; i<n; i++) scanf("%d", &a[i]);
    for (i=0; i<n-1; i++) {
        if (a[i] >= a[i+1]) {
            maxi++;
            if (maxi > b) b = maxi;
        }
        else maxi = 0;
    }
    printf("%d", max(b, c));
    return 0;
}


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

int search(int A, int B, int C){
  int count = 0;
  vector<int>array(3);
  array.at(0) = A;
  array.at(1) = B;
  array.at(2) = C;
  sort(array.begin(), array.end());
  if((array.at(1) - array.at(0)) % 2 == 0){
    count += (array.at(1) - array.at(0)) / 2;
    count += array.at(2) - array.at(1);
  }else{
    array.at(0) += 1;
    array.at(2) += 1;
    count++;
    count += (array.at(1) - array.at(0)) / 2;
    count += array.at(2) - array.at(1);  
  }
  return count;
}

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  
  cout << search(A, B, C) << endl;
  
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

const (
	initialBufSize = 10000
	maxBufSize     = 1000000
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
	mod int = 1e9 + 7
)

func main() {
	H := getInt()

	divNum := 0
	for ; ; {
		if H == 1 {
			break
		}

		H /= 2
		divNum++
	}

	sum := 0

	for i := 0; i <= divNum; i++ {
		sum += pow(2, i)
	}

	fmt.Println(sum)
}

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray) - 1])
}

func calcMod(x int) int {
	return x % mod
}


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

// ---------------------------template starts here-------------------------- 

#define int long long int
#define pb push_back
#define MAX INT_MAX
#define endl "\n"
#define precise std::cout << std::fixed;std::cout << std::setprecision(6); 
#define zerobits(x) __builtin_ctzll(z)
#define F first
#define S second  
#define mp make_pair
#define MIN INT_MIN
#define MOD 1000000007
#define FO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

set <int> s;
bool ar[100001];
void seive() {
    ar[0] = ar[1] = true;

    for(int p=2; p*p<=100001; p++) {
        if(ar[p] == false) {
            for(int i=p*p;i<=100001;i+=p)
                ar[i] = true ;
        }
    }

    for(int p=2;p<=100001;p++) {
        if(ar[p] == false)
            s.insert(p);
    }
}

bool is_palindrome(string str) {
    int len = str.length();
    for(int i=0;i<=len/2;i++) {
        if(str[i] != str[len-1-i])
            return false;
    }
    return true;
}

int binexpo(int x, int y, int p) {    
    int res = 1;     // Initialize result  
    x = x % p; // Update x if it is more than or  
                // equal to p  

    while (y > 0)  {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;
}
// --------------------------template ends here------------------------------

void solve() {
    int n;
    cin >> n;

    int sum = 0;    
    for(int i=1;i<=n;i++) {
        if(i%3 != 0 && i%5 != 0)
            sum += i;
    }
    cout << sum;
    return;

}

int32_t main() {
    FO;
    solve();
    return 0;
}

Measured memory_bytes: 3616
import sys
input = sys.stdin.readline
n, k = [ int(v) for v in input().split() ]
tree_list = [0]*n

for i in range(n):
	tree_list[i] = int(input())

tree_list = sorted(tree_list)


ans = n*10**9
for i in range(n-k+1):
	d = tree_list[k-1+i] - tree_list[i]
	ans = min(ans,d)
print(ans)

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

# define Rep(i,a,b) for(int i=a;i<=b;i++)
# define _Rep(i,a,b) for(int i=a;i>=b;i--)
# define RepG(i,u) for(int i=head[u];~i;i=e[i].next)

typedef long long ll;

const int N=1e5+5;

template<typename T> void read(T &x){
   x=0;int f=1;
   char c=getchar();
   for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
   for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+c-'0';
    x*=f;
}

int n,k;
bool vis[N];

int main()
{
    read(n),read(k);
    Rep(i,1,k){
        int x,y;
        read(x);
        while(x--)read(y),vis[y]=true;
    }
    int ans=0;
    Rep(i,1,n)if(!vis[i])ans++;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 3768