akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

using System.Collections;

class Program
{
    static void Main()
    {
        int N = int.Parse(Console.ReadLine());

        var txyList = Enumerable.Range(0, N).Select(n => Console.ReadLine())
            .Select(s => s.Split(' '))
            .Select(arr => arr.Select(s => int.Parse(s)).ToArray())
            .Select(arr => new { t = arr[0], x = arr[1], y = arr[2] })
            .ToList();

        txyList.Insert(0, new { t = 0, x = 0, y = 0 });

        bool isOK = true;

        foreach(var itm in txyList.Zip(txyList.Skip(1), (elm1, elm2) => new { elm1, elm2 } ))
        {
            var current = itm.elm1;
            var next = itm.elm2;

            var time = next.t - current.t;
            var distance = Math.Abs(current.x - next.x) + Math.Abs(current.y - next.y);

            if(time < distance || (time - distance) % 2 != 0)
            {
                isOK = false;
                break;
            }
        }

        Console.WriteLine(isOK ? "Yes" : "No");
    }

    static long calcGCD(long num1, long num2)
    {
        if(num1 < num2)
        {
            var tmp = num1;
            num1 = num2;
            num2 = tmp;
        }

        while(true)
        {
            long res;
            long div = Math.DivRem(num1, num2, out res);

            if (res == 0)
            {
                return num2;
            }
            else
            {
                num1 = num2;
                num2 = res;
            }
        }
    }
}


static class MathUtil
{
    public static T Max<T>(params T[] datas)
    {
        return datas.Max();
    }

    public static T Min<T>(params T[] datas)
    {
        return datas.Min();
    }

    public static IEnumerable<IEnumerable<int>> GetPermutation(int n)
    {
        if (n == 0)
        {
            yield return Single(0);
            yield break;
        }

        for (int i = 0; i <= n; i++)
        {
            foreach (var x in GetPermutation(n - 1))
            {
                yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1));
            }
        }
    }

    private static IEnumerable<int> Single(int x)
    {
        yield return x;
    }

    public static IEnumerable<int> EnumeratePrimeNumbers()
    {
        List<int> primes = new List<int>() { 2 };
        yield return 2;

        for (int i = 3; i < int.MaxValue; i++)
        {
            bool isPrime = true;
            int Sqrt = (int)Math.Sqrt(i) + 1;

            foreach (var prime in primes)
            {
                if (prime > Sqrt)
                {
                    break;
                }
                if (i % prime == 0)
                {
                    isPrime = false;
                    break;
                }
            }

            if (isPrime)
            {
                primes.Add(i);
                yield return i;
            }
        }
    }
}




Measured memory_bytes: 20400
import sys
import collections
import math

n = int(input())
A = [int(x) for x in input().split()]

R = [0] * n

idx = 0
for i in range(n-1, -1, -2):
    R[idx] = A[i]
    idx += 1

for i in range(n % 2, n, +2):
    R[idx] = A[i]
    idx += 1

print(" ".join([str(i) for i in R]))

sys.exit(0)


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

bool ifodd(int i,string S){
  char x = 'a' + i;
  int count=0,N=S.size();
  for(int j=0;j<N;j++){
    if(S[j]==x){
      count ++;
    }
  }
  if(count%2==0){
    return true;
  }else{
    return false;
  }
}

