akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second

void solve() {
    int n, d, a;
    cin >> n >> d >> a;
    vector<pll> X(n);
    rep(i, n) {
        ll x, h;
        cin >> x >> h;
        X[i] = {x, h};
    }
    sort(all(X));
    queue<pll> que;
    ll acc = 0;
    ll ans = 0;
    rep(i, n) {
        while(que.size() && X[i].fi > que.front().fi) {
            acc -= que.front().se;
            que.pop();
        }
        X[i].se -= acc * a;
        ll damage = max(0LL, (X[i].se + a - 1) / a);
        acc += damage;
        ans += damage;
        que.push({X[i].fi + 2 * d, damage});
    }
    cout << ans << endl;
    return ;
}

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


Measured memory_bytes: 6656
// Codeforces 1.12.6
// AtCoder 1.6
// Paiza 1.7.3

package main

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

type (
	in struct {
		Scanner *bufio.Scanner
	}
	str string
	lm  struct{}
	su  struct{}
)

func (in *in) s() string {
	in.Scanner.Scan()
	return in.Scanner.Text()
}

func (in *in) i() int64 {
	return in.ibase(10)
}

func (in *in) ibase(base int) int64 {
	i, _ := strconv.ParseInt(in.s(), base, 64)
	return i
}

func (in *in) ss(n int64) []string {
	a := make([]string, n)
	for i := range a {
		a[i] = in.s()
	}
	return a
}

func (in *in) is(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = in.i()
	}
	return a
}

func (in *in) imat(h int64, w int64) [][]int64 {
	a := make([][]int64, h)
	for y := range a {
		a[y] = make([]int64, w)
		for x := range a[y] {
			a[y][x] = in.i()
		}
	}
	return a
}

func stdin() in {
	scn := bufio.NewScanner(os.Stdin)
	scn.Split(bufio.ScanWords)
	max := 200000
	buf := make([]byte, max)
	scn.Buffer(buf, max)
	return in{Scanner: scn}
}

