akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <map>
#include <functional>
#include <cstring>
#include <queue>
#include <cmath>
#include <deque>
#include <list>
#include <iomanip>
#include <fstream>
#include <string>
#include <iterator>
#include <set>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
#define mp make_pair
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, N) FOR(i, 0, N)
#define SZ(x) ((int)(x).size())
 
const int MAXN = 200007, INF = 100000007;
 
int main()
{	
	ll K; int N = 50;
	cin >> K;
	cout << N << endl;
	REP(i, K % N) cout << K/N + 2*N - (K % N) - 1 << ' ';
	REP(i, N - (K % N)) cout << K/N + N - (K % N) - 1 << ' ';
	//cout << endl; system("pause");//please
	return 0;
}//don't forget about const, please

Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String C = sc.next();
    String A = "abcdefghijklmnopqrstuvwxyz";
    int idx = A.indexOf(C);
    System.out.println(A.substring(idx+1,idx+2));
  }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A, B, C, D, N, ans=0;
    vector<int> V(3);
    char tmp1, tmp2;
    string S;
    bool flag=true;
    cin >> A >>B;
    ans = A+B<24 ? A+B : A+B-24;
    
    cout <<ans<<endl;
    

    // string S;
    // cin >>S;
    // cout << S + "pp"<<endl;
    // if(A+B==C || B+C==A || C+A==B)
    // 	puts("Yes");
    // else
    // 	puts("No");
}


Measured memory_bytes: 256
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<math.h>
#include<time.h>
#include<vector>
#include<bitset>
#include<memory>
#include<utility>
#include<fstream>
#include<stdio.h>
#include<sstream>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[200005],b[200005];
int k;
bool cmp(int x,int y)
{
    return (x&k)<(y&k);
}
int main()
{
    #ifdef absi2011
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int n;
    scanf("%d",&n);
    int i;
    for (i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for (i=0;i<n;i++)
    {
        scanf("%d",&b[i]);
    }
    int ans=0;
    for (k=1;k<(1<<29);k|=(k<<1))
    {
        sort(a,a+n,cmp);
        sort(b,b+n,cmp);
        int j;
        for (j=0;j<n;j++)
        {
            if ((a[j]&k)>(k/2))
            {
                int now=a[j]&k;
                now=k-now+1;
                int ans1=lower_bound(b,b+n,now,cmp)-b;
                int ans2=upper_bound(b,b+n,now+k/2,cmp)-b;
                ans2-=ans1;
                //these are 0
                ans^=((n-ans2)&1)*((k+1)/2);
            }
            else
            {
                int now=a[j]&k;
                now=k-now;
                int ans1=upper_bound(b,b+n,now,cmp)-b;
                int ans2=lower_bound(b,b+n,now-k/2,cmp)-b;
                ans2=ans1-ans2;
                //these are 0
                ans^=(ans2&1)*((k+1)/2);
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1792
import java.io.*;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        init();

        int k = nextInt(), n = nextInt();
        int[] houses = new int[n];
        for (int i = 0; i < n; i++) {
            houses[i] = nextInt();
        }

        int minDistance = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            int last = i == 0 ? n - 1 : i - 1;
            int point = last == n - 1 ? houses[last] : houses[last] + k;
            minDistance = Math.min(point - houses[i], minDistance);
        }

        System.out.println(minDistance);
    }

    //Input Reader
    private static BufferedReader reader;
    private static StringTokenizer tokenizer;

    private static void init() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    private static String next() throws IOException {
        String read;
        while (!tokenizer.hasMoreTokens()) {
            read = reader.readLine();
            if (read == null || read.equals(""))
                return "-1";
            tokenizer = new StringTokenizer(read);
        }

        return tokenizer.nextToken();
    }

    private static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
}


Measured memory_bytes: 46900
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const int CASES = 2;

void solve() {
    ll n; cin >> n;
    ll ans = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            for (int k = 1; k <= n; ++k) {
                ans += __gcd(i, __gcd(j,k));
            }
        }
    }

    cout << ans << endl;
}

int main() {
#ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt", "input5.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
#else

    solve();

#endif
    return 0;
}


Measured memory_bytes: 3636
n, k = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)

if k >= n - 1
  puts (a[-1] - a[0]).abs
  exit
end

dp = [0xffffffff] * n
dp[0] = 0
(1...n).to_a.each do |i|
  lim = i - k >= 0 ? i - k : 0
  (i - 1).downto(lim) do |j|
    v = dp[j] + (a[i] - a[j]).abs

    dp[i] = v if v < dp[i]
  end
end

puts dp[-1]

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

#include <boost/range/adaptors.hpp>
#include <boost/range/combine.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t n, m;
    cin >> n >> m;

    vector<vector<int64_t>> p(8, vector<int64_t>(n));
    for (auto i : irange(0L, n)) {
        std::array<int64_t, 3> x;
        cin >> x[0] >> x[1] >> x[2];

        for (auto s : irange(0uL, 8uL)) {
            for (auto j : irange(0L, 3L)) {
                p[s][i] += (((s >> j) & 1uL) > 0) ? x[j] : -x[j];
            }
        }
    }

    int64_t ans = numeric_limits<int64_t>::min();
    for (auto s : irange(0uL, 8uL)) {
        sort(p[s].rbegin(), p[s].rend());

        int64_t pp = 0;
        for (auto i : irange(0L, m)) {
            pp += p[s][i];
        }

        ans = max(ans, pp);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
  void run() {
    Scanner sc = new Scanner(System.in);

    char[] s = sc.nextLine().toCharArray();

    int count0 = 0;
    int count1 = 0;
    for (int i = 0; i < s.length; i++) {
      if (s[i] == 'g') {
        count0++;
      } else {
        count1++;
      }
    }

    System.out.println(Math.min(count0, (int)((count0 - count1)/2)));
  }
 
  public static void main(String[] args) {
    new Main().run();
  }
}


