akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;


#define ll long long
#define ull unsigned ll
#define vi vector <int>
#define ii pair <int, int>
#define vii vector <ii>
#define vll vector <ll>
#define vull vector <ull>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define INF (int)1e9
#define EPS 1e-9
#define pb emplace_back
#define PI acos(-1.0)
#define endl "\n"
#define mp make_pair
#define DEBUG 0



int main ()

{
    fast;
    
    int n;
    cin >> n;

    for (int i=1; i<=9; i++)
    {
        for (int j=1; j<=9; j++)
        {
            if (i*j == n)
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    


    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        //値を取得
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
    
        int count = 0;  //文字数カウント
        int max = 0;    //最大文字数
        
        for (int i = 0; i < S.length(); ++i){
            if (S.charAt(i) == 'A' || S.charAt(i) == 'C' || S.charAt(i) == 'G' || S.charAt(i) == 'T'){    //該当するものがあった場合
                ++count;
                max = Math.max(count,max);  //大きい方を代入
            } else {
                count = 0;
            }
        }
        
        System.out.println(max);
        
    }
}

Measured memory_bytes: 35604
using System;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            var count = 0;
            for(var i = 0; i < n; i++){
                var _ = Console.ReadLine().Split();
                var l = int.Parse(_[0]);
                var r = int.Parse(_[1]);

                count += (r - l + 1);
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13140
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter

n = ni()
v = list(li())

odd = Counter(v[::2])
even = Counter(v[1::2])

odd_cm = odd.most_common(2)
even_cm = even.most_common(2)

odd_cm.append((0,0))
even_cm.append((0,0))

if odd_cm[0][0] != even_cm[0][0]:
    print(n - odd_cm[0][1] - even_cm[0][1])
    
else:
    print(min(n - odd_cm[1][1] - even_cm[0][1],
              n - odd_cm[0][1] - even_cm[1][1]))

Measured memory_bytes: 18696
#include<bits/stdc++.h>
using namespace std;
#define MAX 200000

int main() {
    int N, a[MAX], b[MAX];
    int count = 0;

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

    for (int i=N; i>0; i--) {
        int A = a[i-1];
        if (i>N/2) b[i-1] = A;
        else {
            int sum = 0;
            for (int j=2; j*i<=N; j++) {
                sum += b[j*i-1];
            }
            sum %= 2;
            if (sum==A) b[i-1] = 0;
            else b[i-1] = 1;
        }
        count += b[i-1];
    }

    cout << count << endl;
    for (int i=0; i<N; i++) if (b[i]==1) printf("%d ", i+1);

    return 0;
}

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

int main() {
    stack<int> st;
    while (!cin.eof()) {
        string s;
        cin >> s;
        if (s == "") break;
        char c = s.at(0);
        switch (c) {
        int a, b;
        case '*':
          a = st.top(); st.pop();
          b = st.top(); st.pop();
          st.push(a * b);
          continue;
          break;
        case '+':
          a = st.top(); st.pop();
          b = st.top(); st.pop();
          st.push(a + b);
          continue;
          break;
        case '-':
          a = st.top(); st.pop();
          b = st.top(); st.pop();
          st.push(b - a);
          continue;
          break;
        }

        st.push(stoi(s));
    }
    cout << st.top() << endl;
}


Measured memory_bytes: 3180
import math
def factorization(n):
    i = 2
    factors = []
    while i <= math.floor(n**0.5):
        if n%i == 0:
            factors.append(i)
            n //= i
        else:
            i += 1
    if n>1:
        factors.append(n)
    return factors
#約数列挙
N = int(input())
ls = []
if N == 1:
    print(1)
else:
    for i in range(1,N+1):
        ls.extend(factorization(i))
    ls.sort()
    ans = 1
    now = 1
    now_2 = 0
    for i in range(len(ls)):
        if i == 0:
            now_2 = ls[i]
        else:
            if ls[i] == now_2:
                now += 1
            else:
                ans *= (now+1)
                now = 1
                now_2 = ls[i]
    ans *= (now+1)
    print(ans%(10**9+7))

Measured memory_bytes: 3188
from collections import defaultdict
N = int(input())
A = map(int, input().split(' '))
A = list(A)
s = [0] * (N+1)

for i in range(len(A)):
    s[i+1] = s[i] + A[i]

h = defaultdict(int)
ans = 0
for i, n in enumerate(s):
    ans += h[s[i]]
    h[s[i]] += 1

print(ans)


Measured memory_bytes: 44352
#include<bits/stdc++.h> 
using namespace std;
int main(int argc, char const *argv[])
{
   int x, y;
   cin >> x >> y;
   for (int i = 0; i <= x; ++i)
   {
       int leg = 2 * i + 4 * (x - i);
       if (leg == y)
        return cout << "Yes", 0;
   }
   cout << "No";
   return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
        print(v[i],i==(int)(v.size())-1?suc:2);
}
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
ll quick(ll a,ll b)
{
	ll ret=1;
	while(b)
	{
		if(b&1) ret=ret*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ret;
}
const int maxn=1e5+7;
ll kd[maxn];
int main()
{
	int n,k;
	cin>>n>>k;
	vi fac;
	for(int i=1;i*i<=n;i++)
	{
		if(n%i==0)
		{
			fac.push_back(i);
			if(i*i!=n) fac.push_back(n/i);
		}
	}
	sort(fac.begin(),fac.end());
	ll ans=0;
	for(int i=0;i<fac.size();i++)
	{
		int c=fac[i];
		if(n&1)
			kd[i]=quick(k,c/2+1);
		else{
			if(n/2%c==0)
				kd[i]=quick(k,c);
			else kd[i]=quick(k,c/2);
		}
		for(int j=0;j<i;j++)
			if(fac[i]%fac[j]==0) kd[i]=(kd[i]-kd[j]+mod)%mod;
		ans+=kd[i]*c%mod;
		ans%=mod;
	//	dbg(i,kd[i],c,ans);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

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

		new Main().run();
	}

	@SuppressWarnings("unchecked")
	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		loop: while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			Map<String, Integer>[] supers = new Map[n];
			for (int i = 0; i < n; i++)
				supers[i] = new HashMap<String, Integer>();
			Map<String, Integer> min = new HashMap<String, Integer>();
			for (int i = 0; i < n; i++) {
				int k = scanner.nextInt();
				for (int j = 0; j < k; j++) {
					String name = scanner.next();
					int value = scanner.nextInt();
					supers[i].put(name, value);
					if (!min.containsKey(name) || min.get(name) > value)
						min.put(name, value);
				}
			}
			int q = scanner.nextInt();
			String[] name = new String[q];
			for (int i = 0; i < q; i++)
				name[i] = scanner.next();
			int m = scanner.nextInt();
			List<Point>[] lists = new List[n + 1];
			for (int i = 0; i <= n; i++)
				lists[i] = new ArrayList<Main.Point>();

			while (m-- > 0) {
				int s = scanner.nextInt();
				int t = scanner.nextInt();
				int d = scanner.nextInt();
				lists[s].add(new Point(t, d));
				lists[t].add(new Point(s, d));
			}
			int sum = 0;
			for (int i = 0; i < q; i++) {
				if (!min.containsKey(name[i])) {
					System.out.println("impossible");
					continue loop;
				}
				sum += min.get(name[i]);
			}
			int[][] dp = new int[n + 1][1 << q];
			for (int[] dp1 : dp)
				Arrays.fill(dp1, 1 << 20);
			PriorityQueue<Point> pq = new PriorityQueue<Point>();
			pq.offer(new Point(0, 0, 0));
			int ans = 0;
			int[] bits = new int[n];
			for (int i = 0; i < n; i++) {
				int bit = 0;
				for (int j = 0; j < q; j++) {
					if (supers[i].containsKey(name[j])
							&& supers[i].get(name[j]).equals(min.get(name[j])))
						bit |= 1 << j;
				}
				bits[i] = bit;
			}
			while (!pq.isEmpty()) {
				Point p = pq.poll();
				int t = p.t;
				int cost = p.cost;
				int bit = p.bit;
				if (t == 0 && bit == (1 << q) - 1) {
					ans = cost;
					break;
				}
				if (dp[t][bit] < cost)
					continue;
				dp[t][bit] = cost;
				if (t > 0)
					bit |= bits[t - 1];
				for (Point point : lists[t])
					pq.offer(new Point(point.t, cost + point.cost, bit));

			}
			System.out.println(sum + " " + ans);
		}
	}

	class Point implements Comparable<Point> {
		int t, cost, bit;

		@Override
		public String toString() {
			return "Point [t=" + t + ", cost=" + cost + ", bit=" + bit + "]";
		}

		public Point(int t, int cost, int bit) {
			super();
			this.t = t;
			this.cost = cost;
			this.bit = bit;
		}

		public Point(int t, int cost) {
			super();
			this.t = t;
			this.cost = cost;
		}

		@Override
		public int compareTo(Point o) {
			if (cost == o.cost)
				return o.bit - bit;
			return cost - o.cost;
		}
	}
}

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

template<class T> void chmax(T &a, T b) {
    if (a < b) a = b;
}

int main()
{
  int n, w;
  cin >> n >> w;
  vector<int> weight(n), value(n);
  rep(i, n)
    cin >> weight[i] >> value[i];
  vector<ll> dp(w + 1, 0);
  for (int i=0; i<n; i++)
    for (int j=w-weight[i]; j>=0; j--)
      chmax(dp[j+weight[i]], dp[j] + value[i]);
  cout << dp[w] << endl;
  return 0;
}

Measured memory_bytes: 1024
import collections
H, W = map(int, input().split())
S = [list(input()) for i in range(H)]
q = collections.deque()
ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            continue
        q.append((i, j))
        tmp = [[-1]*W for i in range(H)]
        tmp[i][j] = 0
        while(q):
            y, x = q.popleft()
            if y > 0 and tmp[y-1][x] < 0 and S[y-1][x] != "#":
                q.append((y-1, x))
                tmp[y-1][x] = tmp[y][x] + 1
                ans = max(ans, tmp[y-1][x])
            if y < H-1 and tmp[y+1][x] < 0 and S[y+1][x] != "#":
                q.append((y+1, x))
                tmp[y+1][x] = tmp[y][x] + 1
                ans = max(ans, tmp[y+1][x])
            if x > 0 and tmp[y][x-1] < 0 and S[y][x-1] != "#":
                q.append((y, x-1))
                tmp[y][x-1] = tmp[y][x] + 1
                ans = max(ans, tmp[y][x-1])
            if x < W - 1 and tmp[y][x+1] < 0 and S[y][x+1] != "#":
                q.append((y, x+1))
                tmp[y][x+1] = tmp[y][x] + 1
                ans = max(ans, tmp[y][x+1])
print(ans)


Measured memory_bytes: 3444
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;

int main(){
  string s;

  while(cin >> s, s != "0000"){
    if(s[0] == s[1] && s[0] == s[2] && s[0] == s[3]){
      cout << "NA" << endl;
      continue;
    }

    int ans = 0;

    while(s != "6174"){
      sort(s.begin(), s.end());
      string S = s;
      sort(s.rbegin(), s.rend());
      string L = s;
      int N = atoi(L.c_str()) - atoi(S.c_str());

      char buff[10];
      sprintf(buff, "%04d", N);
      buff[4] = 0;
      s = string(buff);

      ans++;
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 1268
import java.util.Scanner;

public class Main {
  private static final long MOD = 1000_000_000 + 7;
  // Pascal's triangle.
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int Y = sc.nextInt();
    if ((X + Y) % 3 != 0) {
      System.out.println(0);
      return;
    }
    // v1=(1,2) * b // Use b times.
    // v2=(2,1) * a // Use a times.
    // (x,y)=(2a+b,a+2b)
    int a = (2 * X - Y) / 3;
    int b = (2 * Y - X) / 3;
    if (a < 0 || b < 0) { // ref. Knight's tour: covers all board if negative vector is allowed.
      System.out.println(0);
      return;
    }
    // a+b C a = (a+b)!/((a+b - a)! a!) = (a+b)! / (b! a!)
    System.out.print(combi(a, b));
  }

  private static long combi(int a, int b) {
    long ab = 1;
    int large = Math.min(a, b);
    int small = Math.max(a, b);
    for (int i = large + 1; i <= a + b; i++) {
      ab *= i;
      ab %= MOD;
    }
    long div = 1;
    for (int i = 1; i <= small; i++) {
      div *= i;
      div %= MOD;
    }
    return (ab * inv(div)) % MOD;
  }

  // Fermit's small theorem:
  // https://www.geeksforgeeks.org/compute-ncr-p-set-3-using-fermat-little-theorem/
  // http://hos.ac/slides/20130319_enumeration.pdf
  // https://discuss.codechef.com/t/best-known-algos-for-calculating-ncr-m/896/2
  private static long combi0(int a, int b) {
    long[] f = new long[a + b + 1];
    f[1] = 1;
    for (int i = 2; i <= a + b; i++) {
      f[i] = (f[i - 1] * i) % MOD;
    }

    return ((f[a + b] * inv(f[a])) % MOD) * inv(f[b]) % MOD;
  }
  // Inverse of n in modular MOD (using Fermat's small theorem).
  // returns n^(MOD-2)
  private static long inv(long n) {
    long rem = MOD - 2;
    long res = 1;
    while (rem > 0) {
      if ((rem & 1) == 1) {
        res *= n;
        res %= MOD;
      }
      rem >>= 1;
      n *= n;
      n %= MOD;
    }
    return res;
  }
}


Measured memory_bytes: 22996
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var s = Console.ReadLine();
        int curMaxLength = 0;
        var hash = new RollingHash(s);
        for (int i = 0; i < s.Length; i++)
            for (int j = i; j < s.Length; j++)
                while (curMaxLength < j - i && j + curMaxLength < n && hash.Slice(i, curMaxLength + 1) == hash.Slice(j, curMaxLength + 1)) curMaxLength++;
        Console.WriteLine(curMaxLength);
    }
}

class RollingHash
{
    const ulong MASK30 = (1UL << 30) - 1;
    const ulong MASK31 = (1UL << 31) - 1;
    const ulong MOD = (1UL << 61) - 1;
    const ulong POSITIVIZER = MOD * ((1UL << 3) - 1);
    static uint Base;
    static ulong[] powMemo = new ulong[500000 + 1];
    static RollingHash()
    {
        Base = (uint)new Random().Next(129, int.MaxValue);
        powMemo[0] = 1;
        for (int i = 1; i < powMemo.Length; i++)
            powMemo[i] = CalcMod(Mul(powMemo[i - 1], Base));
    }

    ulong[] hash;

    public RollingHash(string s)
    {
        hash = new ulong[s.Length + 1];
        for (int i = 0; i < s.Length; i++)
            hash[i + 1] = CalcMod(Mul(hash[i], Base) + s[i]);
    }

    public ulong Slice(int begin, int length)
    {
        return CalcMod(hash[begin + length] + POSITIVIZER - Mul(hash[begin], powMemo[length]));
    }

    private static ulong Mul(ulong l, ulong r)
    {
        var lu = l >> 31;
        var ld = l & MASK31;
        var ru = r >> 31;
        var rd = r & MASK31;
        var middleBit = ld * ru + lu * rd;
        return ((lu * ru) << 1) + ld * rd + ((middleBit & MASK30) << 31) + (middleBit >> 30);
    }

    private static ulong Mul(ulong l, uint r)
    {
        var lu = l >> 31;
        var ld = l & MASK31;
        var rd = r & MASK31;
        var middleBit = lu * rd;
        return  ld * rd + ((middleBit & MASK30) << 31) + (middleBit >> 30);
    }

    private static ulong CalcMod(ulong val)
    {
        val = (val & MOD) + (val >> 61);
        if (val > MOD) val -= MOD;
        return val;
    }
}

Measured memory_bytes: 17160
fun main(arr:Array<String>) {
    val (n,t) = readLine()!!.split(" ").map { it.toInt() }
    val keiro = (1..n).map { readLine()!!.split(" ").map { it.toInt() }.let { Keiro(it[0], it[1]) } }.filter { it.time <= t }.sortedBy { it.cost }
    if(keiro.isEmpty()) {
        println("TLE")
    } else {
        println(keiro[0].cost)
    }
}

class Keiro(val cost:Int, val time:Int)


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

typedef long long ll;
typedef pair<int, int> ii;

const int N = 1001, M = 2001;
int n, m, a, b;
vector<int> edge[N];
vector<int> path;
unordered_map<int, int> mp;

bool check(int from, int to) {
  int s = mp[from];
  int e = mp[to];
  // index [s, e] in path
  for (int i = s; i <= e; ++i) {
    int cur = path[i];
    int next = (i == e ? path[s] : path[i + 1]);
    for (int v : edge[cur]) {
      if (v != next) {
        if (mp.count(v) && mp[v] >= s) {
          return false;
        }
      }
    }
  }
  return true;
}

void dfs(int u) {
  for (int v : edge[u]) {
    if (mp.count(v)) {
      // find cycle
      if (check(v, u)) {
        int s = mp[v];
        int e = mp[u];
        cout << e - s + 1 << endl;
        for (int i = s; i <= e; ++i) {
          cout << path[i] << endl;
        }
        exit(0);
      }
    } else {
      path.push_back(v);
      mp[v] = path.size() - 1;
      dfs(v);
      mp.erase(v);
      path.pop_back();
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> a >> b;
    edge[a].push_back(b);
  }
  for (int i = 1; i <= n; ++i) {
    path.push_back(i);
    mp[i] = 0;
    dfs(i);
    mp.erase(i);
    path.pop_back();
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

const int MAX_N = 8;
int N, A, B, C;
int l[MAX_N];

int dfs(int a, int b, int c, int now, int total){
    if(now==N){
        if(a==0 || b==0 || c==0) return 1000000000;
        return total + abs(A-a) + abs(B-b) + abs(C-c) - 30;
    }

    int t1 = dfs(a+l[now], b, c, now+1, total+10);
    int t2 = dfs(a, b+l[now], c, now+1, total+10);
    int t3 = dfs(a, b, c+l[now], now+1, total+10);
    int t4 = dfs(a, b, c, now+1, total);
    
    int ret = min(t1,t2);
    ret = min(ret, t3);
    ret = min(ret, t4);

    return ret;
}

int main(){
    cin >> N >> A >> B >> C;

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

    int ans = dfs(0,0,0,0,0);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int X = scan.nextInt();
        if (X == 3 || X == 5 || X == 7) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 21716
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 
int main()
{
  string S;
  cin >> S;

  int MIN = INF;
  REP(i,S.size() - 2){
    string a = S.substr(i,3);
    int b = stoi(a);
    int c = max(b-753,753-b);
    MIN = min(MIN,c);
  }
  cout << MIN << endl;
}

Measured memory_bytes: 256
/*
Author: Sagar Gupta
E mail: sagar.june97p@gmail.com
*/

#pragma comment(linker, "/STACK:268435456")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl ("\n")
#define deb(n) cerr << #n << " = " << (n) << '\n'
#define FOR(i, n) for (int(i) = 0; (i) < n; (i)++)
#define PI (3.141592653589)
#define ordered_set tree<int, null_type, std::less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define MOD 1000000007
using ll = long long;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed;
    cout.precision(10);
    // Those who cannot acknowledge themselves, will invariably fail

    int x, a, b;
    cin >> x >> a >> b;
    if(abs(x - a) < abs(x - b))
    {
        cout << "A";
    }
    else
    {
        cout << "B";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct UnionFind
{
    vector<ll> par;
    vector<ll> rank;
    vector<ll> sz;
    UnionFind(ll n) : par(n), rank(n), sz(n)
    {
        for(ll i = 0; i < n; i++)
        {
            par[i] = i;
            rank[i] = 0;
            sz[i] = 1;
        }
    }
    ll root(ll x)
    {
        if(par[x] == x) return x;
        else return par[x] = root(par[x]);
    }
    void unite(ll x, ll y)
    {
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(rank[x] < rank[y])
        {
            par[x] = y;
            sz[y] += sz[x];
        }
        else
        {
            par[y] = x;
            sz[x] += sz[y];
            if(rank[x] == rank[y]) rank[x]++;
        }
    }
    bool same(ll x, ll y)
    {
        return root(x) == root(y);
    }
    ll size(ll x)
    {
        x = root(x);
        return sz[x];
    }
};

int main()
{
    ll n, m;
    cin >> n >> m;
    struct edge { ll from; ll to;};
    vector<edge> d(m);
    for(ll i = 0; i < m; i++)
    {
        ll a, b;
        cin >> d[i].from >> d[i].to;
    }


    vector<ll> ans;
    ll count = n * (n-1) / 2;
    ans.push_back(count);

    UnionFind tree(n+1);
    for(ll i = m -1; i >= 0; i--)
    {
        edge e = d[i];
        ll x = e.from;
        ll y = e.to;
        if(!tree.same(x, y))
        {
            ll px = tree.size(x);
            ll py = tree.size(y);
            tree.unite(x, y);

            count = count - (px+py)*(px+py-1) / 2 + px * (px-1) / 2 + py * (py-1) / 2;
        }

        ans.push_back(count);
    }
    for(ll i = m-1; i >=0; i--)
    {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 6132
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		
		int x = in.nextInt();
		int a = in.nextInt();
		
		out.println(x < a ? "0" : "10");
		
		out.close();
	}
	
	static class InputReader
	{
		public BufferedReader reader;
		public StringTokenizer tokenizer;
		
		public InputReader(InputStream stream)
		{
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}
		
		public String next()
		{
			while(tokenizer == null || !tokenizer.hasMoreTokens())
			{
				try
				{
					tokenizer = new StringTokenizer(reader.readLine());
				}
				catch(IOException e)
				{
					throw new RuntimeException(e);
				}
			}
			
			return tokenizer.nextToken();
		}
		
		public int nextInt()
		{
			return Integer.parseInt(next());
		}
		
		public long nextLong()
		{
			return Long.parseLong(next());
		}
	}
}

Measured memory_bytes: 21204
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
using namespace std;



int main() {
  long long n;
  int hex[] = {0, 1, 2, 3, 5, 7, 8, 9};
  while (cin >> n, n) {
    string res = "";
    while (n) {
      stringstream ss;
      ss << hex[n%8];
      res = ss.str() + res;
      n /= 8;
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#define MOD 1000000007
#define INT long long int
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
//const long long INF = numeric_limits<long long>::max();


int main()
{
    int N,T;
    cin>>N>>T;
    T--;
    int A[N],B[N];
    REP(i,N)cin>>A[i]>>B[i];
    int dp[N+1][T+1];
    REP(i,N+1)REP(j,T+1) dp[i][j]=0;
    vector<int> from[N+1][T+1];
    from[N][0] = {0,0};
    for (int i=N-1;i>=0;i--){
        for (int j=0;j<=T;j++){
            if (j<A[i]){
                dp[i][j] = dp[i+1][j];
                from[i][j]={i+1,j};
            }else{
                if (dp[i+1][j] > dp[i+1][j-A[i]]+B[i]){
                    dp[i][j]=dp[i+1][j];
                    from[i][j]={i+1,j}; 
                }else{
                    dp[i][j] = dp[i+1][j-A[i]]+B[i];
                    from[i][j] = {i+1,j-A[i]};
                }
            }
        }
    }

    int ans=dp[0][T];
    bool loop[N];
    REP(i,N)loop[i]=true;
    int idx=0,j=T;
    while(j > 0 && idx<N){
        int nxtj = from[idx][j][1];
        if (nxtj != j){
            loop[idx] = false;
            j=nxtj;
        }
        idx++;
    }

    for (int i=0;i<N;i++){
        if (loop[i]){
            ans = max(ans,dp[0][T]+B[i]);
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 529792
import sys
x,y=map(int,input().split())
ans=10**22
if y>=x:
    ans=min(ans,y-x)
if -y>=x:
    ans=min(ans,-y-x+1)
if y>=-x:
    ans=min(ans,y+x+1)
if -y>=-x:
    ans=min(ans,-y+x+2)
print(ans)

Measured memory_bytes: 38384
#include <iostream>
//#include <string>
using namespace std;
//#define int long long
//#define _DEBUG
class UnionFindTree{
    private:
    int P[10010];
    public:
    UnionFindTree(int N){
        for(int i=0; i<=N; i++) P[i] = i;
    }
    int root(int a){
        if (P[a] == a) return a;
        return (P[a] = root(P[a]));
    }
    bool is_same_set(int a, int b){
        return root(a) == root (b);
    }
    void unite(int a, int b){
        P[root(a)] = root(b);
    }
};
signed main(){
    int n, q;
    while(cin >> n >> q){
        auto uft = UnionFindTree(n);
        for(int i=0; i<q; i++){
            int c, x, y;
            cin >> c >> x >> y;
            if(c==0){
                uft.unite(x,y);
            }else{
                cout << uft.is_same_set(x,y) << endl;
            }
        }
    }
}


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

int main() {
  int a, b;
  cin >> a >> b;

  string ans;
  if (a * b % 2 == 1) {
    ans = "Odd";
  } else {
    ans = "Even";
  }
  cout << ans << endl;
  return 0;
}

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

vector<vector<int> > edges;
int ans = 0;

int dfs(int v, int p){
	vector<int> ends = {0, 0};
	for(int w : edges[v]){
		if(w == p) continue;
		int x = dfs(w, v);
		ends.push_back(1+x);
	}
	sort(ends.begin(), ends.end());
	reverse(ends.begin(), ends.end());
	ans = max(ans, ends[0] + ends[1]);
	return ends[0];
}

int main(){
	int n;
	cin >> n;
	edges.resize(n);
	for(int i = 0; i < n-1; i++){
		int a, b;
		cin >> a >> b;
		a--; b--;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	dfs(0, -1);
	int diam = ans;
	if(diam % 3 != 1){
		cout << "First" << '\n';
	} else {
		cout << "Second" << '\n';
	}
}

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


int main() {
int a,b,k;
cin >> a>> b >> k;
int c = max(a,b);
int count = 0;
for(int i = c;i > 0;i--){
  if(a%i==0&&b%i==0){
    count++;
  }

  if(count == k){
    cout << i <<endl;
    return 0;
  }
  }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
string S;int flag1=0,flag2=0;
cin>>S;
for(int i=1;i<=S.size();i++){
    if(i%2==0){
        if(!(S[i-1]=='L' || S[i-1]=='U' || S[i-1]=='D'))
            flag1=1;
    }
    else
    {
        if(!(S[i-1]=='R' || S[i-1]=='U' || S[i-1]=='D'))
            flag2=1;
    }
}
if(flag1!=1 && flag2!=1)
    cout<<"Yes";
else
    cout<<"No";
}




Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
#include <functional>
#include <random>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vvvl> vvvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef long double LD;
typedef vector<LD> vld;
typedef vector<pair<LD, LD>> vpld;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
typedef vector<vvpl> vvvpl;
typedef pair<ll, PL> TL;
typedef vector<TL> vtl;
typedef vector<vtl> vvtl;
typedef long double ld;
typedef vector<ld> vld;
const ll LINF = 1e18;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

template <typename T> T gcd(T a, T b) {return (a == 0) ? b : gcd(b%a, a);}
template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b;}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec /* copy */){
    sort(ALL(vec)); vec.erase(unique(vec.begin(), vec.end()), vec.end()); return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
//friend bool operator<(const tpl& lhs, const tpl& rhs){
//    return std::tie(lhs.l, lhs.r) < std::tie(rhs.l, rhs.r);
//}

bool bit(ll st, ll b){return ((st>>b)&1) == 1;}


int main(){
#ifdef __DEBUG_LOCAL__
    ifstream file("../../../../../in.txt"); if(file.is_open()) cin.rdbuf(file.rdbuf());
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    
    ll H, A; cin >> H >> A;
    cout << (H + A-1) / A << endstr;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define M 1046527
#define h1(key) (key%M)
#define h2(key) (1+(key%(M-1)))
string s[M];

int getCode(char c){
  switch(c){
  case 'A':
    return 1;
    break;
  case 'C':
    return 2;
    break;
  case 'G':
    return 3;
    break;
  }
  return 4;
}

long long getKey(string in){
  long long sum = 0, p = 1;
  for(int i = 0 ; i < (int)in.size() ; i++){
    sum += (getCode(in[i]) * p);
    p *= 5;
  }
  return sum;
}

long long hash_f(long long key, int i){
  return (h1(key) + i * h2(key)) % M;
}

bool find(string in){
  long long key = getKey(in);
  
  for(int i=1;;i++){
    long long h = hash_f(key, i);
    if(s[h] == in) return true;
    else if(s[h].size() == 0) return false;
  }
}

void insert(string in){
  long long key = getKey(in);
  int i;
  for(i=1;;i++){
    long long h = hash_f(key, i); 
    if(s[h].size() == 0){
      s[h] = in;
      break;
    }
  }
}

int main(){
  int n;
  string command, in;
  cin >> n;
  for(int i = 0 ; i < n ; i++){
    cin >> command >> in;
    if(command == "insert"){
      insert(in);
    }else{
      if(find(in)){
    cout << "yes" << endl;
      }else{
    cout << "no" << endl;
      }
    }
  }
    
}


Measured memory_bytes: 42880
while True:
    n,m = map(int,input().split(" "))
    if n == 0:
        break

    items = []
    for i in input().split(" "):
        items.append(int(i))


    #全探索
    items2 = items
    sums = []
    for i in range(len(items)):
        for j in range(len(items)):
            if i == j:
                continue
            sums.append(items[i] + items2[j])

    sums.sort(reverse=True)
    for i in range(len(sums)):
        if sums[i] <= m:
            print(sums[i])
            break
        if i == len(sums) - 1:
            print("NONE")



Measured memory_bytes: 55332
//-O2 is required.
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef vector<int> V;
map<V,int>m;
//map<V,pair<pair<int,int>,V> >track;
//V v1,v2;
pair<int,int>vec2nvec;
int bfs(V &v, int back){
	if(!back&&m.find(v)!=m.end()){
		//v1.clear();
		//vec2nvec=make_pair(0,0);
		//v2=v;
		return m[v];
	}
	set<V>s;
	queue<pair<V,int> >q;
	if(back)m[v]=0;
	s.insert(v);
	int i,j;
	for(q.push(make_pair(v,0));!q.empty();){
		V vec=q.front().first;
		int depth=q.front().second;
		q.pop();
		if(back&&depth>3)return 0;
		for(i=0;i<vec.size();i++)
			for(j=i+1;j<vec.size();j++){
				V nvec=vec;
				reverse(nvec.begin()+i,nvec.begin()+j+1);
				if(!back&&m.find(nvec)!=m.end()){
					//v1=vec;
					//vec2nvec=make_pair(i,j);
					//v2=nvec;
					return depth+1+m[nvec];
				}
				if(!s.insert(nvec).second)continue;
				if(back)m[nvec]=depth+1;
				//track[nvec]=make_pair(make_pair(i,j),vec);
				q.push(make_pair(nvec,depth+1));
			}
	}
	return 0;
}
//void backtrack(V &v){
//	if(track.find(v)==track.end())return;
//	backtrack(track[v].second);
//	printf("%d %d\n",track[v].first.first+1,track[v].first.second+1);
//}
//void forwardtrack(V &v){
//	if(track.find(v)==track.end())return;
//	printf("%d %d\n",track[v].first.first+1,track[v].first.second+1);
//	backtrack(track[v].second);
//}
main(){
	V prob;
	int i=0,t,n;
	for(scanf("%d",&n);i<n;i++){
		if(scanf("%d",&t)==-1)return 0;
		prob.push_back(t);
	}
	V goal=prob;
	sort(goal.begin(),goal.end());
	bfs(goal,1);
	printf("%d\n",bfs(prob,0));
	//backtrack(v1);
	//if(vec2nvec.first!=vec2nvec.second)printf("%d %d\n",vec2nvec.first+1,vec2nvec.second+1);
	//forwardtrack(v2);
}

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

#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll=long long;
const double PI=3.14159265358979323846;



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

    if(N>M){
        cout << "safe";
    }else{
        cout << "unsafe";
    }


}



/*
    int a[N][2];

    rep(i,N){
        rep(j,2){
            cin >> a[i][j];
        }
    }

    rep(i,N-1){
        for(int j=i+1;j<N;j++){
            int dlx = a[i][0] - a[j][1];
            int dly = a[j][0] - a[j][1];
            rep[]
        }
    }
*/

Measured memory_bytes: 3636
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

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

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func main() {
	sc := NewScanner()
	D := sc.nextIntSlice(5)
	ans := 0
	max := 0
	for i := 0; i < 5; i++ {
		n := D[i] % 10
		if n != 0 && max < 10-n {
			max = 10 - n
		}
		if n != 0 {
			ans += D[i] + (10 - n)
		} else {
			ans += D[i]
		}
	}
	fmt.Println(ans - max)
}


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

h.reverse()
ans = 0
temp = 0
for i in range(n-1):
    if h[i+1] >= h[i]:
        temp += 1
    else:
        ans = max(temp, ans)
        temp = 0

ans = max(temp, ans)
print(ans)


Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vb= vector<bool>;
using vl= vector<ll>;
using vs= vector<string>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(){
  int n;
  bool ans=0;
  cin >> n;
  vi a(n);
  rep(i,0,n){
    cin >> a[i];
  }
  sort(all(a));
  rep(i,1,n){
    if(a[i]==a[i-1]){
      ans=1;
    }
  }
  if(ans){
    cout << "NO" << endl;
  }else{
    cout << "YES" << endl;
  }
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define ld long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define gr vector<vpii>
#define str string
#define mask vector<bool>
#define vs vector<str>
#define ordered_set_of(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
#define fi first
#define se second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define nub(x) x.resize(unique(all(x)) - x.begin())
#define TWO class T1, class T2
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define GAME_OVER return 0
using namespace std;
using namespace __gnu_pbds;
char _$ = ' ';
struct sep {sep(char c) {_$ = c;}};
ostream& operator<<(ostream& o, sep s) {return o;}
template<TWO> ostream& operator<<(ostream& o, pair<T1, T2> x) {return o << x.fi << ' ' << x.se;}
template<TWO> istream& operator>>(istream& i, pair<T1, T2>& x) {return i >> x.fi >> x.se;}
template<class T> ostream& operator<<(ostream& o, vector<T> x) {for (auto it : x) o << it << _$; return o;}
template<class T> istream& operator>>(istream& i, vector<T>& x) {for (auto& it : x) i >> it; return i;}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int a, b;
    cin >> a >> b;
    cout << max(a + b, max(a - b, a * b)) << endl;
    GAME_OVER;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int n, m, x, y,s,t;
	cin >> n >> m >> x >> y;
	for (int i = 0; i < n; ++i) {
		cin >> s;
		if (s > x)x = s;
	}
	for (int i = 0; i < m; ++i) {
		cin >> t;
		if (t < y)y = t;
	}
	if (x < y)cout << "No War" << "\n";
	else cout << "War" << "\n";
	return 0;
}

Measured memory_bytes: 256
A = [int(input()) for _ in range(5)]

pos, minn = 0, 10
for i, a in enumerate(A):
    if a % 10 < minn and a % 10 != 0:
        minn = a % 10
        pos = i

res = 0
for i, a in enumerate(A):
    if i == pos:
        res += a
    else:
        if a % 10 == 0:
            res += a
        else:
            res += a + (10 - (a % 10))
print(res)


Measured memory_bytes: 3060
n = int(input())
nums = list(map(int,input().split()))
nums.sort()
ans = 0
cnt = {}
flag = [0]*1000005
for i in nums:
  cnt[i] = cnt.get(i,0) + 1

for i in nums:
  if flag[i] == 0 and cnt[i] == 1:
    ans += 1
  if flag[i] == 1:
    continue
  for j in range(i,1000001,i):
    flag[j] = 1

print(ans)

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

int64_t gcd(int64_t A,int64_t B){
  if(B==0){return A;}
  return gcd(B,A%B);
}

int main(){
  int64_t K;
  cin>>K;
  int64_t sum=0;
  for(int64_t a=1;a<=K;++a){
    for(int64_t b=1;b<=K;++b){
      for(int64_t c=1;c<=K;++c){
        sum += gcd(gcd(a,b),c);
      }
    }
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int N;
vector<int>A;




int main()
{

	cin >> N;

	A = vector<int>(N);

	vector<int>c(N+1);

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

		c[A[i]]++;
	}

	long long sum = 0;
	for (int i = 1; i <= N; i++) {
		if (c[i] > 1) {
			sum += ((long long)c[i] * (c[i] - 1)) / 2;
		}
	}

	for (int i = 0; i < N; i++) {
		int t = c[A[i]];
		long long ans = sum - (t - 1);

		cout << ans << " ";

	}
	cout << endl;

	return 0;
}



Measured memory_bytes: 4096
a = [2, 5, 5, 4, 5, 6, 3, 7, 6]
N, M = list(map(int, input().split()))
A = sorted(set(list(map(int, input().split()))), reverse=True)
B = sorted([a[i-1] for i in A])

dp = [-1] * (N+1)
for b in B:
    if b < N+1:
        dp[b] = 1

for i in range(1, N+1):
    for b in B:
        if i < b:
            break
        else:
            dp[i] = max(dp[i], dp[i-b]+1)
digit = dp[-1]

for n in A:
    x = a[n-1]
    if N-x >= 0:
        while dp[N-x] == digit-1:
            print(n, end='')
            N -= x
            digit -= 1
        if N == x:
            print(n, end='')
            N -= x

Measured memory_bytes: 4196
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <climits>
#define ll long long
#define MAX 25 * 1e13
#define N  200010

#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define EB(X) emplace_back(X)
#define REP(i,a) for(int i=0;i<(a);++i)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
#define VI vector<int>;

using namespace std;
int MOD = 1000000007;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x,y,z;
  int x1,y1,z1;
  cin >> x >> y >> z;
  x1 = z;
  y1 = x;
  z1 = y;
  cout << x1 << " " << y1 << " " << z1 << endl;

  return 0;
}



Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
r = [A[0]]
m = 10**9 + 7
ans = 0

for i in range(1, N):
  r.append(A[i] + r[i - 1])
  
for i in range(N - 1):
  ans += A[i] * (r[N - 1] - r[i])

ans = ans % m

print(ans)

Measured memory_bytes: 31700
from collections import Counter

def combination2(n):
    return int(n * (n-1) / 2)

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

c = Counter(a)
s = 0

for i in c.values():
    s += combination2(i)

for i in a:
    n = c[i]
    ans = s - combination2(n) + combination2(n-1)
    print(ans)




Measured memory_bytes: 25892
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define CST(x) cout<<fixed<<setprecision(x)
#define PI 3.14159265359
#define MOD 1000000007
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;




int main(){

    int h,w;
    cin >> h >> w;
    vector<string> fi(h);
    int road = 0;
    rep(i,h){
        cin >> fi.at(i);
        rep(j,w) if(fi.at(i).at(j) == '.') road++;
    }
    vector<vector<int>> dist(h,vector<int>(w));
    rep(i,h)rep(j,w) dist.at(i).at(j) = -1;
    dist.at(0).at(0) = 0;

    queue<pint> que;
    que.push(pint(0,0));

    vector<int> dx = {1,0,-1,0};
    vector<int> dy = {0,1,0,-1};

    while (!que.empty()) {
        pint v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        int x = v.first;
        int y = v.second;

        rep(dir,4){
            int nx = x + dx.at(dir);
            int ny = y + dy.at(dir);

            if(nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
            if(fi.at(nx).at(ny) == '#') continue;
            if(dist.at(nx).at(ny) == -1){
                dist.at(nx).at(ny) = dist.at(x).at(y)+1;
                que.push(pint(nx,ny));
            }
        }
        
    }
    int ans = dist.at(h-1).at(w-1) == -1 ? -1 : road - dist.at(h-1).at(w-1) -1;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main()
{
	int n;cin>>n;
	vector<int> a(n);
	rep(i,n)cin>>a[i];

	int ans = INT_MAX;
	for(int i=-100;i<=100;i++)
	{
		int sum=0;
		rep(j,n)
		{
			sum += (a[j]-i)*(a[j]-i);
		}
		ans = min(ans, sum);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
//typedef __int64 LL;
typedef pair<int,int> P;
const int INF=100000000;
const int MOD_2=998244353;

int main()
{
	int h,n;
	cin>>h>>n;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		h-=x;	
	}
	if(h<=0)cout<<"Yes"<<"\n";
	else cout<<"No"<<"\n";
	return 0;
}
	

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $N);
fscanf(STDIN, "%d %d", $T, $A);
$H = explode(" ", trim(fgets(STDIN)));
$diff = PHP_INT_MAX;
$ans = NULL;
for ($i = 0; $i < $N; $i++) {
    $temp = $T - $H[$i] * .006;
    $d = abs($temp - $A);
    if ($d < $diff) {
        $ans = $i + 1;
        $diff = $d;
    }
}
echo $ans;


Measured memory_bytes: 4604
#include <stdio.h>
main()
{
  int a, b, i, j, k;

  scanf("%d%d", &a, &b);

  if(a<b){
	i = a;
	j = b;
  }
  else{
	i = b;
	j = a;
  }

  while(j != 0){
	k = j;
	j = i%j;
	i = k;
  }

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

  return 0;
}

Measured memory_bytes: 592
#実験
# -*- coding: utf-8 -*-
n, m, q = map(int, input().split())
integer_set = [list(map(int, input().split())) for _ in range(q)]
a = [1]
score = 0
 
# 深さ優先探索(Depth First Search)
def dfs(seq):
    if len(seq) == n:
        global score
        tmp_score = 0
        for a, b, c, d in integer_set:
            if seq[b-1] - seq[a-1] == c:
                tmp_score += d
            else:
                tmp_score += 0
        score = max(score, tmp_score)
    else:
        for i in range(seq[-1], m+1):
            tmp_seq = seq.copy()
            tmp_seq.append(i)
            dfs(tmp_seq)
 
dfs(a)
print(score)

Measured memory_bytes: 9184