func (*lm) max(a int64, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func (*lm) min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func (*lm) abs(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func (lm *lm) gcd(a, b int64) int64 {
	if a < b {
		a, b = b, a
	}
	if b == 0 {
		return a
	}
	return lm.gcd(b, a%b)
}

func (lm *lm) lcd(a, b int64) int64 {
	gcd := lm.gcd(a, b)
	return gcd * (a / gcd) * (b / gcd)
}

func (*su) arr(arr []int64) string {
	ret := make([]string, len(arr))
	for i, x := range arr {
		ret[i] = strconv.FormatInt(x, 10)
	}
	return strings.Join(ret, " ")
}

func (su *su) mat(matrix [][]int64) string {
	ret := make([]string, len(matrix))
	for i := range matrix {
		ret[i] = su.arr(matrix[i])
	}
	return strings.Join(ret, "\n")
}

func (*su) bool(b bool) str {
	if b {
		return "Yes"
	}
	return "No"
}

func (s str) upper() string {
	return strings.ToUpper(string(s))
}

func (s str) lower() string {
	return strings.ToLower(string(s))
}

func main() {
	// utilities.
	const zz int64 = int64(0)
	const mod int64 = int64(1000000007)
	in, lm, su := stdin(), lm{}, su{}
	_, _, _ = in, lm, su

	// read here.
	n := in.i()
	a := in.is(n)

	// solve here.
	t := make([]float64, n)
	for j := range t {
		t[j] = 1
	}

	for i := range a {
		for j := range t {
			if i == j {
				continue
			}
			t[j] *= float64(a[i])
		}
	}
	numerator := t[0] * float64(a[0])
	denominator := 0.0
	for _, tt := range t {
		denominator += tt
	}
	ans := numerator / denominator

	printable := ans
	// print here.
	fmt.Println(printable)
}


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

using namespace std;

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

    int max_difference = -1;
    for (int i = 0; i < N-1; ++i) {
        for (int j = i+1; j < N; ++j) {
            max_difference =  max(max_difference, abs(A[i]-A[j]));
        }
    }

    cout << max_difference << endl;

    return 0;
}

Measured memory_bytes: 256
H,W=gets.split.map &:to_i
s=H.times.map{gets.chop.chars}
H.times do |i|
  W.times do |j|
    next if s[i][j]==?#
    s[i][j]=0
    [i-1,i,i+1].each do |y|
      [j-1,j,j+1].each do |x|
        next unless 0<=y && y<H
        next unless 0<=x && x<W
        next if y==i && x==j
        s[i][j]+=1 if s[y][x]==?#
      end
    end
  end
end
puts s.map &:join


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

using namespace std;

#define mod 1e9+7

int main()

{

    int n,k;

    cin>>n>>k;

    int a[n];

    for(int i=0;i<n;i++)

    {

        cin>>a[i];

    }

    sort(a,a+n);

    int ans=0;

    for(int i=0;i<k;i++)

    {

        ans+=a[i];

    }

    cout<<ans;

    return 0;

}

Measured memory_bytes: 3632
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

int main() {
    ll A, B;
    cin >> A >> B;
    if (A + B < 10) {
        cout << A + B << endl;
    }
    else {
        cout << "error" << endl;
    }
}

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

int main(){
    int n,k,x[100];
    cin>>n;
    cin>>k;
    for(int i=0;i<n;i++) cin>>x[i];
    int s=0;
    for(int i=0;i<n;i++){
        s+=2*min(abs(x[i]),abs(x[i]-k));
    }
    cout<<s<<endl;
}

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

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

    vector<pair<long long, long long> > res;

    long long dame = n;
    if(n % 2 == 1) dame--;

    for(long long i = 1; i <= n; i++){
        for(long long j = 1; j <= n; j++){
            if(j <= i || j == dame) continue;
            res.push_back(make_pair(i, j));
        }
        dame--;
    }

    cout << res.size() << endl;
    for(auto p : res){
        cout << p.first << " " << p.second << endl;
    }
    return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

ll nCr(ll n, ll r){
  if(n-r < r) r = n-r;
  if(r == 0) return 1;
  if(r == 1) return n;
  ll res = 1;
  for(ll i = 1; i <= r; i++){
    res *= n--;
    res /= i;
  }
  return res;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, P; cin >> N >> P;
  vector<ll> A(N, 0);
  ll odd = 0, eve = 0;
  REP(i, N){
    cin >> A[i];
    if(A[i]%2){
      odd++;
    }else{
      eve++;
    }
  }

  if(P == 1){
    if(odd != 0){
      ll res1 = 0;
      for(ll i = 1; i <= odd; i += 2){
        res1 += nCr(odd, i);
      }
      ll res2 = 0;
      if(eve == 0){
        cout << res1 << endl;
        return 0;
      }else{
        for(ll i = 0; i <= eve; i++){
          res2 += nCr(eve, i);
        }
      }
      cout << res1*res2 << endl;
      return 0;
    }else{
      cout << 0 << endl;
      return 0;
    }
  }else{
    ll res1 = 0, res2 = 0;
    for(ll i = 0; i <= odd; i += 2){
      res1 += nCr(odd, i);
    }
    for(ll i = 0; i <= eve; i++){
      res2 += nCr(eve, i);
    }
    cout << res1*res2 << endl;
  }
}

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



int main(){
    int n;
    cin >> n;
    int arr[200];
    for (int i = 0;i < n * 2;i++){
        cin >> arr[i];
    }
    int res[200] = {arr[0]};
    for (int i = 1;i < n;i++){
        res[i] = res[i - 1] + arr[i];
    }
    res[n] = res[0] + arr[n];
    for (int i = n+1; i < n * 2;i++){
        res[i] = max(res[i-1], res[i-n]) + arr[i];
    }
    cout << res[n*2 - 1];
    return 0;
}

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

int main(){
  int N, K;
  cin >> N >> K;
  
  string S;
  
  cin >> S;
  
  if (S[K - 1] == 'A') {
    S[K - 1] = 'a';
  }
  
  else if(S[K - 1] == 'B') {
    S[K - 1] = 'b';
  }
  
  else {
    S[K - 1] = 'c';
  }
  
  cout << S << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+5;
string A[N];
int n;
long long sum,mem[N];
long long fact(int i){
    if(!i) return 1;
    if(mem[i]!=-1) return mem[i];
    return mem[i]=fact(i-1)*i*1ll;
}
long long ans(int i){
if(i<=1) return 0;
if(i==2) return 1;
return fact(i)/(fact(i-2)*2);
}
long long spdAns(int i){
    if(i<=1) return 0;
    if(i==2) return 1;
    long long ret=1;
    ret=1ll*i*(i-1) / 2;
    return ret;
}
map<string,int> mp;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    memset(mem,-1,sizeof mem);
    cin>>n;
    for(int i=0;i<n;++i){
        cin>>A[i];
        sort(A[i].begin(),A[i].end());
        mp[A[i]]++;
    }
    long long ze=0;
    map<string,int>::iterator it = mp.begin();
    while(it!=mp.end()){
        
        ze+=spdAns(it->second);
        it++;
    }
    /*sort(A,A+n);
    int re=1;
    string cur=A[0];
    for(int i=1;i<=n;++i){
       if(cur!=A[i]){
        sum+=ans(re);
      //  cout<<re<<endl;
        re=0;
        cur=A[i];
       }
       re++;
    }*/

    cout<<ze<<endl;
    return 0;
}


Measured memory_bytes: 19072
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			map.put(a[i], map.getOrDefault(a[i], 0) + 1);
		}
		int res = 0;
		int numDouble = 0;
		for (Integer value: map.values()) {
			int check = value % 2;
			if (value % 2 == 1) {
				res += 1;
			} else if (value % 2 == 0) {
				numDouble += 1;
			}
		}
		
		res += numDouble - numDouble%2;
		System.out.println(res);

		
		
		

	}
}


Measured memory_bytes: 51896
#include <stdio.h>

int main(){
    int i, j, k;
    int n, x, s;
    
    while(scanf("%d %d", &n, &x), n > 0){
        s = 0;
        
        for(i = 1; i <= n; ++i){
            for(j = i + 1; j <= n; ++j){
                for(k = j + 1; k <= n; ++k){
                    if(i + j + k == x){
                        ++s;
                    }
                }
            }
        }
        
        printf("%d\n", s);
    }
    
    return 0;
}


Measured memory_bytes: 2112
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

bool ok(const vector<string>& grid, const vector<vector<int> >& m, int t)
{
  const int H = grid.size(), W = grid[0].size();
  vector<vector<int> > visited(H, vector<int>(W, false));
  visited[0][0] = true;
  queue<pair<int,int> > q;
  q.push(make_pair(0, 0));
  while (!q.empty()) {
    const int x = q.front().first;
    const int y = q.front().second;
    q.pop();
    if (grid[x][y] == 't') {
      return true;
    }
    for (int d = 0; d < 4; d++) {
      static const int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1};
      const int z = x + dx[d], w = y + dy[d];
      if (0 <= z && z < H && 0 <= w && w < W
          && !visited[z][w]
          && (grid[z][w] != '#' || m[z][w] <= t)) {
        visited[z][w] = true;
        q.push(make_pair(z, w));
      }
    }
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  int W, H;
  cin >> W >> H;
  vector<string> grid(H);
  for (int i = 0; i < H; i++) {
    cin >> grid[i];
  }
  int N;
  cin >> N;
  static const int INF = 10000000;
  vector<vector<int> > m(H, vector<int>(W, INF));
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    m[y][x] = i+1;
  }

  if (!ok(grid, m, N)) {
    cout << "-1" << endl;
    return 0;
  }

  int lo = 0, hi = N;
  while (lo < hi) {
    const int mid = (lo + hi)/2;
    if (ok(grid, m, mid)) {
      hi = mid;
    } else {
      lo = mid+1;
    }
  }
  cout << lo << endl;
  return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}