int main(){
  string S;
  cin >> S;
  for(int i=0;i<26;i++){
    if(!ifodd(i,S)){
      cout <<"No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

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

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl



signed main() {

	int A, B;
	cin >> A >> B;


	if (A >= 13) cout << B << endl;
	else if (A >= 6) cout << B / 2 << endl;
	else cout << 0 << endl;




	return 0;
}


Measured memory_bytes: 256
/*
ID: simpgoo1
TASK: 
LANG: C++14            
*/
// timus 219263UI
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <ctime>
#include <queue>
#include <vector>
#include <cstdlib>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long ll;
#define y1 needtrainharder
#define F first
#define S second
#define gg exit(0)
#define sz() size()
#define sz() size()
#define sz() size()
#define sz() size()
#define sz() size()
#define sz() size()
#define sz() size()
#define sz() size()
#define sz() size()
#define sz() size()
#define sz() size()
#define sz() size()
#define sz() size()
#define sz() size()
#define sz() size()

#define pb push_back
#define mp make_pair
#define skip continue
#define all(x) x.begin(), x.end()
#define boost ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL)
#define file(s,x) if(x == 1)freopen(s".in","r",stdin),freopen(s".out","w",stdout);
#define task "sorting"
const int INF = 1e9 + 100;  
const ll INFLL = 1e18 + 100;  
const int MAXN = 3e5 + 100; 

ll n, m;

int main(){ 
  boost; 
  srand(time(NULL));
  if(fopen(task".in", "r")){  
    freopen(task".in", "r", stdin);
    freopen(task".out","w",stdout); 
  }
  
  cin >> n >> m;

  ll ans = 0;

  while(n <= m){
    ++ans;
    n<<=1;
  }

  cout<<ans;


  return 0;
}


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

int main(){
  string a,b,c;
  cin>>a>>b>>c;
  transform (a.begin (), a.end (), a.begin (), ::toupper);
  transform (b.begin (), b.end (), b.begin (), ::toupper);
  transform (c.begin (), c.end (), c.begin (), ::toupper);
  cout<<a.at(0)<<b.at(0)<<c.at(0)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
//#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long l, r, m,s,h;
	cin >> l >> r;
	if (l % 2019 == 0 || r % 2019 == 0) {
		cout << 0;
		return 0;
	}
	//if (l - l % 2019 + l >= l && l - l % 2019 + l <= r && r >= 2019) cout << 0;
	if (r - l <= 2040)
       {
		long long mm = 100000000;
		for (long long i = l; i <= r; ++i)
			for (long long j = i + 1; j <= r; ++j) {
				if (i*j % 2019 < mm) mm = i * j % 2019;
			}
		cout << mm;
	}
	else cout << 0;
	return 0;
}

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

int main () {
  string s;
  cin >>s;
  bool h =false;
  if(s =="hi")h =true;
  if(s =="hihi") h =true;
  if(s =="hihihi") h =true;
  if(s =="hihihihi") h =true;
  if(s =="hihihihihi")h =true;
  
  if(h==true){
    cout <<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
return 0;
}






Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String S = sc.next();
		int result = 0;
		int one =  0;

		for(int i = 0 ; i < S.length() ; i++){
			result = S.indexOf("1", i);
			if(result != -1){
				one +=1;
				i = result;
			}
		}

		int zero = S.length() - one;
		if(one >= zero){
			System.out.println(2 * zero);
		}else{
			System.out.println(2 * one);
		}

	}

}


Measured memory_bytes: 24404
#include<bits/stdc++.h>
using namespace std;
const int maxn=200010;
int n,f[maxn];
char s[maxn];
int main()
{
	cin>>n;
	scanf("%s",s+1);
	for (int i=1;i<=n;i++)
	{
		if (s[i]=='#')
		{
			f[i]=f[i-1]+1;
		}
		else
		{
			f[i]=f[i-1];
		}
	}
	int ans=1e9;
	for (int i=0;i<=n;i++)
	{
		ans=min(ans,f[i]+(n-i-(f[n]-f[i])));
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1280
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count = 0
i = 0
while i <= a:
    j = 0
    while j <= b:
        k = 0
        while k <= c:
            if 500 * i + 100 * j + 50 * k == x:
                count += 1
            k += 1
        j += 1
    i += 1
print(count)


Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

const int N = 1 << 15;

int main() {
  vector<int> primes;
  vector<bool> is_prime(N + 1, true);
  is_prime[0] = is_prime[1] = false;
  for (int p = 2; p <= N; ++p) {
    if (is_prime[p]) {
      for (int k = 2; k * p <= N; ++k) {
        is_prime[k * p] = false;
      }
    }
  }
  for (int i = 0; i <= N; ++i) {
    if (is_prime[i]) {
      primes.push_back(i);
    }
  }
  while (true) {
    int count = 0;
    int n;
    cin >> n;
    if (n == 0) {
      return 0;
    }
    for (int i = 0; primes[i] <= n / 2; ++i) {
      if (is_prime[n - primes[i]]) {
        ++count;
      }
    }
    cout << count << endl;
  }
}

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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;

const ll mod = (ll)1e9 + 7;
const ll mxN = 200200;




int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;

	string s;
	cin>>s;
	ll ans= 1e18;
	for(int i=0;i+2<s.length();i++)
		ans=min(ans,(ll)abs(stoi(s.substr(i,3LL))-753));
	cout<<ans;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
const ll P = 1e9+7;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  ll n;
  cin>>n;
  vector<bool> prime(n+1,true);
  repeat(i,2,n+1) {
    if(prime[i]) {
      repeat(j,2,n+1) {
        if(j*i>n) break;
        prime[j*i]=false;
      }
    }
  }
  vector<ll> ps;
  repeat(i,2,n+1){
    if(prime[i]) ps.push_back(i);
  }
  vector<ll> cnt(n+1);
  repeat(i,2,n+1) {
    ll x = i;
    for(auto& p : ps) {
      while(x%p==0) {
        cnt[p]++;
        x/=p;
      }
    }
  }
  ll a = 1;
  rep(i,n+1) {
    a*=(cnt[i]+1);
    a%=P;
  }
  cout << a << endl;
  return 0;
}


Measured memory_bytes: 764
s=input()
f=s[:(len(s)-1)//2]
l=s[(len(s)+3)//2-1:]
flag="Yes"
for i in range(len(s)//2):
    if s[i]==s[-i-1]:
        pass
    else:
        flag="No"
        break
if flag=="Yes":
    for j in range(len(f)//2):
        if f[j]==f[-j-1]:
            pass
        else:
            flag="No"
            break
if flag=="Yes":
    for x in range(len(l)//2):
        if l[x]==l[-x-1]:
            pass
        else:
            flag="No"
            break
print(flag)

Measured memory_bytes: 3064
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;

/*----------macros----------*/

//input, output================
#define fastio                          \
std::ios::sync_with_stdio(false);       \
std::cin.tie(nullptr);                  \
std::cout.tie(nullptr)

#define endl '\n'
#define fcout(a)                        \
cout << fixed << setprecision((int)(a))

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef vector<int>     Vi;
typedef vector<ll>      Vl;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF    = (ll)1e9 + 1;
constexpr ll INFll  = (ll)1e18 + 1;
constexpr ll MOD1   = 1000000007;
constexpr ll MOD2   = 998244353;
constexpr ld PI     = 3.141592653589793L;

//member================
#define psb push_back
#define epb emplace_back
#define psf push_front
#define mkp make_pair
#define fst first
#define snd second

//others================
#define sz(x)                           \
(int) x.size()

#define all(x)                          \
(x).begin(), (x).end()

#define rall(x)                         \
(x).rbegin(), (x).rend()

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

#define reps(i, n)                      \
for(int i = 1; (i) <= (n); ++(i))

#define rrep(i, n)                      \
for(int i = n - 1; (i) >= 0 ; --(i))

#define repbit(bit, n)                  \
for(int bit = 0; (bit) < (1 << (n)); ++(bit))

#define ifbit(bit, i)                   \
if((bit) & (1 << (i)))

#define CtoI(c)                         \
int((c)) - int('0')

#define ItoC(c)                         \
char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b)
{ return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b)
{ return a > b && (a = b, true); }

// Vi  dx = {1, 0, -1, 0},
//     dy = {0, 1, 0, -1};

// Vi  dx2 = { 1,1,0,-1,-1,-1,0,1 },
//     dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/



/*----------main------------*/

int main() {
fastio;

    int a, b; cin >> a >> b;
    if(a%2 != 0 && b%2 != 0){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;

return 0;
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int n;
  cin>>n;
  int ans = 0;
  int bef;
  cin>>bef;
  REP(i,n){
    int x;
    cin>>x;
    ans = __gcd(ans, abs(bef-x));
    bef = x;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define debug(a) cout<<a<<endl
#define pii pair<int,int>
#define maxn 500009
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    double n,k;
    cout<<fixed<<setprecision(12);
    cin>>n>>k;
    double ans=0;
    for(int i=1;i<=n;i++){
        if(i<k)ans+=1.0/(n*(pow(2,ceil(log10(k/i)/log10(2)))));
        else ans+=1.0/n;
    } 
    cout<<ans<<endl;
    return 0;
}
///usar double sempre ou long double
///pensar em casos que coisas dao negativas
///N esquecer de limpar as coisas em quest de varios testes
///OLHAR A COMPLEXIDADE PRA VER SE N PASSA POR BRUTE FORCE OU BRUTE FORCE COM ALGUMAS OTIMIZACOES

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;

ll mod = 1e9 + 7;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll inf = 1ll << 60;
int jmax = 100100;

vector<vector<ll>> dp(2010, vector<ll>(2010));
void combi() {
    dp.at(0).at(0) = 1ll;
    rp(i, 1, 2010) {
        dp.at(i).at(0) = 1ll;
        dp.at(i).at(i) = 1ll;
        rp(j, 1, i) {
            dp.at(i).at(j) = dp.at(i-1).at(j) + dp.at(i-1).at(j-1); 
            dp.at(i).at(j) %= mod;
        }
    }
}

int main() {
    ll n, k;
    scanf("%lld%lld", &n, &k);
    ll res;
    combi();
    rp(i, 1, k+1) {
        res = dp.at(n-k+1).at(i);
        res *= dp.at(k-1).at(i-1);
        res %= mod;
        printf("%lld\n", res);
    }
    return 0;
}

Measured memory_bytes: 32000
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a, b)*b;}
const int IINF=(1<<30);
const ll LLINF = 1LL<<60;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  string s;
  cin >> s;
  for (int i = 0; i < s.length() - 1; i++){
    if(s[i] - s[i+1] != 0){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> vi;
#define endl '\n'
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define rf(i,a,b) for(int i=a;i>=b;i--) 
#define fast_io ios_base::sync_with_stdio(0);
#define show(x) cout<<x<<endl;
#define pret(x) cout<<x<<endl; return 0;
#define disp(x) cout<<x<<" ";
#define let(x,y) cout<<x<<" "<<y<<endl;
ll MOD=1e9+7;
const int maxn=2e5+5;

int32_t main(){
    fast_io;
    int n;
    cin>>n;
    n = n%10;
    if(n==2 or n==4 or n==5 or n==7 or n==9){
        show("hon");
    }
    else if(n==3){
        show("bon");
    }
    else{
        show("pon");
    }
    return 0;
}

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

typedef long long ll;
#define PI 3.1415926535897932384626433
#define mod 1000000007

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

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

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(b, n * a) << endl;
    return 0;
}


Measured memory_bytes: 256
N = gets.to_i
A = gets.split.map{|i|i.to_i}
index = A.index{|i|i != 0}
psum = 0
nsum = 0
pcnt = 0
ncnt = 0
case A[0] <=> 0
when 1
	psum = A[0]
	pcnt = 0
	nsum = -1
	ncnt = A[0] + 1
when -1
	psum = 1
	pcnt = -A[0] + 1
	nsum = A[0]
	ncnt = 0
else
	psum = 1
	pcnt = 1
	nsum = -1
	ncnt = 1
end
(1 .. N - 1).each{|i|
	if i.odd?
		pd = [A[i], -psum - 1].min
		psum += pd
		pcnt += (A[i] - pd).abs
		nd = [A[i], -nsum + 1].max
		nsum += nd
		ncnt += (A[i] - nd).abs
	else
		pd = [A[i], -psum + 1].max
		psum += pd
		pcnt += (A[i] - pd).abs
		nd = [A[i], -nsum - 1].min
		nsum += nd
		ncnt += (A[i] - nd).abs
	end
}
puts [pcnt, ncnt].min


Measured memory_bytes: 11156
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define vsort(v) sort(all(v))
#define mod 1000000007
using data=pair<ll,ll>;

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

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;
}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

void printmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  For(i,0,H+2){
    For(j,0,W+2){cout<<a[i*(W+2)+j];}
    cout<<endl;
  }
}
void inputmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  string ss;
  For(i,1,H+1){
    cin>>ss;
    For(j,1,W+1){
      if(ss[j-1]=='#'){
        a[i*(W+2)+j]=1;
      }else{
        a[i*(W+2)+j]=0;
      }
    }
  }
}


int main(){
  ll i,j,k,N,M,K,p;
  string ss;
  cin>>ss;
  N=ss.size();
  if(N==1){
    if(ss[i]=='5'||ss[i]=='?'){cout<<1<<endl;}
    else{cout<<0<<endl;}
    return 0;
  }
  vector<ll> v(N);
  mat ans(N,vec(13,0));
  rep(i,N){
    v[i]=ss[i]-'0';
  }
  //bf set
  if(v[0]<10){
    ans[0][v[0]]++;
  }else{
    rep(i,10){
      ans[0][i]++;
    }
  }
  //start
  rep1(i,N){
    if(v[i]==('?'-'0')){
      rep(j,13){
        rep(k,10){
          if(ans[i-1][j]==0)continue;
          p=(j*10+k)%13;
          ans[i][p]=(ans[i][p]+ans[i-1][j])%mod;
        }
      }
    }else{
      rep(j,13){
        p=(j*10+v[i])%13;
        ans[i][p]=(ans[i][p]+ans[i-1][j])%mod;
      }
    }
  }
  cout<<ans[N-1][5]<<endl;
  return 0;
}

Measured memory_bytes: 14464
#include <bits/stdc++.h>
#define ll long long 
#define mod 1000000007
using namespace std;
inline int read()
{int x=0,f=0;
char c=getchar();
while (c<'0'||c>'9') 
{if (c=='-') f=1;
c=getchar();
}
while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
if (f) x=-x;
return x;
}
int a[100005],b[100005],n,m,st,ed;
ll da[100005],db[100005];
priority_queue <pair<ll,int> > q;
int head[100005],nxt[400005],u[400005],v[400005],w[400005],o[400005],tot=0;
inline void add(int a,int b,int c)
{tot++;nxt[tot]=head[a];head[a]=tot;v[tot]=b;u[tot]=a;w[tot]=c;}
inline void work1()
{memset (da,0x2f,sizeof(da));
da[st]=0;a[st]=1;
q.push(make_pair(0,st));
while (!q.empty())
{int t=(q.top()).second;
ll d=-(q.top()).first;
q.pop();
if (da[t]!=d) continue;
for (int i=head[t];i;i=nxt[i])
{if (da[v[i]]>da[t]+w[i])
{da[v[i]]=da[t]+w[i];a[v[i]]=a[t];
q.push(make_pair(-da[v[i]],v[i]));
}
else
{if (da[v[i]]==da[t]+w[i]) 
{a[v[i]]+=a[t];
if (a[v[i]]>=mod) a[v[i]]-=mod;
}
}
}
}
}
inline void work2()
{memset (db,0x2f,sizeof(db));
db[ed]=0;b[ed]=1;
q.push(make_pair(0,ed));
while (!q.empty())
{int t=(q.top()).second;
ll d=-(q.top()).first;
q.pop();
if (db[t]!=d) continue;
for (int i=head[t];i;i=nxt[i])
{if (db[v[i]]>db[t]+w[i])
{db[v[i]]=db[t]+w[i];b[v[i]]=b[t];
q.push(make_pair(-db[v[i]],v[i]));
}
else
{if (db[v[i]]==db[t]+w[i]) 
{b[v[i]]+=b[t];
if (b[v[i]]>=mod) b[v[i]]-=mod;
}
}
}
}
}
int main (){
	int i,j,k,ta,tb,tc;
	n=read();m=read();
	st=read();ed=read();
	for (i=1;i<=m;i++)
	{ta=read();tb=read();tc=read();
	add(ta,tb,tc);add(tb,ta,tc);
	}
	work1();work2();
	int num=a[ed],ans=1ll*num*num%mod;
	for (i=1;i<=n;i++)
	{if (da[i]+db[i]==da[ed]&&da[i]==db[i])
	{int ways=1ll*a[i]*b[i]%mod;
	ans-=1ll*ways*ways%mod;
	if (ans<0) ans+=mod;
	}
	}
	for (i=1;i<=tot;i++)
	{if (da[u[i]]+w[i]+db[v[i]]==da[ed])
	{if (da[u[i]]*2ll<da[ed]&&db[v[i]]*2ll<da[ed])
	{int ways=1ll*a[u[i]]*b[v[i]]%mod;
	ans-=1ll*ways*ways%mod;
	if (ans<0) ans+=mod;
	}
	}
	}
	printf ("%d\n",ans);
	return 0;
}
	
	
	

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

int main() {
    int N, cnt=0;
    cin >> N;
    string A, B, C;
    cin >> A;
    cin >> B;
    cin >> C;

    for(int i=0; i<N; i++){
        if(A.at(i)!=B.at(i) && A.at(i)!=C.at(i) && B.at(i)!=C.at(i)) cnt+=2;
        else if(A.at(i)==B.at(i) && A.at(i)==C.at(i)) cnt+=0;
        else if(A.at(i)==B.at(i) || A.at(i)==C.at(i) || B.at(i)==C.at(i)) cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <cmath>
#include <random>
#include <cctype>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define MK make_pair
#define PB push_back
#define VI vector<int>
#define VII vector<int,int>
#define MSI map<string,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define W1 while(1);
const int MOD = 1000000007;
int main()
{
	string S;
	string abc;
	abc = "abcdefghijklmnopqrstuvwxyz";
	VI count;
	cin >> S;
	REP(i, S.size())
	{
		count.resize(26);
		REP(j, 26)
		{
			if (abc.at(j) == S.at(i))count.at(j)++;
		}
	}
	REP(i,26)
	{
		if (count.at(i) % 2 != 0)
		{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""



"""
import sys


def solve(N, M, A):
    MOD = 10**9 + 7
    A = set(A)
    if N == 1:
        return 1 if 1 not in A else 0
        
    dp = [0] * (N+1)
    dp[0] = 1
    dp[1] = 1 if 1 not in A else 0
    for i in range(2, N+1):
        if i in A:
            dp[i] = 0
        else:
            dp[i] = (dp[i-2] + dp[i-1]) % MOD
    return dp[-1]


def main(args):
    N, M = map(int, input().split())
    A = [int(input()) for _ in range(M)]
    ans = solve(N, M, A)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 13184
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  int ans = 0;
  int now = 0;
  int H[N];
  FOR(i,0,N) cin >> H[i];
  FOR(i,0,N-1) {
    if (H[i+1] <= H[i]) now++;
    else {
      ans = max(ans, now);
      now = 0;
    }
  }
  ans = max(ans, now);
  cout << ans << endl;
}


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

string s;

int main(){
	cin >> s;
	bool def = false;
	for(int i = 0; i < s.length() - 1; i++){
		if(s[i] == s[i + 1]){
			def = true;
			cout << i + 1 << " " << i + 2 << endl;
			break;
		}
		else if(s[i] == s[i + 2]){
			def = true;
			cout << i + 1 << " " << i + 3 << endl;
			break;
		}
	}
	if(def == false) cout << "-1 -1" << endl;
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<deque>
using namespace std;
int N;
long A[1<<17];
main()
{
	cin>>N;
	for(int i=0;i<N;i++)cin>>A[i];
	sort(A,A+N);
	int L=0,R=N-1;
	deque<long>P;
	long ans=0,sum=0;
	int witch=0;
	while(R>=L)
	{
		if(witch)
		{
			if(!P.empty())sum+=abs(P.back()-A[L]);
			P.push_back(A[L++]);
		}
		else
		{
			if(!P.empty())sum+=abs(P.back()-A[R]);
			P.push_back(A[R--]);
		}
		witch=!witch;
	}
	ans=sum;
	for(int i=0;i<N;i++)
	{
		sum-=abs(P[N-2]-P[N-1]);
		sum+=abs(P[0]-P[N-1]);
		long now=P.back();
		P.pop_back();
		P.push_front(now);
		ans=max(ans,sum);
	}
	reverse(A,A+N);
	L=0,R=N-1;
	P.clear();
	sum=0;
	witch=0;
	while(R>=L)
	{
		if(witch)
		{
			if(!P.empty())sum+=abs(P.back()-A[L]);
			P.push_back(A[L++]);
		}
		else
		{
			if(!P.empty())sum+=abs(P.back()-A[R]);
			P.push_back(A[R--]);
		}
		witch=!witch;
	}
	ans=max(ans,sum);
	for(int i=0;i<N;i++)
	{
		sum-=abs(P[N-2]-P[N-1]);
		sum+=abs(P[0]-P[N-1]);
		long now=P.back();
		P.pop_back();
		P.push_front(now);
		ans=max(ans,sum);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef vector<int> vi;

#define PB push_back
#define rep(i,x) for(int i=0;i<(x);++i)
#define all(a) a.begin(),a.end()

template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

int main()
{
	int D, N, M;
	vi d;
	while (cin >> D, D) {
		cin >> N >> M;
		d.clear(); d.PB(0); d.PB(D);

		rep(i, N - 1) d.PB(get<int>());

		sort(d);

		int sum = 0;

		rep(i, M) {
			int k; cin >> k;
			int pos1 = lower_bound(all(d), k) - d.begin() - 1;
			int pos2 = lower_bound(all(d), k) - d.begin();
			if (pos1 == -1) pos1 = 0;
			sum += min(abs(k - d[pos1]), abs(k - d[pos2]));
		}

		cout << sum << endl;
	}
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main(void){
    string s;
    cin >> s;
    int flag = 1;
    if(s[0] != 'A') flag = 0;

    int cnt_C = 0;
    for(int i=2; i<=s.length()-2; i++){
        if(s[i] == 'C') cnt_C++;
        else if(isupper(s[i])) flag = 0;
    }
    if(cnt_C != 1) flag = 0;

    if(isupper(s[1])) flag = 0;
    if(isupper(s[s.length()-1])) flag = 0;

    if(flag) cout << "AC" << endl;
    else cout << "WA" << endl;
    return 0;
}

Measured memory_bytes: 3568
N, H = map(int, input().split())

A = []
B = []

for _ in range(N):
  a, b = map(int, input().split())
  A.append(a)
  B.append(b)
  

def solve():
  count = 0
  remain = H
  
  B.sort()
  
  max_a = max(A)
  
  while B:
    if remain <= 0:
      return count
    
    b = B.pop()
    
    if b < max_a:
      break
      
    remain -= b
    count += 1
  
  count += (remain + max_a - 1) // max_a
    
  return count

print(solve())

Measured memory_bytes: 62040
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define INF 0x3f3f3f3f
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
const ll mod=1000000007;
const double PI = atan(1) * 4;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const int N = 1e6+10;

int main() {
	string s;
	int k;
	cin>>k;
	cin>>s;
	int len = s.length();
	rep(i, 0, min(k, len)) cout<<s[i];
	if(len > k)
	cout<<"...";
	return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>

int main(void)   
{
    char S[500000];
    long long int i,top,bottom,count=0,range1=0,range2=0;
    
    scanf("%s",S);
    
    //何連続で<もしくわ>が来てるか数えて、連続数分だけ初項0公差1の等差数列
    
    top=0;
    bottom=0;
    i = 1;
    while(S[i]!='\0'){
        if(S[i-1]=='<' && S[i]=='>'){
            top = i;
            range1 = top - bottom;
            //count += ;
        } else if(S[i-1]=='>' && S[i]=='<'){
            bottom = i;
            range2 = bottom - top;
            //printf("range2 = %d, range1 = %d\n",range2,range1);
            if(range2 > range1){
                count+=range2*(range2+1)/2;
                count+=range1*(range1-1)/2;
            } else {  
                count+=range1*(range1+1)/2;
                count+=range2*(range2-1)/2;
            }
        }
        i++;
    }
    if(S[i-1] == '<'){
        range1 = i - bottom;
        count+=range1*(range1+1)/2;
        //printf("range1 =%d\n",range1);
    } else {
        bottom = i;
        range2 = bottom - top;
        //printf("range2 = %d, range1 = %d\n",range2,range1);
        if(range2 > range1){
            count+=range2*(range2+1)/2;
            count+=range1*(range1-1)/2;
        } else {  
            count+=range1*(range1+1)/2;
            count+=range2*(range2-1)/2;
        }
    }
    
    //printf("S=%s, i= %d\n",S,i);

    printf("%lld\n",count);
    
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+10;
typedef long long LL;
LL a[N],s[N];


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int tests=1;
	//cin>>tests;
	while(tests--)
	{
		int n;
		scanf("%d",&n);

		LL sum=0;
		for(int i=1;i<=n;i++)
		{
			scanf("%lld",&a[i]);
			s[i]=(s[i-1]+a[i]);
		}
		for(int i=1;i<=n;i++)
		{
			LL x=(a[i]*((s[n]-s[i])%1000000007))%1000000007;
			sum=(sum+x)%1000000007;
		}
		printf("%lld",sum);
	}
	return 0;
}



Measured memory_bytes: 6908
a,b,c,d=map(int,input().split())
X=c-a
Y=d-b
ans1='R'*X+'U'*Y
ans2='L'*X+'D'*Y
ans3='D'+'R'*(X+1)+'U'*(Y+1)+'L'
ans4='U'+'L'*(X+1)+'D'*(Y+1)+'R'
print(ans1+ans2+ans3+ans4)

Measured memory_bytes: 9052
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]
#print(ans[j], end = "") 改行無しで出力
#[0]*n
n, m = map(int, input().split())

g = n*(n-1)/2
k = m*(m-1)/2

print(int(g+k))


Measured memory_bytes: 2940
#include<iostream>
#include<cmath>
#include<vector>
#include<map>
#include<string>
#include<algorithm>
#include<regex>
using namespace std;
int main(){
  string S;
  cin >> S;
  bool yymm = regex_match(S, regex("\\d\\d(0[1-9]|1[0-2])"));
  bool mmyy = regex_match(S, regex("(0[1-9]|1[0-2])\\d\\d"));
  if(yymm){
    if(mmyy) cout << "AMBIGUOUS" << endl;
    else cout << "YYMM" << endl;
  }else{
    if(mmyy) cout << "MMYY" << endl;
    else cout << "NA" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
let () =
  let n = read_int () in
  let s = read_line () in
  let ar = Array.make n 0 in
  String.iteri (fun i c ->
              if c = 'I' then ar.(i) <- 1 else ar.(i) <- (-1)) s;
  Array.fold_left (fun (x, y) z -> let w = y + z in (max x w, w)) (0, 0) ar |> fst |> string_of_int |> print_endline


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int n,a,b;
    cin>>n>>a>>b;
    if (a>b) {
        cout<<0<<endl;
    } else {
        if (n>1) {
            long long int min=a+b+a*(n-2);
            long long int max=a+b+b*(n-2);
            cout<<max-min+1<<endl;
        } else {
            if (a==b) {
                cout<<1<<endl;
            } else {
                cout<<0<<endl;
            }
        }
    }
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const ll MOD = 1e9+7;
const double EPS = 1e-9;


int main(int argc, const char * argv[]) {
  ll N; cin >> N;
  cout << N*(N-1)/2 << endl;
  return 0;
}

Measured memory_bytes: 256
N=int(input())
T,A=map(int,input().split())
H=list(map(int,input().split()))
ls=[]
for i in range(N):
  x=T-float(H[i])*0.006
  y=abs(x-(A))
  ls.append(y)
z=min(ls)
Z=ls.index(z)+1
print(Z)

Measured memory_bytes: 3060
using System;
class Program
{
	static void Main(string[] args)
	{
		// 整数の入力
		int a = int.Parse(Console.ReadLine());
		// スペース区切りの整数の入力
		//string[] input = Console.ReadLine().Split(' ');
		//int b = int.Parse(input[0]);
		//int c = int.Parse(input[1]);
		// 文字列の入力
		//string s = Console.ReadLine();
		//出力
		//Console.WriteLine((a+b+c) + " " + s);
		if(a%2 == 0)
		 a = a/2;
		else
		 a = (a+1)/2;

		Console.WriteLine(a);
	}
}


Measured memory_bytes: 13140
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
using namespace std;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	
	for(int X=1; X<=50000; X++){
		double w = X * 1.08;
		int n = (int)w;
		if(n == N){
			printf("%d\n", X);
			return 0;
		}
	}
	printf(":(\n");
	return 0;
}



Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
const int N = 200001;
using namespace std;


string f(string a, string b) {
    int dp[8][10];
    memset(dp, 0, sizeof dp);
    for (int i = a.size() - 1; i >= 0; i--) {
        if (b[i] == '?') {

            for (int j = a[i] - '0' + 1; j < 10; j++) {
                dp[i][j] = 1;
            }
        }
    }
}



int main() {
//    cout << fixed << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    int n;
    cin >> n;
    set<string> s;
    while (n--) {
        string ss;
        cin >> ss;
        s.insert(ss);
    }
    
    cout << s.size();


}

Measured memory_bytes: 19212
import sys
input=lambda: sys.stdin.readline().rstrip()

N = int(input())

S_p = []
S_n = []

for i in range(N):
  end = 0
  mim = 0
  for c in input():
    if c == "(":
      end += 1
    else :
      end -= 1
    mim = min(mim,end)
  
  if end >= 0:
    S_p.append([mim, end])
  else:
    S_n.append([end-mim, end])
  
S_p.sort(reverse=True)
S_n.sort(reverse=True)
#print(S_p)
#print(S_n)

check = 0
flag = True
for i in range(len(S_p)):
  if check + S_p[i][0] >= 0:
    check += S_p[i][1]
  else:
    flag = False
    break
  #print(check)
  
for i in range(len(S_n)):
  if check + S_n[i][1] - S_n[i][0] >= 0:
    check += S_n[i][1]
  else:
    flag = False
    break
  #print(check)
  
if check == 0 and flag:
  flag = True
else:
  flag = False

print("Yes" if flag else "No")

Measured memory_bytes: 223244
#include<stdio.h>

int main(){
    int x, y, min, max, rem;

    scanf("%d %d", &x, &y);

    if(x == y){
        printf("%d\n", x);
        return 0;
    }

    if(x < y){
        min = x;
        max = y;
    }else{
        min = y;
        max = x;
    }

    while(min > 0){
        rem = max%min;
        max = min;
        min = rem;
    }

    printf("%d\n", max);

    return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
map<string , int > mp;
int main()
{
int n;
string s;
cin>>n>>s;
int counter=0;
for(int i=0;i<s.size();i++){
    if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
         counter++;
         i+=2;
    }

}
cout<<counter;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1ll;while(b){if(b&1)ans=ans*a%MOD;a=a*a%MOD;b>>=1;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
char s[maxn];
int n;
std::vector<int> v[1230];
int tree[maxn];
int lowbit(int x)
{
	return x&(-x);
}
int add(int id,int k)
{
	while(id<=n)
	{
		tree[id]+=k;
		id+=lowbit(id);
	}
}
int query(int id)
{
	int res=0;
	while(id>=1)
	{
		res+=tree[id];
		id-=(lowbit(id));
	}
	return res;
}
int vis[maxn];
int num[maxn];
int main()
{
	//    freopen("C:\\Users\\DH_M\\Desktop\\code_io\\in.txt.txt","r",stdin);
	//    freopen("C:\\Users\\DH_M\\Desktop\\code_io\\out.txt.txt","w",stdout);
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1;i<=n;i++)num[s[i]-'a']++,v[s[i]-'a'].push_back(i);
    int ok=0;
    for(int i=0;i<26;i++){
        if(num[i]%2)ok++;
    }
    if(ok>1){printf("-1");return 0;}
	// int n=len;
	repd(i,1,n+1)
	{
		add(i,1);
	}
	ll ans=0;
	repd(i,1,n)
	{
		if(!vis[i])
		{
			int x=v[s[i]-'a'][(sz(v[s[i]-'a'])-1)];
			if(i==x){
         	   ans+=(query(n)-query(i))/2;
	        }
	        else{
	            ans+=(query(n)-query(x));
	        }
			add(i,-1);
			add(x,-1);
			vis[x]=vis[i]=1;
			v[s[i]-'a'].erase(v[s[i]-'a'].end()-1);
		}
	}
	cout<<ans<<endl;
    return 0;
}

inline void getInt(int* p) {char ch;do {ch = getchar();}
while (ch == ' ' || ch == '\n');if (ch == '-') {*p = -(getchar() - '0');
while ((ch = getchar()) >= '0' && ch <= '9') {*p = *p * 10 - ch + '0';}}
else {*p = ch - '0';while ((ch = getchar()) >= '0' && ch <= '9')
{*p = *p * 10 + ch - '0';}}}


Measured memory_bytes: 11512
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    string ss;
    cin>>ss;
    if(ss=="ABC") cout<<"ARC"<<'\n';
    else cout<<"ABC"<<'\n';
    return 0;
}


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

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

    }
    cout << ans << endl;
}


Measured memory_bytes: 5640
#include <iostream>
#include <cmath>
#include <vector>
#define LIM 1000000

using namespace std;

int main(void) {
	int X;
	cin >> X;
	vector<int> p(LIM+1,1);
	p[0] = p[1] = 0;
	for (int i = 2; i < sqrt(LIM)+1; ++i) {
		if (p[i] == 1) {
			for (int j = 2; i*j < LIM+1; ++j) {
				p[i*j] = 0;
			}
		}
	}
	for (int i = X; i < LIM; ++i) {
		if (p[i] == 1) {
			cout << i << endl;
			break;
		}
	}
	return 0;
}


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

int main()
{
    int H, W;
    while (true)
    {
        cin >> H >> W;
        if (H == 0 && W == 0)
        {
            break;
        }
        for (int i = 0; i < H; i++)
        {
            if (i == 0 || i == H - 1)
            {
                for (int j = 0; j < W; j++)
                {
                    cout << '#';
                }
            }
            else
            {
                cout << '#';
                for (int j = 1; j < W - 1; j++)
                {
                    cout << '.';
                }
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
#define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
#define memmin(x) memset((x),-1,sizeof((x)))
#define memzer(x) memset((x), 0,sizeof((x)))
#define meminf(x) memset((x),0x3f,sizeof((x)))
#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}


void solve(){

  int n,m,a[100005],b[100050],c,ans=0;
  string str;
  vpi ed;
  cin >> n >> m ;
  FOR(i,n){
    int x,y;
    cin >> x >> y;
    ed.bash(pii(x,y));
  }
  sort(ALL(ed));
  int tmp=0;
  FOR(i,n){
    if(tmp+ed[i].second<=m){
      ans+=ed[i].first*ed[i].second;
      tmp+=ed[i].second;
    }else{
      ans+=ed[i].first*(m-tmp);
      break;
    }
  }
  cout << ans fin;
}
struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;signed main(){solve();return 0;}


Measured memory_bytes: 2420
import java.util.Scanner;
import java.util.Arrays;

public class Main{
  static int n;
  static int[] a, b;
  static long k;

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

    n = sc.nextInt();
    k = sc.nextLong();
    a = new int[n];
    b = new int[n];
    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
      b[i] = sc.nextInt();
    }

    Pair[] ba = new Pair[n];
    for(int i = 0; i < n; i++){
      ba[i] = new Pair(a[i], b[i]);
    }

    Arrays.sort(ba);

    int ans = -1;
    long sum = 0;
    for(int i = 0; i < n; i++){
      sum += (long)ba[i].c;
      if(sum >= k){
        ans = ba[i].v;
        break;
      }
    }

    System.out.println(ans);
  }

  static class Pair implements Comparable< Pair >{
    int v, c;

    Pair(int v, int c){
      this.v = v;
      this.c = c;
    }

    @Override
      public int compareTo(Pair p){
        if(v == p.v){
          return Integer.compare(c, p.c);
        }
        return Integer.compare(v, p.v);
      }

    @Override
      public boolean equals(Object obj){
        if(!(obj instanceof Pair)){
          return false;
        }
        Pair p = (Pair)obj;
        return v == p.v && c == p.c;
      }
  }
}


Measured memory_bytes: 65180
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define SQ(x) (x)*(x)
#define MN(a,b) a = min(a,(__typeof__(a))(b))
#define MX(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#ifdef BALBIT
#define IOS()
#define bug(...) fprintf(stderr,"#%d (%s) = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define bug(...)
#endif

const int iinf = 1e9+10;
const ll inf = 1ll<<60;
const ll mod = 1e9+7 ;


void GG(){cout<<"0\n"; exit(0);}

ll mpow(ll a, ll n, ll mo = mod){ // a^n % mod
    ll re=1;
    while (n>0){
        if (n&1) re = re*a %mo;
        a = a*a %mo;
        n>>=1;
    }
    return re;
}

ll inv (ll b, ll mo = mod){
    if (b==1) return b;
    return (mo-mo/b) * inv(mo%b,mo) % mo;
}

const int maxn = 1e6+5;



signed main(){
    IOS();
    int n; cin>>n;
    int k; cin>>k;
    vector<int> a(n);
    for (int i = 0; i<n; ++i) cin>>a[i];
    for (int i = 0; i<k; ++i) {
        vector<int> b(n);
        for (int j = 0; j<n; ++j) {
            b[max(0, j-a[j])]++;
            if (j+a[j]+1<n) b[j+a[j]+1]--;
        }
        bool done = 1;
        for (int j = 0; j<n; ++j) {
            if (j) b[j] += b[j-1];
            if (b[j] != n) done = 0;
        }
        a=b;
        if (done) break;
        bug(i);
    }

    for (int i = 0; i<n; ++i) {
        cout<<a[i]<<' ';
    }
}


Measured memory_bytes: 5000
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int S[100005],T[100005],n,ans,sum;
int A[100005],B[100005],sa,sb;
int fa[100005],Do[200005];
int gg(){printf("-1");return 0;}
int ask(int x){if(fa[x]==x)return x;return fa[x]=ask(fa[x]);}
void unite(int x,int y){fa[x]=y;}
int main(){
//  freopen("duliu.in","r",stdin);
//  freopen("duliu.out","w",stdout);
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&A[i]),sa^=A[i];A[n+1]=sa;
    for(int i=1;i<=n;i++)scanf("%d",&B[i]),sb^=B[i];B[n+1]=sb;
    memcpy(S,A,sizeof A);memcpy(T,B,sizeof B);
    n++;sort(S+1,S+1+n);sort(T+1,T+1+n);
    for(int i=1;i<n;i++)if(S[i]!=T[i])return gg();
    for(int i=1;i<=n;i++)
    	if(A[i]!=B[i]||(i==n)){
			Do[++sum]=A[i];
			Do[++sum]=B[i];
			if(i<n)ans++;
		}
	if(ans==0)return printf("0"),0;
	sort(Do+1,Do+1+sum);
	sum=unique(Do+1,Do+sum+1)-Do-1;
	for(int i=1;i<=sum;i++)fa[i]=i;
	for(int i=1;i<=n;i++){
		if(A[i]!=B[i]){
			A[i]=lower_bound(Do+1,Do+1+sum,A[i])-Do;
			B[i]=lower_bound(Do+1,Do+1+sum,B[i])-Do;
			unite(ask(A[i]),ask(B[i]));
		}
	}
	for(int i=1;i<=sum;i++)ans+=(fa[i]==i);
	printf("%d",ans-1);
}
/*
3
1 2 3
1 3 2
*/
/*
4
1 4 2 6
1 2 4 6
*/
/*
10
1 3 3 9 4 5 1 6 4 0
4 1 3 9 10 4 3 1 6 5
*/
/*
5
1 2 4 8 0
2 1 15 8 4
*/
/*
10
1 2 3 4 4 5 6 7 8 12
2 1 4 3 4 0 5 6 7 8
*/
/*
10
1 2 3 4 5 6 7 8 9 10
10 1 2 3 4 5 6 7 8 9
*/
/*
10
1 2 3 4 5 6 7 8 9 10
2 1 4 3 6 5 8 7 10 9
*/
/*
9
1 2 3 4 5 6 7 8 9
9 1 2 3 4 5 6 7 8
*/

Measured memory_bytes: 4480