akhauriyash/Code-Regression huggingface dataset:
unittest
{
	assert( [ "4 2 6" ].parse.expand.solve == 7 );
	assert( [ "7 3 4" ].parse.expand.solve == 8 );
	assert( [ "314159265 35897932 384626433" ].parse.expand.solve == 48518828981938099 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto kab = input.front.split.to!( long[] );
	return tuple( kab[ 0 ], kab[ 1 ], kab[ 2 ] );
}

auto solve( long k, long a, long b )
{
	auto ans = 1L;
	if( 2 < b - a )
	{
		while( 0 < k )
		{
			if( 2 <= k && a <= ans )
			{
				ans += b - a;
				k -= 2;
			}
			else
			{
				ans++;
				k--;
			}
		}
	}
	else
	{
		ans += k;
	}
	return ans;
}


Measured memory_bytes: 256
import statistics as st


#'''
nn = int(input())
base_temp, ave_temp = map(int, input().split())
hh = [int(i) for i in input().split()]
'''

n=2
base_temp = 12
ave_temp = 5
hh = [1000, 2000, 1200]
'''

def temp(b, h):
    return b - h * 0.006

list = []

for h in hh:
    list.append(temp(base_temp, h))



#print(list)
#m = st.mean(list)

list2 = [abs(i - ave_temp) for i in list]
#print(list2)

print(list2.index(min(list2)) + 1)
'''
for h in hh:
    list2.append(temp(base_temp, h))
'''



#print(temp(12, 1000))


Measured memory_bytes: 5660
package main

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

const (
	spade   = "S"
	heart   = "H"
	clover  = "C"
	diamond = "D"
)

var scan = bufio.NewScanner(os.Stdin)

func main() {
	scanWords()
	itemNum := readNextInt()
	list := make(map[string]map[int]int)
	list[spade] = make(map[int]int)
	list[heart] = make(map[int]int)
	list[clover] = make(map[int]int)
	list[diamond] = make(map[int]int)

	for i := 1; i <= 13; i++ {
		list[spade][i] = 0
		list[heart][i] = 0
		list[clover][i] = 0
		list[diamond][i] = 0
	}

	for i := 0; i < itemNum; i++ {
		mark := readNextString()
		num := readNextInt()
		list[mark][num]++
	}

	printMissingCards(list, spade)
	printMissingCards(list, heart)
	printMissingCards(list, clover)
	printMissingCards(list, diamond)
}

func printMissingCards(list map[string]map[int]int, mark string) {
	slice := make([]int, 0, 13)
	for num, count := range list[mark] {
		if count == 0 {
			slice = append(slice, num)
		}
	}

	sort.Sort(sort.IntSlice(slice))

	for _, value := range slice {
		fmt.Printf("%s %d\n", mark, value)
	}
}

func scanWords() {
	scan.Split(bufio.ScanWords)
}

func readNextInt() int {
	input, err := strconv.Atoi(readNextString())
	if err != nil {
		panic(err)
	}
	return input
}

func readNextString() string {
	scan.Scan()
	return scan.Text()
}



Measured memory_bytes: 1120
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define FILL(a, n, x) memset((a), (x), sizeof ((a)[0]) * (n))
#define COPY(a, n, b) memcpy((b), (a), sizeof ((a)[0]) * (n))
using namespace std;

typedef long long li;

// const int mod = 1e9 + 7, inv2 = mod + 1 >> 1;
// inline int Add(int x) { return x >= mod ? x - mod : x; }
// inline void Add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
// inline int Sub(int x) { return x < 0 ? x + mod : x; }
// inline void Sub(int &x, int y) { x -= y; if (x < 0) x += mod; }
// inline int Mul(int x, int y) { return (li)x * y % mod; }

// int Pow(int x, int y) {
//   int z = 1;
//   for (; y; y >>= 1) {
//     if (y & 1) z = Mul(z, x);
//     x = Mul(x, x);
//   }
//   return z;
// }

// ----------------------------------------

const int maxn = 1000;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
const char dc[] = "LURD";
const li infl = 1e18;

int n;
int x[maxn], y[maxn];
int m;
int d[maxn];

void Solve(li X, li Y) {
  for (int i = 0; i < m; ++i) {
    li X2, Y2, val = infl;
    char chosen;
    for (int t = 0; t < 4; ++t) {
      li x = X - dx[t] * d[i];
      li y = Y - dy[t] * d[i];
      li v = abs(x) + abs(y);
      if (v < val) {
        val = v;
        X2 = x;
        Y2 = y;
        chosen = dc[t];
      }
    }
    X = X2;
    Y = Y2;
    putchar(chosen);
  }
  putchar('\n');
}

int main(void) {
  scanf("%d", &n);
  bool odd = false, even = false;
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", x + i, y + i);
    if (x[i] + y[i] & 1) {
      odd = true;
    } else {
      even = true;
    }
  }
  if (odd && even) {
    puts("-1");
    return 0;
  }

  if (even) d[m++] = 1;
  for (int i = 0; i <= 30; ++i) {
    d[m++] = 1 << i;
  }
  reverse(d, d + m);
  printf("%d\n", m);
  for (int i = 0; i < m; ++i) {
    printf("%d%c", d[i], " \n"[i == m - 1]);
  }

  for (int i = 0; i < n; ++i) {
    Solve(x[i], y[i]);
  }
  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N = ii()

for i in range(11):
    if 1000 * i >= N:
        print(1000 * i-N)
        exit()


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

using namespace std;

#define PI 3.14159265358979323846264338327950L

int main(void){

    string str;

    cin>>str;

    if(str[str.size()-1] == 's'){
        str += 'e';
    }
    str+='s';

    cout<<str<<endl;

    return 0;
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    string X;
    cin >> X;
    vector<int> x;
    int prev = 0;
    REP(i, X.length()-1){
        if(X[i] != X[i+1]){
            x.pb(i-prev+1);
            prev = i+1;
        }
    }
    x.pb(X.length()-prev);

    int ans = X.length();
    int n = x.size();
    for (int i = (X[0]=='T')?1:0; i < n-1; i+=2)
    {
        if(x[i] > x[i+1]){
            ans -= x[i+1]*2;
            if(i < n-1) x[i+2] += (x[i]-x[i+1]);
        }else{
            ans -= x[i]*2;
            if(i < n) x[i-1] += (x[i+1]-x[i]);
        }
        // ans -= min(x[i], x[i+1])*2;
    }
    pr(ans);
}

Measured memory_bytes: 1024
/*
"Won't stop until I'm phenomenal."
- Phenomenal, Eminem
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define ff first
#define Shazam ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
#define test() int t; cin>>t; while(t--)
#define fl(i,a,b) for(int i = a ; i <b ;i++)
#define get(a) fl(i,0,a.size())  cin>>a[i];
#define pra(a) fl(i,0,a.size()) cout<<a[i]<<" ";	cout<<endl;
#define pr(a,n) fl(i,0,n) cout<<a[i]<<" ";	cout<<endl;
const ll INF = 2e18;
const int inf = 2e9;
const int mod1 = 1e9 + 7;



int main(){
    Shazam;
    int n; cin>>n;
    vector<ll> a(n); 
    get(a);
    ll odd = 0;
    ll even = 0;
    for(int i = 0; i < n; i++){
        if(i&1)
            odd+=a[i];
        else
            even+=a[i];
    }
    ll x = (even-odd)/2;
    for(int i = 1; i < n; i++){
        cout<<2*x<<" ";
        x = a[i-1] - x;
    }
    cout<<2*x<<endl;
    return 0;
}

Measured memory_bytes: 3956
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  rep(i,N) cin >> s[i];
  rep(i,N) sort(s[i].begin(), s[i].end());
  map<string, ll> mp;
  rep(i,N) mp[s[i]]++;
  ll ans = 0;
  auto begin = mp.begin(), end = mp.end();
  for (auto i = begin; i != end; i++) ans += (i->second)*(i->second - 1) / 2;
  cout << ans << endl;
  return 0;
}

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

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.141592653589793238462643383279;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    string S,T; cin >> S >> T;
    int NS = S.size(), NT = T.size();
    VI SA(NS+1,0), SB(NS+1,0), TA(NT+1,0), TB(NT+1,0);
    REP(i,NS){
        if(S[i] == 'A') SA[i+1] = 1;
        else SB[i+1] = 1;
    }
    REP(i,NS){
        SA[i+1] += SA[i];
        SB[i+1] += SB[i];
    }
    REP(i,NT){
        if(T[i] == 'A') TA[i+1] = 1;
        else TB[i+1] = 1;
    }
    REP(i,NT){
        TA[i+1] += TA[i];
        TB[i+1] += TB[i];
    }

    int q; cin >> q;
    REP(i,q){
        int a,b,c,d; cin >> a >> b >> c >> d;
        int sa = SA[b] - SA[a-1], sb = SB[b] - SB[a-1];
        int ta = TA[d] - TA[c-1], tb = TB[d] - TB[c-1];
        if(sa < ta) tb += 2*(ta-sa);
        else sb += 2*(sa-ta);

        cout << (abs(sb-tb)%3 == 0 ? "YES" : "NO") << en;
    }
    return 0;
}

Measured memory_bytes: 2432
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
  static InputReader in;
  static PrintWriter out;




  static class Solution {
    void solve() throws IOException {
      int n = in.nextInt();
      out.println(factorial(n));
      
//      End solve()
    }
    
    long factorial(int x) {
      long factorial = x;
      
      if (x == 0) {
        return 1;
      } else {
        factorial *= factorial(x - 1);
      }
      
      return factorial;
    }
//    End Solution
}


  public static void main(String[] args) throws IOException {
    in = new InputReader(System.in);
    out = new PrintWriter(System.out);
    Solution solver = new Solution();
    solver.solve();
    out.close();
}


  static class InputReader {
    public BufferedReader br;
    public StringTokenizer st;

    public InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream));
    }

    public int nextInt() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Integer.parseInt(st.nextToken());
    }

    public long nextLong() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Long.parseLong(st.nextToken());
    }

    public String next() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return st.nextToken();
    }

    public double nextDouble() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Double.parseDouble(st.nextToken());
    }

  }

}

Measured memory_bytes: 23924
#include <iostream>
using namespace std;
int main()
{
    while(1)
    {
        int n;
        cin>>n;if(!n)return 0;
        int gn[7]={0};
        for(int i=0;i<n;++i){
            int a,ag=0;
            cin>>a;
            if(a>=10)ag++;
            if(a>=20)ag++;
            if(a>=30)ag++;
            if(a>=40)ag++;
            if(a>=50)ag++;
            if(a>=60)ag++;
            gn[ag]++;
        }
        for(int i=0;i<7;++i)cout<<gn[i]<<endl;
    }
    return 0;
}

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

#define F first
#define S second
#define int long long
#define ull unsigned long long
#define pb push_back

using namespace std;
const int N = 210000;
int n, a[N];
bool ok(int x){
    int s = 0;
    for (int i = 0; i < x + 1; i++)
        s += a[i];
    for (int i = x + 1; i < n; i++)
        if (s + s >= a[i]) s += a[i]; else return 0;
    return 1;
}
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    int l = -1, r = n;
    while(r - l > 1){
        int mid = (r + l) / 2;
        if (ok(mid)) r = mid; else l = mid;
    }
    cout << n - r;
}


Measured memory_bytes: 1024
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
long long dp[100001][3] = {};
vector<long long> vertexs[100001];
int main() {
#define int long long
	iostream::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	REP(i, m) {
		int a, b;
		cin >> a >> b;
		vertexs[a].push_back(b);
	}
	int s, t;
	cin >> s >> t;
	REP(i, 100001) {
		REP(q, 3) {
			dp[i][q] = LONG_INF;
		}
	}
	dp[s][0] = 1;
	queue<pair<int, int>> next;
	next.push(make_pair(s, 0));
	while (next.empty() == false) {
		pair<int, int> now = next.front();
		next.pop();
		now.second++;
		for (int q = 0; q < vertexs[now.first].size(); ++q) {
			int next_itr = vertexs[now.first][q];
			if (dp[next_itr][now.second % 3] == LONG_INF) {
				dp[next_itr][now.second % 3] = now.second;
				next.push(make_pair(next_itr, now.second));
			}
		}
	}
	if (dp[t][0] != LONG_INF) {
		cout << dp[t][0]/3 << endl;
	}
	else {
		cout << -1 << endl;
	}
}

Measured memory_bytes: 8064
package main

import (
	"fmt"
)

func main() {
	c := make([][]int, 3)
	for i:=0; i<3; i++ {
		c[i] = make([]int, 3)
		fmt.Scan(&c[i][0], &c[i][1], &c[i][2])
	}

	a := []int{0, -1, -1}
	b := []int{-1, -1, -1}

	i := 0
	for j:=0; j<3; j++ {
		b[j] = c[i][j] - a[i]
	}
	for i=1; i<3; i++ {
		for j:=0; j<3; j++ {
			a[i] = c[i][j] - b[j]
		}
	}

	for ai:=0; ai<3; ai++ {
		for bi:=0; bi<3; bi++ {
			if a[ai] + b[bi] != c[ai][bi] {
				fmt.Println("No")
				return
			}
		}
	}
	fmt.Println("Yes")
}

Measured memory_bytes: 512
N = int(input())
ss = []
for _ in range(N): ss.append(input())

from collections import Counter

ctr = Counter(ss)
counted = ctr.most_common()
# print(counted)
ans = []
for i in range(len(counted)):
    tup = counted[i]
    if i == 0:
        ans.append(tup[0])
        continue
    if counted[i][1] != counted[i - 1][1]:
        break
    ans.append(tup[0])

ans.sort()
for a in ans: print(a)


Measured memory_bytes: 47672
local n = io.read("*n")
local t = {}
for i = 1, n do
  local a = io.read("*n")
  if not t[a] then t[a] = 0 else t[a] = t[a] + 1 end
end
local rm = 0
for k, v in pairs(t) do
  rm = rm + v
end
if rm % 2 == 1 then rm = rm + 1 end
print(n - rm)


Measured memory_bytes: 1280
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
#define int long long
signed main(){
	int a,b,n;
	while( scanf("%lld %lld %lld", &a, &b, &n) != EOF ){
		int s=0;
		a = a % b;
		for(int i=1;i<=n;i++){
			a *= 10;
			s += a/b;
			a = a - a/b*b;
		}
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 3140
#include<bits/stdc++.h>
#define taskname "A"
#define pb push_back
#define mp make_pair
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
const int maxn = 5e5 + 5;
const int logn = log2(maxn) + 1;
const int mod = 1e9 + 7;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if(fopen(taskname".INP", "r")) {
        freopen(taskname".INP", "r", stdin);
        freopen(taskname".OUT", "w", stdout);
    }
    string s;
    cin >> s;
    ll res = 0;
    for(int i = 0 ; i < (int)s.size() ; ++i){
        ll ans = 0;
        for(int j = i ; j < (int)s.size() ; ++j){
            ans = ans * 10 + s[j] - '0';
            res += (ll)ans * (1ll << (max(0 , i - 1))) * (1ll << (max(0 , (int)s.size() - j - 2)));
        }
    }
    cout << res;
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <string>
using namespace std;
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(int)(n); i++)
typedef long long ll;
const int INF = numeric_limits<int>::max();
const int MOD = (1e9 + 7);


int main(){
  int N, M, dist, ans, d;
  cin >> N >> M;
  int C[N][2], D[M][2];
  rep(i, N){
    cin >> C[i][0] >> C[i][1];
  }
  rep(i, M){
    cin >> D[i][0] >> D[i][1];
  }
  rep(i, N){
    int d = INF;
    rep(j, M){
      dist=abs(C[i][0] - D[j][0]) + abs(C[i][1] - D[j][1]);
      if(dist < d){
        ans = j+1;
      }
      d = min(dist, d);
    }
    cout << ans << endl;
  }
      
 
 }


Measured memory_bytes: 256
import fractions
from functools import reduce

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N = int(input())

A = [0]*N
for i in range(N):
    A[i]=int(input())



print(lcm_list(A))

Measured memory_bytes: 5048
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Edge=pair<int,ll>;
using Graph=vector<vector<ll> >;//ll or Edge
using Edge=pair<int,ll>;
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// g++ -o a a.cpp -Wall -lm -std=c++17

int main(){
    ll n;cin>>n;
    string S;cin>>S;
    ll r=0;
    rep(i,n){
        if(S[i]=='R')r++;
    }
    ll ans=0;
    rep(i,r){
        if(S[i]=='W')ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3748
import fractions
def main():
    A, B, C, D = map(int, input().split())
    num = (B - A + 1)  - (get_num(B, C, D) - get_num(A-1, C, D))
    print(num)

def get_num(x, C, D):
    num_C = x // C
    num_D = x // D
    f = fractions.gcd(C, D)
    f2 = C*D//f
    num_CD = x // f2
    return num_C  + num_D - num_CD

if __name__  == '__main__':
    main()

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

using namespace std;

using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FORE(i, a, b) for(int i=(a);i<=(b);++i)
#define FORR(i, a, b) for(int i=(b-1);i>=(a);--i)
#define FORRE(i, a, b) for(int i=(b);i>=(a);--i)
#define rep(i, n) for(int i=0;i<(n);++i)
#define repe(i, n) for(int i=0;i<=(n);++i)
#define repr(i, n) for(int i=(n-1);i>=0;--i)
#define repre(i, n) for(int i=(n);i>=0;--i)
#define ALL(v) (v).begin(),(v).end()
#define SP cout<<fixed<<setprecision(10)
typedef pair<int, int> P;
const int INF = (int) 1e9;
const int MOD = (int) 1e9 + 7;

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

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int a,p;
	cin>>a>>p;
	
	cout<<(a*3+p)/2<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;

int ceil(int x, int y) { return (x % y == 0) ? x / y : x / y + 1; }

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }

int lcm(int x, int y) { return x / gcd(x, y) * y; }

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

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

  bool ok = true;
  int b = h[0] - 1;
  for (int i = 1; i < n; i++) {
    if (h[i] - 1 >= b)
      b = h[i] - 1;
    else if (h[i] >= b)
      b = h[i];
    else {
      ok = false;
      break;
    }
  }

  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;
const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;

#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl

#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

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

#define FOREACH(x,a) for(auto&& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])

#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}

#define ALL(obj) (obj).begin(),(obj).end()

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template <class T = ll>
T IN(){T x;cin>>x;return (x);}

template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}

template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}

#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc

// #include <boost/multiprecision/cpp_ll.hpp>
// using namespace boost::multiprecision; // cpp_ll

#define P pair<ll,ll>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>

#define pb(a) push_back(a)
#define mp make_pair

signed main(){
    CIN(n);
    VC1(n,a);
    double ave = accumulate(ALL(a), 0LL) * 1.0 / n;
    double diffmax = 1e9;
    int ans = 0;
    REP(i,n){
        double diff = abs(ave - a[i]);
        if(diffmax > diff){
            diffmax = diff;
            ans = i;
        }
    }
    COUT(ans);

}


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

using namespace std;

int main() {
    int N, K;
    int h[100000];
    int ans = INT_MAX;

    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        cin >> h[i];
    }
    sort(h, h+N);

    for (int i = 0; i <= N-K; i++) {
        ans = min(ans, h[i+K-1] - h[i]);
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 640
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

int main(){
  ll x,k,d; cin>>x>>k>>d;
  if( x<0 ) x*=-1;
  ll n=x/d;
  ll mi=numeric_limits<ll>::max();
  if(n >= k){
    mi = x - k*d;
    cout<<mi<<endl;
    return 0;
  }
  if((k-n)%2==0){
    mi=x%d;
  }else{
    mi=d-x%d;
  }
  cout<<mi<<endl;
}

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

int A[500000];
int count;

void exchange(int i, int max){
  int kari;
  kari=A[i];
  A[i]=A[max];
  A[max]=kari;
}

void maxHeappify(int i){
  int r,l,max;
  r=2*i;
  l=2*i+1;

  if(l<=count && A[l]>A[i]) max=l;
  else max=i;
  if(r<=count && A[r]>A[max]) max=r;

  if(max!= i){
    exchange(i,max);
    maxHeappify(max);
  }
}


int main(int argc, char const *argv[]) {
    int i;
    scanf("%d",&count);
    for (i = 1; i <= count; i++) {
      scanf("%d",&A[i]);
    }
    for ( i = count/2;i>=1; i--) {
      maxHeappify(i);
    }
    for ( i = 1; i <= count; i++) {
      printf(" %d",A[i]);
    }
    printf("\n");

  return 0;
}

Measured memory_bytes: 2548
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int l, r, d;
  cin >> l >> r >> d;
 
  int ans = 0;

  for (int i = l; i <= r; i++) {
    //cout << "debug:" << i << endl;
  	if((i % d) == 0) {
      ans++;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3616
#include <stdio.h>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <list>

#define MAX 1000000

using namespace std;

int main() {
	list<int> L;

	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (i == 0) L.push_back(x);
		else if (i % 2) {
			L.push_back(x);
		}
		else {
			L.push_front(x);
		}
	}

	if (n % 2 == 1) {
		for (list<int>::iterator it = L.begin(); it != L.end(); it++) {
			if (it != L.begin()) cout << " ";
			cout << *it;
		}
	}
	else {
		vector<int> V(MAX);
		int i = 0;
		for (list<int>::iterator it = L.begin(); it != L.end(); it++) {
			V[i] = *it;
			i++;
		}
		i--;
		while (i >= 0) {
			cout << V[i];
			if (i != 0) cout << " ";
			i--;
		}
		
	}
	cout << endl;
	return 0;
}


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

int main(){
  string S;
  string res;
  int a,b;
  cin >> S;
  std::string A;
  std::string B;
  A = A + S.at(0) + S.at(1);
  B = B + S.at(2) + S.at(3);
  a = atoi(A.c_str());
  b = atoi(B.c_str());
  if((a > 12 || a == 0) && b < 13 && 0 < b){
    res = "YYMM";
  }else if(0 < a && a < 13 && (b > 12 || b == 0)){
    res = "MMYY";
  }else if(0 < a && a < 13 && 0 < b && b < 13){
    res = "AMBIGUOUS";
  }else res = "NA";
  
  cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


int main(){
    ll n;
    cin >> n;

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

    vector<ll> ans(n,0);
    for(int i = 0; i < 60; i++){
        ll cnt = 0;
        for(int j = 0; j < n; j++){
            if(a[j] & (1LL<<i)){
                cnt++;
            }
        }
        for(int j = 0; j < n; j++){

            if(cnt%2==0){
                if(a[j]&(1LL<<i)){
                    ans[j] += 1LL<<i;
                }

            }else{
                if(a[j]&(1LL<<i)){
                    ;
                }else{
                    ans[j] += 1LL<<i;
                }
            }
        }
    }


    for(int i = 0; i < n; i++){
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;

}


Measured memory_bytes: 6344
import math

def dist(x, y):
    return math.sqrt(x**2+y**2)

# in_values = input()

l = list(map(int, input().split()))
n = l[0]
d = l[1]

count = 0
for _ in range(n):
    l = list(map(int, input().split()))
    if dist(l[0], l[1]) <= d:
        count+=1

print(count)

Measured memory_bytes: 8972
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,a,b) for(int i=a;i<=b;i++)
inline ll r() {
	ll x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	if(c=='-')f=-1,c=getchar();
	while(isdigit(c))x=x*10+c-'0',c=getchar();
	return x*f;
}
#define d r()
ll n,k,mx;
ll a[1000010];
bool check(ll m){
	ll cut=0;
	f(i,1,n){
		cut+=(a[i]%m==0)?(a[i]/m-1):(a[i]/m);
		if(cut>k)return 0;
	}
	return 1;
}
int main(){
	n=d,k=d;
	f(i,1,n)a[i]=d,mx=max(mx,a[i]);
	ll l=0,r=mx,mid;
	while(l+1<r){
		mid=(l+r)/2;
		if(check(mid))r=mid;
		else l=mid;
	}
	cout<<r;
	return 0;
}

Measured memory_bytes: 5152
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
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 ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
string dfs(ll n, string s) {
	if (n == 0) return s;
	ll Base = 1;
	while (Base * 26 < n) {
		Base *= 26;
	}
	rep(i, 26) {
		ll num = (i + 1) * Base;
		char c = 'a' + i;
		char b = 'a' + i - 1;
		if (num == n) return s + c;
		else if (num > n) return dfs(n - (num - Base), s + b);
		else if (i == 25) return dfs(n - (num - Base), s + b);
	}
}
const int N = 101010;
int main() {
	/*
	ll n;
	cin >> n;
	cout << dfs(n, "") << endl;
	*/
	int n;
	cin >> n;
	V a(n);
	VL cnt(N, 0);
	ll sum = 0;
	rep(i, n) {
		cin >> a[i];
		cnt[a[i]]++;
		sum += a[i];
	}
	int q;
	cin >> q;
	rep(qqq, q) {
		int b, c;
		cin >> b >> c;
		ll diff = c - b;
		sum += diff * (cnt[b]);
		cnt[c] += cnt[b];
		cnt[b] = 0;
		cout << sum << endl;
	}
	return 0;
}

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