int main2() {
  int N = nextLong();
  vector< vector<int> > g(N);
  REP(i, N-1) {
    int a = nextLong() - 1;
    int b = nextLong() - 1;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  REP(i, N) sort(ALL(g[i]));
  ll ans = 0;

  REP(i, N) ans += (ll)(i+1) * (N-i);

  for (int R = 0; R < N; R++) {
    for (int v : g[R]) {
      if (v < R)
          ans -= (ll)(v+1) * (N - R);
    }
  }

  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 15100
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) std::memset(arg,n,sizeof(arg))
#define mp std::make_pair
#define pb push_back
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::vector<ll> vll;
typedef std::set<int> si;
typedef std::string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
ll N,S;
ll f(ll b,ll n){
  if(n<b) return n;
  else return f(b,n/b)+n%b;
}
vll divisor(ll a){//aの約数が全列挙されたベクトルを返す
  vll res;
  for(ll i=1;i*i<=a;i++){//iはsqrt(a)まで調べれば十分
    if(a%i==0){
      res.push_back(i);
      if(i!=a/i) res.push_back(a/i);
    }
  }
  return res;
}

int main(){
  cin>>N>>S;
  if(S>N){
    prin(-1);
  }
  else if(N==S){
    prin(N+1);
  }
  else{
    ll res;
    bool ff=false;
    vll v=divisor(N-S);
    std::sort(v.begin(),v.end());
    rep(i,v.size()){
      if(f(v[i]+1,N)==S){
	ff=true;
	res=v[i]+1;
	break;
      }
    }
    if(ff) prin(res);
    else prin(-1);
  }
  return 0;
}


Measured memory_bytes: 256
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**6)
INF = float('inf')
MOD = 10 ** 9 + 7
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rf(): return float(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]
def rf_(): return [float(_) for _ in rs().split()]
def divisors(n, sortedresult=True):
    div = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            div.append(i)
            if i != n // i:
                div.append(n//i)
    if sortedresult:
        div.sort()
    return div
# endregion
T = list(rs())
for i in range(len(T)):
    if T[i] == '?':
        if i > 0 and T[i - 1] == 'P':
            T[i] = 'D'
        elif i < len(T) - 1 and (T[i + 1] == '?' or T[i + 1] == 'D'):
            T[i] = 'P'
        else:
            T[i] = 'D'
print(''.join(T))


Measured memory_bytes: 82604
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

class Market{
public:
	int time;
	int cost;

	Market(){

	}
	Market(int _time,int _cost){
		time = _time;
		cost = _cost;
	}
};

int n,t,s;
vector<Market> market;

const int INF = 1000000;

int dp[3001][3001];

void debug(){
	printf("|----|");
	for(int j=0;j<=t;j++){
		printf("|-%2d-",j);
	}
	puts("");
	for(int i=0;i<=n;i++){
		printf("|-%2d-|",i);
		for(int j=0;j<=t;j++){
			printf("|%3d ",dp[i][j]);
		}
		puts("");
	}
	puts("");
}

int main(){
	scanf("%d %d %d",&n,&t,&s);
	int a,b;
	market.push_back( Market(0,0) );
	for(int i=0;i<n;i++){
		scanf("%d %d",&b,&a);
		market.push_back( Market(a,b) );
	}
	/*
	for(int i=0;i<=n;i++){
		printf("%d:%d,%d\n",i,market[i].time,market[i].cost);
	}
	*/
	for(int i=1;i<=n;i++){
		for(int j=1;j<=s;j++){
			if(market[i].time > j){
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			}else{
				dp[i][j] = max(dp[i-1][j-market[i].time] + market[i].cost,max(dp[i-1][j],dp[i][j-1]));
			}
		}
	}
	//debug();
	for(int i=1;i<=n;i++){
		for(int j=s+1;j<=t;j++){
			if(j - market[i].time < s){
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			}else{
				dp[i][j] = max(dp[i-1][j-market[i].time] + market[i].cost,max(dp[i-1][j],dp[i][j-1]));
			}
		}
	}
	//debug();
	printf("%d\n",dp[n][t]);
}

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

int main() {
    int n; cin >> n;
    string s, t;
    cin >> s >> t;
    for(int i = 0; i < n; i++) {
        bool ok = 1;
        int j = 0, idx = i;
        while (idx < n && j < n && s[idx] == t[j]) {
            idx++, j++;
        }
        if (idx == n) {
            /*cout << s;
            for (int k = j; k < n; k++) cout << t[k];*/
            cout << n + n - j << "\n";
            return 0;
        }
    }
    cout << n * 2 << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int> S(N);
  for(int i=0;i<N;i++){
    cin>>S.at(i);
  }
  sort(S.begin(),S.end());
  int sum=0;
  for(int i=0;i<N-1;i++){
    sum += S.at(i);
  }
  if(S.at(N-1)<sum) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 
ll a[32];
int main() {
	ll n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		ll k;
		cin>>k;
		for(int i=0;i<k;i++){
			int b;
			cin>>b;
			b--;
			a[b]++;
		}
	}
	ll ans=0;
	for(int i=0;i<m;i++){
		if(a[i]==n){
			ans++;
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

using edge = pair<int, ll>;
vector<edge> g[100010];
int N;
ll ret;
int sz[100010];
int rt;
bool hf;

void dfs(int v, int p)
{
	sz[v] = 1;
	int mx = 0;

	for (auto e : g[v]) if (e.fi != p) {
		dfs(e.fi, v);
		mx = max(mx, sz[e.fi]);
		sz[v] += sz[e.fi];
		int t = min(sz[e.fi], N - sz[e.fi]);
		ll ad = t * 2;

		if (t * 2 == N) {
			hf = 1;
			--ad;
		}

		ret += ad * e.se;
	}

	if (p != -1) {
		mx = max(mx, N - sz[v]);
	}

	if (mx <= N/2) {
		rt = v;
	}
}

int main() {
	cin >> N;
	rep(i, N-1) {
		ll a, b, c;
		cin >> a >> b >> c;
		--a; --b;
		g[a].eb(b, c);
		g[b].eb(a, c);
	}

	dfs(0, -1);

	if (!hf) {
		ll mn = 1e9;
		for (auto e : g[rt]) {
			mn = min(mn, e.se);
		}
		ret -= mn;
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 14976
//بسم الله الرحمن الرحيم
///   ***   ---   |||		 In the name of ALLAH		|||   ---   ***   ///
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define el << endl
#define PI 3.141592653589793238
#define _test_ int t; cin >> t; while(t--)
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define file() freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout)
ll gcd ( ll  a, ll b ) { return __gcd ( a, b ); }
ll lcm ( ll a, ll b ) { return a * ( b / gcd ( a, b ) ); }
int dx[]={0,0,+1,-1,+1,-1,-1,+1};
int dy[]={+1,-1,0,0,+1,-1,+1,-1};
///*......................*//* LET'S BEGIN (-_^) *//*............................///
const int mx= 2e6+123;
int n,a[mx],ans,m=1;

void _case_()
{
   string s,t;
   cin >> s >> t;
   for(int i=0;i<s.size();i++)
       if(s[i]==t[i]) ans++;
       cout << ans el;
}

int main()
{

    optimize();
    //_test_
    _case_();
    return 0;

}

///////////*  N A Y E M  *///////////

Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

int main()
{
	int A, B, C;
	
	std::cin >> A >> B >> C;

	std::cout << std::max(C - (A- B), 0) << "\n";
}


Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding("utf8");

const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});

const lines = [];

reader.on("line", (line) => {
  lines.push(line);
});

const role = ([top, back, right, left, front, bottom], d) => {
  switch (d) {
    case "N":
      [top, front, bottom, back] = [back, top, front, bottom];
      break;
    case "S":
      [top, front, bottom, back] = [front, bottom, back, top];
      break;
    case "W":
      [top, left, bottom, right] = [right, top, left, bottom];
      break;
    case "E":
      [top, left, bottom, right] = [left, bottom, right, top];
      break;
    case "R":
      [front, left, back, right] = [left, back, right, front];
      break;
  }
  return [top, back, right, left, front, bottom];
};

const cd = (d1, d2) => {
  let ret = true;
  for (let i = 0; i < 6; i++) {
    if (d1[i] !== d2[i]) {
      ret = false;
      break;
    }
  }
  return ret;
};

reader.on("close", () => {
  let dice1 = lines[0].split(" ");
  let dice2 = lines[1].split(" ");
  let match = false;
  for (let i = 0; i < 4; i++) {
    for (let j = 0; j < 4; j++) {
      for (let k = 0; k < 4; k++) {
        match = cd(dice1, dice2);
        if (match) break;
        dice1 = role(dice1, "R");
      }
      match = cd(dice1, dice2);
      if (match) break;
      dice1 = role(dice1, "E");
    }
    match = cd(dice1, dice2);
    if (match) break;
    dice1 = role(dice1, "N");
  }

  console.log(match ? "Yes" : "No");
});



Measured memory_bytes: 20308
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ O(logN)
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//

bool acgt(char c) {
    if (c == 'A' || c == 'C' || c == 'G' || c == 'T') {
        return true;
    }
    else return false;
}


int main() {

    string s; cin >> s;
    int n = s.size();
    int dp[n]; rep(i,n) dp[i] = 0;
    if (acgt(s[0])) ++dp[0];
    for (int i = 1; i < n; ++i) {
        if (acgt(s[i])) dp[i] = dp[i-1] + 1;
        else dp[i] = 0;
    }
    int ans = 0;
    rep(i,n) ans = max(ans, dp[i]);
    out(ans);


    return 0;
}










Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
	    int N = scanner.nextInt();
	    
	    if (N % 1000 == 0) {
			System.out.println(0);
		} else {
			System.out.println(1000 - (N % 1000));
 
		}
	    

	}

}

Measured memory_bytes: 35560
#include<iostream>
#include<math.h>
using namespace std;

int main(){
  int n,k;
  cin >> n >> k;
  int cnt=0;
  for(int i=1;i<100000;i++){
    cnt++;
    if(pow(k,i)>n){
      break;
    }
  }
  cout << cnt << endl;
}
  


Measured memory_bytes: 256
import java.awt.geom.Point2D;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		scan.close();

		Point2D.Double a = new Point2D.Double(0.0d, 0.0d);
		Point2D.Double b = new Point2D.Double(100.0d, 0.0d);
		System.out.printf("%.8f %.8f \n", a.getX(), a.getY());
		koch(n, a, b);
		System.out.printf("%.8f %.8f \n", b.getX(), b.getY());
	}

	public static void koch(int n, Point2D a, Point2D b) {
		if(n == 0) return;
		Point2D s = new Point2D.Double();
		Point2D t = new Point2D.Double();
		Point2D u = new Point2D.Double();
		double th = Math.PI * 60.0 / 180.0;

		double sx = (2.0 * a.getX() + 1.0 * b.getX()) / 3.0;
		double sy = (2.0 * a.getY() + 1.0 * b.getY()) / 3.0;
		s.setLocation(sx, sy);

		double tx = (1.0 * a.getX() + 2.0 * b.getX()) / 3.0;
		double ty = (1.0 * a.getY() + 2.0 * b.getY()) / 3.0;
		t.setLocation(tx, ty);

		double ux = (tx - sx) * Math.cos(th) - (ty - sy) * Math.sin(th) + sx;
		double uy = (tx - sx) * Math.sin(th) + (ty - sy) * Math.cos(th) + sy;
		u.setLocation(ux, uy);

		koch(n - 1, a, s);
		System.out.printf("%.8f %.8f \n", s.getX(), s.getY());

		koch(n - 1, s, u);
		System.out.printf("%.8f %.8f \n", u.getX(), u.getY());

		koch(n - 1, u, t);
		System.out.printf("%.8f %.8f \n", t.getX(), t.getY());

		koch(n - 1, t, b);
	}
}



