akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <string>
using namespace std;
int main(void){
	int a,b = 0,c = 0;
	string x;
	string y;
	cin>>a;
	for(int i = 0;i<a;i++){
		cin>>x>>y;
		if(x == y) c += 1,b += 1;
		else if(x>y) b += 3;
		else  if(x<y) c += 3;
		
		
	}
	cout<<b<<" "<<c<<endl;
	return 0;
}


Measured memory_bytes: 3160
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
using namespace std;
int main(){
    int A,B;
    cin >> A >> B;
    if(A<13){
        if(6<=A){
            cout << B/2 << endl;
        }else{
            cout << 0 << endl;
        }
    }else{
        cout << B << endl;
    }
    
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,n) for(int i=1; i<(n); i++)
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
#define int long long
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;
using namespace std;
long long h[10000010],x[10000010];
signed main(){
      
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string s1,s2,s3;
  cin>>s1>>s2>>s3;

  cout<<(char)(s1[0]-('a'-'A'))<<(char)(s2[0]-('a'-'A'))<<(char)(s3[0]-('a'-'A'))<<'\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <utility>
#include <queue>

using namespace std;
typedef long long signed int ll;

constexpr int inf = INT32_MAX / 2;

class djikstra {
private:
	ll* d = nullptr;
	map<int, map<int, ll>> p;
	int sz = 0;
public:
	void add_path(int from, int to, ll cost) {
		p[from][to] = cost;
	}
	void compute(int from,int nodes) {
		sz = nodes;
		if (d != nullptr) delete d;
		d = new ll[nodes];
		auto cmp = [this](int a, int b) {return d[a] > d[b]; };
		priority_queue <ll, vector<ll>, decltype(cmp)> q(cmp);
		for (int i = 0; i < nodes; i++) d[i] = INT64_MAX / 2;
		d[from] = 0;
		q.push(from);
		while (!q.empty()) {
			for (auto& e : p[q.top()]) {
				if (d[e.first] > d[q.top()] + e.second) {
					d[e.first] = d[q.top()] + e.second;
					q.push(e.first);
				}
			}
			q.pop();
		}
	}
	ll operator[](int node) {
		if (node >= sz) return INT64_MAX/2;
		return d[node];
	}
};

int main() {
	int n,ch;
	cin >> n >> ch;
	vector<vector<pair<int, int>>> st;
	st.resize(ch);
	for (int i = 0; i < n; i++) {
		int s, t, c;
		cin >> s >> t >> c;
		st[c-1].emplace_back(s, t);
	}
	vector<pair<int,int>> ev;
	for (auto& e : st) {
		sort(e.begin(), e.end());
		for (auto itr = e.begin(); e.end() - itr > 1; itr++) {
			if (itr->second != (itr + 1)->first) {
				ev.emplace_back(itr->first,-1);
				ev.emplace_back(itr->second, 1);
			}
			else (itr + 1)->first = itr->first;
		}
		if (e.size() > 0) {
			ev.emplace_back((e.end() - 1)->first, -1);
			ev.emplace_back((e.end() - 1)->second, 1);
		}
	}
	sort(ev.begin(), ev.end());
	int cur = 0, mx = 0;
	for (auto& e : ev) {
		cur -= e.second;
		mx = max(mx, cur);
	}
	cout << mx << endl;
}


Measured memory_bytes: 3572
N = int(input())

n = N
a = []
while n % 2 == 0:
    a.append(2)
    n //= 2
f = 3
while f * f <= n:
    if n % f == 0:
        a.append(f)
        n //= f
    else:
        f += 2
if n != 1:
    a.append(n)

pset = list(set(a))

#print(a)
#print(pset)

M = len(pset)
number = 0

for i in range(M):
    p = pset[i]
    c = a.count(p)
    if c >= 1 and c<3:
        number += 1
    elif c >= 3 and c<6:
        number += 2
    elif c >= 6 and c<10:
        number += 3
    elif c >= 10 and c<15:
        number += 4
    elif c >= 15 and c<21:
        number += 5
    elif c >= 21 and c<28:
        number += 6
    elif c >= 28 and c<36:
        number += 7
    elif c >= 36 and c<45:
        number += 8
    elif c >= 45 and c<55:
        number += 9
    else:
        number += 10

print(number)


Measured memory_bytes: 9256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>

ll n, ans = 1, s[110000], t[110000];
int main() {
	cin >> n;
	t[0] = 3;
	REP(i, n) cin >> s[i];
	REP(i, n)s[i]++;
	REP(i, n) {
		ans *= t[s[i] - 1] - t[s[i]];
		t[s[i]]++;
		ans %= MOD;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1792
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

public class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.call(in,out);
        out.close();
    }

    static class TaskA {
        public void call(InputReader in, PrintWriter out) {
           String s ,a;
           int count=0;
           s = in.next();
           a = in.next();
            for (int i = 0; i <s.length(); i++) {
                if(s.charAt(i)!=a.charAt(i)){
                    count++;
                }
            }
            out.println(count);





        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }


    }
}

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

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

typedef vector<int> vint;
typedef long long ll;

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

  int x, y;
  cin >> x >> y;
  rep(i, x + 1) {
    int t = i;
    int k = x - i;
    if (k * 4 + t * 2 == y) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3648
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 100000007
#define SIZE 10005
#define PI 	3.14159265358979323846

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,c;
    cin >> n >> m >> c;
    int result=0;
    int b[10000];
    REP(i,m)cin >> b[i];
    REP(i,n){
        int ans = c;
        REP(j,m){
            int input;
            cin >> input;
            ans += input*b[j];
        }
        if(ans>0)result++;
    }
    cout << result << endl;
}


Measured memory_bytes: 256
/*
[abc141] D - Powerful Discount Tickets
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()

const int MAX_N = 1e5;

int N, M;
int A[MAX_N];

ll solve() {
    priority_queue<int> q;
    for (int i = 0; i < N; i++) {
        q.push(A[i]);
    }

    for (int i = 0; i < M; i++) {
        int a = q.top();
        q.pop();
        q.push(a / 2);
    }

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ans += q.top();
        q.pop();
    }

    return ans;
}

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

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 1276
#include<stdio.h>

int main(){
  int a,b,max,d=1,c,e;
  scanf("%d %d",&a,&b);
  if(a<b){
    e=a;
    a=b;
    b=e;
  }
  c=a%b;
  if(c==0){
    max=a;
  }else if(b<c){
    for(d=1;d<=b;d++){
      if(b%d==0 && c%d==0){
	max=d;
      }
    }
  }else{
    for(d=1;d<=c;d++){
      if(b%d==0 && c%d==0){
	max=d;
      }
    }
  }
  printf("%d\n",max);
}



Measured memory_bytes: 2108
/**
 * Contest : AtCoder Beginner Contest 160
 * Contest URL : https://atcoder.jp/contests/abc160
 * Problem : A - Coffee
 * Problem URL : https://atcoder.jp/contests/abc160/tasks/abc160_a
 */

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair < int, int >;

// This section is for Policy Based Data Structure, more precisely Ordered Set.
// All Functions of set works here, in addition we have order_of_key() and find_by_order() function. find_by_order() returns iterator
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<functional>
using namespace __gnu_pbds;

// 1. Custom Set
template < class T, class COMP >
using custom_set = tree < T, null_type, COMP, rb_tree_tag, tree_order_statistics_node_update >;

// 2. Ordered Set
template < class T >
using ordered_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;

// 3. Ordered Multi Set
// For storing multiple occurance of same value we need to use pair. In pair first value is our key and second is useless count variable.
// order_of_key(make_pair(key, 0)) returns first occurance of a value, order_of_key(make_pair(key, INT_MAX)) returns last occurance.
template < class T >
using ordered_multiset = tree < pair < T, int >, null_type, less < pair < T, int > >, rb_tree_tag, tree_order_statistics_node_update >;

// 4. Ordered Map
template < class T, class U >
using ordered_map = tree < T, U, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
// Policy End

void solve() {
	string s;
	cin >> s;
	if (s.size() == 6 && s[2] == s[3] && s[4] == s[5]) {
		cout << "Yes" << endl; //""
	} else {
		cout << "No" << endl; //""
	}
}

int main() {
	ios_base::sync_with_stdio (false);
	cin.tie (0); cout.tie (0);
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}



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

int main() {
  string S; cin>>S;
  int cnt;
  if(S=="SSS") cnt=0;
  if(S=="RRR") cnt=3;
  if(S=="RSS" || S=="SRS" || S=="SSR" || S=="RSR") cnt=1;
  if(S=="RRS" || S=="SRR") cnt=2;
  cout << cnt << endl;
}


Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int a = scanner.nextInt(), b = scanner.nextInt(), c = scanner.nextInt();
			boolean result = false;
			for (int i = a; i < lcm(a, b); i += a) {
				if (c == i % b) {
					result = true;
					break;
				}
			}
			System.out.println(result ? "YES" : "NO");
		}
	}

	/**
	 * @param a
	 * @param b
	 * @return aとbの最小公倍数
	 */
	private static int lcm(int a, int b) {
		int temp;
		long c = a;
		c *= b;
		while ((temp = a % b) != 0) {
			a = b;
			b = temp;
		}
		return (int) (c / b);
	}
}


