akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ADAY 86400
using namespace std;
typedef long long ll;

int main(void){
  ll n;
  while(cin >> n, n){
    vector < pair < ll, ll > > t;
    for(ll i=0; i < n; i++){
      pair<ll, ll> tmp;
      int h, m, s;
      scanf("%d:%d:%d", &h, &m, &s);
      tmp.first = (ll)(h * 3600 + m * 60 + s);
      scanf("%d:%d:%d", &h, &m, &s);
      tmp.second = (ll)(h * 3600 + m * 60 + s);
      t.push_back(tmp);
    }

    sort(t.begin(), t.end());

    ll ans = 0, movin = 0, ind = 0;
    vector<ll> q;
    for(ll now=0; now <= ADAY; now++){
      while(!q.empty() && now == q[0]){
        movin--;
        q.erase(q.begin());
      }
      while(ind < n && now == t[ind].first){
        q.push_back(t[ind].second);
        sort(q.begin(), q.end());
        movin++;
        ind++;
        ans = max(ans, movin);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1516
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long llint;

llint n;
llint a[100005];
void solve(){
  cin >> n;
  for(int i=1;i<=n;i++)cin >> a[i];
  llint ans=0;
  for(int i=1;i<=n;i++){
    if(a[a[i]]==i){
      ans++;
    }
  }
  cout << ans/2 << endl;

}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdlib>
#include<complex>
using namespace std;
typedef complex<double> Po;
 
double cross(Po a,Po b)
{
	return a.real()*b.imag() - a.imag()*b.real();
}
 
double area(Po a,Po b, Po c)
{
	return abs(cross(b-a,c-a))/2;
}
 
bool inter(Po a, Po b,Po c,Po x)
{
	return (fabs(area(a,b,x)+area(b,c,x)+area(c,a,x)-area(a,b,c))<1e-10);
}
 
int main()
{
	Po p[4];
	double a, b;
	char c, d;

	while(cin >> a >> c >> b){
		p[0] = Po(a, b);
		for(int i=1; i<4; i++)
		{
			cin >> c >> a >> d >> b;
			p[i] = Po(a, b);
		}
		if(inter(p[0],p[1],p[2],p[3]) || inter(p[0],p[2],p[3],p[1]) || inter(p[0],p[1],p[3],p[2]) || inter(p[1],p[2],p[3],p[0]))
			cout << "NO\n";
		else cout << "YES\n";
	}
}

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

#define N 1000

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

  ll x; cin >> x;
  ll a, b;

  ll *tab = new ll[N];
  for (int i = 0; i < N; i++) {
    tab[i] = pow(i - N / 2, 5);
  }

  for (ll i = 0; i < N; i++) {
    for (ll j = 0; j < N; j++) {
      if (tab[i] - tab[j] == x) {
        a = i - N / 2;
        b = j - N / 2;
        printf("%lld %lld\n", a, b);
        delete[] tab;
        return 0;
      }
    }
  }


  return 0;
}


Measured memory_bytes: 4196
#include <iostream>
#include <vector>
#include <stdlib.h>
using namespace std;
void swap(vector<int> &x,int i,int j){
  int tmp;
  tmp = x[i];
  x[i] = x[j];
  x[j] = tmp;
} 
void qSort(vector<int> &x,vector<int> &p,vector<int> &q,int left,int right){
  //  cout << "aa" << endl;
  int i,j;
  int pivot;
  i = left;
  j = right;
 
  pivot = x[(j+i)/2];
  while(true){
    while(x[i] < pivot)i++;
    while(pivot < x[j])j--;
    if(i >= j)break;
    swap(x,i,j);
    swap(p,i,j);
    swap(q,i,j);
    i++;
    j--;
  }
  if(left < i-1){
    qSort(x,p,q,left,i-1);
  }
  if(j+1 < right+1){
    qSort(x,p,q,j+1,right);
  }
 
  
}
int check(vector<int> h){
  for(int i = 0;i < h.size()-1;i++){
    if(h[i] <= h[i+1]){
      
    }else return 0;
  }
  return 1;
}
int main(){
  vector<int> h;
  vector<int> p;
  vector<int> q;
  int m,n,a;
  int current;// = a;
  int flag;// = -1;
  int ff = 0;
  while(true){
    
    cin >> n >> m >> a;
    if(n == 0 && m == 0 && a == 0){
      return 0;
    }
    
    vector<int> h;
    vector<int> p;
    vector<int> q;
    h = vector<int>(m);
    p = vector<int>(m);
    q = vector<int>(m);
    for(int i = 0;i < m;i++){
      cin >> h[i] >> p[i] >> q[i];
    }
    
    if(h.size() > 1)
	  qSort(h,p,q,0,h.size()-1);
    /* for(int i = 0;i < h.size();i++){
      cout<< h[i] << " " << p[i]<< " " << q[i]<<endl;
    }
    return 0;*/
    /*if(check(h)){
      cout << "yes" << endl;
    }else{
      cout << "no" << endl;
      }*/
    
    current = a;
    flag = -1;
    for(int i = h.size()-1;i >= 0;i--){
      if(flag != h[i]){
	if(q[i] == current){
	  flag = h[i];
	  current = p[i];
	}else if(p[i] == current){
	  flag = h[i];
	  current = q[i];
	}
      }
      }
	
    cout << current << endl;
    /*ff++;
    cout << ff << endl;
    std::vector<int>().swap(h);
    std::vector<int>().swap(q);
    std::vector<int>().swap(p);*/
  }
  
}

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

int main() {

    int n;

    cin >> n;

    bool f[n][10];

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

    int p[n][11];

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

    int ans = -(1<<30);

    for(int i=1; i < 1<<10; i++){

        int tmp = 0;
        for(int j=0; j<n; j++){

            int count = 0;
            for(int k=0; k<10; k++){
                if((i>>k&1)&&f[j][k]){
                    count++;
                }
            }
            tmp += p[j][count];
        }
        ans = max(ans,tmp);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
def main():
    YES="Yes"
    NO="No"

    A = []
    B = [[0]*3 for i in range(3)]
    for _ in range(3):
        l = list(map(int, input().split()))
        A.append(l)
    N = int(input())
    for _ in range(N):
        b = int(input())
        for i in range(3):
            for j in range(3):
                if A[i][j] == b:
                    B[i][j] = 1
    for i in range(3):
        isBingoRow = True
        isBingoCol = True
        for j in range(3):
            isBingoRow = isBingoRow and (B[i][j] == 1)
            isBingoCol = isBingoCol and (B[j][i] == 1)
        if isBingoRow or isBingoCol:
            print(YES)
            return
    if B[0][0]==1 and B[1][1]==1 and B[2][2]==1:
        print(YES)
        return
    if B[0][2]==1 and B[1][1]==1 and B[2][0]==1:
        print(YES)
        return
    print(NO)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
x,y = map(int,input().split())
flag = 0
for i in range(0,x+1):
    #鶴だけ固定
    now = y - 2 * i
    #亀の足の数 = y - 2×鶴の足の数
    if now % 4 == 0:
        #足の数が4で割り切れたら
        if now //4 == (x - i):
            #足の数の商が (x - i)と一致したら
            print("Yes")
            flag += 1
            break
if flag == 0:
    print("No")

Measured memory_bytes: 9116
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())

if a == b:
    print("NO")

As = v * t + a
Bs = w * t + b

if v > w:
    if abs(a - b)/abs(v - w) <= t:
        print("YES")
    else:
        print("NO")
else:
    print("NO")

Measured memory_bytes: 9168
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int r, g;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        r = sc.nextInt();
        g = sc.nextInt();
        solve();
    }

    void solve() {
        System.out.println(2 * g - r);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

using namespace std;
using ll = uint64_t;

int main()
{
    // いくわ！

    ll n, k; cin >> n >> k;

    vector<ll> a(n);
    for (ll& i : a) cin >> i;

    // K = 1001110
    //   ->1000001

    // K の 1 のところを 0 にする、ケースを全部かんがえる
    // K = 1001110
    //     0XXXXXX
    //     Y000XXX
    //     Y000YXX
    //     Y000Y0X
    //     Y000YY0
    // かいてさしあげましょうか？

    ll ret = 0;
    for (int h = 60; h >= 0; h--)
    {
        if (k & (1LL << h)) {
            // c = h 桁目を 1 -> 0 にしたときの一番良い X
            ll c = k;
            // h 桁目を落とす
            c -= (1LL << h);

            for (int l = 60; l >= h+1; l--) {
                if (c & (1LL << l)) {
                    int r = 0; // l 桁目が立ってる数
                    for (int i = 0; i < n; i++) {
                        if (a[i] & (1LL << l)) {
                            r++;
                        }
                    }
                    if (r > n-r) {
                        // l 桁目を 0 にする
                        c &= ~(1LL << l);
                    } else {
                        // l 桁目を 1 にする
                        c |= (1LL << l);
                    }
                }
            }
            for (int l = h-1; l >= 0; l--) {
                // l 桁目をきめりゅ
                int r = 0; // l 桁目が立ってる数
                for (int i = 0; i < n; i++) {
                    if (a[i] & (1LL << l)) {
                        r++;
                    }
                }
                // もし立ってるほうが立ってないのより、多かったら、
                // l 桁目は立ってないほうがいい。
                if (r > n-r) {
                    // l 桁目を 0 にする
                    c &= ~(1LL << l);
                } else {
                    // l 桁目を 1 にする
                    c |= (1LL << l);
                }
            }

            ll cret = 0;
            for (int i = 0; i < n; i++) {
                cret += c ^ a[i];
            }
            ret = max(cret, ret);
        }
    }
    // 全部 Y
    {
        ll c = k;
        for (int l = 60; l >= 0; l--) {
            if (c & (1LL << l)) {
                int r = 0;
                for (int i = 0; i < n; i++) {
                    if (a[i] & (1LL << l)) {
                        r++;
                    }
                }
                if (r > n-r) {
                    // l 桁目を 0 にする
                    c &= ~(1LL << l);
                } else {
                    // l 桁目を 1 にする
                    c |= (1LL << l);
                }
            }
        }

        ll cret = 0;
        for (int i = 0; i < n; i++) {
            cret += c ^ a[i];
        }
        ret = max(cret, ret);
    }
    cout << ret << endl;


    return 0;
    // K = 10
    // X =


    // 二進数で表現するわよ！
    // K  = 100
    // A0 = 000
    // A1 = 000
    // A2 = 100

    // あなたの答えは 100 よね？
    // でもほんとうは 011 のほうがよくてよ？
    // 100 -> 100 + 100 + 0
    // 011 -> 011 + 011 + 111
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
string s;
int a;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> a >> s;
    cout << (a < 3200 ? "red" : s);
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
	int N = Integer.parseInt(scan.next());
	int T = Integer.parseInt(scan.next());
	int[] A = new int[N];
	for (int i = 0; i < N; i++) {
	    A[i] = Integer.parseInt(scan.next());
	}
	
	int[] min = new int[N-1];
	min[0] = A[0];
	for (int i = 1; i < N-1; i++) {
	    min[i] = A[i] < min[i-1] ? A[i] : min[i-1];
	}
	
	int[] max = new int[N-1];
	max[N-2] = A[N-1];
	for (int i = N-3; i > -1; i--) {
	    max[i] = A[i+1] > max[i+1] ? A[i+1] : max[i+1];
	}

	int _min = 0;
	int _max = Integer.MAX_VALUE;
	int count = 0;
	int maxValue = 0;
	for (int i = 0; i < N-1; i++) {
	    if(_min != min[i] || _max != max[i]) {
		_min = min[i];
		_max = max[i];
		int value = _max - _min;
		if(value > maxValue) {
		    maxValue = value;
		    count = 1;
		} else if(value == maxValue) {
		    count++;
		}
	    }
	}

	System.out.println(count);
	scan.close();
    }
}


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

class UnionFind
{
private:
    vector<int> parents;

public:
    int n_roots;
    UnionFind(int n) : parents(n), n_roots(n)
    {
        for (int i = 0; i < n; i++)
        {
            parents.at(i) = -1;
        }
    }

    bool is_root(int x)
    {
        return parents.at(x) < 0;
    }

    int size(int x)
    {
        return -parents.at(find(x));
    }

    int find(int x)
    {
        if (is_root(x))
            return x;
        parents.at(x) = find(parents.at(x));
        return parents.at(x);
    }

    void unite(int x, int y)
    {
        x = find(x);
        y = find(y);
        if (x == y)
            return;
        if (size(x) < size(y))
            swap(x, y);
        parents.at(x) -= size(y);
        parents.at(y) = x;
        n_roots--;
    }

    bool same(int x, int y)
    {
        return find(x) == find(y);
    }
};

int main()
{
    int N, M;
    cin >> N >> M;

    UnionFind tree(N);
    vector<int> l(M, -1);
    for (int i = 0; i < N; i++)
    {
        int Ki;
        cin >> Ki;
        for (int j = 0; j < Ki; j++)
        {
            int Lij;
            cin >> Lij;
            Lij--;
            if (l.at(Lij) < 0)
            {
                l.at(Lij) = i;
            }
            else
            {
                tree.unite(i, l.at(Lij));
            }
        }
    }
    cout << ((tree.n_roots == 1) ? "YES" : "NO") << endl;
}


Measured memory_bytes: 3964
N = int(input())
c,s,f = [], [], []
for _ in range(N-1):
    ci,si,fi = map(int, input().split())
    c.append(ci)
    s.append(si)
    f.append(fi)

for i in range(N):
    t = 0
    pos = i
    while True:
        if pos == N-1:
            print(t);break
        if t<s[pos]: t = s[pos]
        if t%f[pos]==0:
            t += c[pos]
            pos += 1
        else:
            t = (t//f[pos]+1)*f[pos]

Measured memory_bytes: 3064
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

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

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

type Point struct {
	x, y int
}

type PR []Point

func (a PR) Len() int      { return len(a) }
func (a PR) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a PR) Less(i, j int) bool {
	if a[i].y == a[j].y {
		return a[i].x > a[j].x
	}
	return a[i].y > a[j].y
}

type PB []Point

func (a PB) Len() int      { return len(a) }
func (a PB) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a PB) Less(i, j int) bool {
	if a[i].x == a[j].x {
		return a[i].y < a[j].y
	}
	return a[i].x < a[j].x
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n := nextInt()
	pr, pb := make(PR, n), make(PB, n)
	for i := 0; i < n; i++ {
		pr[i] = Point{nextInt(), nextInt()}
	}
	for i := 0; i < n; i++ {
		pb[i] = Point{nextInt(), nextInt()}
	}
	sort.Sort(pr)
	sort.Sort(pb)

	ans := 0
	used := make([]bool, n)
	for i := 0; i < n; i++ {
		// pbを基準にする
		for j := 0; j < n; j++ {
			if used[j] {
				continue
			}
			if pb[i].x > pr[j].x && pb[i].y > pr[j].y {
				ans++
				used[j] = true
				break
			}
		}
	}

	puts(ans)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for( int i=a; i<b; i++ )
#define REP(i,n) rep(i,0,n)
using lli = long long int;
using ulli = unsigned long long int;
typedef pair<lli,lli> P;
struct edge{ int u, v, cost; };
struct DirectedGraph
{
  int vertex_num;
  int edge_num;
  vector<edge> edge_list;
  vector< vector<int> > adj_list;
};

void displayVector(vector<lli> v)
{
	lli n = v.size();
	REP(i,n){
		cout << v[i] << " " ;
	}
	cout << endl;
}

vector<lli> argsort(vector<lli> v)
{
	lli n = v.size();
	vector<lli> indices(n);
	REP(i,n){ indices[i] = i; }

	sort(indices.begin(), indices.end(), [&v](lli i1, lli i2) {
        return v[i1] > v[i2];
  });

	return indices;
}


int main(){
	int n; cin >> n;
	vector<lli> a(n), b(n), c(n);
	REP(i,n){ cin >> a[i]; }
	REP(i,n){ cin >> b[i]; }
	REP(i,n){ cin >> c[i]; }

	sort(a.begin(), a.end() );
	sort(c.begin(), c.end() );

	lli res = 0;
	REP(i, n){
		lli tmp_b = b[i];
		res += (lower_bound(a.begin(), a.end(), b.at(i)) - a.begin())
                  * (c.end() - upper_bound(c.begin(), c.end(), b.at(i)));;
	}
	cout << res << endl;
  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define lp(i, n) for (int i = 0; i < (n) ; ++i)
#define sz(v) (ll)(v).size()
#define int long long
#define mod 1000000007

void solve() {
        int a; cin >> a;
        long double b; cin >> b;
        int ans= round(b*100);
        cout << (a* ans)/ 100<< "\n";
}

int32_t main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        int t = 1;
        //cin >> t;
        lp(i, t) {
                solve();
        }
return 0;
}


Measured memory_bytes: 3792
#include<stdio.h>
#include<string.h>
#define min(a,b) ((a)>(b)?(b):(a))
int main(){
  char s[111111];
  scanf("%s",s);
  int i=0,r=0,b=0;
  for(;i<strlen(s);i++){
    if(s[i]=='0') r++;
    else if(s[i]=='1') b++;
  }
  printf("%d",min(r,b)*2);
}


Measured memory_bytes: 256
from collections import deque


def bfs(graph, n, start):
    visited = [0] * (n+1)
    visited[start] = 1
    start = min(graph.keys())
    queue = deque([])
    queue.append(start)
    pos = {}
    pos[start] = 0

    while queue:
        u = queue.popleft()
        for v in graph[u].keys():
            if  visited[v]:
                continue
            visited[v] = u
            queue.append(v)

    print('Yes')
    [print(i) for i in visited[2:]]
    return True

def resolve():
    n,m = map(int,input().split())
    graph = {i: {} for i in range(1,n+1)}

    for _ in range(m):
        a,b = map(int,input().split())
        graph[a][b] = graph[b][a] = 1

    bfs(graph, n, 1)

if __name__ == "__main__":
    resolve()


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

// Perform prime factorization.
//
// The time complexity is O(sqrt(n)).
//
// Input: n is an integer greater than or equal to 2.
// Output: in the case of 540 = 2^2 * 3^3 * 5, {(2, 2), (3, 3), (5, 1)}.
template <typename T> std::vector<std::pair<T, T>> prime_factor(T n) {
  std::vector<std::pair<T, T>> res;
  for (T k = 2; k * k <= n; ++k) {
    T num = 0;
    while (n % k == 0)
      n /= k, ++num;
    if (num != 0)
      res.push_back(std::make_pair(k, num));
  }
  if (n != 1)
    res.push_back(std::make_pair(n, 1));
  return res;
}

int main() {
  int n;
  std::cin >> n;
  auto primes = prime_factor(n);

  std::cout << n << ":";
  for (auto p : primes)
    for (int i = 0; i < p.second; ++i)
      std::cout << " " << p.first;
  std::cout << std::endl;

  return 0;
}



Measured memory_bytes: 3108
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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


int main() {

    double N, T, A;
    cin >> N ;
    cin >> T >> A;
    vector<double> H(N);

    double tmp = 1e9, tmp2;
    int ans;
    REP(i, N){
        cin >> H[i];
        tmp2 = abs(T - H[i] * 0.006 - A);
        //cout << tmp2 << endl;
        if (tmp2 < tmp){
            tmp = tmp2;
            ans = i + 1;
        }
    }

    cout << ans << 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);
        
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        
        if (A % 2 != 0 || B % 2 != 0 || C % 2 != 0) {
        	System.out.println(0);
        	return;
        }
        
        
        for (int i = 1; i <= 30; i++) {
        	long a = B/2 + C/2;
        	long b = A/2 + C/2;
        	long c = B/2 + A/2;
        	
        	if (a % 2 != 0 || b % 2 != 0 || c % 2 != 0) {
            	System.out.println(i);
            	return;
        	} else {
        		A = a;
        		B = b;
        		C = c;
        	}
        }
        
        System.out.println(-1);
    }
}



Measured memory_bytes: 22612
//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <string>
#include <string.h>
#include <cstdlib>
#include <climits>
#include <cstdio>
#include <vector>
#include <bitset>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define PI 3.14159265
#define base 27
#define  fi first
#define  se second

#define TASK "Papple Sort"

using namespace std;
typedef long long lli;
typedef long double lb;
typedef unsigned long long ull;
typedef pair<int,int> pa;
const long long mod =1e9+7;
const long long oo=1e15+7;
const int maxn=1e6+1;
const int maxN=1e3+1;

/******************************************************************************
 *                                                                            *
 *                       Be a warrior not a worrier!! =)))                    *
 *                                                                            *
 *                                                                            *
 *****************************************************************************/
 char a[maxn];
 int n=0;
 int st[maxn];
 vector<int> pos[maxn];
 int doi[maxn];
void in()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    freopen(TASK".inp","r",stdin);
    freopen(TASK".out","w",stdout);
}
void update(int x)
{
      for(;x<=n;x+=x&-x)
      {
            st[x]++;
      }
}
int query(int x)
{
      int res=0;
      for(;x>0;x-=x&-x)
      {
            res+=st[x];
      }
      return res;
}
void solve()
{
      fill_n(doi,maxn,-1);
      char c;
      while(cin>>c)
      {
            a[++n]=c;
      }
      for(int i=1;i<=n;i++)
      {
            pos[a[i]-'a'].push_back(i);
      }
      int cnt=0;
      for(int i=0;i<=25;i++)
      {
            int s=pos[i].size();
            cnt+=(s%2==1);
            if(cnt>1)
            {
                  cout<<-1;
                  exit(0);
            }
            int x=0,y=s-1;
            while(x<=y)
            {
                  doi[pos[i][x]]=pos[i][y];
                  x++;
                  y--;
            }
      }
      lli ans=0;
      int p;
      for(int i=1;i<=n;i++)
      {
            if(doi[i]!=-1&&doi[i]!=i)
            {
                  ans+=query(i);
                  ans+=query(doi[i]);
                  update(doi[i]);
            }
            if(doi[i]==i)
            {
                  p=i;
            }
      }
      if(n%2==1)
      {
            for(int i=1;i<=n;i++)
            {
                  if(doi[i]==-1) continue;
                  if(i<p&&doi[i]<p)
                  {
                        ans++;
                  }
                  else if(i>p&&doi[i]>p) ans++;
            }
      }
      cout<<ans;
}