Measured memory_bytes: 43492
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;cin>>a>>b;
  int res = 0 ;
  if(a==1){res+=300000;}
  if(a==2){res+=200000;}
  if(a==3){res+=100000;}
  if(b==1){res+=300000;}
  if(b==2){res+=200000;}
  if(b==3){res+=100000;}
  if(a==1&&b==1){res+=400000;}
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.stdio;
import std.string;
import std.range;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

void main() {
    auto s = readln.chomp;
    writeln(s[0] == s[2] ? "Yes" : "No");
}


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


int main(){
    
    int n;
    int input;
    vector<int> vec(100,1);
    int num = 0;
    
    scanf("%d", &n);
    for(int i = 0;i < n; i++){
        scanf("%d", &input);
        if(vec[input-1] == 1){
            vec[input-1] = 0;
            num++;
        }
    }

    printf("%d", num);
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
static const int N = 501;
static const int INFTY = (1<<21);

int main(){
  int M[N][N];
  int n, u, k, v; 
  int i, j;

  scanf("%d", &n);

  for ( i = 0; i <n; i++ ){
    for ( j = 0; j <n; j++ ) M[i][j] = 0;
  }
  
  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &u, &k);
    u--;
    for ( j = 0; j < k; j++ ){
      scanf("%d", &v);
      v--;
      M[u][v] = 1;
    }
  }
  
  for ( i = 0; i < n; i++ ){
    for ( j = 0; j < n; j++ ){
      if ( j ) printf(" ");
      printf("%d", M[i][j]);
    }
    printf("\n");
  }

  return 0;
}



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