Measured memory_bytes: 26172
from queue import deque

n, s = map(int, input().split())
q = deque()
t = 0
ans = 1e6
for a in map(int, input().split()):
    t += a
    q.append(a)
    if t < s:
        continue
    while t >= s:
        t -= q.popleft()
    ans = min(ans, len(q) + 1)
print(ans if ans < 1e6 else 0)

Measured memory_bytes: 15952
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define fi first
#define se second
#define pb(i) push_back(i)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define mes(a,b) memset(a,b,sizeof(a))
#define sbs(i,j) substr(i,j)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6+10;
const int INF = 0x3f3f3f3f;
const int inf = - INF;
const int mod = 1e9+7;
const double pi = acos(-1.0);

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n,m;
    while(cin>>n>>m)
    {
        ll ans;
        if(n>(m/2))
            ans=m/2;
        else
        {
            ans=n;
            m-=n*2;
            ans+=m/4;
        }
        cout<<ans<<endl;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

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

	int a, b;
	cin >> a >> b;
	if(a + b >= 10){
		cout << "error" << endl;
	}else{
		cout << a + b << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include "atcoder/all"
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {

    int t;
    cin >> t;
    rep(_, t) {
        ll n, m, a, b;
        cin >> n >> m >> a >> b;

        ll ans = atcoder::floor_sum(n, m, a, b);
        cout << ans << endl;

    }
}

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

using namespace std;

int n,a,b;

int main(){
	scanf("%d%d%d", &n, &a, &b);
	
	if(n == 1 && a != b) return 0 * printf("0\n");
	if(n == 2 || n == 1) return 0 * printf("1\n");
	if(b < a) return 0 * printf("0\n");
	
	printf("%lld\n", (long long)(n - 2) * (b - a) + 1LL);
}


Measured memory_bytes: 256
def take(n, lis):
    if n >= len(lis):
        return lis
    if n <= 0:
        return []
    else:
        return lis[:n]


n, k = list(map(int, input().split(" ")))
vs = list(map(int, input().split(" ")))
if n == 1:
    print(max(0, vs[0]))
    exit()
if k == 1:
    print(max(0, vs[0], vs[-1]))
    exit()
scores = []
score = 0
length = min(n, k)
for gets in range(length + 1):
    for left in range(gets + 1):
        right = gets - left
        retnum = k - gets
        get_list = take(left, vs) + take(right, vs[::-1])
        minus = sorted([get for get in get_list if get <= 0])
        score = sum(get_list) - sum(take(retnum, minus))
        scores.append(score)
print(max(0, *scores))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define Rushia_mywife ios::sync_with_stdio(0);cin.tie(0);
#define rep(i,head,n) for(int i=(head);i<n;i++)
#define int long long
#define F first
#define S second
#define pb push_back
#define p2(n) (1<<(n))
#define lg2(n) __lg(n)
using namespace std;
using pii = pair<long long,long long>;
using ld = long double;
mt19937 mt_rand(time(0));
const int mod = 1000000007;
const int hnum = 998244353;
const ld PI = acos(-1);
const int N = 3e5+10;

int n,m,k;
set<pii>s;
map<int,int> x;
map<int,int> y;
int mx,my;
vector<int>ansx,ansy;

void solve(){
    cin >> n >> m >> k;
    rep(i,0,k){
        int a,b; cin >> a >> b;
        x[a]++; y[b]++;
        mx = max(mx,x[a]);
        my = max(my,y[b]);
        s.insert({a,b});
    }
    int sx = 0,sy = 0;
    for(auto i:x){
        if(i.S==mx){
            sx++;
            ansx.pb(i.F);
        }
    }
    for(auto i:y){
        if(i.S==my){
            sy++;
            ansy.pb(i.F);
        }
    }
    if(sx*sy>k)
        cout << mx+my << '\n';
    else{
        for(auto i:ansx){
            for(auto j:ansy){
                if(!s.count({i,j})){
                    cout << mx+my << '\n';
                    return;
                }
            }
        }
        cout << mx+my-1 << '\n';
    } 
}

signed main(){
    Rushia_mywife
    solve();
}

Measured memory_bytes: 67824
from collections import deque

n = int(input())
Q = deque()
for _ in range(n):
    query = input()
    if query=='deleteFirst':
        Q.popleft()
    elif query=='deleteLast':
        Q.pop()
    else:
        q, x = query.split()
        if q=='insert':
            Q.appendleft(x)
        else:
            try:
                Q.remove(x)
            except ValueError:
                pass

print(' '.join(Q))


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

int main(){
	int a,b,c,d;
	int start,end;

	cin >>a >>b >>c >>d;
	if(a>=c)start=a;
	else start=c;
	if(b<=d)end=b;
	else end=d;
	if(end-start>0)cout<<end-start<<endl;
	else cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        String str=sc.next();
        BigInteger a=new BigInteger(str);
        str=sc.next();
        BigInteger b=new BigInteger(str);
        System.out.println(a.remainder(b));
    }
}



Measured memory_bytes: 26476
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>
#include <set>

#define mod 1000000007

using namespace std;
 
int main(void){
	
	int N, M, a[51], b[51];
	
	cin >> N >> M;
	
	for(int i=0; i<M; i++)
		cin >> a[i] >> b[i];
	
	multiset<int> c;
	
	for(int i=0; i<M; i++){
		c.insert(a[i]);
		c.insert(b[i]);
	}
	
	for(int i=0; i<N; i++)
		cout << c.count(i+1) << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a,n=0;
    scanf("%d",&a);
    if(a/100==1){
        n+=1;
        a%=100;
    }
    if(a/10==1){
        n+=1;
        a%=10;
    }
    n+=a;
    printf("%d\n",n);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  int N,L;
  cin>>N>>L;
  vector<int> value;
  for(int i=0; i<N;i++){
    value.push_back(L+i);
  }
  int min=100000000;
  int sum=0;
  int a;
  int remove;
  for(int i=0; i<value.size(); i++){
    sum+=value[i];
    a=value[i];
    if(a<0){
      a=a*-1;
    }
    if(a<min){
      min=a;
      remove=value[i];
    }
  }
  cout<<sum-remove<<endl;


  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<deque>
#include<sstream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<bitset>
#include<time.h>
#include<cstdlib>
#include<cassert>
#define ll long long
#define fi first
#define se second
using namespace std;

int n,m;
bool a[9][9];
                   
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin); 
    freopen("out","w",stdout);
#endif
  cin>>n>>m;
  for(int i=0;i<m;i++){
    int to,from;
    cin>>to>>from;
    to--;from--;
    a[to][from]=1;
    a[from][to]=1;
  }
  vector<int> v;
  for(int i=0;i<n;i++){
    v.push_back(i);
  }
  ll ans=0;
  do{
    if(v[0]!=0)break;
    bool flag=1;
    for(int i=0;i<(int)v.size()-1;i++){
      if(!a[v[i]][v[i+1]])flag=0;
    }
    if(flag)ans++;
  }while(next_permutation(v.begin(),v.end()));
  cout<<ans<<"\n";
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

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

int solver(string str);

int solver(string str){
    int l, r;
    l = 0;
    r = str.size()-1;
    while(l<r){
        if(str.at(l) != str.at(r)) return 0;
        l++;
        r--;
    }
    return 1;
}

int main(){
    string str;
    int cnt = 0;
    while(cin >> str){
        cnt += solver(str);
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <cmath>

using namespace std;

long long INF = 3e18;

bool score(vector<long long> &A, vector<long long> &F, const long long K, long long T){

	long long sumA = 0, dA;
	int N = A.size();	
	
	for(int i = 0; i < N; i++){
		sumA += max(0ll, A[i] - T/F[i]);
		//dA = A[i] - T/F[i];
		//if (dA >= 0) sumA += dA;
	}		
	if (sumA <= K) return true;
	
	return false;
}

long long bs(vector<long long> &A, vector<long long> &F, const long long K){

	long long LEFT = -1, RIGHT = INF;
	while(LEFT + 1 < RIGHT){
		
		long long T = (LEFT + RIGHT)/2;
		
		bool check = score(A, F, K, T);		
		
		if(check == true){//go bigger: target was too small
			RIGHT = T;
			
		}else{//go smaller
			LEFT = T;		
		}
		
	}	
	
	
	return RIGHT;	
}


int main() {
	
	long long K;
	int N;
	cin >> N >> K;
	vector<long long> F, A;
	//vector<vector<int>> Z(N,vector<int> (3));
		
	long long x;
	for(int i = 0; i < N; i++){
		cin >> x;
		A.push_back(x);
	}
	
	for(int i = 0; i < N; i++){
		cin >> x;
		F.push_back(x);
	}
	
	sort(A.begin(), A.end());
	sort(F.rbegin(), F.rend());
	
	
	long long answer = bs(A,F,K);
	cout << answer << endl;

	


	return 0;
	
}




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

int main()
{
		string s;
		int r = 0;

		cin >> s;

		for (int i = 1; i <= 4; i++)
		{
			if (s[i] == s[i - 1])
			{
				r = 1;
			}
		}

		if (r == 1)
		{
			cout << "Bad" << endl;
		}
		else
		{
			cout << "Good" << endl;
		}
  
	return 0;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N, K = MAP()
P = LIST()
C = LIST()

loop_point = [0]*N
loop_count = [0]*N
searched = [0]*N

for i in range(N):
	if searched[i]:
		continue
	idx = i
	points = 0
	cnt = 0
	while not searched[P[idx]-1]:
		idx = P[idx]-1
		searched[idx] = 1
		cnt += 1
		points += C[idx]
	loop_count[i] = cnt
	loop_point[i] = points

	while not loop_point[P[idx]-1]:
		idx_next = P[idx]-1
		loop_count[idx_next] = loop_count[idx]
		loop_point[idx_next] = loop_point[idx]
		idx = idx_next

ans = -INF
for i in range(N):
	p = 0
	idx = i
	loop = loop_point[i] > 0 and K > loop_count[i]
	for j in range(1, min(K+1, loop_count[i]+1)):
		idx = P[idx] - 1
		p += C[idx]
		if loop:
			final_p = p + loop_point[i]*((K-j)//loop_count[i])
		else:
			final_p = p
		ans = ans if ans > final_p else final_p
print(ans)

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

using namespace std;

typedef long long ll;

ll N, C, K;

int main(){
  cin >> N >> C >> K;
  vector<int> T(N);

  for(int i = 0; i < N; i++)  cin >> T[i];
  sort(T.begin(), T.end());

  int res = 0, k = T[0], c = 1, index = 1;
  while(index < N){
    if(c >= C){
      c = 1;
      res++;
      k = T[index];
      //cout << index << endl;
    }
    else if(T[index] - k > K){
      res++;
      c = 1;
      k = T[index];
    }
    else c++;
    index++;
  }

  cout << res+1 << endl;

  return 0;

}


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

const int kN = 1'000'000 + 5;
const int kInf = 1'000'000'000;
vector<pair<int, int>> e[kN], b[kN];
vector<int> g[kN];
int uf[kN], d[kN], v[kN];

int Find(int x) {
    if (x == uf[x]) return x;
    return uf[x] = Find(uf[x]);
}

void Merge(int x, int y) {
    uf[Find(x)] = Find(y);
}

int main() {
    int n, m; scanf("%d%d", &n, &m);
    for (int i = 0; i < m; ++i) {
        int u, v, w; scanf("%d%d%d", &u, &v, &w);
        --u, --v, --w;
        g[u].push_back(v);
        g[v].push_back(u);
        e[w].emplace_back(u, v);
    }
    for (int i = 0; i < n; ++i) uf[i] = i;
    int z = n;
    for (int i = 0; i < kN; ++i) {
        if (e[i].empty()) continue;
        for (auto &v : e[i]) Merge(v.first, v.second);
        vector<int> u;
        for (auto &v : e[i]) {
            u.push_back(Find(v.first));
            u.push_back(Find(v.second));
        }
        sort(u.begin(), u.end());
        u.resize(unique(u.begin(), u.end()) - u.begin());
        for (auto &v : e[i]) {
            {
                int f = Find(v.first);
                int p = lower_bound(u.begin(), u.end(), f) - u.begin();
                b[v.first].emplace_back(z + p, 1);
                b[z + p].emplace_back(v.first, 0);
            }
            {
                int f = Find(v.second);
                int p = lower_bound(u.begin(), u.end(), f) - u.begin();
                b[v.second].emplace_back(z + p, 1);
                b[z + p].emplace_back(v.second, 0);
            }
        }
        for (auto &v : e[i]) {
            uf[v.first] = v.first;
            uf[v.second] = v.second;
        }
        z += u.size();
    }
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
    for (int i = 0; i < z; ++i) d[i] = kInf;
    d[0] = 0;
    pq.emplace(0, 0);
    while (!pq.empty()) {
        int x = pq.top().second; pq.pop();
        if (v[x]++) continue;
        for (auto &e : b[x]) {
            if (d[e.first] > d[x] + e.second) {
                d[e.first] = d[x] + e.second;
                pq.emplace(d[e.first], e.first);
            }
        }
    }
    if (d[n - 1] == kInf) d[n - 1] = -1;
    printf("%d\n", d[n - 1]);
    return 0;
}


Measured memory_bytes: 103800
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n=INT()
    s=[]
    for i in range(n):
        s.append(STR())
    s=set(s)
    print(len(s))
if __name__ == '__main__':
    do()

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

int main() {
	int n;
	for (cin >> n; n; --n) {
		int a = 0;
		int b = 0;
		bool result = true;
		for (int i = 0; i < 10; ++i) {
			int ball;
			cin >> ball;
			if (ball > a) {
				a = ball;
			}
			else if (ball > b) {
				b = ball;	
			}
			else if (result) {
				result = !result;
			}
		}
		cout << (result ? "YES" : "NO") << endl;
	}
	return 0;
}

Measured memory_bytes: 1148
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T & a, U & ... b) { cin >> a; IN_(b ...); };
template<typename T> void OUT(T && a) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

template<typename T> istream & operator>>(istream & s, vector<T> & v) { RF(e, v) { s >> e; } return s; }
template<typename T> ostream & operator<<(ostream & s, vector<T> const & v) {
	inc(i, SI(v)) { s << (i == 0 ? "" : " ") << v[i]; }
	return s;
}

int main() {
	IN(int, n);
	vector<LL> a(n);
	cin >> a;
	map<LL, LL> I, J;
	LL ans = 0;
	inc(i, n) {
		I[i - a[i]]++;
		J[i + a[i]]++;
	}
	inc(i, n) {
		ans += I[i + a[i]];
		ans += J[i - a[i]];
	}
	OUT(ans / 2);
}


Measured memory_bytes: 50160
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll mod = 1000000007;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    vector<vector<int> > a(n,vector<int>(3,0));
    vector<vector<int> > dp(n,vector<int>(3,0));
    for(int i=0;i<n;i++)
    {
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    dp[0][1] = a[0][1];
    dp[0][0] = a[0][0];
    dp[0][2] = a[0][2];
    for(int i=1;i<n;i++)
    {
        dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + a[i][0];
        dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + a[i][1];
        dp[i][2] = max(dp[i-1][0],dp[i-1][1]) + a[i][2];
    }
    cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
    
    
}

Measured memory_bytes: 11136
n = int(input())
a = list(map(int, input().split()))
for i in range(1, len(a)):
    print(*a)
    v = a[i]
    j = i - 1
    while j >= 0 and a[j] > v:
        a[j + 1] = a[j]
        j -= 1
    a[j + 1] = v
print(*a)

Measured memory_bytes: 6756
#include"bits/stdc++.h"
using namespace std;

int main()
{
    int N, K, R, S, P; string T;
    cin >> N >> K >> R >> S >> P >> T;

    long sum = 0;
    bool isLose[100010] = { false };
    for (int i = 1; i <= N; i++) {
        if (isLose[i]) continue;

        int next = i + K;
        if (next <= N && T[i-1] == T[next-1]) isLose[next] = true;

        if (T[i-1] == 'r') sum += P;
        else if (T[i-1] == 's') sum += R;
        else sum += S;
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
//#define scanf scanf_s

int d[] = { -1, 1, -4, 4 };
int main()
{
	queue<pair<string, int>> q;
	q.push(make_pair("01234567", 0));
	map<string, int> map;
	map["01234567"] = 0;

	while (q.size())
	{
		string s = q.front().first;
		int n = q.front().second;
		q.pop();
		int zero = s.find("0");
		REP(i, 4)
		{
			if (zero + d[i] >= 0 && zero + d[i] < 8&&!(zero==3&&d[i]==1)&&!(zero==4&&d[i]==-1))
			{
				string tmp = s;
				swap(tmp[zero], tmp[zero + d[i]]);
				if (map.find(tmp) == map.end())
				{
					q.push(make_pair(tmp, n + 1));
					map[tmp] = n + 1;
				}
			}
		}
	}

	char c[8];
	while (cin >> c[0])
	{
		FOR(i, 1, 8) cin >> c[i];
		string ans = "";
		REP(i, 8) ans += c[i];
		cout << map[ans] << endl;
	}
	return 0;
}

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

typedef long long ll;
 
int main(){
  int n, m, r;
  cin >> n >> m >> r;
  int INF = 1000000007;
  vector<vector<int>> dist(n, vector<int>(n, INF));
  vector<int> d(r);
  for(int i=0; i<r; i++){
    int k;
    cin>>k;
    k--;
    d[i] = k;
  }
  sort(d.begin(), d.end());
  
  for(int i=0; i<m; i++){
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    dist[a][b] = c;
    dist[b][a] = c;
  }
  for(int k=0; k<n; k++){
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
        dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
      }
    }
  }
  int ans=INF;
  do{
    int tmp=0;
    for(int i=1; i<r; i++){
      tmp += dist[d[i-1]][d[i]];
    }
    ans = min(ans, tmp);
  }while(next_permutation(d.begin(), d.end()));
  cout << ans << endl;
  return 0;
}


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

#define M 1046527
#define NIL -1
#define L 14

char H[M][L];

int getChar(char ch){
  if(ch == 'A') return 1;
  else if(ch == 'C') return 2;
  else if(ch == 'G') return 3;
  else if(ch == 'T') return 4;
  else return 0;
}

long long getKey(char str[]){
  long long sum = 0,p = 1,i;
  for(i=0;i<strlen(str);i++){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){
  return key % M;
}
int h2(int key){
  return 1 + (key % (M - 1));
}

int find(char str[]){
  long long key,i,h;
  key = getKey(str);
  for(i=0;;i++){
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0) return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key,i,h;
  key = getKey(str);
  for(i=0;;i++){
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0){
      strcpy(H[h],str);
      return 0;
    }
  }
}

int main(){
  int i,n;
  char str[L],com[9];
  for(i=0;i<M;i++) H[i][0] = '\0';
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %s",com,str);
    
    if(com[0] == 'i'){
      insert(str);
    }
    else{
      if(find(str)){
	printf("yes\n");
      }
      else {
	printf("no\n");
      }
    }
  }
  return 0;
}



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

int main()
{


 string s;
 cin>>s;

 int q;
 cin>>q;

 int r=0;
 string before = "";
 string after = "";
 while(q--)
 {
     int t;
     cin>>t;

     if(t==1)
        r++;
     else
     {
         int f;
         char c;
         cin>>f>>c;;

         if(f==1)
         {
             if(r%2==0)
             {
                  before+=c;
             }
             else
                after+=c;

         }
         else
         {
            if(r%2==0)
                after+=c;
            else
            {
              before+=c;
            }
         }

     }
 }
 reverse(before.begin(),before.end());
 before+=s;
 before+=after;

 s=before;
 if(r%2)
    reverse(s.begin(),s.end());
 cout<<s<<endl;

    return 0;
}


Measured memory_bytes: 1348
#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>
#define FI first
#define SE second
#define PB push_back
#define MT make_tuple
using namespace std;
typedef tuple<int, int> TI1;
typedef tuple<int, int, int> TI2;
static const int INF = 1ll << 24;
static const int MBIT = 1048576;
static const int mod = 100000;
static const int dx[] = { 1, -1, 0, 0, };
static const int dy[] = { 0, 0, 1, -1 };

short N, M;
short fld[21 * 21];
int dp[2][3][MBIT];
int ans = 0;
int all = 1;
int main() {
	//int sum = 0;
	//for (int i = 0; i < 20; ++i)sum += pow(2, i);
	//cout << sum << " " << (int)pow(2, 20) << endl;
	cin >> N >> M;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < M; ++j) {
			char c;
			cin >> c;
			if (c == '?') fld[i*M + j] = 3, all *= 3;
			if (c == 'J')fld[i*M + j] = 0;
			if (c == 'O')fld[i*M + j] = 1;
			if (c == 'I')fld[i*M + j] = 2;
			all %= mod;
		}
	}
	if (fld[0] != 3)dp[0][fld[0]][0] = 1;
	else {
		dp[0][0][0] = 1;
		dp[0][1][0] = 1;
		dp[0][2][0] = 1;
	}
	int maxbit = 0;
	for (int i = 0; i < M; ++i) {
		maxbit += pow(2, i);
	}
	int bit = 1 << M;
	int bit1 = 1 << (M - 1);
	int bit2 = 1 << (M - 2);
	for (int i = 0; i < M * N - 1; ++i) {
		int p1 = (i + 1) & 1;
		int p2 = i & 1;
		for (int j = 0; j < 3; ++j) {
			for (int k = 0; k <= maxbit; ++k) {
				int t1 = k << 1;
				if (t1&bit)t1 -= bit;
				int t2 = t1 + 1;
				if ((k&bit1) && j == 2 && (i + 1) % M != 0)continue;
				if (fld[i + 1] == 3) {
					dp[p1][0][t1] = (dp[p1][0][t1] + dp[p2][j][k]) % mod;
					if (!(k&bit2) || (i + 2) % M == 0)dp[p1][2][t1] = (dp[p1][2][t1] + dp[p2][j][k]) % mod;
					if (j == 0 && (i + 1) % M != 0)dp[p1][1][t2] = (dp[p1][1][t2] + dp[p2][j][k]) % mod;
					else dp[p1][1][t1] = (dp[p1][1][t1] + dp[p2][j][k]) % mod;
				}
				else if (fld[i + 1] == 0) {
					dp[p1][0][t1] = (dp[p1][0][t1] + dp[p2][j][k]) % mod;
				}
				else if (fld[i + 1] == 1) {
					if (j == 0 && (i + 1) % M != 0)dp[p1][1][t2] = (dp[p1][1][t2] + dp[p2][j][k]) % mod;
					else dp[p1][1][t1] = (dp[p1][1][t1] + dp[p2][j][k]) % mod;
				}
				else if (fld[i + 1] == 2) {
					if (!(k&bit2) || (i + 2) % M == 0)dp[p1][2][t1] = (dp[p1][2][t1] + dp[p2][j][k]) % mod;
				}
				dp[p2][j][k] = 0;
			}
		}
	}
	for (int j = 0; j < 3; ++j) {
		for (int k = 0; k <= maxbit; ++k) {
			ans += dp[(M  * N - 1) & 1][j][k];
			ans %= mod;
		}
	}
	cout << (all%mod - ans%mod + mod) % mod << endl;
	return 0;
}

Measured memory_bytes: 25660
#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define SZ(x) ((int)x.size()-1)
#define ms(a,b) memset(a,b,sizeof a)
#define F(i,a,b) for (int i=(a);i<=(b);++i)
#define DF(i,a,b) for (int i=(a);i>=(b);--i)
using namespace std;
inline int read(){
	char ch=getchar(); int w=1,c=0;
	for(;!isdigit(ch);ch=getchar()) if (ch=='-') w=-1;
	for(;isdigit(ch);ch=getchar()) c=(c<<1)+(c<<3)+(ch^48);
	return w*c;
}
int main(){
	int s,t,d;
	cin>>d>>t>>s;
	double tim=1.0*d/s;
	if (tim<=t) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}


Measured memory_bytes: 3580
from sys import stdin
import fractions

n,m,x,y = [int(x) for x in stdin.readline().rstrip().split()]

lx = list(map(int,stdin.readline().rstrip().split()))
ly = list(map(int,stdin.readline().rstrip().split()))

lx.sort()
ly.sort()

if lx[-1]>=ly[0]:
    print("War")
    exit()

li = []

for i in range(lx[-1]+1,ly[0]+1):
    li.append(i)

for i in li:
    if x<i<=y:
        print("No War")
        exit()

print("War")

Measured memory_bytes: 5244
#include<stdio.h>

int main(void)
{

int a, b, c, d;
scanf("%d %d %d", &a, &b, &c);
if (a>b)
{
	d = a;
	a = b;
	b = d;
}
if (b>c)
{
	d = b;
	b = c;
	c = d;
}
if (a>b)
{
	d = a;
	a = b;
	b = d;
}
printf("%d %d %d\n", a, b, c);


return 0;

  }


Measured memory_bytes: 2052
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#define int long long 
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
pair<int, int>a[114514]; int b[114514]; int n;
signed main() {
	int cnta = 0, cntb = 0;
	cin >> n;
	rep(i, n)cin >> a[i].second >> b[i];
	rep(i, n)a[i].first = a[i].second + b[i];
	sort(a, a + n);
	rep(i, n)b[i] = a[i].first - a[i].second;
	for (int i = n - 1; i >= 0; i -= 2)cnta += a[i].second;
	for (int i = n - 2; i >= 0; i -= 2)cntb += b[i];
	cout << cnta - cntb << endl;
	getchar(); getchar(); return 0;
}

Measured memory_bytes: 2560
import java.util.Scanner;

class Main{
    public static void main(String[] args){
	int i;
	int j;
	int key;
	int count = 0;
	Scanner scan = new Scanner(System.in);

	int n = scan.nextInt();
	int S[] = new int[n];
	for(i=0 ; i<n ; i++){S[i] = scan.nextInt();}

	int q = scan.nextInt();
	int T[] = new int[q];
	for(j=0 ; j<q ; j++){T[j] = scan.nextInt();}

	int l;
	int r;
	int m;
	for(j=0 ; j<q ; j++){
	    key = T[j];
	    l = 0;
	    r = n;
	    m = (l+r)/2;
	    
	    while(true){
		if(key > S[n-1]){break;}
		
		if(key == S[m]){
		    count++;
		    break;
		}
		else if(key!=S[m] && l==m){break;}
		
		else if(key < S[m]){
		    r = m;
		    m = (l+r)/2;
		}
		else if(key > S[m]){
		    l = m+1;
		    m = (l+r)/2;
		}
	    }
	}

	System.out.println(count);

    }
}



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

int main(){
  int a,b,c,d,p;
  
  int x = 0, y = 0;
  
  int ans = 0;
  
  cin >> a >> b >> c >> d >> p;
  
  x = a * p;
  
  if(p > c){
  	y = b + (p - c) * d;
  }else{
  	y = b;
  }
  
  if(y > x){
  	ans = x;
  }else{
  	ans = y;
  }
  
  cout << ans << endl;

}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t n;
  cin >> n;
  int64_t k;
  cin >> k;
  vector<int64_t>x(100010);
  for(int i = 0;i < n;++i){
int b,c;
    cin >> b >> c; 
    x.at(b) += c;}
  int64_t d = 0;
  int64_t e = -1;
  for(int i = 0;i < 100010;++i){
    d += x.at(i);
    if(d >= k){
      e = i;
      break;}
  }
  cout << e << endl;
}


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