int main()
{
    //in();
    solve();

}


Measured memory_bytes: 30584
import sys
input = sys.stdin.readline
n, m, k = map(int,input().split())
A = [list(map(int,input().split())) for i in range(m)]
B = [list(map(int,input().split())) for i in range(k)]
# print(A)
# print(B)
for i in range(m):
    for j in range(2):
        A[i][j] -= 1
for i in range(k):
    for j in range(2):
        B[i][j] -= 1
# print(A)
# print(B)
 
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

    def size(self, x):
        # print(x)
        if self.parents[x] < 0:
            return -self.parents[x]  # 必ず正
        # if x<0:
        #     return -x
        # else:
        #     self.parents[x] = -abs(self.size(self.parents[x]))
        #     return abs(self.parents[x])
        else:
            self.parents[x] = -self.size(self.parents[x])  # 必ず負
            return -self.parents[x]  # 必ず正

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def n_cc(self):  # 連結成分の数
        A = [i for i in self.parents if i < 0]
        return len(A)
 
U = UnionFind(n)
for i in range(m):
    a = A[i][0]
    b = A[i][1]
    U.union(a, b)
C = [0] * n
 
for i in range(m):
    a = A[i][0]
    b = A[i][1]
    C[a] -= 1
    C[b] -= 1
for i in range(k):
    a = B[i][0]
    b = B[i][1]
    if U.find(a) == U.find(b):
        C[a] -= 1
        C[b] -= 1