int main() {
    int A, B, C, D;
    int L, R;

    cin >> A >> B >> C >> D;
    L = A + B;
    R = C + D;

    if( L > R ){
        cout << "Left" << endl;
    } else if ( L == R ){
        cout << "Balanced" << endl;

    } else if ( L < R ){
        cout << "Right" << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    final Scanner sc = new Scanner(System.in);

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

    int[] x;
    int[] y;
    int n;

    private void run() {
        n = sc.nextInt();
        x = new int[n];
        y = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
        }

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

        double sum = 0;
        int count = 0;
        sum += calcDistance(a);
        count++;

        while (nextPermutation(a)) {
            sum += calcDistance(a);
            count++;
        }

        System.out.println(sum/(double)count);
    }

    private double calcDistance(int[] a) {
        double sum = 0;
        double distance = 0;
        for (int i = 1; i < n; i++) {
            distance = Math.sqrt(Math.pow(x[a[i-1]]-x[a[i]],2)+Math.pow(y[a[i-1]]-y[a[i]],2));
            sum += distance;
        }
        return sum;
    }

    public static boolean nextPermutation(int[] a) {
        for (int i = a.length - 1; i > 0; --i) {
            if (a[i - 1] < a[i]) {
                int swapIndex = find(a[i - 1], a, i, a.length - 1);
                int temp = a[swapIndex];
                a[swapIndex] = a[i - 1];
                a[i - 1] = temp;
                Arrays.sort(a, i, a.length);
                return true;
            }
        }
        return false;
    }

    // destより大きい要素の中で最小のもののインデックスを二分探索で探す
    private static int find(int dest, int[] a, int s, int e) {
        if (s == e) {
            return s;
        }
        int m = (s + e + 1) / 2;
        return a[m] <= dest ? find(dest, a, s, m - 1) : find(dest, a, m, e);
    }
}



Measured memory_bytes: 22484
#include <stdio.h>
#include <string.h>
int main()
{
	char s[110];
	int ans = 0;
	scanf("%s", s);
	int len = strlen(s);
	int i = 0, j = len-1;
	while(i<j)
	{
		if(s[i]!=s[j]) ans++;
		i++; j--;
	}
	printf("%d\n", ans);
	return 0;
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int ans[600][600];

void solve(vector<int>a,vector<int>b,int cnt){
	if(a.empty()||b.empty())return;
	rep(i,a.size())rep(j,b.size()){
		ans[a[i]][b[j]]=ans[b[j]][a[i]]=cnt;
	}
	cnt++;
	vector<int>l1(a.begin(),a.begin()+a.size()/2),r1(a.begin()+a.size()/2,a.end());
	vector<int>l2(b.begin(),b.begin()+b.size()/2),r2(b.begin()+b.size()/2,b.end());
	solve(l1,r1,cnt);
	solve(l2,r2,cnt);
}
int main(){
	int n;cin>>n;
	vector<int>a(n/2),b(n-n/2);
	rep(i,n){
		if(i<n/2)a[i]=i;
		else b[i-n/2]=i;
	}
	solve(a,b,1);
	
	/*
	int x=n/2,y=n-n/2;
	rep(i,x)rep(j,y){
		a[i][x+j]=a[x+j][i]=1;
	}
	rep(i,x)rep(j,x){
		if(i==j)continue;
		a[i][j]=2;
	}
	rep(i,y)rep(j,y){
		if(i==j)continue;
		a[x+i][x+j]=2;
	}*/
	rep(i,n){
		for(int j=i+1;j<n;j++)cout<<ans[i][j]<<' ';
		cout<<endl;
	}
}

Measured memory_bytes: 1664
#include <stdio.h>

int factorial(int a){
    if(a<=1) return 1;
    else return a*factorial(a-1);
}

int main(void){
    // Your code here!
    int n;
    int p[9];
    int q[9];
    int a=0 ,b=0;
    
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%d", &p[i]);
    }
    for(int i=0; i<n; i++){
        scanf("%d", &q[i]);
    }
    
    int x[9];
    for(int i=0; i<n; i++){
        x[i]=1;
    }
    
    for(int i=0; i<n; i++){
        x[p[i]-1]=0;
        int count=0;
        for(int j=0; j<p[i]; j++){
            count += x[j];
        }
        a+=(count)*factorial(n-i-1);
    }
    
    for(int i=0; i<n; i++){
        x[i]=1;
    }
    for(int i=0; i<n; i++){
        x[q[i]-1]=0;
        int count=0;
        for(int j=0; j<q[i]; j++){
            count += x[j];
        }
        b+=(count)*factorial(n-i-1);
    }
    if(a<b) printf("%d", b-a);
    else printf("%d", a-b);
}


