akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	int n, x; cin >> n >> x;
	vector<int> l(n);

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

	int pos = 0;
	int ans = 1;
	for (int i = 0; i < n; i++) {
		if (pos + l[i] <= x) {
			ans++;
			pos += l[i];
		}
		else {
			cout << ans << endl;
			return 0;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string stin() {string s; cin>>s; return s;}
/***** MAIN *****/
signed main() {
  string s = stin();
  string sub_s = stin();
  bool restorable = false;

  // 後ろからsubstring(sub_s)が入るかどうか探索
  for(int i = s.size()-sub_s.size(); i >= 0; --i) {
    bool restorable_sub = true;
    for(int j = 0; j < sub_s.size(); ++j) {
      if(s[i+j] == '?') continue;
      if(s[i+j] == sub_s[j]) continue;
      else {
        restorable_sub = false;
        break;
      }
    }
    
    // substringが入るとき、'?'ごとsubstringに置き換え
    if(restorable_sub) {
      for(int j = 0; j < sub_s.size(); ++j) {
        s[i+j] = sub_s[j];
      }
      restorable = true;
      break;
    }
  }

  // substringがどこにも入らなかった時
  if(!restorable) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  // substringで置き換えたところ以外は'a'で埋める（辞書順で最も前の文字列を作る）
  for(int i = 0; i < s.size(); ++i) {
    if(s[i] == '?') cout << 'a';
    else cout << s[i];
  }
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 256
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
using namespace std;
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
int dx[4]={0,0,-1,1},dy[4]={1,-1,0,0};


int main(int argc, char const *argv[]) {
  int n,m;
  ll ans=0,cnt=0;
  pll data[100010];
  std::cin >> n >> m;
  for(int i=0; i<n; i++) std::cin >> data[i].first >> data[i].second;
  sort(data,data+n);

  for(int i=0; i<n; i++){
    if(cnt+data[i].second>=m){
      ll p=0;
      while(cnt<m){
        cnt++;
        ans+=data[i].first;
      }
      std::cout << ans << '\n';
      return 0;
    }

    else{
      cnt+=data[i].second;
      ans+=data[i].second*data[i].first;
    }
  }
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n,x;
	cin >> n >> x;
	vector<ll> a(n);
	FOR(i,0,n)cin>>a[i];
	SORT(a);
	ll ans = 0;
	FOR(i,0,n){
		if(x>=a[i]){
			if(i==n-1){
				if(x!=a[i])break;
			}
			ans++;
			x -= a[i];
		}else{
			break;
		}
	}
	cout << ans << endl;
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

constexpr int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
constexpr int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
bool comp(pii a, pii b) {
	return a.first + a.second > b.first + b.second;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<pii> v(n);
	REP(i, n) {
		int a, b;
		cin >> a >> b;
		v[i] = { a,b };
	}
	sort(ALL(v),comp);
	ll ans = 0;
	REP(i, n) {
		if (i % 2 == 0) {
			ans += v[i].first;
		}
		else {
			ans -= v[i].second;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    ll X,A;cin>>X>>A;
    if (X>=A){cout<<10<<endl;}
    else if (X<A){cout<<0<<endl;}

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define inf 2147483647 //int値の最大値
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define cint(n) int n;cin>>n;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int main() {
    int a,b,m;cin>>a>>b>>m;
    vector<int> A(a);
    vector<int> B(b);
    int mina=inf;
    int minb=inf;
    rep(i,a){
        cin>>A[i];
        mina=min(mina,A[i]);
    }
    rep(i,b){
        cin>>B[i];
        minb=min(minb,B[i]);
    }
    int minsum=mina+minb;
    rep(i,m){
        int ai,bi,c;cin>>ai>>bi>>c;
        minsum=min(minsum,A[ai-1]+B[bi-1]-c);
    }
    cout<<minsum;
    return 0;
}


Measured memory_bytes: 4036
n,m = map(int,input().split())
x = list(map(int,input().split()))
if n >= m:
    print(0)
    exit()
x.sort()
y = [x[i+1]-x[i] for i in range(m-1)]
y.sort(reverse = True)
count = x[m-1]-x[0]
count -= sum(y[:n-1])
print(count)

Measured memory_bytes: 13960
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	int x[10000],n,i;
	long long sum=0,max=-1000000000,min=1000000000;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>x[i];
		sum += x[i];
		if(min>x[i]){
			min=x[i];
		}if(max<x[i]){
			max=x[i];
		}
	}
	cout<<min<<" "<<max<<" "<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3136
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;

inline int read()
{
	int f=1,x=0;
	char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-') f=-1; ch=getchar();}
	while(isdigit(ch)) {x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}

int n,ans=1e9;
char a[1000005];
int w[1000005],b[1000005];

int main()
{
	int i;
	n=read();
	scanf("%s",a+1);
	for(i=1;i<=n;i++)
	{
		b[i]=b[i-1];
		if(a[i]=='#')
		    b[i]++;
	}
	for(i=n;i>=1;i--)
	{
		w[i]=w[i+1];
		if(a[i]=='.')
		    w[i]++;
	}
	for(i=0;i<=n;i++)
	    ans=min(ans,b[i]+w[i+1]);
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 7168
import collections
N, M = map(int, input().split())
mod = pow(10, 9) + 7

def prime_factorize(K):
    ans = []
    i = 2
    while i ** 2 <= K:
        if K % i == 0:
            K //= i
            ans.append(i)
        else:
            i += 1
    if K != 1:
        ans.append(K)
    
    return ans

def combination(N, r):
    ans = N
    for i in range(1, r):
        ans *= ((N - i) % mod) * pow(i + 1, mod - 2, mod)
        ans %= mod
    
    return ans

prime_nums = dict(collections.Counter(prime_factorize(M)))

ans = 1
for num in prime_nums.values():
    ans *= combination(N - 1 + num, num)
    ans %= mod

print(ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
   ll n;cin>>n;
   ll ans=100000000000001;
   for(ll i=1;i*i<=n;i++){
       if(n%i==0){
           ans=min(ans,i-1+n/i-1);
       }
   }
   cout<<ans;
}

Measured memory_bytes: 256
Uses math;
var
	n,i,z,w,a,b,t:Longint;
	s:String;
begin
	readln(n,z,w);
	if n=1 then begin
		read(b);
		writeln(abs(b-w));
		exit;
	end;
	setlength(s,22222);
	readln(s);
	i:=length(s);
	while s[i]>' ' do dec(i);
	for z:=i+1 to length(s) do b:=b*10+ord(s[z])-48;
	dec(i);
	t:=i;
	while(i>0)and(s[i]>' ')do dec(i);
	for z:=i+1 to t do a:=a*10+ord(s[z])-48;
	writeln(Max(abs(b-w),abs(a-b)));
end.


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
/* ------------------------------------------------ */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ------------------------------------------------ */

int main() {
    int n;
    cin >> n;
    int ans = 1;
    while(ans * 2 <= n) {
        ans *= 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
import java.util.*;

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

        int val1 = sc.nextInt();
        int val2 = sc.nextInt();
        int val3 = sc.nextInt();

        List<Integer> k = new ArrayList<>();
        int loop = val1 > val2 ? val1 : val2;
        for (int i = 1; i <= loop; i++) {
            if ((val1 % i == 0) && (val2 % i == 0)) {
                k.add(i);
            }
        }
        Collections.sort(k);
        System.out.println(k.get((k.size() - 1) - (val3 - 1)));
    }
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

string solve()
{
    int h,w;
    cin >>h >>w;
    vector<string> s(h);
    rep(i,h) cin >>s[i];

    int dx[4]={1,-1,0,0}, dy[4]={0,0,1,-1};
    #define IN(x,y) (0<=x && x<w && 0<=y && y<h)

    int px,py;
    rep(i,h)rep(j,w)if(s[i][j]=='%')
    {
        py = i;
        px = j;
    }

    while(1)
    {
        vector<string> ns(s);
        rep(i,h)rep(j,w)if(s[i][j]=='@')
        {
            rep(k,4)
            {
                int nx = j+dx[k], ny = i+dy[k];
                if(IN(nx,ny) && (s[ny][nx]=='.'||s[ny][nx]=='%')) ns[ny][nx]='@';
            }
        }

        rep(i,h)rep(j,w)if(s[i][j]=='$')
        {
            rep(k,4)
            {
                int nx = j+dx[k], ny = i+dy[k];
                if(IN(nx,ny) && s[ny][nx]!='#') ns[ny][nx]='$';
            }
        }

        s = ns;
        if(s[py][px]=='@') return "Yes";
        if(s[py][px]=='$') return "No";
    }
}

int main()
{
    cout << solve() << endl;
    return 0;
}

Measured memory_bytes: 3292
import scala.io.StdIn._
import scala.math._

object Main extends App with StdInHelper {
  val ss = readStrings
  val a = BigDecimal(ss(0).toLong)
  val b = BigDecimal(ss(1).toDouble)

  println((a * b).setScale(0, scala.math.BigDecimal.RoundingMode.FLOOR))
}

trait StdInHelper {
  def readStrings = readLine.split(" ")
  def readInts = readLine.split(" ").map(_.toInt)
  def readLongs = readLine.split(" ").map(_.toLong)
  def readDoubles = readLine.split(" ").map(_.toDouble)
}


Measured memory_bytes: 54896
#include <stdio.h>

int main(){
	
	int a, b;
	scanf("%d%d", &a, &b);
	if (b % a == 0){
		printf("%d\n", a + b);
	}
	else if (b % a != 0){
		printf("%d\n", b - a);
	}
	return 0;
}

Measured memory_bytes: 1728
def larger(x, y):
	if x > y: return x
	else: return y

n = int(raw_input())
v = map(int, raw_input().split())
lst1 = []
lst2 = []
for i in range(0, n):
	if i % 2 == 1: lst1.append(v[i])
	else: lst2.append(v[i])
lst1.sort()
lst2.sort()
firstnumber1 = 0
firstcount1 = 0
secondnumber1 = 0
secondcount1 = 0
firstnumber2 = 0
firstcount2 = 0
secondnumber2 = 0
secondcount2 = 0
tmp1 = lst1[0]
cnt1 = 1
tmp2 = lst2[0]
cnt2 = 1

for i in range(1, n/2):
	if tmp1 != lst1[i]:
		if firstcount1 < cnt1:
			secondnumber1 = firstnumber1
			secondcount1 = firstcount1
			firstnumber1 = tmp1
			firstcount1 = cnt1
		elif secondcount1 < cnt1:
			secondnumber1 = tmp1
			secondcount1 = cnt1
		tmp1 = lst1[i]
		cnt1 = 1
	else: cnt1 += 1
	if tmp2 != lst2[i]:
		if firstcount2 < cnt2:
			secondnumber2 = firstnumber2
			secondcount2 = firstcount2
			firstnumber2 = tmp2
			firstcount2 = cnt2
		elif secondcount2 < cnt2:
			secondnumber2 = tmp2
			secondcount2 = cnt2
		tmp2 = lst2[i]
		cnt2 = 1
	else: cnt2 += 1
if firstcount1 < cnt1:
	secondnumber1 = firstnumber1
	secondcount1 = firstcount1
	firstnumber1 = tmp1
	firstcount1 = cnt1
elif secondcount1 < cnt1:
	secondnumber1 = tmp1
	secondcount1 = cnt1
if firstcount2 < cnt2:
	secondnumber2 = firstnumber2
	secondcount2 = firstcount2
	firstnumber2 = tmp2
	firstcount2 = cnt2
elif secondcount2 < cnt2:
	secondnumber2 = tmp2
	secondcount2 = cnt2

if firstnumber1 == firstnumber2:
	print n - larger(secondcount1+firstcount2, firstcount1+secondcount2)
else:
	print n - firstcount1 - firstcount2

Measured memory_bytes: 11312
def group(xs)
  if xs[0] == 0
    group xs[1..-1]
  elsif xs.size == 0
    []
  else
    g = []
    rest = []
    xs.size.times {|i|
      if xs[i] != 0
        g << xs[i]
      else
        rest = xs[i+1..-1]
        break
      end
    }
    [g] + group(rest)
  end
end

def sum(xs)
  if xs.size > 0
    xs.inject :+
  else
    0
  end
end

def solve(g)
  m = g.min
  gs = group(g.map{|x| x - m})
  m + sum(gs.map{|h| solve(h)})
end

_ = gets.to_i
xs = gets.split.map(&:to_i)
p sum(group(xs).map{|g| solve(g)})


Measured memory_bytes: 3964
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b); }

const int MAXN=500000;
const int MOD=1000000007;

int n;
int a[MAXN];

int asum[MAXN+1];
pair<int,int> ord[MAXN+1];
int zerocnt[MAXN+2];

int b[MAXN+1],nb;
int dp[MAXN+1];


int calc(int val) {
	int ret=0;
	if(val==0) {
		assert(nb>=2&&b[0]==0&&b[nb-1]==n);
		int dpsum=1; dp[0]=1;
		FOR(i,1,nb) {
			dp[i]=dpsum;
			dpsum=(dpsum+dp[i])%MOD;
		}
		ret=dp[nb-1];
	} else {
		assert(nb>=1);
		int dpsum=0;
		REP(i,nb) {
			int idx=b[i];
			if(i==0) {
				dp[i]=1;
				dpsum=(dpsum+dp[i])%MOD;
			} else {
				int pidx=b[i-1];
				dp[i]=(dp[i-1]+(ll)dpsum*(zerocnt[idx]-zerocnt[pidx]))%MOD;
				dpsum=(dpsum+dp[i])%MOD;
			}
		}
		ret=asum[n]==val?dp[nb-1]:dpsum;
	}
	//printf("%d = %d\n",val,ret);
	//printf("b:"); REP(i,nb) printf(" %d=%d",b[i],dp[i]); puts("");
	return ret;
}

int solve() {
	asum[0]=0; REP(i,n) asum[i+1]=asum[i]^a[i];
	zerocnt[0]=0; REPE(i,n) zerocnt[i+1]=zerocnt[i]+(asum[i]==0?1:0);
	
	//printf("asum:"); REPE(i,n) printf(" %d",asum[i]); puts("");
	
	int ret=0;
	REPE(i,n) ord[i]=MP(asum[i],i); sort(ord,ord+n+1);
	for(int l=0,r=l;l<=n;l=r) {
		int val=ord[l].first;
		while(r<=n&&ord[r].first==val) ++r;
		if(asum[n]!=0&&asum[n]!=val) continue;
		nb=0; FOR(i,l,r) b[nb++]=ord[i].second;
		ret=(ret+calc(val))%MOD;
	}
	return ret;	
}

void run() {
	scanf("%d",&n);
	REP(i,n) scanf("%d",&a[i]);
	printf("%d\n",solve());
}

int main() {
	run();
	return 0;
}

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

int main() {
    string s;
    cin >> s;
    vector<int> count(2);
    for(int i = 0;i < s.size();i++){
        if((i % 2 && s[i] == '0')||(!(i % 2) && s[i] == '1')) count[0]++;
        if((i % 2 && s[i] == '1')||(!(i % 2) && s[i] == '0')) count[1]++;
    }
    cout << min(count[0], count[1]) << endl;
    return 0;
}

Measured memory_bytes: 512
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            char[] s = in.nextLine().toCharArray();
            int ans = s.length;
            for (int i = 0; i < s.length - 1; i++)
                if (s[i] != s[i + 1])
                    ans = Math.min(ans, Math.max(i + 1, s.length - i - 1));
            out.println(ans);
        }

    }

    static class InputReader {
        BufferedReader br;

        public InputReader(InputStream is) {
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            this.br = br;
        }

        public String nextLine() {
            String str = null;
            try {
                str = br.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return str;
        }

    }
}



Measured memory_bytes: 24660
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a;
  for(int i=0;;i++){
    cin>>a;
    double b[1000]={0.0000000000},c=0.000000000,d=0.000000000;
    if(a==0)break;
    for(int j=0;j<a;j++){
        cin>>b[j];
        d+=b[j];
    }
    d=d/a;
    for(int j=0;j<a;j++){
        c+=(b[j]-d)*(b[j]-d);
    }
    c=c/a;
    cout <<setprecision(10)<<sqrt(c)<<endl;
  }
  return 0;
}

Measured memory_bytes: 3264
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N;
    cin >> N;
    cout << (N+1)/2 << endl;
}

Measured memory_bytes: 764
N, M = map(int, input().split())

ABC = []
for _ in range(M):
    a, b, c = map(int, input().split())
    ABC.append((a, b, c))
edges = ABC[:]

graph = {}
for a,b,c in edges:
    if not a in graph:
        graph[a] = {}
    if not b in graph:
        graph[b] = {}
    graph[a][b] = c
    graph[b][a] = c


from heapq import heappush, heappop

def dijkstra(graph, start):
    A = [None] * (N+1)
    queue = [(0, start)]
    while queue:
        path_len, v = heappop(queue)
        if A[v] is None: # v is unvisited
            A[v] = path_len
            for w, edge_len in graph[v].items():
                if A[w] is None:
                    heappush(queue, (path_len + edge_len, w))

    # to give same result as original, assign zero distance to unreachable vertices             
    return [0 if x is None else x for x in A]

shrtest = [[0]*(N+1)]
for a in range(1, N+1):
    sub_shrtest = dijkstra(graph, a)
    shrtest.append(sub_shrtest)
#print(shrtest)

ans = 0
for a,b,c in edges:
    if shrtest[a][b] != c:
        ans += 1
print(ans)

Measured memory_bytes: 3700
L,R=map(int,input().split())
i=0
j=0
l=0
r=0
md=float("inf")
if R-L>=673:
    print("0")
else:
    l=L%2019
    r=R%2019
    if l>r:
        print("0")
    elif l<r:
        l=L%2019
        r=R%2019
        for i in range(l,r+1):
            for j in range(i+1,r+1):
                if (i*j)%2019<md:
                    md=(i*j)%2019
                #print(i,j)
        print(md)


Measured memory_bytes: 39152
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n,l;cin >> n >> l;
  vector<string> s(n);
  rep(i,n) cin >> s[i];

  sort(s.begin(), s.end());
  rep(i,n) cout << s[i];
  cout << "\n";
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
   string x;

   cin >> x;

   long long s = 0;

   for(int i = 0; i < x.length(); i++) {
        s += x[i] - '0';
   }
   s%9 == 0 ? cout << "Yes" : cout << "No";
   return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#define inf 1000000000

using namespace std;
typedef pair<int, int> P;

struct SegTree{
	int size;
	vector<P> seg;
	
	SegTree(){}
	SegTree(int size){
		this->size = size;
		seg.resize(1<<(size+1));
	}
	
	void init(){
		for(int i = 0; i < (1<<(size+1)); i++) seg[i] = make_pair(inf, inf);
	}
	
	void update(int i, P val)
	{
		i += (1 << size);
		seg[i] = val;
		while(i > 1){
			i /= 2;
			seg[i] = min(seg[i*2], seg[i*2+1]);
		}
	}

	P query(int a, int b, int k, int l, int r)
	{
		if(b < l || r < a) return make_pair(inf, inf);
		if(a <= l && r <= b) return seg[k];
		P lval = query(a, b, k*2, l, (l+r)/2);
		P rval = query(a, b, k*2+1, (l+r)/2+1, r);
		return min(lval, rval);
	}
	P query(int a, int b)
	{
		return query(a, b, 1, 0, (1<<size)-1);
	}
};

SegTree odd(18), even(18);

struct Range{
	int l, r;
	P p1, p2;
	
	Range(){}
	Range(int a, int b){
		l = a, r = b;
		calc();
	}
	void calc(){
		if(l%2){
			p1 = odd.query(l, r);
			p2 = even.query(p1.second+1, r);
		}
		else{
			p1 = even.query(l, r);
			p2 = odd.query(p1.second+1, r);
		}
	}
	bool operator>(const Range& obj)const{
		return p1 > obj.p1;
	}
};

int N;
priority_queue< Range, vector<Range>, greater<Range> > Q;
vector<int> ans;

int main(void)
{
	odd.init(), even.init();
	
	cin >> N;
	int p;
	for(int i = 1; i <= N; i++){
		cin >> p;
		if(i%2) odd.update(i, make_pair(p, i));
		else even.update(i, make_pair(p, i));
	}
	
	Range rg;
	Q.push(Range(1, N));
	while(Q.size()){
		rg = Q.top(), Q.pop();
		ans.push_back(rg.p1.first);
		ans.push_back(rg.p2.first);
		if(rg.p1.second != rg.l) Q.push(Range(rg.l, rg.p1.second-1));
		if(rg.p2.second != rg.r) Q.push(Range(rg.p2.second+1, rg.r));
		if(rg.p1.second+1 != rg.p2.second) Q.push(Range(rg.p1.second+1, rg.p2.second-1));
	}
	
	for(int i = 0; i < ans.size(); i++){
		cout << ans[i];
		if(i != ans.size()-1) cout << " ";
	}
	cout << endl;
	
	return 0;
}

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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    char prev_c = 'R';
    int prev_index;
    int counter = 1;
    int a[n];
    fill(a, a + n, 0);
    for (int i = 1; i < n; i++) { 
        if (prev_c != s[i]) {
            if (prev_c == 'R') {
                a[i] += counter / 2;
                a[i - 1] += counter - counter / 2;
                prev_index = i;
            } else {
                a[prev_index - 1] += counter / 2;
                a[prev_index] += counter - counter / 2;
            }
            prev_c = s[i];
            counter = 1;
        } else {
            counter++;
        }
    }
    a[prev_index - 1] += counter / 2;
    a[prev_index] += counter - counter / 2;
    cout << a[0];
    for (int i = 1; i < n; i++) {
        cout << ' ' << a[i];
    }
    cout << endl;
    return 0;
}


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


int main(int argc, char const *argv[])
{
    char a;
    char b;
    cin>>a>>b;
    
    if (a=='H'&&b=='H') {
        cout<<'H';
    }else
    
    if (a=='H'&&b=='D') {
        cout<<'D';
    }else
    
    if (a=='D'&&b=='H') {
        cout<<'D';
    }
    else
    {
        cout<<'H';
    }
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define EB(x) emplace_back(x)
#define DEBUG(x) cout << (#x) << ": " << (x) << endl
#define DEBUG_VEC(v)            \
    cerr << #v << ": ";         \
    REP(__i, (v).size())        \
    cerr << ((v)[__i]) << ", "; \
    cerr << endl

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

int main()
{
    ios::sync_with_stdio(false);
    int W, H, x, y;
    cin >> W >> H >> x >> y;

    double area = (double) W * H / 2;
    int dup = (2 * x == W and 2 * y == H);
    cout << area << " " << dup << endl;
    return 0;
}


Measured memory_bytes: 256
import itertools
n = int(input())
a = list(map(int, input().split()))

cumsum = list(itertools.accumulate(a))

min_ = 2 * 10 ** 9
sum_ = cumsum[-1]
for i in range(n-1):
    min_ = min(min_, abs(cumsum[i] - (sum_ - cumsum[i])))

print(min_)

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

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

using namespace std;

int main() {
  while(1){
    int x,y,s;
    cin>>x>>y>>s;
    if(!x)break;
    int mx = 0;
    REP(i,s) {
      if (!i) continue;
      REP(j,s) {
        if(!j) continue;
        int p1 = (i*(100+x))/100;
        int p2 = (j*(100+x))/100;
        if (p1 + p2 != s) continue;
        int q1 = (i*(100+y))/100;
        int q2 = (j*(100+y))/100;
        mx = max(mx, q1+q2);
      }
    }
    cout << mx << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
/*
ID: toooooEasy or RafaelSaddatimov
PROG:
*/
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define MAX 200005
#define MAXN 10001
#define LOGMAX 30
#define SQMAX 200
#define SZ (MAX / SQMAX + 1)
#define MOD 1000000007
#define INF 2000000009
#define EPS 1e-9
#define ll long long
#define F first
#define S second
#define all(a) a.begin(), a.end()
#define pb push_back
#define io ios_base::sync_with_stdio(false); cin.tie(0)
using namespace std;

int main() {
    string s;
    ll k;
    cin >> s >> k;
    int cur = 0;
    for(; cur < s.size() && s[cur] == '1'; ++cur);
    if(cur + 1 > k) puts("1");
    else printf("%c\n", s[cur]);
}


Measured memory_bytes: 256
import numpy as np

N = int(input())
h = [0]+list(map(int, input().split()))+[0]

diff = np.diff(h).tolist()
max_list = []
min_list = []

sign = 1
for i, d in enumerate(diff):
    if d > 0 and sign < 0:
        sign = d
        min_list.append(h[i])

    if d < 0 and sign > 0:
        sign = d
        max_list.append(h[i])


def add(val, max_list, min_list):
    if len(max_list) > 1:
        min_val = min(min_list)
        split_index = min_list.index(min_val)+1
        return min_val-val + \
            add(min_val, max_list[:split_index], min_list[:split_index-1]) + \
            add(min_val, max_list[split_index:], min_list[split_index:])
    else:
        return max_list[0]-val


if max(h) == 0:
    print(0)
else:
    print(add(0, max_list, min_list))


Measured memory_bytes: 14476
#include<bits/stdc++.h>
using namespace std;
int main()
{

    long long int a,b,c,d,e=1,r[1000],f,h;
    while(scanf("%lld%lld",&a,&b)==2)
    {
        c=a;

        while(b!=0)
        {
            d=b%10;
            r[e]=d;
            b=b/10;
            e++;
        }

        for(f=e-1;f>=1;f--)
        {
           c=c*10+r[f];

        }
       h=sqrt(c);

        if(h*h==c)
        {
            cout<<"Yes"<<endl;
        }
        else
        {
            cout<<"No"<<endl;
        }
    }
    return 0;


}


Measured memory_bytes: 256
import java.util.*;

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

    if (s <= w) {
      System.out.println("unsafe");
    } else {
      System.out.println("safe");
    }
  }
}


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

using namespace std;
using ll = long long;
using ld = long double;

unordered_map<ll, ll> result_cache;
unordered_map<ll, ll> target_num_table;

ll combi2(ll num) {
  return num*(num-1)/2;
}

int main() {
  ll N;
  vector<ll> a;
  std::cin >> N;

  for (auto i{0ul}; i < N; ++i)
  {
    ll input;
    cin >> input;
    a.emplace_back(input);
    if (target_num_table.find(input) == target_num_table.end())
    {
      target_num_table.emplace(input, 1);
    }
    else
    {
      ++target_num_table[input];
    }
  }
  ll combis = 0ul;
  for (auto itr{target_num_table.begin()}, end{target_num_table.end()}; itr != end; ++itr)
  {
    combis += combi2(itr->second);
  }
  for (const auto n: a)
  {
    std::cout << (combis - target_num_table[n] + 1) << std::endl;
  }

  return 0;
}


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


int main() {
  int n ;
  cin >> n ;
  
  vector<int> vec(n);
  for(int i=0 ;i<n;i++){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(),vec.end());
  
  cout << vec.at(n-1)-vec.at(0) << endl;
}

Measured memory_bytes: 256
using System;

namespace CA {
	class Prg {
		static void Main() {
			string[] str = new string[2];
			while(true){
				str = Console.ReadLine().Split(' ');
				if (int.Parse(str[0]) < int.Parse(str[1])) Console.WriteLine(str[0] + " " + str[1]);
				else if (str[0] == "0" && str[1] == "0") break;
				else Console.WriteLine(str[1] + " " + str[0]);
			}
		}
	}
}

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

int main() {
  int N, M;
  cin >> N >> M;
  
  long ans = 0;
  
  if (N > 1) {
    ans = ans + (N * (N - 1) / 2);
  }

  if (M > 1) {
    ans = ans + (M * (M - 1) / 2);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
// ------ Class ------ //
class QuickUnionFind {
private:
	unsigned size_; std::vector<unsigned> g; std::vector<std::vector<unsigned> > v;
public:
	QuickUnionFind() : size_(0), g(std::vector<unsigned>()), v(std::vector<std::vector<unsigned> >()) {};
	QuickUnionFind(unsigned size__) : size_(size__) {
		g.resize(size_); v.resize(size_);
		for (unsigned i = 0; i < size_; i++) g[i] = i, v[i] = { i };
	};
	unsigned size() { return size_; }
	unsigned root(unsigned x) { return g[x]; }
	unsigned size(unsigned x) { return v[x].size(); }
	bool same(unsigned x, unsigned y) { return g[x] == g[y]; }
	void unite(unsigned x, unsigned y) {
		x = g[x], y = g[y];
		if (x == y) return;
		if (v[x].size() < v[y].size()) std::swap(x, y);
		v[x].insert(v[x].end(), v[y].begin(), v[y].end());
		for (auto &e : v[y]) g[e] = x;
		v[y].clear();
	}
	bool operator==(const QuickUnionFind& u) { return g == u.g; }
	bool operator!=(const QuickUnionFind& u) { return g != u.g; }
};


long long n, q, a[200000], b[200000];
char J[200000]; int K[200000];
int main() {
	while (true) {
		cin >> n >> q; if (n == 0 && q == 0)break;
		for (int i = 0; i < 200000; i++)b[i] = 0;
		for (int i = 2; i <= n; i++) cin >> a[i];
		for (int i = 0; i < q; i++) {
			cin >> J[i] >> K[i]; if (J[i] == 'M')b[K[i]]++;
		}
		QuickUnionFind UF(n + 2); long long sum = 0;
		for (int i = 2; i <= n; i++) { if (b[i] == 0)UF.unite(i, a[i]); }
		for (int i = q - 1; i >= 0; i--) {
			if (J[i] == 'M' && K[i] != 1) {
				b[K[i]]--;
				if (b[K[i]] == 0)UF.unite(a[K[i]], K[i]);
			}
			if (J[i] == 'Q') {
				int D = K[i];
				while (true) {
					if (UF.same(a[D], K[i]) == false) {
						sum += D; break;
					}
					D = a[D];
				}
			}
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 15580
#include<iostream>
#include<string>
#include<vector>

int main(){

    size_t n, q;
    std::string s;

    std::cin >> n >> q >> s;

    std::vector<size_t> v(n, 0);

    for(size_t i = 1; i < n; i++){
        if(s.at(i) == 'C' && s.at(i - 1) == 'A'){
            v[i] = 1;
        }

        v[i] += v[i - 1];
    }

    for(size_t i = 0; i < q; i++){
        size_t l, r;
        std::cin >> l >> r;

        std::cout << v[r - 1] - v[l - 1] << std::endl; 
    }
    
    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

/**
 * https://abc064.contest.atcoder.jp/tasks/abc064_a
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		String r = sc.next();
		String g = sc.next();
		String b = sc.next();
		sc.close();
		
		int num = Integer.parseInt(r+g+b);
		
		String ans = num % 4 == 0 ? "YES" : "NO";
		System.out.println(ans);
		

	}

}

Measured memory_bytes: 21844
/*
 * ID: ITP1_6_A
 * Problem: Reversing Numbers
 */

#include <stdio.h>

int main(void)
{
    int a[1000];
    int n;

    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", a + i);

    for (int i = n - 1; i >= 0; i--) {
        if (i != n - 1)
            putchar(' ');
        printf("%d", a[i]);
    }
    puts("");

    return 0;
}



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

using ll = long long;

// 繰り返し自乗法(x^nをmで割った余り) O(logn)
ll power(ll x, ll n, ll m) {
  ll res = 1;
  if (n > 0) {
    res = power(x, n / 2, m);
    if(n % 2 == 0) res = (res * res) % m;
    else res = (((res * res) % m) * x) % m;
  }
  return res;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, p;
  string s;
  cin >> n >> p >> s;
  
  map<ll, ll> mp;
  mp[0]++;
  ll now = 0, ans = 0;
  if (p == 2 || p == 5) {
    for (int i = 0; i < n; i++) {
      now *= 10;
      now += s.at(i) - '0';
      now %= p;
      if (now == 0) ans += i + 1;
    }
    cout << ans << '\n';
    return 0;
  }
  for (int i = n - 1; i >= 0; i--) {
    now += (s.at(i) - '0') * power(10, n - i - 1, p);
    now %= p;
    ans += mp[now];
    mp[now]++;
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 1044
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int N;
	scanf("%d",&N);
	printf("%d\n",N*800-(N/15*200));
}


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

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  ll d = c - a - b;
  if (d > 0 && d * d > 4 * a * b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A.begin(), A.end(), greater<int>());
  int a = 0, b = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      a += A[i];
    } else {
      b += A[i];
    }
  }
  cout << a - b << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;

int main(){

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

    int n = s.size();

    map<char, char> m;
    map<char, char>::iterator itr;

    bool endflag = false;
    for(int i=0; i<n; i++){
        if(m.find(s[i]) == m.end()){
            for(itr = m.begin(); itr != m.end(); itr++){
                if((*itr).second == t[i]){
                    endflag = true;
                }
            }
            if(endflag) break;
            m.emplace(s[i], t[i]);
        }
        else{
            if(m[s[i]] != t[i]){
                endflag = true;
            }
        }
        if(endflag) break;
    }

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

    return 0;
}

Measured memory_bytes: 776
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <iomanip>

using namespace std;

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

   long long ans=0;
   long long num=0;
   long long a=0;
   long long b=0;
   long long ab=0;
   for(int i=0;i<n;i++){
      for(int j=0;j<s[i].size()-1;j++){
         if(s[i][j]=='A' && s[i][j+1]=='B')num++;
      }
   }
   for(int i=0;i<n;i++){
      if(s[i][0]=='B' && s[i][s[i].size()-1]=='A')ab++;
      else {
         if(s[i][0]=='B')b++;
         if(s[i][s[i].size()-1]=='A')a++;
      }
   }
   ans+=num;
   if(ab>=2){
      ans+=ab-1;
      ab=1;
   }
   if(a>0 || b>0)ans+=min(a,b)+ab;
   cout<<ans<<endl;
}

   


Measured memory_bytes: 512
# frozen_string_literal: true

n, k = gets.split.map(&:to_i)
r, s, p = gets.split.map(&:to_i)
t = gets.chomp

c = Hash.new
c['r'] = p
c['s'] = r
c['p'] = s

d = Array.new(n) { false }
sum = 0

k.times do |i|
  sum += c[t[i]]
end
(k..(n - 1)).each do |i|
  if t[i] == t[i - k] && !d[i - k]
    d[i] = true
    next
  end

  sum += c[t[i]]
end

puts sum


Measured memory_bytes: 4732
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long n = in.nextLong();
        List<Long> nums = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            nums.add(in.nextLong());
        }

        long smallest = Collections.min(nums);
        System.out.println(((n + smallest - 1) / smallest) + 4);
    }
}


Measured memory_bytes: 23252
import math

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))


def Order(n, s):
    cnt = 1
    num_list = []
    for i in range(n):
        num_list.append(i + 1)
    for i in range(n):
        index = num_list.index(s[i])
        cnt += index * math.factorial(n - i - 1)
        del num_list[index]

    return cnt


ans = Order(N, P) - Order(N, Q)
if ans < 0:
    ans *= -1
print(ans)


Measured memory_bytes: 3064
#include<stdio.h>

int search(int s[],int n,int t)
{
	int i=0;
	s[n]=t;
	
	while(s[i]!=t)
	{
		i++;
	}
	
	return i != n;
}

int main(void)
{
	int n,s[10000];
	int q,t;
	int i,sum=0;
	
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&s[i]);
	}
	
	scanf("%d",&q);
	for(i=0;i<q;i++)
	{
		scanf("%d",&t);
		if(search(s,n,t))
		{
			sum++;
		}
	}
	printf("%d\n",sum);
	
	
	return 0;
}