Measured memory_bytes: 35736
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 5000000
using namespace std;
typedef int hp[MAXN+5];
char str[MAXN+5];
int sum=0;
hp N,d;
void Str_To_Hp(char *s,hp &x)
{
	int len=strlen(s);
	for(int i=0;i<len;i++)
		x[len-i]=s[i]-'0';
	x[0]=len;
}
void Clear(hp &x)
{
	for(int i=x[0];i>=0;i--)
		x[i]=0;
}
void Add(hp &a,int b)
{
	int len=a[0];
	sum-=a[1];
	a[1]+=b;
	for(int i=1;true;i++)
	{
		sum+=a[i]%10;
		if(a[i]>=10)
		{
			sum-=a[i+1];
			a[i+1]+=a[i]/10;
			a[i]%=10;
		}
		else
		{
			len=max(i,len);
			break;
		}
	}
	len++;
	while(len>1&&a[len]==0)
		len--;
	a[0]=len;
}
void Mul(hp a,int b,hp &c)
{
	Clear(d);
	int len=a[0];
	for(int i=1;i<=len;i++)
	{
		d[i]+=a[i]*b;
		d[i+1]+=d[i]/10;
		d[i]%=10;
	}
	len++;
	while(d[len])
	{
		d[len+1]+=d[len]/10;
		d[len]%=10;
		len++;
	}
	while(len>1&&d[len]==0)
		len--;
	d[0]=len;
	for(int i=0;i<=len;i++)
		c[i]=d[i];
}
bool Check(int k)
{
	int sum=0;
	for(int i=1;i<=N[0];i++)
		sum+=N[i];
	if(sum>9*k)
		return false;
	return true;
}
int main()
{
	scanf("%s",str);
	Str_To_Hp(str,N);
	Mul(N,9,N);
	sum=0;
	for(int i=1;i<=N[0];i++)
		sum+=N[i];
	for(int k=1;true;k++)
	{
		Add(N,9);
		if(sum<=9*k)
		{
			printf("%d\n",k);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 8320
import re

s_s = []

while True:
    try:
        d = input()
        reg = re.compile('\d+')

        for line in d.splitlines():
            ma = reg.findall(line)
        
        ma_int = [int(n) for n in ma]
        
        s = sum(ma_int)
        s_s.append(s)
        
    except EOFError:
        break

print(sum(s_s))


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

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

const int N = 5e3 + 53;
int p[N], c[N];

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

	int n, k;
	cin>>n>>k;
	for(int i = 1; i <= n; i++){
		cin>>p[i];
	}
	for(int i = 1; i <= n; i++){
		cin>>c[i];
	}
	ll ans = -2e18;
	for(int i = 1; i <= n; i++){
		int v = i;
		vector<ll> vec;
		while(p[v] != i){
			vec.push_back(c[v]);
			v = p[v];
		}
		vec.push_back(c[v]);
		int len = vec.size();
		for(int i = 1; i < len; i++){
			vec[i] += vec[i - 1];
		}
		for(int i = 0; i < len; i++){
			if(i == k)break;
			ll tmp = vec[i] + ((k - i - 1)/len)*max(vec.back(), 0LL);
			ans = max(ans, tmp);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3804
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int merge(vector<int>& as, int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    vector<int> ls(n1 + 1), rs(n2 + 1);
    for (int i = 0; i < n1; i++) {
        ls[i] = as[left + i];
    }
    for (int i = 0; i < n2; i++) {
        rs[i] = as[mid + i];
    }
    ls[n1] = rs[n2] = INT_MAX;
    for (int i = 0, j = 0, k = left; k < right; k++) {
        if (ls[i] <= rs[j]) {
            as[k] = ls[i++];
        } else {
            as[k] = rs[j++];
        }
    }
    return right - left;
}

int merge_sort(vector<int>& as, int left, int right) {
    if (left + 1 >= right) {
        return 0;
    }
    int mid = (left + right) / 2;
    int ret = 0;
    ret += merge_sort(as, left, mid);
    ret += merge_sort(as, mid, right);
    ret += merge(as, left, mid, right);
    return ret;
}

int main() {
    int n;
    cin >> n;
    vector<int> as(n);
    for (auto& a : as) {
        cin >> a;
    }
    int comparison = merge_sort(as, 0, n);
    for (int i = 0; i < n; i++) {
        if (i > 0) {
            cout << " ";
        }
        cout << as[i];
    }
    cout << endl;
    cout << comparison << endl;
}

Measured memory_bytes: 5056
# A - Simple Calculator
x,y = map(int,input().split())

# 初めと終わりに B を押すとき
ans1 = -y - (-x) + 2
# 初めだけ B を押すとき
ans2 = y - (-x) + 1
# 終わりだけ B を押すとき
ans3 = -y - x + 1
# B を押さないとき
ans4 = y - x

ans = [ans1,ans2,ans3,ans4]
ans = [a for a in ans if a > 0]
ans = min(ans)
print(ans)

Measured memory_bytes: 9184
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = (1ll<<31)-1;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w,a,b;
    cin >> h >> w >> a >> b;
    string s1 = "",s2 = "";
    rep(i,a){
        s1 += '0';
        s2 += '1';
    }
    rep(i,w-a){
        s1 += '1';
        s2 += '0';
    }
    rep(i,b) PRINT(s1);
    rep(i,h-b) PRINT(s2);
}


Measured memory_bytes: 1280
use proconio::input;
use std::cmp;

fn main() {
    input! {
        n: usize,
        k: usize,
    }

    let max = 510000;
    let m = 1000000007;

    let mut fac = vec![0; max];
    let mut finv = vec![0; max];
    let mut inv = vec![0; max];

    let mut ans = 0;
    com_init(&mut fac, &mut finv, &mut inv, max, m);
    for i in 0..cmp::min(n, k+1) {
        ans += com(n, i, &fac, &finv, m) * com(n - 1, n - i - 1, &fac, &finv, m) % m;
        ans %= m;
    }
    println!("{}", ans);
}

fn com_init(
    fac: &mut Vec<isize>,
    finv: &mut Vec<isize>,
    inv: &mut Vec<isize>,
    max: usize,
    m: isize,
) {
    fac[0] = 1;
    fac[1] = 1;
    finv[0] = 1;
    finv[1] = 1;
    inv[0] = 0;
    inv[1] = 1;

    let mut i = 2;
    while i < max {
        fac[i] = fac[i - 1] * i as isize % m;
        inv[i] = m as isize - inv[m as usize % i] * (m / i as isize) % m;
        finv[i] = finv[i - 1] * inv[i] % m;
        i += 1;
    }
}

fn com(n: usize, k: usize, fac: &Vec<isize>, finv: &Vec<isize>, m: isize) -> isize {
    if n < k {
        return 0;
    }
    fac[n] * (finv[k] * finv[n - k] % m) % m
}


Measured memory_bytes: 13932
use std::io;
use std::str::FromStr;

fn input_tuple() -> (usize, usize) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<usize> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn main() {
    let (n, m) = input_tuple();
    let mut ans = vec![10; n];
    for i in 0..m as usize {
        let (s, c) = input_tuple();
        if ans[s - 1] != 10 && ans[s - 1] != c {
            println!("-1");
            return;
        }
        ans[s-1] = c;
    }
    let mut flag = true;
    if n == 1 && m == 0 {
        println!("0");
        return;
    }
    for i in 0..n {
        if flag {
            if ans[i] == 10 {
                ans[i] = 1;
            }
            flag = false;
            if ans[i] == 0 && n != 1 {
                println!("-1");
                return;
            }
        } else {
            if ans[i] == 10 {
                ans[i] = 0;
            }
        }
    }
    for a in ans {
        print!("{}", a);
    }
    println!();
}


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

int main(){
  int n;
  cin>>n;
  bool b=0;
  int x[n];
  for(int i=0;i<n;i++) cin>>x[i];
  sort(x,x+n);
  for(int i=0;i<n;i++)
    if(x[i]==x[i+1]){
      b=1;
      break;
    }
      if(b==0)
    cout<<"YES"<<endl;
      else
    cout<<"NO"<<endl;
}


Measured memory_bytes: 4428
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

if __name__ == '__main__':
    a,b, c = map(str ,input().split())
    ans = 0
    if b == "+":
        ans = int(a)+int(c)
    else:
        ans = int(a)-int(c)

    print(ans)



Measured memory_bytes: 3828
#include<bits/stdc++.h>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
	  long long  i,j,n,m;
     int tc;
     
     	long long  odd=0,even=0,k;
      
     		 cin>>n;
             long long a,b,c;
             for(i=1;i<=n;i++)
             {
             	for(j=1;j<=n;j++)
             	{
             		for( k=1;k<=n;k++)
             		{
             			odd+=__gcd(i,__gcd(j,k));
					 }
				 }
			 }
			 cout<<odd<<endl;
          
	return 0;
}

Measured memory_bytes: 3636
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws Exception {

		Scanner sc = new Scanner(System.in);
		boolean open = false;
		int n = sc.nextInt();
		Set<String> key = new HashSet<String>();
		for (int i = 0; i < n; i++) {
			key.add(sc.next());
		}
		int m = sc.nextInt();
		// 開錠された時は、"Opened by "の後に続けてIDを、
		//
		// 施錠された時は、"Closed by "の後に続けてIDを、
		//
		// IDが登録されていないものだった場合は"Unknown "の後に続けてIDを それぞれ1行に出力せよ。
		for (int i = 0; i < m; i++) {
			String str = sc.next();
			if (key.contains(str)) {
				if (open) {
					System.out.println("Closed by " + str);
				} else {
					System.out.println("Opened by " + str);
				}
				open = !open;
			} else {
				System.out.println("Unknown " + str);
			}
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

void solve() {
	int n;
	cin >> n;
	
	vi a(n), b(n);
	for(int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}	
	
	sort(all(a));
	sort(all(b));
	
	if(n % 2) {
		cout << b[n / 2] - a[n / 2] + 1 << endl; 
	} else cout << ((b[n / 2 - 1] + b[n / 2]) - (a[n / 2 - 1] + a[n / 2])) + 1 << endl;  
}

int main(){
	ios_base::sync_with_stdio(false);
	solve();
    return 0;
}

Measured memory_bytes: 4736
#include <cmath>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
#define REP(i,n) for(int i = 0; i < n; i++)

long long calcLucasNumber(int n){
    if(n == 0)  
        return 2;
    else if(n == 1) 
        return 1;
    else 
        return calcLucasNumber(n-1) + calcLucasNumber(n-2);
}

int main(void)
{
    int N;
    cin >> N;
    long long L[87] = {0};
    L[0] = 2; 
    L[1] = 1;
    for(int i = 2; i <= N; i++){
        L[i] = L[i-1] + L[i-2];
    }

    cout << L[N] << endl;
    

    // cout << calcLucasNumber(N) << endl;
    return 0;
}


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

int main () {
    int H , N;
    cin >> H >> N;
    vector <int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }
    int sum = 0;
    int i = 0;
    while(i < N){
        sum = sum + A.at(i);
        i++; 
    }

    if(sum >= H){
        cout << "Yes" << endl;
    }

    else{
        cout << "No" << endl;
    }

}

Measured memory_bytes: 640
n,a,b = list(map(int, input().split()))

if (a+b) == 0:
  print(0)
else:
  trial_num = n // (a + b)
  amari = n % (a + b)
  
  if a == 0:
    print(0)
  else:
    if a <= amari:
      print(trial_num*a + a)
    else:
      print(trial_num*a + amari)

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,m;
    cin >> n >> m;
    if(m==n) cout << "Yes" <<"\n";
    else cout << "No" <<"\n";
    



}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int N, i, j,ans = 0;
    int d[100];
    
    scanf("%d", &N);
    
    for(i = 0; i < N; i++){
        scanf("%d", &d[i]);
    }
    
    for(i = 0; i < N; i++){
        for(j = 0; j < i; j++){
            scanf("%d", &d[j]);
            ans = ans + (d[i] * d[j]);
        }
    }
    printf("%d\n", ans);
    
}


Measured memory_bytes: 1732
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)
#define rrep(i,x) for(int i=(int)x-1;i>=0;--i)
#define rrep1(i,x) for(int i=(int)x;i>=1;--i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}

constexpr int inf = 1e9;
constexpr ll linf = 3e18;
constexpr double eps = 1e-9;

string S;
string A[] = {
    "dream",
    "dreamer",
    "erase",
    "eraser",
};

int memo[100010];

bool dfs(int i)
{
    if (i == S.length()) return true;
    if (~memo[i]) return memo[i];

    bool res = false;

    rep(j, 4) {
        if (S.substr(i, A[j].length()) == A[j]) {
            res |= dfs(i + A[j].length());
        }
    }

    return memo[i] = res;
}

signed main()
{
    cin >> S;
    memset(memo, -1, sizeof memo);

    cout << (dfs(0)?"YES":"NO") << endl;
}


Measured memory_bytes: 2432
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		String s = sc.next();
		int length = s.length();
		if(a>=1 && a<=5 && b>=1 && b<= 5) {
			if((a+b+1) != length) {
				System.out.println("No");
				return;
			}else {
				char c = s.charAt(a);
				if(c != '-') {
					System.out.println("No");
					return;
				}else {
					
					String[] str = s.split("-");
					if(str.length==2) {
						String A = str[0];
						String B = str[1];
						for(int i=0; i<a; i++) {
							char t = A.charAt(i);
							int tmp = Integer.valueOf(t);
							if(tmp<48 || tmp>57) {
								System.out.println("No");
								return;
							}
						}
						for(int i=0; i<b; i++) {
							char t = B.charAt(i);
							int tmp = Integer.valueOf(t);
							if(tmp<48 || tmp>57) {
								System.out.println("No");
								return;
							}
						}
						System.out.println("Yes");
						return;
					}else {
						System.out.println("No");
						return;
					}
				}
			}
		}
		

		
	
	}
}