# print(C)
ANS = []
for i in range(n):
    ANS.append(U.size(i) + C[i] - 1)
print(" ".join([str(i) for i in ANS]))

Measured memory_bytes: 118236
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    int a[5];
    for(int i= 0;i<5;i++) cin >>a[i];
    int k;cin>>k;
    for(int i =0;i<5;i++){
    	for(int j = 0;j<5;j++){
           if(abs(a[i] -a[j])>k){
            cout<<":(";
             return 0;
           } 
        }
    }
    cout<<"Yay!"; 
    return 0;
}

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

int main(){
    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    ll d = 2 * c * min(x, y);
    if(x > y) d += a * (x - y);
    else d += b * (y - x);
    ll e = a * x + b * y;
    ll f = c * 2 * max(x, y);
    cout << min({d, e, f}) << endl;
    return 0;
}

Measured memory_bytes: 256
module PQ = Set.Make(struct type t = int * int * int let compare = compare end)
let () =
  Scanf.scanf "%d %d" @@ fun n m ->
  let g = Array.init n (fun _ -> []) in
  for _ = 1 to m do
    Scanf.scanf " %d %d" @@ fun u v ->
    g.(u-1) <- v-1 :: g.(u-1);
  done;
  Scanf.scanf " %d %d" @@ fun s t ->
  let s, t = s-1, t-1 in
  let dist = Array.init 3 (fun _ -> Array.make n (max_int / 3)) in
  let rec loop pq =
    if PQ.is_empty pq then () else
    let d,x,m = PQ.min_elt pq in
    let pq = PQ.remove (d,x,m) pq in
    if d > dist.(m).(x) then loop pq else begin
      let m = (m+1) mod 3 in
      List.fold_left (fun pq y -> 
        if d+1 >= dist.(m).(y) then pq else begin
          dist.(m).(y) <- d+1;
          PQ.add (d+1, y, m) pq
        end
      ) pq g.(x) |> loop
    end
  in
  loop PQ.(singleton (0, s, 0));
  if dist.(0).(t) < max_int/3 then Printf.printf "%d\n" (dist.(0).(t) / 3)
  else print_endline "-1"


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