Measured memory_bytes: 2108
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;


public class Main {

	Scanner sc;
	
	ArrayList<LinkedList<Integer>> adjacent;
	boolean[] visited;
	
	int ni(){
		return sc.nextInt();
	}
	
		void dfs(int x){
		for(int y:adjacent.get(x)){
			if(!visited[y]){
				visited[y]=true;
				dfs(y);
			}
		}
		System.out.println(x);
	}
	
	void io(){
		sc=new Scanner(System.in);
		
		int m=ni(), n=ni();
		
		adjacent=new ArrayList<LinkedList<Integer>>();
		for(int i=0;i<=m;++i){
			adjacent.add(new LinkedList<Integer>());
		}
		
		int last=0;
		
		for(int i=0;i<n;++i){
			int x=ni(), y=ni();
			//y->xの枝を張る (yはxより後, 根に行くほど後)
			adjacent.get(y).add(x);
			
			//最後に這入った奴は分かっている
			if(last==0||last==x) last=y;
		}
		visited=new boolean[m+1];
		
		dfs(last);
	}
	
	void debug(Object...os){
		System.err.println(Arrays.deepToString(os));
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().io();
	}

}

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

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

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

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


signed main(void) {
	int n;
	string s;
	cin >> n >> s;
	ll r = 0;
	ll g = 0;
	ll b = 0;
	rep(i,n) {
		if (s[i] == 'R')r++;
		else if (s[i] == 'G')g++;
		else if (s[i] == 'B')b++;
	}
	ll ans = r * g*b;
	rep(i, n) {
		rep1(j, n) {
			//cout << i << " " << i + j << " " << i + 2 * j << endl;
			if ((i + 2*j)>=n)continue;
			else if (s[i] != s[i + j] && s[i + j] != s[i + 2 * j] && s[i + 2 * j] != s[i]) {
				ans--;
				//cout << s[i] << " " << s[i + j] << " " << s[i + 2 * j] << endl;
			}
		}
	}
	print(ans);
}

