akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#define MAXN 100010
#define LL long long
using namespace std;

struct Point{
	int id; 
	Point(const int &_id):id(_id){}
	bool operator < (Point x) const;
};

int n,size,x1,x2;
int p[MAXN][2],d;
map<int,int> T1,T2;
set<Point> S[MAXN<<1];
int rk[3][MAXN],st[MAXN];
bool visit[MAXN];
int cnt[MAXN];
queue<int> Q;

bool Point::operator < (Point x) const{
	if(p[id][0]==p[x.id][0]) return id<x.id;
	return p[id][0]<p[x.id][0];
}

int dis(int x,int y){
	return abs(p[x][0]-p[y][0])+abs(p[x][1]-p[y][1]);
}

void pre_gao(int x){
	int temp=0;
	for(set<Point>::iterator it=S[x].begin();it!=S[x].end();it++)
		rk[st[x]][it->id]=++temp;
}

int cnt_set(int x,int type,int l,int r){
	if(!x) return 0;
	p[0][0]=r+1;
	set<Point>::iterator it2=S[x].upper_bound(0);
	p[0][0]=l;
	set<Point>::iterator it1=S[x].upper_bound(0);
	if(it1!=S[x].end())
		return (it2==S[x].end()?S[x].size()+1:rk[type][it2->id])-rk[type][it1->id];
	else return 0;
}

void gay(int x,int l,int r){
	if(!x) return;
	p[0][0]=r+1;
	set<Point>::iterator it2=S[x].upper_bound(0);
	p[0][0]=l;
	set<Point>::iterator it1=S[x].upper_bound(0);
	while(it1!=it2){
		if(!visit[it1->id]){
			visit[it1->id]=1;
			Q.push(it1->id);
		}
		set<Point>::iterator it3=it1;
		it3++;
		S[x].erase(it1);
		it1=it3;
	}
}

int calc_cnt(int x){
	int res=0;
	res+=cnt_set(T1[p[x][0]+p[x][1]+d],1,p[x][0]+1,p[x][0]+d);
	res+=cnt_set(T2[p[x][0]-p[x][1]+d],2,p[x][0],p[x][0]+d-1);
	res+=cnt_set(T1[p[x][0]+p[x][1]-d],1,p[x][0]-d,p[x][0]-1);
	res+=cnt_set(T2[p[x][0]-p[x][1]-d],2,p[x][0]-d+1,p[x][0]);
	return res;
}

void bfs(){
	Q.push(x1); Q.push(x2);
	visit[x1]=visit[x2]=1;
	while(!Q.empty()){
		int x=Q.front();
		Q.pop();
		gay(T1[p[x][0]+p[x][1]+d],p[x][0],p[x][0]+d);
		gay(T2[p[x][0]-p[x][1]+d],p[x][0],p[x][0]+d);
		gay(T1[p[x][0]+p[x][1]-d],p[x][0]-d,p[x][0]);
		gay(T2[p[x][0]-p[x][1]-d],p[x][0]-d,p[x][0]);
	}
}

int main(){
#ifdef DEBUG
	freopen("E.in","r",stdin);
#endif
	scanf("%d%d%d",&n,&x1,&x2);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&p[i][0],&p[i][1]);
		int t1=p[i][0]+p[i][1],t2=p[i][0]-p[i][1];
		if(!T1.count(t1)) st[T1[t1]=++size]=1;
		if(!T2.count(t2)) st[T2[t2]=++size]=2;
		S[T1[t1]].insert(i);
		S[T2[t2]].insert(i);
	}
	d=dis(x1,x2);
	for(int i=1;i<=size;i++) pre_gao(i);
	for(int i=1;i<=n;i++) cnt[i]=calc_cnt(i);
	bfs();
	LL ans=0;
	for(int i=1;i<=n;i++)
		if(visit[i]) ans+=cnt[i];
	ans/=2;
	printf("%lld\n",ans);
	return 0;
}


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