int main(){
  int n,k,m,g;
  g=0;
  cin >> n >> k;
  vector<int> v;
  for(int i=0; i<n ; i++){
    cin >> m;
    v.push_back(m);
  }
  sort(v.begin(),v.end());
  for(int i=0; i<k; i++){
    g+=v[i];
  }
  cout << g << endl;
}

Measured memory_bytes: 3560
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  cout << n / 3 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;
#define MOD 1000000007
#define INF 1000000

int main()
{
  int K;cin>>K;
  string S;cin>>S;
  if (S.size()<=K)
  {
    cout<<S<<endl; 
  }
  else
  {
    for (int i=0;i<K;i++)
    {
      cout<<S[i]; 
    }
    cout<<"..."<<endl;
  }
}

Measured memory_bytes: 3628
//
// Created by rect0r on 16-02-2020.
//
#include <bits/stdc++.h>
#define ll long long
#define mod1 (pow(10,9)+9)
#define mod2 (pow(10,7)+7)
#define lim pow(10,9)
#define vi vector <int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
/*#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "w", stdout);
#endif*/
    ll T;
    //cin >> T;
    T = 1;
    while (T--) {
        int n,k;
        cin>>n>>k;
        int ans=k;
        for(int i=1;i<n;i++)
            ans*=(k-1);
        cout<<ans;
        cout << '\n';
    }
    return 0;
}

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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){
    int N, M, Q; cin>>N>>M>>Q;
    vec_int L(M), R(M);
    vec_int p(Q), q(Q);
    rep(i,M)cin>>L.at(i)>>R.at(i);
    rep(i,Q)cin>>p.at(i)>>q.at(i);


    vector<vector<int>> train_ss(N+1, vector<int>(N+1,0));
    rep(i,M){
        train_ss.at(L.at(i)).at(R.at(i))++;
    }

    vector<vector<int>> honsuu(N+1, vector<int>(N+1,0)); // honsuu.at(i).at(j): iからjまでの区間に含まれている電車の本数
    for(int i=1;i<N+1;i++){
        for(int j=i;j<N+1;j++){
            if(i==j){
                honsuu.at(i).at(j) = train_ss.at(i).at(j);
            }else{
                int temp = 0;
                for(int k=i;k<=j;k++){
                    temp+=train_ss.at(k).at(j);
                }
                honsuu.at(i).at(j) = honsuu.at(i).at(j-1) + temp;
            }
        }
    }

    rep(i,Q){
        cout<<honsuu.at(p.at(i)).at(q.at(i))<<endl;
    }


    return 0;
}