int main(){
	int n;cin >> n;
	map<string, int> mapa;
	int maxi=0;
	for(int i=0;i<n;i++){
		string s;cin >> s;
		mapa[s]++;
		maxi=max(maxi, mapa[s]);
	}
	for(auto i:mapa){
		if(i.second==maxi)
			cout << i.first << "\n";
	}
}

Measured memory_bytes: 25216
#include <iostream>

using namespace std;

int main(){
    int n;
    cin >> n;
    int a[n];
    int b[n];
    int c[n - 1];
    int result = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        a[i]--;
    }
    for(int i = 0; i < n; i++){
        cin >> b[i];
        result += b[i];
    }
    for(int i = 0; i < n - 1; i++){
        cin >> c[i];
    }
    for(int i = 1; i < n; i++){
        if(a[i] - a[i - 1] == 1){
            result += c[a[i - 1]];
        }
    }
    cout << result << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

int main(int argc, char *argv[]){
    int sumD=0, sumD2=0;
    int N, d;
    std::cin >> N;
    for(int i=0; i<N; ++i){
        std::cin >> d;
        sumD += d;
        sumD2 += d*d;
    }
    std::cout << (sumD*sumD - sumD2)/2 << std::endl;
    return 0;
}


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

//定数
const long long MOD1=1000000007;
const long long MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const long long dx[]={0,1,0,-1,1,-1,1,-1};
const long long dy[]={1,0,-1,0,1,1,-1,-1};