Measured memory_bytes: 128
#include<iostream>

using namespace std;

int main()
{
	int money[100][5];
	int n,i,j,k;
	int ans[100];
	
	for(i=0;i<100;i++)
		ans[i]=10000000;
	
	for(i=0;i*2<51;i++)
	{
		if(i%5!=0)
			money[i*2][0]=i*380;
		else
			money[i*2][0]=(i*380)*80/100;
	}
	for(i=0;i*3<51;i++)
	{
		if(i%4!=0)
			money[i*3][1]=i*550;
		else
			money[i*3][1]=(i*550)*85/100;
	}
	for(i=0;i*5<51;i++)
	{
		if(i%3!=0)
			money[i*5][2]=i*850;
		else
			money[i*5][2]=(i*850)*88/100;
	}
	
	for(i=0;2*i<51;i++)
	{
		for(j=0;2*i+3*j<51;j++)
		{
			for(k=0;2*i+3*j+5*k<51;k++)
			{
				if(ans[2*i+3*j+5*k]>money[2*i][0]+money[3*j][1]+money[5*k][2])
					ans[2*i+3*j+5*k]=money[2*i][0]+money[3*j][1]+money[5*k][2];
			}
		}
	}
	
	for(;;)
	{
		cin >> n;
		if(n==0)
			break;
		cout << ans[n/100] << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h> 
using namespace std; 
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
int players[100001];
int main()
{
  flash;
	int n,k,s;
	cin>>n>>k>>s;
	ve hedi;
	int ans=0;
	for (int i = 0; i < s; ++i)
	{
		int yo;cin>>yo;
		yo--;
		players[yo]++;
	}
	for (int i = 0; i < n; ++i)
	{
		{
			if(k-(s-players[i])>0)cout<<"Yes"<<'\n';
			else cout<<"No"<<'\n';
		}
	}
  return 0;
}
//code the AC sol !
// BS/queue/map


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

using namespace std;
#define ll long long
#define ld long double
const int N=2e5 + 5;
const ll mod = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    int n;
    cin >> n;
    set<string> s;
    string str;
    while(n--) {
        cin >> str;
        s.insert(str);
    }
    cout << s.size() << endl;
    return 0;
}


Measured memory_bytes: 19244
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<queue>
#include<algorithm>
#include<iomanip>
#include<typeinfo>
#include<complex>
using namespace std;
using ll = long long int;
const int mod = 1e9 + 7;
#define rep(i, a, b) for(ll i = a;i < b; i++)
const long double PI = (acos(-1));

int main() {

	string s;
	cin >> s;
	int n = s.size();

	int cnt1 = 0, cnt2 = 0;
	
	rep(i, 0, n) {
		if (i % 2 == 0) {
			if (s[i] == '0') cnt1++;
			if (s[i] == '1') cnt2++;
		}
		else {
			if (s[i] == '0') cnt2++;
			if (s[i] == '1') cnt1++;
		}
	}

	cout << min(cnt1, cnt2) << endl;

	return 0;
}

Measured memory_bytes: 512
N = int(input())
A = list(map(int, input().split()))
nu = 1
bl = 0
if not 1 in A:
    print(-1)
else:
    for i in range(1,N+1):
        if A[i-1] == nu:
            nu += 1
            bl += 1
    print(N-bl)

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

int main(){
    
    int N,M,A,B,ans=0; cin >> N >> M;
    int stage[N];
    vector<vector<int>> data(N);
    for(int i=0;i<N;i++) cin >> stage[i];
    
    for(int i=0;i<M;i++){
        cin >> A >> B;
        data.at(A-1).push_back(B-1);
        data.at(B-1).push_back(A-1);
    }
    
    for(int i=0;i<N;i++){
        int sum = 0;
        if(data.at(i).size()== 0 ){ans++; continue;};
        for(int j=0;j<data.at(i).size();j++){
            if(stage[i] > stage[data.at(i).at(j)]) sum++;
        }
        if(sum == data.at(i).size()) ans++;
    }
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    string s;
    int n;
    cin >> n >> s;
    for (int i = 0; i < n; ++i)
    {
        if (s[i] == 'R')
            s[i] = '0';
        if (s[i] == 'G')
            s[i] = '1';
        if (s[i] == 'B')
            s[i] = '2';
    }
    ll odp = 0;
    vector< vector<ll> > il(n, vector<ll>(3, 0));
    ++il[n - 1][s[n - 1] - '0'];
    for (int i = n - 2; i >= 0; --i)
    {
        il[i][0] = il[i + 1][0];
        il[i][1] = il[i + 1][1];
        il[i][2] = il[i + 1][2];
        ++il[i][s[i] - '0'];
    }
    for (int i = 0; i < n; ++i)
    {
        for (int j = i + 1; j < n - 1; ++j)
        {
            if (s[i] == s[j])
                continue;
            int r = 3 - (s[i] - '0') - (s[j] - '0');
            odp += il[j + 1][r];
            if (j + (j - i) < n && s[j + (j - i)] - '0' == r)
                --odp;
        }
    }
    cout << odp;
    return 0;
}


Measured memory_bytes: 3828
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <queue>
#include <cstring>
#include <string>
#include <cstdio>
#include <cstdlib>


using namespace std;

const int INF = 1e9 + 10;

int w, h;

int field[61][31];

struct Search {
  int y, x;
  int foot;
  int cost;
  Search(int y, int x, int foot, int c): y(y), x(x), foot(foot), cost(c) { }
};

int main() {
  while (true) {
    cin >> w  >> h;
    if (w + h == 0) {
      break;
    }

    int min_cost[2][61][31];
    for (int i = 0; i < 61; i++) {
      for (int j = 0; j < 31; j++) {
        min_cost[0][i][j] = INF;
        min_cost[1][i][j] = INF;
      }
    }


    queue<Search> que;


    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        char c;
        cin >> c;
        if (c == 'X') {
          field[i][j] = -1;
        } else if (c == 'S') {
          field[i][j] = 0;
          min_cost[0][i][j] = 0;
          min_cost[1][i][j] = 0;
          que.push(Search(i, j, 0, 0));
          que.push(Search(i, j, 1, 0));
        } else if (c == 'T') {
          field[i][j] = 10;
        } else {
          field[i][j] = c - '0';
        }
      }
    }

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

    int ans = INF;

    while (!que.empty()) {
      Search s = que.front(); que.pop();
      int next_foot = !s.foot;
      for (int i = 0; i < 9; i++) {
        int ny = s.y + dy[next_foot][i];
        int nx = s.x + dx[next_foot][i];
        
        if (ny < 0 || ny >= h) {
          continue;
        }
        if (nx < 0 || nx >= w) {
          continue;
        }
        if (field[ny][nx] == -1) {
          continue;
        }
        if (field[ny][nx] == 10) {
          ans = min(ans, s.cost);
          continue;
        }
        int cost = s.cost + field[ny][nx];
        if (cost < min_cost[next_foot][ny][nx]) {
          min_cost[next_foot][ny][nx] = cost;
          que.push(Search(ny, nx, next_foot, cost));
        }
      }
    }
    
    if (ans == INF) {
      ans = -1;
    }

    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3116
#include<cstdio>
#include<cstring>
#include<stack>
#include<map>
using namespace std;
map<long long,long long>mp,mp1;
long long a[200005];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		mp[a[i]]++;
	}
	long long ans=0;
	for(int i=1;i<=n;i++)
	{
		if(mp1[a[i]]==0)
		{
			ans+=mp[a[i]]*(mp[a[i]]-1)/2;
			mp1[a[i]]=1;
		}
	}
	for(int i=1;i<=n;i++)
	{
		printf("%lld\n",ans-mp[a[i]]+1);
	}
	return 0;
} 