Measured memory_bytes: 25044
#!/usr/bin/env python3
import sys
import heapq
from collections import defaultdict
INF = float("inf")


class Graph(object):
    def __init__(self, N):
        self.N = N
        self.E = defaultdict(list)

    def add_edge(self, s, t, w):
        self.E[s].append([t, w])
        self.E[t].append([s, w])


def shortestPath(g: Graph, s: int):
    dist = [INF]*g.N
    dist[s] = 0

    prev = [None]*g.N
    Q = []
    heapq.heappush(Q, (dist[s], s))

    while len(Q) > 0:
        _, u = heapq.heappop(Q)
        for v, w in g.E[u]:
            if dist[v] > dist[u] + w:
                dist[v] = dist[u] + w
                prev[v] = u
                heapq.heappush(Q, (dist[v], v))
    return dist, prev


def solve(N: int, M: int, a: "List[int]", b: "List[int]", c: "List[int]"):

    g = Graph(N)
    flag = {}
    for aa, bb, cc in zip(a, b, c):
        g.add_edge(aa-1, bb-1, cc)

        if aa > bb:
            aa, bb = bb, aa
        flag[(aa-1, bb-1)] = False

    for i in range(N-1):
        dist, prev = shortestPath(g, i)

        for j, p in enumerate(prev):
            if p == None:
                continue
            a, b = p, j
            if b < a:
                a, b = j, p
            flag[(a, b)] = True
    tot = 0
    for k in flag:
        if flag[k] == False:
            tot += 1
    print(tot)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int()] * (M)  # type: "List[int]"
    b = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, M, a, b, c)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3700
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <algorithm>
#include <map>
using namespace std;