//型名省略
#define ll long long
#define ull unsigned long long
#define ld long double
#define uld unsigned long double
#define pll pair<long long,long long>
#define tll(n) array<long long,(int)(n)>
#define pcc pair<char,char>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define vt(n) vector<array<long long,(int)(n)>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define Fi first
#define Se second
#define mp make_pair
#define eb emplace_back

//マクロ
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s);i<(long long)(n);i++)
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define lin(s) getline(cin,(s))

//MAX,MIN
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}

//最大公約数,最小公倍数
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}

//累乗
template<typename t>
constexpr t mypow(t a,long long b){
    if(b==0)return 1;
    if(a==0)return 0;
    t x=1;
    while(b>0){
        if(b&1LL)x*=a;
        a*=a;
        b>>=1LL;
        }
    return x;
}
#define pow mypow

//chmin,chmax
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;}

//組み合わせ O(r)
template<typename t>
constexpr t nCr(t n,long long r){
    if(r==0)return 1;
    if(n==0)return 0;
    if(n<r)return 0;
    t x=1;
    for(long long i=1;i<=r;i++){
        x*=n-i+1;
        x/=i;
    }
    return x;
}

//main関数
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin>>n;
    vl P(n);
    rep(i,n)cin>>P[i];
    vl Q(n);
    rep(i,n){
        Q[P[i]-1]=i;
    }
    ll res=1;
    ll now=1;
    rep(i,n-1){
        if(Q[i+1]>Q[i])now++;
        else now=1;
        chmax(res,now);
    }
    cout<<n-res<<endl;
}