int N, A[100009];

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> A[i];

	int sum = 0;
	for (int i = 2; i <= N - 1; i++) {
		if (A[i - 1] < A[i] && A[i] < A[i + 1]) sum++;
		if (A[i - 1] > A[i] && A[i] > A[i + 1]) sum++;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
import bisect
N = int(input())
alist = list(map(int, input().split()))
alist = [0] + alist
sumlist = []
# (j, wj)のリストを作る
for i in range(1,N+1):
    sumlist.append(i+alist[i])
sumlist.sort()
ans = 0
# 差と一致するものを探す
for i in range(1, N+1):
    diff = i - alist[i]
    if diff <= 0:
        continue
    i = bisect.bisect_left(sumlist, diff)
    j = bisect.bisect_right(sumlist, diff)
    ans += j - i
print(ans)

Measured memory_bytes: 32244
#include<stdio.h>

int main(void){
    long h,w;
    scanf("%ld %ld",&h,&w);
    if(h == 1l || w == 1l){
        printf("1");
        return 0;
    }
    printf("%lld",((long long)h*w+1ll)/(long long)2);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


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

	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	ll ans = 0;
	map<ll, ll> mp;
	rep(i, n) {
		ans += mp[-a[i] + i];
		mp[a[i] + i]++;
	}
	cout << ans << '\n';
}

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

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);
  int N;
  cin >> N;
  vector<int> x;
  int ans = 0;
  for (int n = 3; n <= N; n += 2) {
    int cnt = 1;
    for (int i = 1; i * i <= n; i++) {
      if (n % i == 0) {
        cnt++;
        x.push_back(i);
        if (i != 1 && i * i != n) {
          cnt++;
          x.push_back(n / i);
        }
      }
    }
    dumpv(n, cnt, x);
    x.clear();
    if (cnt == 8) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int n,a;
    cin>>n;
    std::deque<long long int> deq(n+1,0);
    std::deque<long long int> numbers;
    std::map<long long int, long long int> map;
    for (long long int i=0;i<n;i++) {
        cin>>a;
        numbers.emplace_back(a);
        if (deq[a]==0){
            deq[a]=1;
            map.emplace(a,1);
        } else {
            map.at(a)++;
        }
    }
    long long int sum=0;
    for (auto itr=map.begin();itr!=map.end();itr++) {
        long long int tmp=itr->second;
        sum+=(tmp*(tmp-1))/2;
    }
    for (long long int j=0;j<n;j++) {
        long long int tmp_sum=sum;
        long long int k=map.at(numbers[j]);
        tmp_sum-=(k*(k-1))/2;
        long long int hoge=k-1;
        tmp_sum+=(hoge*(hoge-1))/2;
        cout<<tmp_sum<<endl;
    }
}