Measured memory_bytes: 18944
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;

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

map<int, int> prime_factor(int n) {
  map<int, int> ret;
  for(int i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	vector<int> a(n);
	map<int, int> lcm;
	REP(i,n) {
		cin >> a[i];
		map<int,int> amp = prime_factor(a[i]);
		for (auto x : amp){
			if(lcm[x.first] < x.second) lcm[x.first] = x.second;
		}
	}
	ll ans = 0LL;
	ll lcm_mod = 1LL;
	for(auto x: lcm){
		REP(i, x.second) lcm_mod = lcm_mod * x.first % MOD;
	}
	REP(i,n){
		ans += lcm_mod * modinv((ll)a[i]);
		ans %= MOD;
	}
	cout << ans << '\n';
	return 0;
}



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

int main() {

  int inning;
  char result[50];

  int base[3];
  int out;
  int point;

  int i,j;
  char c;

  scanf("%d",&inning);
  c=getchar();
  
  for(i=0;i<inning;i++) {
    
    for(j=0;j<3;j++) base[j]=0;
    //printf("%d %d %d\n",base[0],base[1],base[2]);
    out=0;
    
    point=0;

    while(1) {

      fgets(result,sizeof(result),stdin);

      result[strlen(result)-1]='\0';

      if(strcmp(result,"OUT")==0) {
	out++;
      }

      if(strcmp(result,"HOMERUN")==0) {
	
	for(j=0;j<3;j++) {
	  if(base[j]==1) point++;
	  base[j]=0;
	}

	point++;
      }

      if(strcmp(result,"HIT")==0) {
	
	if(base[2]==1) point++;

	for(j=0;j<3;j++) {
	  if(base[j]==0) {
	    base[j]=1;
	    break;
	  }
	}
      }
      //printf("%d %d %d %d %d\n",out,point,base[0],base[1],base[2]);
      if(out==3) break;

    }

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

  }

  return 0;

}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

struct Node {
  int L, R, idx;
  bool operator <(const Node& rhs) const {
    return L < rhs.L;
  }
};

const int N = 500 + 10;
int c[N];

void add(int x) {
  for (; x < N; x += x & -x) {
    c[x]++;
  }
}

int query(int x) {
  int ret = 0;
  for (; x; x -= x & -x) {
    ret += c[x];
  }
  return ret;
}

int main() {
  int n, m, q;
  scanf("%d%d%d", &n, &m, &q);
  vector<ii> a(m);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &a[i].first, &a[i].second);
  }
  sort(a.begin(), a.end());
  vector<Node> b(q);
  for (int i = 0; i < q; ++i) {
    scanf("%d%d", &b[i].L, &b[i].R);
    b[i].idx = i;
  }
  sort(b.begin(), b.end());
  vector<int> ret(q);
  int k = m - 1;
  for (int i = q - 1; i >= 0; --i) {
    for (; k >= 0 && a[k].first >= b[i].L; --k) {
      add(a[k].second);
    }
    ret[b[i].idx] = query(b[i].R);
  }
  for (int i = 0; i < q; ++i) {
    printf("%d\n", ret[i]);
  }
  return 0;
}