Measured memory_bytes: 6340
from math import sqrt, floor

N = int(input())
d = [0] * (N+1)

k = floor(sqrt(N))
for x in range(1, k):
    for y in range(1, k):
        for z in range(1, k):
            c = x*x + y*y + z*z + x*y + y*z + z*x
            if 1 <= c <= N:
                d[c] += 1


for i in range(1, N+1):
    print(d[i])


Measured memory_bytes: 74180
#include <bits/stdc++.h>
using namespace std;
struct process{
  string name;
  int time;
};

int main() {
  int n,q,t = 0;
  cin >> n >> q;
  queue<process> que;
  for(int i = 0;i < n;i++){
    process p;
    cin >> p.name >> p.time;
    que.push(p);
  };
  while(que.size()){
    t += min(que.front().time,q);
    if(que.front().time<=q){
      cout << que.front().name << " " << t << endl;
      que.pop();
    }
    else{
      que.front().time -= q;
      que.push(que.front());
      que.pop();
    }
  }
}



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

/* REPmacro */
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define REPR(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define FOR(i,m,n) for(int i=(int)(m);i<(int)(n);++i)

/*alias*/
//#define ALL(x) (x).begin(),(x).end()
//#define SZ(x) ((int)(x).size())
//#define F first
//#define S second
#define PB push_back
#define MP make_pair 

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

/*struct*/
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;


/* const */
const int INF = 1001001001;
const long long LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const double EPS = 1e-9;

//#define int long long

signed main()
{
  string s;
  cin >> s;
  int i = s.size() - 2;
  auto itr = s.end();
  --itr;
  cout << s[0] << i << *itr;
  return 0;
}

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

int main(){
int a,b,c;
int flag;

cin>>a>>b>>c;

for(int i=0;i<100;i++){
   if(a*i%b==c){
       cout<<"YES";
       flag=0;
       break;
   }
   else{
       flag=1;
   }
}

if(flag==1){
    cout<<"NO";
}

}

Measured memory_bytes: 256
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
#![macro_use]

use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::mem::*;
use std::num::*;
use std::slice::*;

fn main() {
    let (r, w, e) = (stdin(), stdout(), stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());
    // =============================================== //
    let n: usize = io.read();
    let mut a = io.readn::<usize>(n);

    let mut b: Vec<usize> = Vec::new();
    while !a.is_empty() {
        let mut found = false;
        for i in (0..a.len()).rev() {
            if a[i] == i + 1 {
                b.push(i + 1);
                a.remove(i);
                found = true;
                break;
            }
        }
        if !found {
            io.writeln(-1);
            return;
        }
    }
    for &i in b.iter().rev() {
        io.writeln(i);
    }
}

// IO
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug ) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug, T: std::fmt::Debug>(&mut self, val1: S, val2: T) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
}


Measured memory_bytes: 4352
while True:
    n = int(input())
    if n == 0:
        break

    ans = 0
    for i in range(1, n + 1):
        s = i
        for j in range(i + 1, n + 1):
            s += j
            if s == n:
                ans += 1
                break
            elif s > n:
                break
    print(ans)


Measured memory_bytes: 5588
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define forinc(i,a,b) for(int i=a;i<=b;++i)
#define fordec(i,a,b) for(int i=a;i>=b;--i)
#define fi first
#define se second
#define pii pair<int,int>