Measured memory_bytes: 11968
import           Control.Monad
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Maybe
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

main = do
  n <- getInt
  as <- getIntVec n

  h <- VM.new (n+1)
  VM.set h (0::Int)

  forM_ [0..(n-1)] $ \i -> do
    let a = as V.! i
    x <- VM.read h a
    VM.write h a (x+1)

  h' <- V.freeze h
  let csum = V.sum $ V.map (\x -> if x > 1 then x*(x-1)`div`2 else 0) h'

  forM_ [0..(n-1)] $ \i -> do
    let a = as V.! i
        x = h' V.! a
        c1 = if x > 1 then x*(x-1)`div`2 else 0
        c2 = if x > 2 then (x-1)*(x-2)`div`2 else 0
        ans = csum - c1 + c2
    print ans

Measured memory_bytes: 12924
#include<stdio.h>

int main()
{
	int N, L[101],sum=0,hikaku=0;
	scanf("%d", &N);
	for (int i = 0;i < N;i++)
	{
		scanf("%d", &L[i]);
		sum += L[i];
		if (hikaku < L[i])
		{
			hikaku = L[i];
		}
	}
	if (hikaku<sum-hikaku)printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 10000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
typedef pair<P, int> PI;
typedef pair<int, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

int memo[350][1<<10];
int dfs(int s, int c, int bit) {
  if(c==0) {
    if(s==0) return 1;
    return 0;
  }
  if(memo[s][bit] != -1) return memo[s][bit];
  int ret = 0;
  rep(i, 10) {
    if(i * c > s) break;
    if(!(bit & (1<<i))) {
      ret += dfs(s - c*i, c-1, bit | (1<<i));
    }
  }
  return memo[s][bit] = ret;
}

int main() {
  int n, s;
  while(cin >> n >> s) {
    if(s > 340) {
      cout << "0" << endl;
    }else {
      rep(i, s+1) rep(j, 1<<10) memo[i][j] = -1;
      cout << dfs(s, n, 0) << endl;
    }
  }
  return 0;
}

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

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  for(int n = 0; n <= B; n++) {
  if(n>= A && n <= B && (n <= A+K-1 || n >= B-K+1) )
  cout << n << endl; 
  }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a, b, c, n;
	bool _bool = false;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a >> b >> c;
		_bool = false;
		if (a * a == (b* b + c * c) || b*b == a*a + c*c || c*c == a* a + b* b)
		{
			_bool = true;
		}
		if (_bool)
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}


	return 0;
}