Measured memory_bytes: 3628
package main

import (
	"fmt"
	"math"
)

func main() {
	var A, B, C, K int64
	fmt.Scan(&A, &B, &C, &K)

	var ans int64

	if K%2 == 0 {
		ans = A - B
	} else {
		ans = -(A - B)
	}

	if ans > int64(math.Pow(float64(10), float64(18))) {
		fmt.Println("Unfair")
	} else {
		fmt.Println(ans)
	}
}


Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 666666
int r,c,n; pii g[SZ][2],ps[SZ]; int pn=0;
int col(pii x)
{
	if(x.fi==0)
		return x.se;
	if(x.se==c)
		return x.fi+c;
	if(x.fi==r)
		return r+c+c-x.se;
	if(x.se==0)
		return r+r+c+c-x.fi;
	return -1;
}
int st[SZ],sn=0;
int main()
{
	scanf("%d%d%d",&r,&c,&n);
	for(int i=1;i<=n;++i)
	{
		for(int j=0;j<2;++j)
			scanf("%d%d",&g[i][j].fi,&g[i][j].se);
		int s=col(g[i][0]),t=col(g[i][1]);
		if((~s)&&(~t));else continue;
		ps[++pn]=pii(s,i); ps[++pn]=pii(t,i);
	}
	sort(ps+1,ps+1+pn);
	for(int i=1;i<=pn;++i)
	{
		int g=ps[i].se;
		if(sn&&st[sn]==g) --sn;
		else st[++sn]=g;
	}
	if(sn) puts("NO");
	else puts("YES");
}