double L;
main()
{
    cin>>L;
    cout<<setprecision(10)<<fixed;
    double z=L/3;
    double z1=L/3;
    double tmp=L-z-z1;
    cout<<z*z1*tmp;
}


Measured memory_bytes: 256
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 100001;
static const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool int_ceil(T a, T b) { T res = a / b; if(a % b != 0) res++; return res; }
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif

vector<pair<char, int> > Ranlength(string str){
    vector<pair<char, int> > ranlength;

    pair<char, int> f;
    char lastChar;
    int cnt = 0;
    rep(i, str.size()){
        if(lastChar != str[i] || i == str.size()){
            if(i!=0){
                f = make_pair(lastChar, cnt);
                ranlength.push_back(f);
            }
            lastChar = str[i];
            cnt=1;
        }
        else{
            cnt++;
        }
    }
    f = make_pair(lastChar, cnt);
    ranlength.push_back(f);

    // rep(i, ranlength.size()){ // for debug
    //     cout << ranlength[i].first << ranlength[i].second << endl;
    // }
    return ranlength;
}


int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	int n; cin >> n;
	string str; cin >> str;

	auto v = Ranlength(str);

	int k = 0;
	while(v[k].first != '#') {
		k++;
		if(v.size() < k){
			cout << 0 << endl;
			return 0;
		}
	}

	ll sum = 0;
	ll ans = LLINF;
	rep2(i, k, v.size()){
		if(v[i].first == '.') sum += v[i].second;
	}

	chmin(ans, sum);
	rep2(i, k, v.size()){
		if(v[i].first == '#') sum += v[i].second;
		else sum -= v[i].second;
		chmin(ans, sum);
	}

	cout << ans << endl;

	return 0;
}


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

using namespace std;

#define endl "\n"
typedef long long int ll;
#define f first
#define s second

inline void fastio(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
inline void setPrecision(int n){cout.precision(n);}

//DEBUG
#define dbg(x) cerr<<(#x)<<": "<<x<<endl
#define dbgV(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgS(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgM(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
#define dbg2D(x) cerr<<(#x)<<": \n"; for(auto y: x) { for(auto it: y) cerr<<it<<" "; cerr<<endl; } cerr<<endl;
#define dbgA(x, n) cerr<<(#x)<<": "; for(int i=0;i<n;++i) cerr<<x[i]<<" "; cerr<<endl;
#define dbgVP(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;

ll INF = 1e10;
int MOD = 1e9+7;

vector<string> keep;
bool done[9];
int n;

void fn(string now){
    bool all_done = 1;
    for(int i = 1; i <= n; ++i){
        all_done &= done[i];
    }
    if(all_done){
        keep.push_back(now);
        return;
    }
    for(int i = 1; i <= n; ++i){
        if(done[i]) continue;
        done[i] = 1;
        fn(now + to_string(i));
        done[i] = 0;
    }
}

int main(){
    #ifndef ONLINE_JUDGE
        freopen("debug.txt", "w", stderr);
    #endif
    fastio();

    cin >> n;
    string s1 = "", s2 = "";
    for(int i = 0, x; i < n; ++i){
        cin >> x;
        s1 += to_string(x);    
    }
    for(int i = 0, x; i < n; ++i){
        cin >> x;
        s2 += to_string(x);
    }
    fn("");
    dbgV(keep);
    int idx1 = 0;
    for(;idx1 < n, keep[idx1] != s1; ++idx1);
    int idx2 = 0;
    for(;idx2 < n, keep[idx2] != s2; ++idx2);

    dbg(idx1);
    dbg(idx2);
    cout << abs(idx1 - idx2);    

    return 0;
}


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

int main() {
  int k;
  cin >> k;
  int a, b;
  cin >> a >> b;
  int tmp = k;
  for(int i = 2;tmp<=b;i++){
    if(tmp>=a){
      cout << "OK" <<endl;
      return 0;
    }else{
      tmp = k*i;
    }
  }
  cout << "NG" << endl;
  return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
 
const ll M = 1e9 + 7;
ll fac [2000001];
ll ifac[2000001];
 
ll powe(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}
 
ll comb(ll a, ll b){
    ll den = ifac[a-b]* ifac[b] % M;
    return den * fac[a] % M;
}
 
int main()
{
    int x,y;
    cin >> x >> y;
    if((x+y) % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }
    
    ll a = y - (x+y)/3;
    ll b = x - (x+y)/3;
    
    if(a < 0 || b < 0) {
        cout << 0 << endl;
        return 0;
    }
    
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i< a+b+1; i++) fac[i+1] = fac[i]*(i+1) % M;
    for(ll i = 0; i< a+b+1; i++) ifac[i+1] = ifac[i]*powe(i+1, M-2) % M;
    
    cout << comb(a+b,b) << endl;
    return 0;
}

Measured memory_bytes: 14592
#include <iostream>
#include <vector>
#include <bitset>
#include <string>
#include <array>
#include <random>
#include <chrono>
#include <algorithm>
#include <unordered_map>

int main(void){
	int n;
	std::cin >> n;
	std::vector<int> b(n-1);
	for(int i=0;i<n-1;i++)std::cin >> b[i];
	int ans = b[0] + b[n-2];
	for(int i=1;i<n-1;i++){
		ans += std::min(b[i], b[i-1]);
	}
	std::cout << ans << std::endl;
}

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

int prims[1000006];

int cnt;
int mm[1000006],yins[1000006];
void ssp(int n)
{
    for (int i = 2; i <= n; i ++ )
    {
        if (mm[i] == 0) prims[cnt ++ ] = i;

        for (int j = 0; prims[j] <= n / i; j ++ ) {
            mm[prims[j] * i] = 1;
            if (i % prims[j] == 0) break;
        }
    }
}

int main()
{
    ssp(3000);
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        int t;
        scanf("%d",&t);
        for(int i=0; i<cnt; i++) 
        {
            int tot=0;
            while(t%prims[i]==0)
            {
                t/=prims[i];
                tot=1;
            }
            if(tot) yins[prims[i]]++;
        }
        if(t>1) yins[t]++;
    }
    int st=0;
    for(int i=1; i<1000005; i++)
    {
        if(yins[i]>=2) st++;
        if(yins[i]==n)
        {
            cout<<"not coprime"<<endl;
            return 0;
        }
    }
    if(st==0)
    {
        cout<<"pairwise coprime"<<endl;
    }
    else
        cout<<"setwise coprime"<<endl;
    return 0;
}