Measured memory_bytes: 1152
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

const int N=201000;
int n,m,u,v,q[N],d[N],od[N];
ll ret;
VI e[N],cyc;
int dfs(int u,int f,int p) {
	int par=(p==0)?1:-1;
	for (auto v:e[u]) {
		if (v==f||d[v]!=1) continue;
		par+=dfs(v,u,p^1);
	}
	if (f!=0) ret+=abs(par);
	return par;
}
void dfs2(int u) {
	d[u]=0; cyc.pb(u);
	for (auto v:e[u]) if (d[v]==2) {
		dfs2(v);
	}
}
int main() {
	scanf("%d%d",&n,&m);
	if (n-1==m) {
		rep(i,0,m) {
			scanf("%d%d",&u,&v);
			e[u].pb(v); e[v].pb(u);
		}
		rep(i,1,n+1) d[i]=1;
		int c=dfs(1,0,0);
		if (c!=0) {
			puts("-1");
		} else {
			printf("%lld\n",ret);
		}		
	} else {
		rep(i,0,m) {
			scanf("%d%d",&u,&v);
			e[u].pb(v); e[v].pb(u);
			d[u]++; d[v]++;
		}
		int t=0;
		rep(i,1,n+1) if (d[i]==1) {
			q[t++]=i;
		}
		rep(i,0,t) {
			int u=q[i];
			for (auto v:e[u]) {
				if (d[v]==1) continue;
				--d[v];
				if (d[v]==1) q[t++]=v;
			}
		}
		int rt=0;
		rep(i,1,n+1) if (d[i]==2) {
			rt=i;
			break;
		}
		dfs2(rt);
		m=SZ(cyc);
		rep(i,0,m) {
			od[i]=dfs(cyc[i],0,0);
		}
		if (m%2==0) {
			rep(i,0,m) if (i%2==1) od[i]*=-1;
			ll s=0;
			VI v;
			rep(i,0,m) {
				v.pb(s);
				s+=od[i];
			}
			if (s!=0) {
				puts("-1");
				return 0;
			}
			sort(all(v));
			rep(i,0,m/2) ret+=v[i+m/2]-v[i];
			printf("%lld\n",ret);
		} else {
			ll s=0;
			rep(i,0,m) s+=od[i];
			if (s%2!=0) {
				puts("-1");
				return 0;
			}
			s/=2;
			for (int i=1;i<m;i+=2) s-=od[i];
			ll c=s;
			rep(i,0,m) {
				ret+=max(s,-s);
				s=od[i]-s;
			}
			assert(s==c);
			printf("%lld\n",ret);
		}
	}
}