int main()
{
    uint x, a;
    cin >> x >> a;
    if (x < a) {
        cout << "0" << endl;
    } else {
        cout << "10" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
A,B,C,X,Y = map(int,input().split())

res = A*X +B*Y

for i in range(0,max(X,Y)+1):
  cand = 2*i*C + max(0,X-i)*A + max(0,Y-i)*B
  res = min(res,cand)
print(res)






Measured memory_bytes: 8996
from fractions import gcd
from functools import reduce
n = int(input())
t = []


for _ in range(n):
    t.append(int(input()))


def lcm(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(*numbers):
    return reduce(lcm, numbers)


print(lcm_list(*t))


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

int main() {
  
  int N; cin >> N; vector<string> blueCard(N);
  
  for (int i = 0; i < N; i++) cin >> blueCard.at(i);
  
  int M; cin >> M; vector<string> redCard(M);
  
  for (int i = 0; i < M; i++) cin >> redCard.at(i);
  
  int count = 0;
  
  for (int i = 0; i < N; i++) {
    int tmp = 0;
    for (int j = 0; j < N; j++) {
      if (blueCard.at(i) == blueCard.at(j)) tmp++;
    }
    for (int j = 0; j < M; j++) {
      if (blueCard.at(i) == redCard.at(j)) tmp--;
    }
    count = max(count, tmp);
  }
  
  cout << count << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define int long long

using namespace std;

signed main(){
    int n, sum, a;
    cin >> sum >> n;

    for(int i=0;i<n;i++){
        cin >> a;
        sum-=a;
    }

    if(sum<0) cout << "-1" << endl;
    else cout << sum << endl;
    
    return 0;
}       

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include <stdio.h>
#include <ios>     
#include <iomanip> 

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

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

void warshallFloyd(int N);
vector<vector<int>> d;
const int INF = 1e9;

void warshallFloyd(int N){
  for(int k=0; k<N; k++){//経由する頂点
    for(int i=0; i<N; i++){//スタート
      for(int j=0; j<N; j++){//ゴール
        d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
      }
      //cout << d[i][j] << " ";
    }
    //cout << endl;
  }
  //return;
}

int main()
{
  //練習のため入力形式を変えて2回
  //input
  inputInt3(N,M,R);
  vector<int> r(R,0);
  for(int i=0; i<R; i++){
    cin >> r[i];
    r[i] --;
  }
  
  /*vector<vector<pair<int,int>>> graph(M); //graph[from][i番目の辺].<to,cost>
  for(int i=0; i<M; i++){
    int fr, to, cost;
    cin >> fr >> to >> cost;
    fr --; to --;
    graph[fr].pb(mp(to,cost));
    graph[to].pb(mp(fr,cost));
  }
  
  //vector<vector<long>> d(N,vector<long>(N,INF));
  d.assign(N,vector<long>(N,INF));
  for(int i=0; i<N; i++){
    d[i][i] = 0;
  }
  for(int i=0; i<N; i++){
    for(auto edge:graph[i]){
       d[i][edge.fi] = edge.se;
    }
  }*/
  
  d.assign(N,vector<int>(N,INF));//初期化されていたのを確認。
  
  
  for(int i=0; i<N; i++){//各々の街について
    d[i][i] = 0;
  }
  
  for(int i=0; i<M; i++){//各々の道について
    int from, to, time;
    cin >> from >> to >> time;
    from --; 
    to --;
    d[from][to] = min(d[from][to],time);//多重辺対策
    d[to][from] = min(d[to][from],time);//多重辺対策
  }
  
  //main
  
  warshallFloyd(N);
  
  //確認用
  /*for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      cout << d[i][j] << " ";
    }
    cout << endl;
  }*/
  
  // output
  long ans = INF;
  
  sort(r.begin(),r.end());
  
  while(next_permutation(r.begin(), r.end()) ){
    long distance = 0;
    for(int i=0; i<R-1; i++){
      distance += d[r[i]][r[i+1]];
    }
    ans = min(ans,distance);
  }
  
  output(ans);
    
  return 0;
}

Measured memory_bytes: 384
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll=long long;

vector<int> dijkstra(const vector<vector<int>>& edges, int start){
	const int N=edges.size();
	vector<int> d(N, 1e6);
	queue<pair<int,int>> q;
	d[start]=0;
	q.push({0,start});
	while(!q.empty()){
		int befd,pos;
		tie(befd,pos)= q.front();
		q.pop();
		for(auto next:edges[pos]){
			if(befd+1>=d[next])continue;
			d[next]=befd+1;
			q.push({befd+1, next});
		}
	}
	return d;
}

int main()
{
	int N,u,v;
	cin>>N>>u>>v;
	u--;v--;
	vector<vector<int>> edges(N);
	rep(i,N-1){
		int a,b;
		cin>>a>>b;
		a--;b--;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	auto taka = dijkstra(edges, u);
	auto aoki = dijkstra(edges, v);

	int res = 1e6;
	rep(i, N)if(taka[i]==aoki[i]){
		res=min(res, taka[i]);
	}
	if(res==1e6)res=0;
	rep(i,N)if(taka[i]<aoki[i]){
		res=max(res,aoki[i]-1);
	}
	cout<<res<<endl;
	/*
	for(auto num:taka)cout<<num<<" ";
	cout<<endl;
	for(auto num:aoki)cout<<num<<" ";
	cout<<endl;
	*/
	
	return 0;
}


Measured memory_bytes: 6784
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector < int >
#define vll vector < long long >
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int n;
int a[110];

ll solve(){
    cin >> n;
    int sum = 0;
    for(int i = 0, x; i < n; ++i){
        cin >> a[i];
        sum += a[i];
    }
    if(sum % 10) return sum;

    sort(a, a + n);
    for(int i = 0; i < n; ++i){
        if(a[i] % 10 != 0){
            sum -= a[i];
            break;
        }
    }
    return sum % 10 ? sum : 0;
}

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

    cout << solve() << "\n";
    
    return 0;
}


Measured memory_bytes: 256
fn main() {
    let mut buf = String::new();
    let _ = std::io::stdin().read_line(&mut buf).ok();
    let mut buf = buf.split_whitespace();
    let n: usize = buf.next().unwrap().parse().unwrap();
    let m: usize = buf.next().unwrap().parse().unwrap();
    let mut g = vec![vec![];n];
    for _ in 0..m {
        let mut buf = String::new();
        let _ = std::io::stdin().read_line(&mut buf).ok();
        let mut buf = buf.split_whitespace();
        let j: usize = buf.next().unwrap().parse().unwrap();
        let k: usize = buf.next().unwrap().parse().unwrap();
        g[k].push(j);
        g[j].push(k);
    }
    let mut colors = vec![-1;n];
    let mut color = 0;
    for i in 0..n {
        let mut s = Vec::new();
        if colors[i] == -1 {
            s.push(i);
            while s.len() != 0 {
                let p = s.pop().unwrap();
                colors[p] = color;
                for j in &g[p] {
                    if colors[*j] == -1 {
                        s.push(*j);
                    }
                }
            }
        color += 1;
        }
    }
    //println!("{:?}",colors);
    let mut buf = String::new();
    let _ = std::io::stdin().read_line(&mut buf).ok();
    let n: usize = buf.trim().parse().unwrap();
    for _ in 0..n {
        let mut buf = String::new();
        let _ = std::io::stdin().read_line(&mut buf).ok();
        let mut buf = buf.split_whitespace();
        let j: usize = buf.next().unwrap().parse().unwrap();
        let k: usize = buf.next().unwrap().parse().unwrap();
        if colors[j] == colors[k] {
            println!("yes");
        } else {
            println!("no");
        }
    }
}
//fn main() {
//    let mut buf = String::new();
//    let _ = std::io::stdin().read_line(&mut buf).ok();
//    let mut buf = buf.split_whitespace();
//    let n: usize = buf.next().unwrap().parse().unwrap();
//    let m: usize = buf.next().unwrap().parse().unwrap();
//    let mut c = Vec::new();
//    for i in 0..n {
//        c.push(i);
//    }
//    for _ in 0..m {
//        let mut buf = String::new();
//        let _ = std::io::stdin().read_line(&mut buf).ok();
//        let mut buf = buf.split_whitespace();
//        let j: usize = buf.next().unwrap().parse().unwrap();
//        let k: usize = buf.next().unwrap().parse().unwrap();
//        let a = c[k];
//        for i in 0..n {
//            if c[i] == a {
//                c[i] = c[j];
//            }
//        }
//    }
//    let mut buf = String::new();
//    let _ = std::io::stdin().read_line(&mut buf).ok();
//    let n: usize = buf.trim().parse().unwrap();
//    for _ in 0..n {
//        let mut buf = String::new();
//        let _ = std::io::stdin().read_line(&mut buf).ok();
//        let mut buf = buf.split_whitespace();
//        let j: usize = buf.next().unwrap().parse().unwrap();
//        let k: usize = buf.next().unwrap().parse().unwrap();
//        if c[j] == c[k] {
//            println!("yes");
//        } else {
//            println!("no");
//        }
//    }
//}



Measured memory_bytes: 11168
#include <iostream>
#include <string.h>
using namespace std;

long long n;
long long a[200000], c[200001];
long long m = 0;

int main()
{
	memset(c, 0, sizeof(c));

	cin >> n;

	for (long long i = 0; i < n; i++) {
		cin >> a[i];
		c[a[i]]++;
	}

	for (int i = 1; i <= n; i++)
		m += c[i] * (c[i] - 1) / 2;

	for (int i = 0; i < n; i++)
		cout << m - c[a[i]] + 1 << endl;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
long long a,b,c;
int main(){
	cin>>a>>b;
	c=(a+b)/2;
	if (abs(c-a)==abs(c-b))
		cout<<c<<endl;
	else
		cout<<"IMPOSSIBLE"<<endl;
		return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};
const int N=5050;
int a[N];
int32_t main(){
    int k,q;
    cin>>k>>q;
    forn(i,k)cin>>a[i];
    while(q--){
        int n,x,m;
        cin>>n>>x>>m;
        x%=m;
        --n;
        int sum=x,cnt=n/k,rem=n%k;
        forn(i,k){
            int val=a[i]%m;
            if(!val)val=m;
            int cur=cnt;
            if(i<rem)cur++;
            sum+=val*cur;
            dbg(a[i],val,cur);
        }
        ++n;
        cout<<(n-sum/m-1)<<'\n';
    }
    return 0;
}


Measured memory_bytes: 3660
n, k = map(int, input().split())

done = []
now = n

while True:
  if now in done:
    break
  done.append(now)
  if now == 0:
    break
  if now%k == 0:
    done.append(0)
    break
  nex = abs(k - (now - (now//k)*k))
  now = nex

print(str(min(done)))

Measured memory_bytes: 3060
def actual(n, W):
    weights = []

    for i in range(1, n):
        s1, s2 = W[:i], W[i:]

        diff_abs = abs(sum(s1) - sum(s2))

        weights.append(diff_abs)

    return min(weights)

n = int(input())
W = list(map(int, input().split()))

print(actual(n, W))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
using namespace std;

ll dp[2009][2009];
ll s[2009],t[2009];

ll fun(ll i,ll j)
{
  if(i<0 or j<0)
    return 0;
  if(i==0 or j==0)
    return 1;
  else if(dp[i][j]!=-1)
    return dp[i][j];
  else
  {
    if(s[i-1]!=t[j-1])
      return dp[i][j]=(fun(i-1,j)+ fun(i,j-1)-fun(i-1,j-1) +mod)%mod;
    else
      return dp[i][j]=(fun(i-1,j)+fun(i,j-1) )%mod;
  }
}

int main()
{ 
    fast;

    ll n,m,x;
    cin>>n>>m;

    for(ll i=0;i<n;i++)
      cin>>s[i];
    for(ll i=0;i<m;i++)
      cin>>t[i];

    memset(dp,-1,sizeof(dp));

   cout<<fun(n,m)<<endl;
 }


Measured memory_bytes: 32000
#include<queue>
#include<cstdio>

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

using namespace std;

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

int h,w,c;

struct Panel{ int a[8][8]; };
struct Point{ int x,y; };

int count(const Panel &pnl){
	int ans=1;
	bool visited[8][8]={}; visited[0][0]=true;

	queue<Point> qu; qu.push((Point){0,0});
	while(!qu.empty()){
		Point p=qu.front(); qu.pop();
		rep(i,4){
			Point q={p.x+dx[i],p.y+dy[i]};
			if(0<=q.y && q.y<h && 0<=q.x && q.x<w
			&& !visited[q.y][q.x] && pnl.a[q.y][q.x]==c){
				visited[q.y][q.x]=true;
				ans++;
				qu.push((Point){q.x,q.y});
			}
		}
	}

	return ans;
}

int dfs(Panel pnl,int depth){
	if(depth==5) return count(pnl);

	int ans=0;
	char prev=pnl.a[0][0];
	for(int cc=1;cc<=6;cc++) if(cc!=prev) {
		Panel tmp=pnl;

		pnl.a[0][0]=cc;
		bool visited[8][8]={}; visited[0][0]=true;
		queue<Point> qu; qu.push((Point){0,0});
		while(!qu.empty()){
			Point p=qu.front(); qu.pop();
			rep(i,4){
				Point q={p.x+dx[i],p.y+dy[i]};
				if(0<=q.y && q.y<h && 0<=q.x && q.x<w
				&& !visited[q.y][q.x] && pnl.a[q.y][q.x]==prev){
					visited[q.y][q.x]=true;
					pnl.a[q.y][q.x]=cc;
					qu.push((Point){q.x,q.y});
				}
			}
		}

		ans=max(ans,dfs(pnl,depth+1));

		pnl=tmp;
	}

	return ans;
}

int main(){
	for(;scanf("%d%d%d",&h,&w,&c),h;){
		Panel pnl;
		rep(i,h) rep(j,w) scanf("%d",&pnl.a[i][j]);

		printf("%d\n",dfs(pnl,0));
	}

	return 0;
}

Measured memory_bytes: 0
#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 <climits>
#include <random>
#include <iomanip>

using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

#define rep(i,n) for(auto i=0; i<(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

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

const int MOD = 1000000007;

struct Pony
{
    long a, b;
 
    Pony(long a_, long b_)
    {
        a = a_;
        b = b_;
    }
 
    bool operator<(const Pony &another) const
    {
        return b < another.b;
    };
};

int fac(int k){
    int sum = 0;
    for (int i = 1; i <= k; ++i)
    {
        sum += i;
    }
    return sum;
}

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

  long n;

  cin >> n;

  vector<long> a(n);
  fillLong(a, n);

  double sm = 0;

  rep(i, n) {
    sm += (double)1/(double)a[i];
  }

  cout << std::setprecision(10) << 1/sm << endl;
}


Measured memory_bytes: 256