Measured memory_bytes: 7636
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node {
	int key;
	Node *right, *parent, *left;
};

Node *root, *NIL;

Node * treeMinimum(Node *x) {
	while (x->left != NIL)x = x->left;
	return x;
}

Node * find(Node *u, int k) {
	while (u != NIL && k != u->key) {
		if (k < u -> key) {
			u = u->left;
		}
		else u = u->right;
	}
	return u;
}

Node * treeSuccessor(Node *x) {
	if (x->right != NIL)return treeMinimum(x->right);
	Node *y = x->parent;
	while (y != NIL && x == y->right) {
		x = y;
		y = y->parent;
	}
	return y;
}

void treeDelete(Node *z) {
	Node *y;//削除する対象//
	Node *x;//yの子//

	//削除する節点を決める//
	if (z->left == NIL || z->right == NIL)y = z;
	else y = treeSuccessor(z);

	//yの子xを決める//
	if (y->left != NIL) {
		x = y->left;
	}
	else {
		x = y->right;
	}

	if (x != NIL) {
		x->parent = y->parent;
	}

	if (y->parent == NIL) {
		root = x;
	}
	else {
		if (y == y->parent->left) {
			y->parent->left = x;
		}
		else {
			y->parent->right = x;
		}
	}

	if (y != z) {
		z->key = y->key;
	}

	free(y);

}

void insert(int k) {
	Node *y = NIL;
	Node *x = root;
	Node *z;

	z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while (x != NIL) {
		y = x;
		if (z->key < x->key) {
			x = x->left;
		}
		else {
			x = x->right;
		}
	}

	z->parent = y;
	if (y == NIL) {
		root = z;
	}
	else {
		if (z->key < y->key) {
			y->left = z;
		}
		else y->right = z;
	}
}

void inorder(Node *u) {
	if (u == NIL)return;
	inorder(u->left);
	printf(" %d", u->key);
	inorder(u->right);
}

void preorder(Node *u) {
	if (u == NIL)return;
	printf(" %d", u->key);
	preorder(u->left);
	preorder(u->right);
}

int main() {
	int n, i, x;
	string com;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		cin >> com;
		if (com[0] == 'f') {
			scanf("%d", &x);
			Node *t = find(root, x);
			if (t != NIL)printf("yes\n");
			else printf("no\n");
		}
		else if (com == "insert") {
			scanf("%d", &x);
			insert(x);
		}
		else if (com == "print") {
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
		else if (com == "delete") {
			scanf("%d", &x);
			treeDelete(find(root, x));
		}
	}

	return 0;
}


Measured memory_bytes: 22052
#include <iostream>
#include <algorithm>

#define INF (1 << 25)

using namespace std;

int pcost[100][100]; // begin, end
int mcost[100][100];

void Dijkstra( int n, int s, int cost[][100], int *minCost )
{
	bool *end = new bool[n];
	fill(end, end+n, false);
	minCost[s] = 0;
	end[s] = true;
	while(true) {
		int ii = -1, nn = (INF);
		for(int i=0; i < n; ++i) {
			if(end[i] && nn > minCost[i]) {
				nn = minCost[i];
				ii = i;
			}
		}
		if(ii == -1) break;
		end[ii] = false;
		for(int i=0; i < n; ++i) {
			if(minCost[i] > minCost[ii] + cost[ii][i]) {
				minCost[i] = minCost[ii] + cost[ii][i];
				end[i] = true;
			}
		}
	}
}

int main( void )
{
	int minCost1[100], minCost2[100], minCost3[100];

	int n, m, s, g1, g2;
	while(cin >> n >> m >> s >> g1 >> g2, n | m | s | g1 | g2) {
		--s; --g1; --g2;
		for(int i=0; i < n; ++i) {
			fill(pcost[i], pcost[i]+n, INF);
			fill(mcost[i], mcost[i]+n, INF);
			minCost1[i] = minCost2[i] = minCost3[i] = INF;
		}
		for(int i=0; i < m; ++i) {
			int bb, ee, cc;
			cin >> bb >> ee >> cc;
			--bb; --ee;
			pcost[bb][ee] = mcost[ee][bb] = cc;
		}
		Dijkstra(n, s, pcost, minCost1);
		Dijkstra(n, g1, mcost, minCost2);
		Dijkstra(n, g2, mcost, minCost3);

		int ans = INF;
		for(int i=0; i < n; ++i) {
			ans = min(ans, minCost1[i] + minCost2[i] + minCost3[i]);
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1004