Measured memory_bytes: 14336
#include <iostream>

using namespace std;

int main()
{
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	int ans = 0;
	if(a<k)
	{
		ans += a;
		k -= a;
		if(b<k)
		{
			k -= b;
			ans -= k;
		}
	}
	else
	{
		ans += k;
	}
	cout<<ans<<endl;
	return 0;
}

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

int64_t combination(int n, int r)
{
  if (n <= 0) return 0;
  if (n < r) return 0;
  else if (r == 0 || r == n) return 1;
  else if (r == 1) return n;
  
  int64_t prod_n = 1;
  int64_t prod_r = 1;
  
  for (int i = n; i > n - r; i --)
    prod_n *= i;
  for (int i = 2; i <= r; i ++)
    prod_r *= i;
  return (long double)prod_n / (long double)prod_r;
}

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  
  // 読み込み
  for (int i = 0; i < n; i ++)
    cin >> a.at(i);

  // ボールごとの数を数える
  vector<int> vote(n);
  for (int i = 0; i < n; i ++)
    vote.at(a.at(i) - 1)++;
  
  // 組み合わせの数をストア
  vector<int64_t> comb(n);
  for (int i = 0; i < n; i ++)
    comb.at(i) = combination(vote.at(i), 2);

  // さらに総数をストア
  int64_t comb_sum = 0;
  for (int i = 0; i < n; i ++)
    comb_sum += comb.at(i);
  
  // 1個除いた組み合わせの総数をストア
  vector<int64_t> comb_minus_one(n);
  for (int i = 0; i < n; i ++)
    comb_minus_one.at(i) = combination(vote.at(i) - 1, 2);

  // ボールの数を見ながら、組み合わせを求めて総和
  for (int i = 0; i < n; i ++)
  {
    int banned = a.at(i);
    int64_t num = comb_sum - comb.at(banned - 1) + comb_minus_one.at(banned - 1);
    if (num <= 0) num = 0;
    
    cout << num << endl;
  }

  return 0;
}