Measured memory_bytes: 8832
#include<map>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
vector<int> ns;
map<int,int> mp;
int main()
{
	int n;
    cin>>n;
    	int t;
    	for(t=0;t<n;t++) 
    	{
    		int a;
    		cin>>a;
    		if(mp[a] == 0)
    			ns.push_back(a);
    		mp[a] ++;
    	}
    	int ma=0;
    	sort(ns.begin(),ns.end());
    	for(t=0;t<ns.size();t++)
    	{
    		ma = max(ma,mp[ns[t]]);
    		if(t != 0)
    		{
    			if(ns[t-1]+2==ns[t] || ns[t-1]+1==ns[t])
    				ma = max(ma,mp[ns[t-1]]+mp[ns[t]]);
    		}
    		if(t != ns.size()-1)
    		{
    			if(ns[t+1]-2==ns[t] || ns[t+1]-1==ns[t])
    				ma = max(ma,mp[ns[t+1]]+mp[ns[t]]);
    		}
    		if(t!=0 && t!=ns.size()-1)
    		{
    			if(ns[t-1]+1==ns[t] && ns[t+1]-1==ns[t])
    				ma = max(ma,mp[ns[t-1]]+mp[ns[t]]+mp[ns[t+1]]);
    		}
    	}
    	cout<<ma<<endl;
	return 0;
}

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

int menor(const void * x, const void * y){
	int a = *((int *) x), b = *((int *) y);
 
	if (a<b)
		return -1;
	if (a>b)
		return 1;
 
	return 0;
 
}

int main() {
   int n;
   scanf("%d", &n);
   int line[101];
   
   for (int i =0;i < n; ++i)
       scanf("%d", &line[i]);
   
   qsort(line, n, sizeof(line[0]), menor);
   
   int menor = 1000000;
   //printf("%d\n", line[0]);
   //printf("%d\n", line[n-1]);

   for(int p = line[0] ; p < line[n-1] +1 ;++p){
       int soma = 0;
       for (int i = 0; i < n; ++i){
           soma += (line[i] - p)*(line[i] - p);
       }
       if (soma < menor)
        menor = soma;
   }
   printf("%d\n", menor);


    return 0;
}


Measured memory_bytes: 128