int main(){
    string n;
    cin>>n;
    for(int i=0;i<n.size();i++){
        if(n[i] == '7'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
    
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,a,b;
    cin>>n>>a>>b;
    b-=a;
    ll ans=n+1;
    ll num;
    if(b>2){
    	n-=(a-1);
    	num=a;
    	num+=b*(n/2);
    	if(n%2)num++;
    	ans=max(ans,num);
    }
    cout << ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
long power(long n,int m);
int main() {
  long n,m;
  int counter=0;
  scanf("%ld %ld",&n,&m);
  long pt[n][2];
  for (int i=0;i<n;i++) {
    scanf("%ld %ld",&pt[i][0],&pt[i][1]);
    if ( power(m,2) >= power(pt[i][0],2) + power(pt[i][1],2) )
      counter++;
  }
  printf("%d",counter);
  return 0;
}
 
long power (long n,int m) {
  for (int i=1;i<m;i++) 
    n*=n;
  return n;
}

Measured memory_bytes: 4820
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define double long double
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define debug(x) cerr<<#x<<": "<<x<<endl;
#define all(a) a.begin(),a.end()
#define sort(a) sort(all(a))
#define rsort(a) sort(all(a),greater<>())
#define debg(a) cout<<#a<<" "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
template<class T> inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef pair<int,int> P;
const long long MOD=1000000007;
clock_t time_ini = clock();
double time_diff(){
  ll time_tmp = clock();
  const double time = static_cast<double>(time_tmp - time_ini) / CLOCKS_PER_SEC * 1000.0;
  return time;
}
#define saiaku if(time_diff() > 1990)
vector <ll> dp;


void solve(long long N, std::vector<long long> B){
  ll res=0;
  for (ll i = N - 2; i >= 1; i--)
  {
    res += min(B[i], B[i-1]);
  }
  res += B[N-2];
  res += B[0];
  cout << res << endl;
  
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> B(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&B[i]);
    }
    solve(N, std::move(B));
    return 0;
}


Measured memory_bytes: 256
"""
author : halo2halo
date : 4, Feb, 2020
"""

import sys

# import itertools
# import math

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
S=readline().decode('utf8')
print(S.count('ABC'))


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

int main() {
    int d, n;
    while(cin >> d >> n, d){
        [&](){
            vector<int> as(n), es(n), rs(n);
            for (int i = 0; i < n; ++i) {
                cin >> as[i] >> es[i] >> rs[i];
            }
            auto dp = make_v(d+1, 101, -1);
            dp[d][0] = 0;
            queue<pair<int, int>> Q;
            Q.emplace(d, 0);
            while(!Q.empty()){
                int i, j; tie(i, j) = Q.front(); Q.pop();
                if(i == 0) {
                    cout << dp[i][j] << "\n";
                    return;
                }
                for (int k = 0; k < n; ++k) {
                    if(rs[k] <= j){
                        int ii = max(0, i-as[k]), jj = min(100, j+es[k]);
                        if(!~dp[ii][jj]){
                            dp[ii][jj] = dp[i][j]+1;
                            Q.emplace(ii, jj);
                        }
                    }
                }
            }
            puts("NA");
        }();
    }
    return 0;
}


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

using namespace std;
using ll = long long;

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

int main() {
  int n = 5;
  int a[n];
  rep(i, n) cin >> a[i];
  int k;
  cin >> k;

  bool ok = true;
  rep(i, n) rep(j, i) if (abs(a[i] - a[j]) > k) ok = false;

  cout << (ok ? "Yay!" : ":(") << endl;
  return 0;
}


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

int main(){
    int s;cin>>s;
    int A=s/100,B=s%100;
    if((0<A&&A<=12)||(0<B&&B<=12)){
        if(0<A&&A<=12&&0<B&&B<=12) cout<<"AMBIGUOUS"<<endl;
        else if(0<A&&A<=12) cout<<"MMYY"<<endl;
        else cout<<"YYMM"<<endl;
    }
    else cout<<"NA"<<endl;
}

Measured memory_bytes: 256
s=str(input())
ac=s.count("a")
bc=s.count("b")
cc=s.count("c")

if len(s)==1:
    print("YES")
    exit()

if len(s)==2:
    if max(ac,bc,cc)==2:
        print("NO")
    else:
        print("YES")
    exit()

if (len(s)+2)//3<max(ac,bc,cc):
    print("NO")
else:
    print("YES")

Measured memory_bytes: 3188
eval'N,K,*A='+`dd`.split*?,
d=(0..255).map{[0]*101}
d[0][0]=1
A.map{|a|N.times{|j|256.times{d[_1^a][i=N-j]+=d[_1][i-1]*i}}}
p d[K].sum.%10**9+7

Measured memory_bytes: 21556
#include <stdio.h>
 
int main()
{
  int N, K, Q;
  int P[100010];
  int A;

  scanf("%d %d %d", &N, &K, &Q);
  
  for (int i=1; i<=N; i++)
  {
    P[i] = 0;
  }
  
  for (int i=1; i<=Q; i++)
  {
    scanf("%d", &A);
    P[A]++;
  }
  
  for (int i=1; i<=N; i++)
  {
    if (K-Q+P[i]>0)
    {
      printf("Yes\n");
    }
    else
    {
      printf("No\n");
    }
  }  
  
  return 0;  
}


Measured memory_bytes: 896
package main

import (
	"fmt"
)

const a = int(1e9)

func main() {
	var s int
	fmt.Scan(&s)

	x1 := (s - 1) / a
	y1 := 0
	x2 := 0
	y2 := s % a
	if y2 == 0 {
		y2 = a
	}
	x3 := x1 + 1
	y3 := a

	fmt.Printf("%d %d %d %d %d %d\n", x1, y1, x2, y2, x3, y3)
}


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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

lli n,k;
vll a;
lli x = 0;
lli ans = 0;

int main(){
  cin >> n >> k;
  a = vll(n);
  for(lli i = 0;i < n;i++) cin >> a[i];
  for(lli b = 1ll << 62;b > 0;b >>= 1){
    if(x+b > k) continue;
    lli sum = 0;
    for(lli i = 0;i < n;i++){
      if((a[i]&b) == 0) sum += 1;
    }
    if(sum > n-sum) x += b;
  }
  for(lli i = 0;i < n;i++){
    ans += a[i]^x;
  }
  cout << ans << endl;
}


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

int main(){
    int n;cin>>n;
    long long power=1;
    for(int i=2;i<=n;i++){
        power=(power*i)%((long long)pow(10,9)+7);
    }
    cout<<power<<endl;
}

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

priority_queue <int > pq;
int main(void){
	int n,data,ans=0;
	cin>>n;
	for(int i=0;i<n;i++){
		scanf("%d",&data);
		pq.push(data);
	}
	data = -1;
	for(int i=0;i<n;i++){
		if(pq.top() == data){
			ans--;
			data = -1;	
		}else{
			ans++;
			data = pq.top();
		}
		pq.pop();
	}
	cout<<ans<<endl;
} 

Measured memory_bytes: 892
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
  int n;
  string s;
  cin >> s;
  bool f=true;
  reverse(s.begin(),s.end());
  for (int i=0;i < s.size();){
    if (s.substr(i,5)=="maerd"){
      i+=5;
    }
    else if (s.substr(i,7)=="remaerd"){
          i+=7;
    }
    else if (s.substr(i,5)== "esare"){
      i+=5;
    }  
    else if (s.substr(i,6)=="resare"){
        i+=6;
    }
    else {
      f=false;
      break;
    }
  }
  if (f) cout << "YES" << endl;
  else cout << "NO" <<endl;
  
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>

using namespace std;

bool find(const vector<int>& S, int begin, int end, int x) {
  if (end - begin == 1) {
    return S[begin] == x;
  }
  int mid = (begin + end) / 2;
  if (x < S[mid]) {
    return find(S, begin, mid, x);
  } else if (S[mid] < x) {
    return find(S, mid, end, x);
  } else {
    return true;
  }
}

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

  int n;
  cin >> n;
  vector<int> S(n);
  for (int i = 0; i < n; ++i) {
    cin >> S[i];
  }

  int q;
  cin >> q;
  vector<int> T(q);
  for (int i = 0; i < q; ++i) {
    cin >> T[i];
  }

  int count = 0;
  for (int i = 0; i < q; ++i) {
    if (find(S, 0, S.size(), T[i])) {
      ++count;
    }
  }
  cout << count << endl;
}



Measured memory_bytes: 3332
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    n = int(input())
    N = list(str(n))
    
    tmp = 0
    for i in N:
        tmp += int(i)
        
    if n % tmp == 0:
        print("Yes")
    else:
        print("No")
            	
if __name__ == "__main__":
	main()


Measured memory_bytes: 38384
import java.util.Scanner

/**
 * Created by sonetsuyoshi on 2015/12/16.
 */

object Main extends App {
  val sc = new Scanner(System.in)
  val n = sc.nextInt
  val a = Array.fill(n)(sc.nextInt)


  run()

  def run(): Unit = {
    if(firstWin()) println("First")
    else println("Second")
  }

  def firstWin(): Boolean = {
    val nEven = a.count(i => i > 1 && i % 2 == 0)
    val nOdd = a.count(i => i > 1 && i % 2 == 1)
    if(nEven % 2 == 1) true
    else {
      if(nOdd > 1 || nOdd == 0) false
      else {
        val id = a.zipWithIndex.filter(x => x._1 > 1 && x._1 % 2 == 1).apply(0)._2
        a(id) -= 1
        val m = a.reduceLeft((g, i) => gcd(g, i))
        for(i <- 0 until a.size) a(i) /= m
        !firstWin()
      }
    }
  }

  // a <= b
  def gcd(a: Int, b: Int): Int = {
    val c = b % a
    if(c == 0) a
    else gcd(c, a)
  }
}

Measured memory_bytes: 105812
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
using namespace std;
 
int main() {
long long n,d;
cin >> n >> d;
int ans = 0;
for (int i = 0; i < n; i++)
{
    long long x,y;
    cin >> x >> y;
    if (d*d >= x*x + y*y)
    {
        ans = ans + 1;
    }
    
}
cout << ans << endl;

}

Measured memory_bytes: 3600
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static         Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static int K,N;
	static long mod =1000000007;
	public static void main(String[] args) {
		int N=sc.nextInt();
		int K=sc.nextInt();
		long Mmin=0,Mmax=0;
		long ans=0;
		
		Mmax=(long)(2*N-K+1)*K/2;
		Mmin=(long)(K-1)*K/2;
		ans=Mmax-Mmin+1;
		int min=K;
		int max=N-K;
		for(int a=K+1;a<=N+1;a++) {
			Mmin+=min;
			Mmax+=max;
			ans=(ans+Mmax-Mmin+1)%mod;
			if(ans<0)break;
			//System.out.println(ans);
			min++;max--;
			
		}
		p(ans);
		
	}

	
	//static ArrayList<Integer> cc = new ArrayList<>(10001);
	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;

struct edge {
    ll to;
    char cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;
// 入力
int H, W;
vector<vector<char>> field;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int N;

int main(void){
    
    ll X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<ll> p(A), q(B), r(C);
    REP(i, A)cin >> p[i];
    REP(i, B)cin >> q[i];
    REP(i, C)cin >> r[i];

    sort(p.begin(), p.end(), greater<ll>());
    sort(q.begin(), q.end(), greater<ll>());
    // sort(r.begin(), r.end(), greater<ll>());

    vector<ll> sum(X+Y+C);
    REP(i, X)sum.push_back(p[i]);
    REP(i, Y)sum.push_back(q[i]);
    REP(i, C)sum.push_back(r[i]);

    sort(sum.begin(), sum.end(), greater<ll>());

    ll ans = 0;
    REP(i, X+Y){
        ans += sum[i];
    }

    cout << ans << endl;

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


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

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2")

using namespace std;

#define f first
#define s second
#define mp make_pair
#define all(x) x.begin(), x.end()
#define up(x, v) upper_bound(all(x), v)
#define low(x, v) lower_bound(all(x), v)
#define bin(x, v) binary_search(all(x), v)
#define FOR(k, a, b) for(int k = (a); k < (b); ++k)
#define ROF(k, a, b) for(int k = (a); k > (b); --k)
#define fn(k, n) for(int k = 0; k < n; ++k)

#define EPS 1.0e-9

#define X real()
#define Y imag()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
using point = pair<double, double>;
using Vector = complex<double>;

int main() {

	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int N, K;

	cin >> N >> K;

	vi h(N);

	for(int& x : h)
		cin >> x;

	sort(all(h));

	N -= K;

	ll a = 0;

	FOR(i, 0, N) a += h[i];

	cout << a << '\n';

    return 0;
}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void output(bool flag){
	cout<<(flag?"YES":"NO")<<endl;
}
void solve(){
	string str;
	cin>>str;
	int size = str.size();
	vector<int> hist(3,0);
	for(int i=0;i<size;++i){
		hist[str[i]-'a']++;
	}
	sort(hist.begin(),hist.end());
	int ter = size%3;
	bool ans = false;
	if(ter==0){
		if(hist[0]==hist[1] && hist[1]==hist[2] ){
			ans = true;
		}
	}else if(ter==1){
		if( hist[0]==hist[1] && hist[1]+1 ==hist[2] ){
			ans = true;
		}
	}else if(ter==2){
		if( hist[1]==hist[2] && hist[0]+1==hist[1] ){
			ans = true;
		}
	}
	output(ans);
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


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

int main(){
    int n;
    while(cin >> n, n){
        vector<int> a(n);
        for(int i = 0; i < n; i++)  cin >> a[i];
        sort(a.begin(), a.end());
        int ans = 1000000;
        for(int i = 1; i < n; i++)  ans = min(ans, a[i]-a[i-1]);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  string s = "" ;
  string ans;
  cin >> s;
  int g;
 
  vector<int> vec (N); 
  for (int i = 0; i < N; i++) {
    vec.at(i) = s[i];
  }
  
 for(int i = 0; i < N-1; i++){
 	if(vec.at(i) != vec.at(i+1)){
 		ans += vec.at(i);
 	}
 }
 g = ans.size()+1;
  
 
  cout << g << endl;

  }

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define OUT(x) cout << (x) << endl;
#define OUTA(a, n) \
    REP(i, n) { cout << (a[i]) << (i == n - 1 ? "\n" : " "); }
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

int main()
{
    ll N;
    cin >> N;
    vi A(N);
    REP(i, N)
    {
        cin >> A[i];
    }

    vi dp(N + 1);
    REP(i, N)
    {
        ++dp[A[i]];
    }
    ll ans = 0;
    for (ll k = 1; k <= N; ++k)
    {
        ans += dp[k] * (dp[k] - 1) / 2;
    }
    for (ll k = 1; k <= N; ++k)
    {
        OUT(ans - (dp[A[k - 1]] - 1));
    }
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using boost::adaptors::reversed;
using boost::irange;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

constexpr ll N_max = (ll)(2e5+1);

int main() {
    ll N;
    cin >> N;
    if (N == 1){
        cout << 0 << endl;
        return 0;
    }
    bitset<N_max> ok(0);
    bitset<N_max> seen(0);
    for (auto &&i: irange(0LL, N)){
        ll p;
        cin >> p;
        p--;
        seen.set(p);
        if (!seen[p+1]){
            ok.set(p);
        }
    }
    ok.reset(N-1);
    ll len{1};
    ll max_len{1};
    for (auto &&i: irange(1LL, N)){
        if(ok[i-1] && ok[i]){
            len += 1;
        } else {
            len = 1;
        }
        max_len = max(max_len, len);
    }
    if (!ok.any()){
        max_len = 0;
    }
    max_len++;
    cout << N - max_len << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))

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

ll lcm(ll a,ll b){
    return a*b/gcd(b,a);
}


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

    cin>>a>>b>>c>>d;
    ans=b-a+1-(b/c-(a-1)/c + b/d-(a-1)/d - (b/lcm(c,d)-(a-1)/lcm(c,d)) );

    cout <<ans<<endl;

    return 0;

}

Measured memory_bytes: 256
def main():
    s = input()
    t = input()
    check (s,t)


def check(s,t):
    ns = len(s)
    nt = len(t)
    bool = 0

    if ns != nt:
        pass
    else:
        for i in range(ns):
            st = t[i:] + t[:i]
            if s == st:
                bool = 1
            else:
                pass

    if bool == 1:
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    main()


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

using namespace std;

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

    int n, k;
    cin >> n >> k;

    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<bool> win(k + 1);

    for (int i = 1; i <= k; ++i) {
        for (int j : a) {
            if (j <= i && !win[i - j]) win[i] = true;
        }
    }

    cout << (win[k] ? "First" : "Second") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)  for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define deb(x) cerr << #x <<": " << x << '\n';
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long double ld;
typedef long long ll;

int main(){
    ios;
    double n, m; cin >> n >> m;
    int sum = 0;
    vector<int> v(n);
    rep(i,n){
        cin >> v[i];
        sum += v[i];
    }
    double factor = 1.0 / (4.0 * m);
    int count = 0;
    rep(i,n){
        double x = (v[i] + 0.0) / (sum + 0.0);
        if(x >= factor) count++;
    }
    if(count >= m)cout << "Yes";
    else cout << "No";
    return 0;
    }



Measured memory_bytes: 3752
#include <iostream>

using namespace std;

int main()
{
    string s;
    cin >> s;
    int min = 1000;
    for(int i = 0;i<s.length()-2;i++)
    {   
        int a = 100*(s[i]-'0')+10*(s[i+1]-'0')+(s[i+2]-'0')-753;
        if(abs(a)<min)
        {
            min = abs(a);
        }
    }

    printf("%d\n",min);
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <numeric>
using namespace std;
int main() {
    int a,b,c,m,res;
    vector<int> ans;
    for (int i=0;i<3;i++) {
        cin >> m;
        ans.push_back(m);
    }
    sort(ans.begin(),ans.end());
    ans.pop_back();
    res=accumulate(ans.begin(),ans.end(),0);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;

int main() {
  std::cin >> N;

  repi( i, 1, 10 ) repi( j, 1, 10 ) if( i*j == N ) {
    std::cout << "Yes" << endl;

    return 0;
  }

  std::cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <bits/stdc++.h>
#include <queue>
#include <stack>
#include <vector>
#define loop(n) for(ll i=0;i<n;i++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
typedef long long int ll;

unordered_map<ll,vector<ll>> graph;
ll dp[100001];

ll dfs(ll node,ll level)
{
	
	if(dp[node] != -1)
		return level + dp[node];
	ll ans = level;
	auto itr = graph.find(node);
	if(itr == graph.end())
		return ans;
	else
	{
		vector<ll> nbs = graph[node];
		for(ll i=0;i<(ll)nbs.size();i++)
		{
			ans = max(ans,dfs(nbs[i],level+1));
		}
	}
	
	dp[node] = ans - level;
	return ans;
		
}
		
			


int main()
{
    fastio;
    ll n,m;
    cin>>n>>m;
    for(ll i=1;i<=n;i++)
		dp[i] = -1;
		
    for(ll i=0;i<m;i++)
	{
		ll x,y;
		cin>>x>>y;
		auto itr = graph.find(x);
		if(itr == graph.end())
		{
			vector<ll> hold;
			hold.push_back(y);
			graph.insert({x,hold});
		}
		else
		{
			graph[x].push_back(y);
		}
	}
	
	
	ll ans = INT_MIN;
	for(ll i=1;i<=n;i++)
	{
		
		ans = max(ans,dfs(i,0));
	}
	cout<<ans<<endl;
	
	
	
    return 0;
}


Measured memory_bytes: 17636
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    ll a,b,n; cin>>a>>b>>n;
    ll k=min(b,n);
    ll s=floor(a*k/b)-a*floor(k/b);
    ll t=floor(a*(k-1)/b)-a*floor((k-1)/b);
    ll ans=max(s,t);
    cout<<ans<<endl;
}





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

int main() {
  int sx,sy,tx,ty;
  cin >>sx>>sy>>tx>>ty;
  
  int b=tx-sx, a=ty-sy;
  int c=a+1, d=b+1;
  
  rep(i,a) cout << "U";
  rep(i,b) cout << "R";
  rep(i,a) cout << "D";
  rep(i,b) cout << "L";
  cout << "L";
  rep(i,c) cout << "U";
  rep(i,d) cout << "R";
  cout << "D";
  cout << "R";
  rep(i,c) cout << "D";
  rep(i,d) cout << "L";
  cout << "U" << endl;
  return 0;
  
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX / 100;
//const ll INF = (1ll << 31) - 1;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

//bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;


void print_line(vector<ll> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


int main() {

    cpp_int  a, b;

    cin >> a >> b;

    cout << (a % b) << endl;

}



Measured memory_bytes: 3268
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n;
  cin>>n;
  vi d(n);
  rep(i,n){
    cin>>d[i];
  }

  int sum=0;
  rep(i,n){
    FOR(j,i+1,n){
      sum+=d[i]*d[j];
    }
  }

  cout<<sum<<endl;


}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;

ll dp[305][305][305];

int main(int argc, char* argv[])
{
    int n,K;
    scanf("%d%d", &n, &K);
    
    vector<int> h(n);
    map<int,int> z;
    z.insert(make_pair(0,0));
    int i;
    for(i=0; i<n; i++) {
        scanf("%d", &h[i]);
        z.insert(make_pair(h[i],0));
    }

    vector<int> zz;
    int cnt=0;
    auto it=z.begin();
    for(; it!=z.end(); ++it) {
        zz.push_back(it->first);
        it->second=cnt;
        cnt++;
    }

    int j,k;
    for(i=0; i<=n; i++) {
        for(j=0; j<=K; j++) {
            for(k=0; k<=cnt; k++) {
                dp[i][j][k]=LINF;
            }
        }
    }
    dp[0][0][0]=0;
    for(i=0; i<n; i++) {
        for(j=0; j<=K; j++) {
            for(k=0; k<=cnt; k++) {
                if(dp[i][j][k]==LINF) continue;

                dp[i+1][j+1][k]=MIN(dp[i+1][j+1][k],dp[i][j][k]);

                dp[i+1][j][z[h[i]]]=MIN(dp[i+1][j][z[h[i]]], dp[i][j][k]+MAX(0,h[i]-zz[k]));
            }
        }
    }

    ll ans=LINF;
    for(j=0; j<=K; j++) {
        for(k=0; k<=cnt; k++) {
            ans=MIN(ans,dp[n][j][k]);
        }
    }
    printf("%lld\n", ans);

    return 0;
}


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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

LL euclidean_gcd(LL a, LL b) {
  if(a < b) return euclidean_gcd(b, a);
  LL r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  LL A,B,C,D;
  cin>>A>>B>>C>>D;

  LL A_C = ((A-1) / C +1 );
  LL B_C = B / C;
  LL Cnum = max(0LL,B_C  -  A_C+1);
  
  LL A_D = ((A-1) / D +1 );
  LL B_D = B / D;
  LL Dnum = max(0LL,B_D  -  A_D+1);

  LL lcm =C * D / euclidean_gcd(C, D);

  
  LL A_lcm = ((A-1) / lcm +1 );
  LL B_lcm = B / lcm;
  LL lcmnum = max(0LL,B_lcm  -  A_lcm+1);

  cout << (B - A + 1) - Cnum - Dnum + lcmnum << endl;
}


Measured memory_bytes: 256
{-# OPTIONS_GHC -O #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns #-}

import Control.Monad
import Data.List
import Data.Ord (comparing)
import qualified Data.ByteString.Char8 as B

puts :: [(Int,Int)] -> [Int] -> Int -> [(Int,Int)]
puts _ [] _ = []
puts [] (a:as) c = (a,c) : puts [] as c
puts bb@((b,n):bs) aa@(a:as) c
    | b > a = puts bs aa (c+n)
    | True = (a,c) : puts bb as c

main = do
    _ <- getLine
    as <- sortBy (flip $ comparing id).unfoldr (B.readInt.B.dropWhile (==' ')) <$> B.getLine
    --
    bs <- sortBy (flip $ comparing id).unfoldr (B.readInt.B.dropWhile (==' ')) <$> B.getLine
    --
    cs <- (flip zip) [1,1..] . sortBy (flip $ comparing id).unfoldr (B.readInt.B.dropWhile (==' ')) <$> B.getLine
    --
    print $ sum $ map snd $ puts (puts cs bs 0) as 0


Measured memory_bytes: 47484
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
int in[105][105];
int t[105][105];
int dp[105][105];

int stoi (string s )
{
	stringstream ss (s );
	int res = 0;
	ss >> res;

	return res;
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.SPRP", "r", stdin );
	memset (in, -1, sizeof (in ) );
	memset (t, 0, sizeof (t ) );
	memset (dp, 0, sizeof (dp ) );
	string str = "";
	int row = 0, col = 0;
	while (getline (cin, str ) ){
		rep (i, str.length() ){
			if (str[i] == ',' ) str[i] = ' ';
		} // end rep
		col = 0;
		stringstream ss (str );
		string s = "";
		while (ss >> s ){
			in[row][col++] = stoi (s );
		} // end while
 		row++;
	} // end while
/*
	rep (i, row ){
		rep (j, row ){
			cout << setw(2) << in[i][j];
		} // end rep
		cout << endl;
	} // end rep
*/
	int n = (row+1)/2;
	int m = n-1;
	
	rep (i, n ){
		rep (j, n ){
//			cout << "i: " << i << " j: " << j << " i+j: " << i+j << " min(j,m): " << min(j,m ) << endl;
			t[i][j] = in[i+j][min(j, m )];
		} // end rep
		m--;
	} // end rep
/*
	rep (i, n ){
		rep (j, n ){
			cout << setw(2) << t[i][j];
		} // end rep
		cout << endl;
	} // end rep
*/
	dp[0][0] = t[0][0];
	for (int i = 1; i < n; i++ ) dp[i][0] = t[i][0] + dp[i-1][0];
	for (int j = 1; j < n; j++ ) dp[0][j] = t[0][j] + dp[0][j-1];
	for (int i = 1; i < n; i++ ){
		for (int j = 1; j < n; j++ ){
			dp[i][j] = t[i][j] + max (dp[i-1][j], dp[i][j-1] );
		} // end for
	} // end for

	printf ("%d\n", dp[n-1][n-1] );
		
	return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define all(c) begin(c),end(c)
const ll INF = 1e10;
const ll mod = 1e9 + 7;
int main() {
	cin.sync_with_stdio(false);
	ll ans = 1;
	int N;
	cin >> N;
	string s1, s2;
	cin >> s1 >> s2;
	bool flag = false;;
	if (s1[0] == s2[0])ans *= 3;
	else {
		ans *= 6;
		flag = true;
	}
	reps(i, 1, N) {
		if (i == 1 && flag)i++;
		if (s1[i] == s2[i]) {
			if (s1[i - 1] == s2[i - 1])ans *= 2;
			else ans *= 1;
		}
		else {
			if (s1[i - 1] == s2[i - 1])ans *= 2;
			else ans *= 3;
			i++;
		}
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int a, b, c;
  int ans;
  vector<int> aDiv,bDiv;
  cin >> a >> b >> c;
  
  for(int i = 1;i < a;i++){
	if(a % i == 0)
      aDiv.push_back(i);
  }
  for(int i = 1;i < b;i++){
	if(b % i ==0)
      bDiv.push_back(i);
  }
  
  vector<int> minV,maxV;
  int min,max;
  if (aDiv.size() < bDiv.size()){
    minV = aDiv;
    maxV = bDiv;
    min = a;
    max = b;
  }else{
    minV = bDiv;
    maxV = aDiv;    
    min = b;
    max = a;
  }
  
  vector<int> same;
  for(int i = 0;i < minV.size();i++){
  	auto itr = std::find(maxV.begin(), maxV.end(), minV[i]);
    if( itr != maxV.end() ) {
        same.push_back(*itr);
    }
  }
  if( max % min == 0){
    same.push_back(min);
  }
  /*
  for(int i = 0;i < same.size();i++){
    cout << same[i] << " ";
  }
  cout << endl
  */
  cout << same[same.size() - c];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MD 1000000007
#define INF 1ll<<60
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main(){
    string s,t;
    cin>>s>>t;
    int a,b;
    cin>>a>>b;
    string u;
    cin>>u;
    if(s==u) cout<<a-1<<' '<<b<<endl;
    else cout<<a<<' '<<b-1<<endl;
    return 0;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $N);
for ($i = 0; $i < $N; $i++) {
 fscanf(STDIN, "%s %d", $s[], $t[]);
//  echo gettype($s);
//  var_dump($s);
//  var_dump($t);
}

fscanf(STDIN, "%s", $X); // この曲が終わったら寝た
$sum = 0;
$flag = false;
for ($i = 0; $i < $N; $i++) {
//   echo gettype($t[$i]);
  if ($flag) {
     $sum += $t[$i];
  }
  if ($s[$i] == $X) {
     $flag = true;
  }
}
echo $sum;

Measured memory_bytes: 4604
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = map(int, input().split())
uf = UnionFind(N)
ab_list = []
ans =0
for i in range(M):
    a,b = map(int, input().split())
    a, b = a-1, b-1
    ab_list.append([a, b])

for i in range(M):
    uf = UnionFind(N)
    for j in range(M):
        if i == j:
            continue
        uf.union(ab_list[j][0], ab_list[j][1])
    if not uf.same(ab_list[i][0], ab_list[i][1]):
        ans += 1
print(ans)


Measured memory_bytes: 9308
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int N, T, ans = 10e6; cin >> N >> T;
    for (int i = 0; i < N; ++i) {
        int a, b; cin >> a >> b;
        if (b <= T) ans = min(ans, a);
    }
    if (ans != 10e6) printf("%d\n", ans);
    else printf("%s\n", "TLE");
}


Measured memory_bytes: 3760
A,B,C,D = map(int,input().split())
MOD = 998244353

dp = [[0 for _ in range(D+1)] for _ in range(C+1)]
dp[A][B] = 1
#dp[i][j] ヨコi番目でそこまでの最大の高さがj

for i in range(A,C+1):
  for j in range(B,D+1):
    if i > A:
      dp[i][j] += dp[i-1][j]*j
    if j > B:
      dp[i][j] += dp[i][j-1]*i
    if i > A and j > B:
      dp[i][j] -= dp[i-1][j-1]*(i-1)*(j-1)
    dp[i][j] %= MOD

ans = dp[C][D]
print(ans)
      

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

int main(){
    string s;
    cin >> s;


    long long ans = 0;
    for(int i=0; i<s.size(); i++) {
        if( s[i] == '0') ans += 0;
        else if(s[i] == '1' ) ans += 1;
        else if(s[i] == '2' ) ans += 2;
        else if(s[i] == '3' ) ans += 3;
        else if(s[i] == '4' ) ans += 4;
        else if(s[i] == '5' ) ans += 5;
        else if(s[i] == '6' ) ans += 6;
        else if(s[i] == '7' ) ans += 7;
        else if(s[i] == '8' ) ans += 8;
        else if(s[i] == '9' ) ans += 9;
    }

    if(ans % 9 == 0) cout << "Yes";
    else cout <<"No";
    cout << endl;
}

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

inline int D(){
    int t ;
    scanf( "%d" , &t ) ;
    return t ;
}
inline ll LLD(){
    ll t ;
    scanf( "%lld" , &t ) ;
    return t ;
}
//const int INF = 0x3f3f3f3f;
//const int mod=1e9+7;
//const double pi=3.14159265359;
//###################################################################
int main() {
        int n=D();
        string a;
        map<string,int>mp;
        for(int i=0;i<n;i++){
            cin>>a;
            mp[a]++;
        }
        cout<<"AC x "<<mp["AC"]<<"\n";
    cout<<"WA x "<<mp["WA"]<<"\n";
    cout<<"TLE x "<<mp["TLE"]<<"\n";
    cout<<"RE x "<<mp["RE"]<<"\n";


}

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

int main() {
  int ans = 0;
  int N, M, C;
  cin >> N >> M >> C;
  vector<int> B(M);
  for(int i = 0; i < M; i++)
  {
    cin >> B.at(i);
  }

  vector<vector<int>> A(N, vector<int>(M));

  for(int i = 0; i < N; i++)
  {
    for(int j = 0; j < M; j++)
    {
      cin >> A.at(i).at(j);
    }
  }
  
  int sum = 0;

  for(int i = 0; i < N; i++){
    sum = 0;

    for(int j = 0; j < M; j++){
      sum += A.at(i).at(j) * B.at(j);
    }
    
    if(sum + C > 0){
      ans++;
    }
  }
  
  cout << ans << endl;
  
}

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

bool isPrime(int x){
  if(x == 0 || x == 1) return false;

  for(int i = 2; i * i <= x; i++){
    if(x % i == 0){
      return false;
    }
  }

  return true;
}

int main(){
  int n;

  while(cin >> n, n){
    int cnt = 0;

    for(int i = n + 1; i <= n * 2; i++){
      if(isPrime(i)){
        cnt++;
      }
    }

    cout << cnt << endl;
  }
}

Measured memory_bytes: 868
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
sieve=[-1]*(n+1)
for i in range(2,n+1):
  if sieve[i]==-1:
    sieve[i]=i
    for j in range(i*i,n+1,i):
      if sieve[j]==-1:
        sieve[j]=i

Ans=[1]*(n+1)
for i in range(2,n+1):
  p=sieve[i]
  cur=i
  ct=0
  while cur>1:
    if cur%p==0:
      cur//=p
      ct+=1
    else:
      break
  if i==pow(p,ct):
    Ans[i]=i*(ct+1)
  else:
    Ans[i]=Ans[i//(p**ct)]*Ans[p**ct]
print(sum(Ans)-1)

Measured memory_bytes: 224736
N = int(input())
D = dict([])
ans = 0
for k in range(N):
    s = sorted([str(x) for x in input()])
    a = ""
    for e in s:
        a += e
    if a in D:
        ans += D[a]
        D[a] += 1
    else:
        D[a] = 1
print(ans)


Measured memory_bytes: 65112
#include <bits/stdc++.h>
using namespace std;
typedef string S;
long long n,r,i,j;S s;map<pair<S,S>,long long> a;
main() {
	cin>>n>>s;
	for(;i<1<<n;++i){
		S x,y;
		for(j=0;j<n;++j)(i>>j&1?x:y).push_back(s[j]);
		a[{x,y}]++;
	}
	while(i--){
		S x,y;
		for(j=n-1;j>=0;--j)(i>>j&1?y:x).push_back(s[n+j]);
		r+=a[{x,y}];
	}
	cout<<r;
}

Measured memory_bytes: 91904
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <queue>
#include <cmath>
#include <cstdio>

using namespace std;

long long f(unordered_map<long long, long long>& memo, long long h){
    if(h==1) return 1;
    if(memo.find(h)!=memo.end()) return memo[h];
    long long r=f(memo, h/2);
    r=r*2+1;
    memo[h]=r;
    return r;
}

int main(){
    long long h; cin >> h;
    unordered_map<long long, long long> mp;
    cout << f(mp, h) << endl;
    return 0;
}


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

int main() {
	char s[11];	int n = 0;		long long int ans = 0,sum,tmp;
	cin >> s;
	for (int i = 0; i < 10; i++) {
		if ('1' <= s[i] && s[i] <= '9') n++;
		else break;
	}
	for (int mask = 0; mask < (1 << (n - 1)); mask++) {
		sum = 0;
		tmp = s[0] - '0';
		for (int i = 0; i < n - 1; i++) {
			if (mask & (1 << i)) {
				sum += tmp;
				tmp = 0;
			}
			tmp = tmp * 10 + s[i+1] - '0';
		}
		sum += tmp;
		ans += sum;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>

typedef long long ll;

#define FOR(i,a,b) for(ll i = (a);i < (b);++i)
#define REP(i,n) FOR(i,0,n)

#define debug(x) cout << #x << "=" << x << endl;

using namespace std;

int main(void){

    int A,B,C,D;
    cin >> A >> B >> C >> D;

    int distAB = abs(A-B);
    int distBC = abs(B-C);
    int distAC = abs(A-C);

    if((distAB <= D and distBC <= D) or distAC <= D){
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256