Measured memory_bytes: 7296
s = [gets.chomp]
q = gets.to_i
r = false  # true: 反転
q.times do
  t, f, c = gets.chomp.split
  if t == '1'
    r = !r
  else
    if f == '1'
      s = r ? [s, c] : [c, s]
    else
      s = r ? [c, s] : [s, c]
    end
  end
end
s = s.join
puts r ? s.reverse : s


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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

const ll MOD = 1000000007;
const int MAX_N = 100;
int n;
ll dp[MAX_N][4][4][4];

string chr = "ACGT";

int main()
{
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  forn(i,4) forn(j,4) forn(k,4) {
    if (chr[i] == 'A' && chr[j] == 'G' && chr[k] == 'C')
      continue;
    if (chr[i] == 'G' && chr[j] == 'A' && chr[k] == 'C')
      continue;
    if (chr[i] == 'A' && chr[j] == 'C' && chr[k] == 'G')
      continue;
    dp[2][i][j][k] = 1;
  }

  cin >> n;
  for (int i = 3; i < n; i++) {
    forn (j,4) forn (k,4) forn (l,4) forn (c,4) {
      if (chr[c] == 'C') {
        if (chr[k] == 'A' && chr[l] == 'G') continue;
        if (chr[k] == 'G' && chr[l] == 'A') continue;
        if (chr[j] == 'A' && chr[l] == 'G') continue;
        if (chr[j] == 'A' && chr[k] == 'G') continue;
      } else if (chr[c] == 'G') {
        if (chr[k] == 'A' && chr[l] == 'C') continue;
      }
      dp[i][k][l][c] = (dp[i][k][l][c]+dp[i-1][j][k][l]) % MOD;
    }
  }

  ll res = 0;
  forn(i,4) forn(j,4) forn(k,4) {
    res = (res + dp[n-1][i][j][k]) % MOD;
  }

  cout << res << "\n";


  return 0;
}