Measured memory_bytes: 14712
def match?(ar, br, i, j)
  (0...M).each do |y|
    (0...M).each do |x|
      return false if br[y][x] != ar[y + j][x + i]
    end
  end
  return true
end 

N, M = gets.split.map(&:to_i)
na = []
N.times do 
  na.push gets.chomp.split('')
end
ma = []
M.times do 
  ma.push gets.chomp.split('')
end

flag = false
(0..(N - M)).each do |j|
  (0..(N - M)).each do |i|
    if match?(na, ma, i, j)
      flag = true
      break
    end
  end
  break if flag == true
end
puts flag ? "Yes" : "No"
          

Measured memory_bytes: 1916
#include<stdio.h>

int main(){
	//defined var
	int i,j,ans;

	//looping first number
	for( j=1; j<=9; j++ ){
		//looping second number
		for( i=1; i<=9; i++ ){
			//calcurate answer
			ans = i * j ;

			//output result
			printf("%dx%d=%d\n", j, i, ans);
		}
	}

	return 0;
}

Measured memory_bytes: 924
#include<iostream>
using namespace std;
int main(){
long q1,b,c1,c2,q2,p1,p2,qq;
while(cin>>q1){
if(q1==0)break;
cin>>b>>c1>>c2>>q2;
p1=p2=0;

for(;p2<q1;){
if(b<c2){cout<<"NA"<<endl;goto E;}
b-=c2;p2++;
}
if(q1>=q2){
for(;p1<q2;){
if(b<c1-c2)break;
b-=(c1-c2);p1++;p2--;
}
}else{
for(;p1<q1;){
if(b<c1-c2)break;
b-=(c1-c2);p1++;p2--;
}
for(;p1<q2;){
if(b<c1)break;
b-=c1;p1++;
}
}
for(;;){
if(b<c2)break;
b-=c2;p2++;
}
if(p1>0)cout<<p1<<" "<<p2<<endl;
else cout<<"NA"<<endl;
E:;
}
return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}



int main(){
    int a,b,c;cin>>a>>b>>c;
    cout<<(a<=c && a+b>=c ? "YES":"NO");
}



Measured memory_bytes: 256