Measured memory_bytes: 4096
#include<cstdio>
#include<iostream>
#include<ctype.h>
#include<string>
using namespace std;
int main(){
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	if(A + B > C + D){
		cout << "Left" << endl;
	}
	else if(A + B == C + D){
		cout << "Balanced" << endl;
	}
	else{
		cout << "Right" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int n;
    cin >> n;
    if(n == 1){
        cout << "Hello World" << endl;
        return 0;
    }
    int a, b;
    cin >> a >> b;
    cout << a + b << endl;
    return 0;
}


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

using namespace std;

typedef double D;
typedef long long int LL;

#define st first
#define nd second
#define pb push_back
#define PLL pair <LL, LL>
#define PII pair <int, int>

const int N = 1e5 + 7;
const int MX = 1e9 + 7;
const LL INF = 1e18 + 9LL;

int n, m;
char s[N], t[N];

int nwd(int a, int b){
	return b == 0 ? a : nwd(b, a%b);
}

int main(){
	scanf("%d %d", &n, &m);
	scanf("%s %s", s, t);
	
	int d = nwd(n, m);
	for(int i = 0; i < d; ++i)
		if(s[n / d * i] != t[m / d * i]){
			printf("-1");
			return 0;
		}
	
	printf("%lld\n", 1LL * n / d * m);
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <deque>

using namespace std;

int main() {
  int n;
  deque <int> b;

  scanf("%d", &n);

  for(int i=0;i<n;i++) {
    int m;
    scanf("%d", &m);
    if(i%2) {
      b.push_front(m);
    } else {
      b.push_back(m);
    }
  }

  if(n%2) {
    auto last = b.rend();
    last--;
    for(auto it = b.rbegin(); it != b.rend(); it++) {
      printf("%d", *it);
      if(it==last) {
        printf("\n");
      } else {
        printf(" ");
      }
    }
  } else {
    auto last = b.end();
    last--;
    for(auto it = b.begin(); it != b.end(); it++) {
      printf("%d", *it);
      if(it==last) {
        printf("\n");
      } else {
        printf(" ");
      }
    }
  }

  return 0;
}


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

#define rep(i,a,b) for(int (i) = (a) ; (i) < (b) ; (i) ++)
#define scin(a) scanf("%d",&a);
#define scdo(a) scanf("%lf",&a);
#define scch(a) scanf("%s",a);
#define anin(a) printf("%d\n",a);
#define ando(a) printf("%lf\n",a);
#define anch(a) printf("%s\n",a);

int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

int main(void){
	int r,D,x[11];
	scin(r)
	scin(D)
	scin(x[0])
	rep(i,1,11){
		x[i] = r * x[i - 1] - D;
		anin(x[i])
	}
	return 0;
}

Measured memory_bytes: 128
h, w, n = map(int, input().split())
y, x = map(int, input().split())
s = input().rstrip()
t = input().rstrip()


def check(direction, opposite_direction, pos, target):
    for i in range(n):
        if s[i] == direction:
            pos += 1
        if pos == target:
            return False
        if t[i] == opposite_direction and pos > 1:
            pos -= 1
    return True


for d, od, pos, target in [
    ('R', 'L', x, w + 1),
    ('L', 'R', w + 1 - x, w + 1),
    ('D', 'U', y, h + 1),
    ('U', 'D', h + 1 - y, h + 1),
]:
    ok = check(d, od, pos, target)
    if not ok:
        print('NO')
        break
else:
    print('YES')

Measured memory_bytes: 3768
//By Vlgd
#include<bits/stdc++.h>
using namespace std;
struct node{
	int key;
	node *pre,*nxt;	
};
node *head;
void init(){
	head=(node*)malloc(sizeof(node));
	head->pre=head;
	head->nxt=head;
}
void insert(int x){
	node *n=(node*)malloc(sizeof(node));
	n->key=x;
	n->nxt=head->nxt;
	n->pre=head;
	head->nxt->pre=n;
	head->nxt=n;
}
node* find(int x){
	node *t=head->nxt;
	while (t->key!=x&&t!=head) t=t->nxt;
	return t;
}
void byenode(node *t){
	if (t==head) return;
	t->pre->nxt=t->nxt;
	t->nxt->pre=t->pre;
}
void remove(int x){
	node *r=find(x);
	byenode(r);
}
void delf(){
	byenode(head->nxt);
}
void dell(){
	byenode(head->pre);
}
int main(){
	char ins[12];
	int n,xx;
	scanf("%d",&n);
	init();
	for(int i=0;i<n;i++){
		scanf("%s",ins);
		if (strlen(ins)==6){
			scanf("%d",&xx);
			if (ins[0]=='i') insert(xx);//printf("%DSD");
			else if (ins[0]=='d') remove(xx);
		}
		else{
			if (ins[6]=='F') delf(); 
			else if (ins[6]=='L') dell();
		}
	}
	node *t=head->nxt;
	while(t!=head){
		printf("%d",t->key);
		if (t->nxt!=head) printf(" ");
		t=t->nxt;
	}printf("\n");
}


Measured memory_bytes: 37556