Measured memory_bytes: 256
// #line 2 "weighted_union_find.hpp"
#ifndef Weighted_union_find_hpp
#define Weighted_union_find_hpp
#include <cassert>
#include <cstddef>
#include <vector>

template <class Abel>
class weighted_union_find
{
    size_t n;
    std::vector<int> link;
    std::vector<Abel> diff_weight;

public:
    explicit weighted_union_find(size_t _n) : n(_n), link(n, -1), diff_weight(n) {}

    size_t find(const size_t x)
    {
        assert(x < n);
        if(link[x] < 0) return x;
        const size_t root = find(link[x]);
        diff_weight[x] += diff_weight[link[x]];
        return link[x] = root;
    }

    size_t size() const { return n; }
    size_t size(const size_t x) { return -link[find(x)]; }

    Abel weight(size_t x) { return find(x), diff_weight[x]; }

    Abel diff(size_t x, size_t y) { return weight(y) - weight(x); }

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

    bool unite(size_t x, size_t y, Abel w)
    {
        w += weight(x) - weight(y);
        x = find(x), y = find(y);
        if(x == y) return false;
        if(link[x] > link[y]) std::swap(x, y), w = -w;
        link[x] += link[y], link[y] = x;
        diff_weight[y] = w;
        return true;
    }
}; // class weighted_union_find

#endif

#include <iostream>

main()
{
    using namespace std;
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n,m; cin>>n>>m;
    weighted_union_find<long long> uf(n);
    while(m--)
    {
        int l,r,d; cin>>l>>r>>d;
        --l,--r;
        if(uf.same(l,r))
        {
            if(uf.diff(l,r)!=d)
            {
                cout << "No" << "\n";
                return 0;
            }
        }
        else
        {
            uf.unite(l,r,d);
        }
    }
    cout << "Yes" << "\n";
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};


bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int N,res=9999999,A[100001],cnt=1;
  cin >> N;
  REP(i,N)cin >> A[i];
  bool up=true,des=false;
  REP(i,N-1){
    if(A[i] != A[i+1] && !des){
      des = true;
      if(A[i] > A[i+1])
        up = false;
      else
        up = true;
    }else if(up && des){
      if(A[i] > A[i+1]){
        des = false;
        cnt++;
      }
    }else if(!up && des){
      if(A[i] < A[i+1]){
        des = false;
        cnt++;
      }
    }
  }
  cout << min(res,cnt) << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

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

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
const int MOD = 1000000007;
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


Measured memory_bytes: 640
#include <iostream>
#include<stdio.h>
#define MAXSIZE 101
#define PI 3.141592653589
using namespace std;
int main(){

  int n,m,l;
  std::cin >> n>>m>>l;
  int a[MAXSIZE][MAXSIZE]={0};
  int b[MAXSIZE][MAXSIZE]={0};
  long long int c[MAXSIZE][MAXSIZE]={0};

  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      std::cin >> a[i][j];
    }
  }

  for(int i=0;i<m;i++){
    for(int j=0;j<l;j++){
      std::cin >> b[i][j];
    }
  }

  for(int i=0;i<n;i++){
    for(int j=0;j<l;j++){
      for(int k=0;k<m;k++){
        c[i][j]+=a[i][k]*b[k][j];
      }
    }
  }

  for(int i=0;i<n;i++){
    for(int k=0;k<l-1;k++){
      std::cout << c[i][k] << " ";
    }
    std::cout << c[i][l-1] << '\n';

  }


}

Measured memory_bytes: 3256
#include <stdio.h>
#include <string.h>

#define N 10

int main() {
	static char s[N + 1], t[N + 1];
	int n, m, i;

	scanf("%s", s);
	n = strlen(s);
	m = 0;
	for (i = 0; i < n; i++) {
		if (s[i] != 'B')
			t[m++] = s[i];
		else {
			m = m > 0 ? m - 1 : 0;
			t[m] = '\0';
		}
	}
	printf("%s\n", t);
	return 0;
}


Measured memory_bytes: 128
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
dic=defaultdict(int)

for i in range(1,101):
    for j in range(1,101):
        for k in range(1,101):
            dic[i**2+j**2+k**2+i*j+j*k+k*i]+=1

for i in range(n):
    print(dic[i+1])

Measured memory_bytes: 80012
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;
 
#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int dp[100001];
int p[11];
vector<char> d;
int main() {
  int a, b;
  cin >> a >> b;
  a--;
  b--;
  cout << a * b << endl;
}


Measured memory_bytes: 256