akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

//powMod
ll powMod(ll k, ll n, ll mod) {
    ll x = 1;
    while (n > 0) {
        if (n & 1) {
            x = x * k % mod;
        }
        k = k * k % mod;
        n >>= 1;
    }
    return x;
}

// comb (一つのみ) O(r)
ll comb(ll n, ll r, ll mod) {
    ll ret = 1;
    while (true) {
        if (r == 0) break;
        ll N = n % mod;
        ll R = r % mod;
        if (N < R) return 0;
        for (int i = 0; i < R; i++)
        {
            ret = ret * (N - i) % mod;
        }
        ll imul = 1;
        for (int i = 0; i < R; i++)
        {
            imul = imul * (i + 1) % mod;
        }
        ret = ret * powMod(imul, mod - 2, mod) % mod;
        n /= mod; r /= mod;
    }
    return ret;
}

int main() {
    constexpr int MOD = 1e9 + 7;
    int n, a, b; cin >> n >> a >> b;
    cout << (((powMod(2, n, MOD) + MOD - comb(n, a, MOD)) % MOD + MOD - comb(n, b, MOD)) % MOD + MOD - 1) % MOD << endl;
    return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]

comp = [[0,-1],[0,1],[1,-1],[1,1],[1,0],[-1,-1],[-1,0],[-1,1]]
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue
        c = 0
        for e in comp:
            x = j + e[1]
            y = i + e[0]
            if x < 0 or x > W-1:
                continue
            if y < 0 or y > H-1:
                continue
            if S[y][x] == '#':
                c += 1
        S[i][j] = str(c)
    print(''.join(S[i]))
            



Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  ll n, k;
  cin >> n >> k;
  ll ans = k;
  rep(i,n-1){
    ans *= (k - 1);
  }
  print(ans);
}

Measured memory_bytes: 256
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<string>
using namespace std;

long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }
void indexsort(long* first, long* last, long* func) { sort(first, last, [&](long a, long b) {return func[a] < func[b]; }); }
//--------------------

int main() {

	long res = 0;
	long A, B, C; cin >> A >> B >> C;
	
	if (A % 2 == 1 && B % 2 == 1 && C % 2 == 1) res += min(A * B, min(B * C, C * A));

	cout << res << endl;
}

Measured memory_bytes: 256
def main():
    from sys import stdin
    input = stdin.readline
    from time import time
    from random import randint
    start = time()
    D = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for _ in [0]*D]
    ans = [randint(0, 25) for _ in [0]*D]

    def calc_score(ans):
        score = 0
        last = [-1]*26
        for d in range(D):
            ct = ans[d]
            score += s[d][ct]
            last[ct] = d
            for j in range(26):
                score -= c[j]*(d-last[j])
        return score

    score = calc_score(ans)

    while True:
        d = randint(0, D-1)
        new_ct = randint(0, 25)
        past_ct = ans[d]
        ans[d] = new_ct
        new_score = calc_score(ans)
        if new_score > score:
            score = new_score
        else:
            ans[d] = past_ct
        if time() > start+1.8:
            break

    for i in ans:
        print(i+1)


main()


Measured memory_bytes: 81208
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
map<string,int> mp;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    vector<string> check;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        mp[s]++;
        check.push_back(s);
    }
    int m;
    cin>>m;
    for(int i=0;i<m;i++){
        string s;
        cin>>s;
        mp[s]--;
        check.push_back(s);
    }
    check.erase(unique(check.begin(),check.end()),check.end());
    int res=0;
    for(int i=0;i<check.size();i++){
        res=max(res,mp[check.at(i)]);
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
string s;
int main() {
   ll i,j;
    ll k,num=0;

    cin >> s;
    cin >> k;

    for(i=1; i<s.size() ; i++)
    {
      if(s[i]==s[i-1])
      {
        num+=1;
        i+=1;
      }
    }

    num*=k;

    if(s[0]==s[s.size()-1] && s[0]!=s[1] && s[0]!=s[s.size()-2])
    {
      num+=k-1;
    }

if(s[0]==s[s.size()-1])
{
  ll r=0,l=0;

while(s[0]==s[r])
{
  r+=1;
}
while(s[s.size()-1]==s[s.size()-1-l])
{
  l+=1;
}

  if(r%2==1 && l%2==1)
  {
    num+=k-1;
  }
}

  bool even=true;
  for(i=0; i<s.size()-1; i++)
  {
    if(s[i]!=s[i+1])
    {
      even=false;
    }
  }

  if(even)
  {
    num=s.size()*k/2;
  }


// if(s.size()==1)
// {
//   num=k/2;
// }
  cout << num << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>


using namespace std;

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

	cin >> a >> b >> c >> d;

	if (abs(a - c) <= d) {
		cout << "Yes";
	}
	else if (abs(a - b) <= d && abs(c - b) <= d) {
		cout << "Yes";
	}
	else { cout << "No"; }
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define rep(i,l,r)for(int i=(l);i<(r);i++)

int main(void){
  int x;
  scanf("%d",&x);
  if(x==0) printf("1");
  else printf("0");
  return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
vvl G;
vl c, d;
ll id = 1;
 
void dfs(ll v, ll p = -1) {
    for(auto u : G[v]) {
        if(u == p) {
            continue;
        }
        d[u] = c[id];
        id++;
        dfs(u, v);
    }
}
 
int main() {
    ll n;
    cin >> n;    
 
    G.resize(n);
    rep(i, n-1) {
        ll a, b;
        cin >> a >> b;
        a--;  b--;
        G[a].pb(b);
        G[b].pb(a);
    }
 
    c.resize(n);
    rep(i, n) {
        cin >> c[i];
    }
    sort(rall(c));

    ll M = 0;
    exrep(i, 1, n-1) {
        M += c[i];
    }
    out(M);
 
    d.resize(n);
    d[0] = c[0];
    dfs(0);
 
    rep(i, n) {
        cout << d[i] << " ";
    }
 
    cout << endl;
    re0;
}

Measured memory_bytes: 1408
from collections import deque


def bfs(maze, x, y):
    m = [1, 0, -1, 0]
    n = [0, 1, 0, -1]
    queue = deque([[x, y]])
    dist = [[-1] * (w + 2) for _ in range(h + 2)]
    dist[x][y] = 0

    while queue:
        sx, sy = queue.popleft()

        for dx, dy in zip(m, n):
            nx = sx + dx
            ny = sy + dy
            if maze[nx][ny] != '#' and dist[nx][ny] == -1:
                queue.append([nx, ny])
                dist[nx][ny] = dist[sx][sy] + 1

    return max(max(x) for x in dist)


h, w = map(int, input().split())

maze = [['#'] * (w + 2)]
for i in range(h):
    maze.append(['#'] + list(map(str, input())) + ['#'])

maze.append(['#'] * (w + 2))

ans = 0
for sy in range(1, w + 1):
    for sx in range(1, h + 1):
        if maze[sx][sy] != '#':
            ans = max(ans, bfs(maze, sx, sy))

print(ans)


Measured memory_bytes: 3316
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<string> s(n); rep (i, n) cin >> s[i];
    int ac = 0, wa = 0, tle = 0, re = 0;
    rep (i, n) {
        if (s[i] == "AC") ac++;
        else if (s[i] == "WA") wa++;
        else if (s[i] == "TLE") tle++;
        else if (s[i] == "RE") re++;
    }
    cout << "AC x " << ac << "\n";
    cout << "WA x " << wa << "\n";
    cout << "TLE x " << tle << "\n";
    cout << "RE x " << re << "\n";
    return 0;
}

Measured memory_bytes: 6364
#include <stdio.h>
int main(void){
    int a,b,c,tmp;
    scanf("%d %d %d",&a,&b,&c);
    if(a>b){
        tmp=a;
        a=b;
        b=tmp;
    }
    if(b>c){
        tmp=b;
        b=c;
        c=tmp;
    }
    if(a>b){
        tmp=a;
        a=b;
        b=tmp;
    }
    printf("%d %d %d\n",a,b,c);
    return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#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 long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head
 
void solve(){
    int n, T;
    cin >> n >> T;
    int ans = 1001;
    int c, t;
    for (int i = 0; i < n; i++){
        cin >> c >> t;
        if (t <= T) ans = min(ans, c);
    }
    if (ans == 1001) cout << "TLE\n";
    else cout << ans << '\n';
}

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

    //int t; cin >> t; while (t--)
        solve();
}

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

int main() {
    int A, B, M, mina=1000000, minb=1000000, ans, x, y, c;
    cin >> A >> B >> M;
    vector<int> a(A);
    vector<int> b(B);
    
    for(int i=0; i<A; i++) {
        cin >> a.at(i);
        mina=min(mina, a.at(i));
    }
    for(int i=0; i<B; i++) {
        cin >> b.at(i);
        minb=min(minb, b.at(i));
    }

    ans=mina+minb;

    for(int i=0; i<M; i++) {
        cin >> x >> y >> c;
        ans=min(ans, a.at(x-1)+b.at(y-1)-c);
    }

    cout << ans;
}

Measured memory_bytes: 1024
object Main extends App {
	import scala.math._

	val n = scala.io.StdIn.readInt
	val a1 = scala.io.StdIn.readLine.split(" ").map(_.toInt)
	val a2 = scala.io.StdIn.readLine.split(" ").map(_.toInt)

	var ans = 0

	if(n==1) ans = a1.sum + a2.sum

	for(i<-1 until n){
		ans = max(ans, a1.dropRight(n-i).sum + a2.drop(i-1).sum)
	}

	println(ans)
}


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

using namespace std;

const int md = 998244353;

inline void add(int &a, int b) {
  a += b;
  if (a >= md) {
    a -= md;
  }
}

inline int mul(int a, int b) {
  return (long long) a * b % md;
}

inline int power(int a, int b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

inline int inv(int x) {
  return power(x, md - 2);
}

const int gen = 3;
int powers[423456];

void fft(vector <int> &a) {
  int n = a.size();
  for (int i = 0; i < n; i++) {
    int j = 0;
    int x = i, y = n - 1;
    while (y > 0) {
      j = (j << 1) + (x & 1);
      x >>= 1;
      y >>= 1;
    }
    if (i < j) swap(a[i], a[j]);
  }
  for (int len = 1; len < n; len *= 2) {
    int step = n / 2 / len;
    for (int i = 0; i < n; i += 2 * len) {
      int pos = 0;
      for (int j = 0; j < len; j++) {
        int w = powers[pos];
        int u = a[i + j];
        int v = mul(a[i + j + len], w);
        a[i + j] = u + v;
        if (a[i + j] >= md) a[i + j] -= md;
        a[i + j + len] = u - v;
        if (a[i + j + len] < 0) a[i + j + len] += md;
        pos += step;
      }
    }
  }
}

vector <int> multiply(vector <int> a, vector <int> b) {
  int an = a.size();
  int bn = b.size();
  int nn = 1;
  while (nn < 2 * an || nn < 2 * bn) nn <<= 1;
  int root = power(gen, (md - 1) / nn);
  powers[0] = 1;
  for (int i = 1; i <= nn; i++) {
    powers[i] = mul(powers[i - 1], root);
  }
  a.resize(nn);
  b.resize(nn);
  fft(a);
  fft(b);
  for (int i = 0; i < nn; i++) {
    a[i] = mul(a[i], b[i]);
  }
  reverse(++a.begin(), a.end());
  fft(a);
  int inv = power(nn, md - 2);
  for (int i = 0; i < nn; i++) {
    a[i] = mul(a[i], inv);
  }
  a.resize(an);
  return a;
}

const int N = 123456;

int fact[N], inv_fact[N];
char s1[N], s2[N];

int main() {
  fact[0] = inv_fact[0] = 1;
  for (int i = 1; i < N; i++) {
    fact[i] = mul(fact[i - 1], i);
    inv_fact[i] = inv(fact[i]);
  }
  int n, m;
//  scanf("%d %d", &n, &m);
  scanf("%s", s1);
  scanf("%s", s2);
  n = m = 0;
  for (int i = 0; s1[i]; i++) {
    if (s1[i] == '1') {
      if (s2[i] == '0') {
        n++;
      } else {
        m++;
      }
    }
  }
  vector <int> p(m + 1);
  for (int k = 0; k <= m; k++) {
    p[k] = inv_fact[k + 1];
  }
  vector <int> res(m + 1, 0);
  res[0] = 1;
  int x = n;
  while (x > 0) {
    if (x & 1) {
      res = multiply(res, p);
    }
    p = multiply(p, p);
    x >>= 1;
  }
  int ans = 0;
  for (int j = 0; j <= m; j++) {
    add(ans, res[j]);
  }
  ans = mul(ans, mul(fact[n + m], mul(fact[n], fact[m])));
  printf("%d\n", ans);
  cerr << "time = " << clock() << " ms" << endl;
  return 0;
}


Measured memory_bytes: 2044
#include<bits/stdc++.h>
#define INF INT_MAX
#define int long long
using namespace std;
vector<char> ans;
void f(string s,string t){
    int n=s.size();
    int m=t.size();
    int l[n+1][m+1];
    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            if(i==0 || j==0){
                l[i][j]=0;
            }
            else if(s[i-1]==t[j-1]){
                l[i][j]=1+l[i-1][j-1];
            }
            else{
                l[i][j]=max(l[i-1][j],l[i][j-1]);
            }
        }
    }
    int index=l[n][m];
    char lcs[index+1];
    lcs[index]='\0';
    int i=n,j=m;
    while(i>0 && j>0){
        if(s[i-1]==t[j-1]){
            lcs[index-1]=s[i-1];
            index--,i--,j--;
        }
        else if(l[i-1][j]>l[i][j-1]){
            i--;
        }
        else{
            j--;
        }
    }
    cout<<lcs<<endl;
}

int32_t main(){
    string s,t;
    cin>>s>>t;
    f(s,t);
     
}


Measured memory_bytes: 74012
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <cmath>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
int cou[51];

int main(int argc, char const* argv[])
{
  int n, m;
  cin >> n >> m;
  for(int i = 0; i < m; i++){
    int a, b;
    cin >> a >> b;
    a--; b--;
    cou[a]++;
    cou[b]++;
  }
  for(int i = 0; i < n; i++)cout << cou[i] << endl;
	return 0;
}


Measured memory_bytes: 256
N,M=[int(i) for i in input().split()]
joints=[]
patterns=[]
for i in range(M):
	a=[int(j) for j in input().split()]
	joints.append(a[1:])
ans=input().split()
def f(x,i):
	if i==N:
		patterns.append(x)
		return
	f(x+"0",i+1)
	f(x+"1",i+1)
f("",0)
res=0
for pattern in patterns:
	for i in range(len(joints)):#joinは一つの電球につながっているスイッチの一覧
		on=0
		for j in joints[i]:#jはつながっているスイッチの番号
			if pattern[j-1]=="1":
				on+=1
		if on%2==int(ans[i]):
			if i==len(joints)-1:
				res+=1
			else:
				continue
		else:
			break
	

print(res)
		

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _2881
{
    public class Program

    {
        const string NEW_ERA_NAME = "?";

        public static void Main(string[] args)
        {
            while (true)
            {
                string[] line = ReadStAr();
                if (line[0] == "#") break;
                string eraName = (int.Parse(line[1]+ line[2].PadLeft(2, '0')) < 3105) ? line[0] : NEW_ERA_NAME;
                string newYear = (eraName == line[0]) ? line[1] : (int.Parse(line[1]) - 30).ToString();
                Console.WriteLine("{0} {1} {2} {3}",eraName, newYear, line[2],line[3]);
            }  
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }

    }

}



Measured memory_bytes: 15892
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n,m;
	cin>>n>>m;
	vector<pair<long long,long long> > a;
	for(int i=0;i<n;i++){
		long long hoge;
		cin>>hoge;
		a.push_back(make_pair(hoge,1));
	}
	for(int i=0;i<m;i++){
		long long b,c;
		cin>>b>>c;
		a.push_back(make_pair(c,b));
	}
	sort(a.rbegin(),a.rend());
	long long cnt=0;
	long long ans=0;
	for(int i=0;i<n+m;i++){
		if(cnt+a[i].second<=n){
			cnt+=a[i].second;
			ans+=a[i].first*a[i].second;
		}else{
			ans+=a[i].first*(n-cnt);
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 6512
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<string>

using namespace std;

#define rep(i,n) for(int i=0;i<int(n);i++)
#define reps(i,n) for(int i=1;i<=int(n);i++)
#define sint(i) scanf("%d",&i);
#define sintt(i,j) scanf("%d%d",&i,&j);
#define sinttt(i,j,k) scanf("%d%d%d",&i,&j,&k);
#define sintttt(i,j,k,m) scanf("%d%d%d%d",&i,&j,&k,&m);

#define INF 1010000000
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

int main(){
	while(1){
		int n,m;
		int time[101][101];
		int cost[101][101];
		
		rep(i,101)rep(j,101)time[i][j]=cost[i][j]=INF;
		
		sintt(n,m);
		if(n==0)break;
		rep(i,n){
			int a,b,c,d;
			sintttt(a,b,c,d);
			
			time[a][b]=d;
			time[b][a]=d;
			
			cost[a][b]=c;
			cost[b][a]=c;
		}
		
		reps(k,m){
			reps(i,m){
				reps(j,m){
					cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
					time[i][j]=min(time[i][j],time[i][k]+time[k][j]);
				}
			}
		}
		
		int q;
		sint(q);
		rep(i,q){
			int a,b,c;
			sinttt(a,b,c);
			if(c==1){
				printf("%d\n",time[a][b]);
			}else{
				printf("%d\n",cost[a][b]);
			}
		}
	}
}

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

#define fi first
#define se second
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for (int i = a; i <= (b); i++)
#define ROF(i, a, b) for (int i = a; i >= (b); i--)

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<ll>; using vvll = vector<vll>;

int main() {
    int n; cin >> n;
    string s; cin >> s;
    int r = 0, w = 0;
    FOR(i, 0, s.size() - 1) {
        if (s[i] == 'R') r++;
        else w++;
    }
    int ans = r, cur = 0;
    FOR(i, 0, s.size() - 1) {
        if (s[i] == 'R') cur++;
        ans = min(ans, r - cur + max(0, i - r + 1));
    }
    cout << ans << endl;
}

Measured memory_bytes: 3752
import Data.String
import Control.Applicative

main = do
        x <- words <$> getContents
        mapM print (map solve (map read x))

range :: [Int]
range = [0..9]

allList :: [[Int]]
allList = [[a, b, c, d] | a<-range, b<-range, c<-range, d<-range]

solve :: Int -> Int
solve n = length  [y | y<-allList, (foldr (+) 0 y) == n]

Measured memory_bytes: 6136
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    
    string X;
    int num;
    string s[55];
    int t[55];
 
   cin >> N;
   for(int i=0;i<N;i++){
       cin >> s[i] >> t[i];
   }
   cin >> X;
 
   for(int i=0;i<N;i++){
       if(s[i] == X){
           num = i;
           break;
   }
   }
 int time = 0;
   for(int i=num+1;i<N;i++){
       time += t[i];
   }
 
    cout << time;
    return 0;
}

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

int main(){
    int N, K;
    scanf("%d %d", &N, &K);
    set<int> st;
    for(int i=0;i<K;i++){
        int d;
        scanf("%d", &d);
        for(int j=0;j<d;j++){
            int A;
            scanf("%d", &A);
            st.insert(A);
        }
    }
    int SIZE = st.size();
    int ans = N - SIZE;
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 3284
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>

#include <string.h>

using namespace std;

typedef long long ll;

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

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

const int MAX_N = 3000;
const int MAX_T = 3000;

ll dp1[MAX_N + 1][MAX_T + 1];
ll dp2[MAX_N + 1][MAX_T + 1];

ll solve(int n, int t, ll dp[MAX_N + 1][MAX_T + 1], const vector<pair<int, int> > &dishes) {
    if (dp[n][t] != -1) {
        ; // just return dp[n][t];
    } else if (n == 0 || t == 0) {
        dp[n][t] = 0;
    } else if (dishes[n - 1].first > t) {
        dp[n][t] = solve(n - 1, t, dp, dishes);
    } else {
        dp[n][t] = max(
                solve(n - 1, t - dishes[n - 1].first, dp, dishes) + dishes[n - 1].second,
                solve(n - 1, t, dp, dishes)
                );
    }

    return dp[n][t];
}

int main(void) {
    int n, t;
    cin >> n >> t;
    
    vector<pair<int, int> > dishes(n);
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        dishes[i] = {a, b};
    }
    vector<pair<int, int> > rev_dishes(dishes);
    reverse(rev_dishes.begin(), rev_dishes.end());

    memset(dp1, -1, sizeof(ll) * (MAX_N + 1) * (MAX_T + 1));
    memset(dp2, -1, sizeof(ll) * (MAX_N + 1) * (MAX_T + 1));

    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= t; j++) {
            solve(i, j, dp1, dishes);
            solve(i, j, dp2, rev_dishes);
        }
    }
  
    ll max = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= t - 1; j++) {
            chmax(max, dp1[i - 1][j] + dp2[n - i][t - 1 - j] + dishes[i - 1].second);
        }
    }

    cout << max << endl;

    return 0;
}


Measured memory_bytes: 141056
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main(void){
  int a,b,c,d,x;
  cin>>a>>b>>c>>d;
  if((x=min(b,d)-max(a,c))>0) cout<<x<<endl;
  else cout<<0<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>                                     
using namespace std;                                         
                                                             
int main(void) {                                             
  int n;                                                     
  cin >> n;                                                  
  int a;                                                     
  int max = -INT_MAX;                                        
  int min = INT_MAX;                                         
  long long sum = 0;                                         
  for (int i=0; i<n; i++) {                                  
    cin >> a;                                                
    max = std::max(max,a);                                   
    min = std::min(min,a);                                   
    sum += a;                                                
  }                                                          
  cout << min << " " << max << " " << sum << endl;           
  return 0;                                                  
}                                                            
                                                             
                                 

Measured memory_bytes: 3112
N, M = map(int, input().split())
X = sorted(list(map(int, input().split())))

diff_list = [0] * (len(X) - 1)
for i in range(len(X) - 1):
    diff_list[i] = X[i + 1] - X[i]

diff_sorted = sorted(diff_list, reverse=True)[N - 1:]
print(sum(diff_sorted))

Measured memory_bytes: 13960
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  vector<char> s(n);
  for(int i=0;i<n;i++){
    cin >> s[i];
    if(i==(k-1)){
      s[i]+=32;
    }
  }
  for(int i=0;i<n;i++){
    cout << s[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayDeque

// https://atcoder.jp/contests/abc075/tasks/abc075_c

fun main() {
    abc075c()
}

fun abc075c() {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val edges = mutableListOf<Pair<Int, Int>>()
    val nodes = List(n + 1) { mutableSetOf<Int>() }
    repeat(m) {
        val (a, b) = readLine()!!.split(" ").map { it.toInt() }
        edges.add(a to b)
        nodes[a].add(b)
        nodes[b].add(a)
    }
    var count = 0
    for (e in edges) {
        val start = e.first
        val goal = e.second
        val visited = mutableSetOf<Int>()
        val queue = ArrayDeque<Int>()
        var isAvailable = false
        visited.add(start)
        for (node in nodes[start]) {
            if (node == goal) continue
            queue.add(node)
        }
        while (queue.isNotEmpty()) {
            val node = queue.poll()
            if (node == goal) {
                isAvailable = true
                break
            }
            if (node in visited) continue
            visited.add(node)
            for (elm in nodes[node]) {
                if (elm !in visited) queue.add(elm)
            }
        }
        if (!isAvailable) count++
    }
    println(count)
}

Measured memory_bytes: 36704
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <map>
#include<vector>
#include<queue>
#include<bits/stdc++.h>
#define debug(x) cout <<#x<<" = "<<x<<endl
#define debug2(x, y) cout<<x<<" "<<y<<endl
#define gg cout <<"---------------QAQ---------------"<<endl
#define fi first
#define SZ(x) (int)x.size()
#define se second
#define pb push_back
#define inf 0x3f3f3f3f
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<pii, ll> Pii;
template<class T> inline void read(T &x){
    x=0; char c=getchar(); int f=1;
    while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
    while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
const int N = 2e5+10, maxn = 1e6+5;
void FAST(){ios::sync_with_stdio(false);cin.tie(0);}
const ll mod =  998244353;

int n, m, k;

void solve()
{
    printf("%.10f\n", 2.0*PI*n);
}


int main()
{
//    int _; scanf("%d", &_); while(_--)
//    while(~scanf("%d%d", &n, &d))
    while(~scanf("%lld", &n))
    solve();
    return 0;
}


Measured memory_bytes: 3760
/*
    - N red points + N blue points
    - Sort all points by x
    - Then, for each red points, find the blue point such that
    - xBlue > xRed, yBlue > yRed, and yBlue as close as possible
*/
#include <bits/stdc++.h>
using namespace std;

struct Point {
  int x, y;
};

int main() {
	
  // Read input
  int n, count = 0; 
  cin >> n;
  vector<Point> r(n);
  vector<Point> b(n);
  vector<int> bvisited(n, 0);
  for (int i = 0; i < n; ++i) cin >> r[i].x >> r[i].y;
  for (int i = 0; i < n; ++i) cin >> b[i].x >> b[i].y; 
  
  // Solve
  sort(r.begin(), r.end(), [] (const Point &a, const Point &b) {
    return (a.x > b.x) || (a.x == b.x && a.y > b.y);
  });
  sort(b.begin(), b.end(), [] (const Point &a, const Point &b) {
    return (a.x > b.x) || (a.x == b.x && a.y > b.y);
  }); 

  for (int i = 0; i < n; ++i) {
    int min_y = 2*n;
    int min_j = -1;
    for (int j = 0; j < n; ++j) {
      if (!bvisited[j])  {
        bool check_x = (r[i].x < b[j].x);
        bool check_y = (r[i].y < b[j].y);
        if (check_x && check_y) {
          if (b[j].y < min_y) {
            min_y = b[j].y;
            min_j = j;
          } 
        }
      } 
    }

    //cout << r[i].x << ' ' << r[i].y << "\n";
    //cout << i << ' ' << min_j << "\n\n";
    if (min_j != -1 && bvisited[min_j] == 0) {
      bvisited[min_j] = 1;
      count++;
    }
  }

  cout << count << endl;

	return 0;
}


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

int main() {
int M,D,a,b,c=0;
  cin>>M>>D;
  for(int j=1;j<M+1;j++){
    for(int i=20;i<D+1;i++){
      a=i%10;
      b=i/10;
      if(a==1){
        continue;
      }
      else if(j==a*b){
        c++;
      }
    }
  }
  cout<<c<<endl;
}


Measured memory_bytes: 256
x1, y1, x2, y2 = map(int, input().split())

diff_x = x1 - x2
diff_y = y1 - y2
x3, y3 = x2 + diff_y, y2 - diff_x
x4, y4 = x3 + diff_x, y3 + diff_y
print(x3, y3, x4, y4)

Measured memory_bytes: 2940
s = int(input())
u = 1 <= (s//100) <= 12
d = 1 <= (s%100) <= 12
if u:
  if d:
    print("AMBIGUOUS")
  else:
    print("MMYY")
else:
  if d:
    print("YYMM")
  else:
    print("NA")

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define A first
#define B second
#define make_pair MP
#define MOD 1000000007
#define MAXM 100005
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef long long ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }


int mulmd(ll a, ll b){
    ll ret = (a * b) % MOD;
    return (int)ret;

}

inline int power(ll x, ll y, int p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = mulmd(res,x);
        y = y>>1;
        x = mulmd(x,x);
    }
    return (int)res;
}

int submd(ll a, ll b){
    ll ret = a-b;
    if(ret<0){
        ret+=MOD;
    }
    return (int)ret;
}

int addmd(ll a, ll b){
    ll ret = (a + b) % MOD;
    return (int)ret;
}

int phi(int n){
    int result = n;
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            while(n%i==0){
                n=n/i;
            }
            result-=result/i;
        }
    }
    if(n>1) result-=result/n;
    return result;
}

int gcd(int a, int b, int& x, int& y){
    if(a==0){
        x=0;
        y=1;
        return b;
    }
    int x1,y1;
    int d = gcd(b%a, a, x1, y1);
    x = y1 - (b/a)*x1;
    y = x1;
    return d;
}

int arr[100005];

int dist(int x1,int y1,int x2,int y2)
{
    int dx=x2-x1;int dy=y2-y1;
    float ans=sqrt(dx*dx+dy*dy);
    return ceil(ans);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h,a;
    cin>>h>>a;
    int d = h/a;
    if(h%a==0)
        cout<<d;
    else
        cout<<d+1;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
V<int> dy={-1,0,1,0},dx={0,-1,0,1};
map<int,P> mp;
int main(){
  int n;
  cin>>n;
  V<ll> a(n*n);
  for(int i=0;i<n*n;i++)cin>>a[i];
  V<V<ll>> d(n,V<ll>(n));
  int cnt=1;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      d[i][j]=min({i,j,n-i-1,n-j-1});
      mp[cnt++]=P(i,j);
    }
  }
  ll ans=0;
  V<V<bool>> used(n,V<bool>(n,false));
  for(int i=0;i<n*n;i++){
    int s=mp[a[i]].fi,t=mp[a[i]].se;
    ans+=d[s][t];
     queue<P> q;
     d[s][t]--;
     used[s][t]=true;
     q.emplace(s,t);
    while(q.size()){
    int y=q.front().fi,x=q.front().se;
    q.pop();
     for(int j=0;j<4;j++){
       int ny=dy[j]+y,nx=dx[j]+x;
       if(ny<0||ny>=n||nx<0||nx>=n)continue;
       if(d[ny][nx]>d[y][x]+(!used[ny][nx])){
         d[ny][nx]--;
         q.emplace(ny,nx);
       }
      }
    }
}
cout<<ans<<"\n";
}

Measured memory_bytes: 22728
n, c = gets.to_s.split.map{|t| t.to_i }

d = [[0] * (c+1) ] + Array.new(c){ [0] + gets.to_s.split.map{|t| t.to_i } }
grid = Array.new(n){ gets.to_s.split.map{|t| t.to_i } }

counters = Array.new(3){ Array.new(c+1){ 0 } }

# O(N^2)
n.times do |i|
  n.times do |j|
    counters[(i+j)%3][grid[i][j]] += 1
  end
end
# p counters
# O(cP3)
ans = n * n * 1000
1.upto(c) do |s|
  1.upto(c) do |t|
    1.upto(c) do |u|
      
      next if s == t || s == u || t == u
      
      cost = 0
      
      color = s
      counter = counters[0]
      counter.each_with_index do |cnt, col|
        next if col == color
        cost += d[col][color] * cnt
      end
      
      color = t
      counter = counters[1]
      counter.each_with_index do |cnt, col|
        next if col == color
        cost += d[col][color] * cnt
      end
      
      color = u
      counter = counters[2]
      counter.each_with_index do |cnt, col|
        next if col == color
        cost += d[col][color] * cnt
      end
      
      ans = cost if ans > cost
    end
  end
end

puts ans

Measured memory_bytes: 4348
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    unused_imports,
    dead_code
)]
//use permutohedron::LexicalPermutation as _;
use proconio::input;
//use proconio::marker::*;
use std::collections::*;
//use std::cmp::*;
//use std::num;
//use petgraph::unionfind::UnionFind;
const MOD: i64 = 1_000_000_007;
fn main() {
    input! {
        N:i64,mut K:i64
    }
    let mut ans = 0;
    let mut gcd_num = vec![0i64; K as usize + 1];
    for a in (1..=K).rev() {
        gcd_num[a as usize] = modPow(K / a, N);
        for i in 2..=K / a {
            gcd_num[a as usize] = (gcd_num[a as usize] - gcd_num[(a * i) as usize]) % MOD;
        }
        ans = (ans + gcd_num[a as usize] * a % MOD) % MOD;
    }

    ans = (ans + MOD) % MOD;
    println!("{}", ans);
}

fn modPow(x: i64, a: i64) -> i64 {
    if a == 1 {
        x
    } else if a & 1 == 1 {
        x * modPow(x, a - 1) % MOD
    } else {
        modPow(x, a / 2).pow(2) % MOD
    }
}


Measured memory_bytes: 2796
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)

ll e_gcd(ll a, ll b) {
	if (a < b) e_gcd(b, a);
	ll r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}

int main() {

	int N, M;
	char S[112345], T[112345];
	scanf("%d%d", &N, &M);
	scanf("%s%s", S, T);

	map<int, char> mp;

	rep(i, N) mp[i*M] = S[i];

	rep(i, M) {
		if (mp[i*N] && mp[i*N] != T[i]) {
			printf("-1");
			return 0;
		}
	}

	printf("%lld\n", (ll)N* M / e_gcd(N, M));
	return 0;
}


Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define mod2 1000000000
#define mod1 998244353
#define lol ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define F(i, n) for (ll (i) = 0; (i) < (n); (i)++)
#define pb push_back
#define pf push_front
#define mp make_pair
#define f first
#define ss second
int main()
{
    lol;
    ll a;
    cin >> a;
    cout << a + a*a + a*a*a << endl;
}
    

Measured memory_bytes: 3648
/******************************************************************************

                            Online C Compiler.
                Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <stdio.h>

int main()
{
    int sum=0;
    char c;
    int i;
    for(i=0; i<3; i++){
        scanf("%c",&c);
        sum += (c=='1');
    }
    printf("%d\n",sum);
}





Measured memory_bytes: 128
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N, M, Q = list(map(int, sys.stdin.buffer.readline().split()))
LR = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]
P, Q = list(zip(*[map(int, sys.stdin.buffer.readline().split()) for _ in range(Q)]))

P = np.array(P, dtype=int)
Q = np.array(Q, dtype=int)

counts = np.zeros((N + 1, N + 1), dtype=int)
for l, r in LR:
    counts[l, r] += 1
cum = counts.cumsum(axis=1).cumsum(axis=0)

ans = cum[Q, Q] - cum[P - 1, Q] - cum[Q, P - 1] + cum[P - 1, P - 1]
print(*ans, sep='\n')


Measured memory_bytes: 103076
#include <iostream>

int main()
{
    char b;
    std::cin >> b;

    switch (b) {
    case 'A':
        std::cout << 'T' << std::endl;
        break;
    case 'T':
        std::cout << 'A' << std::endl;
        break;
    case 'C':
        std::cout << 'G' << std::endl;
        break;
    case 'G':
        std::cout << 'C' << std::endl;
        break;
    }
}


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

#define ll long long
#define ull unsigned long long
#define pb push_back
#define pf push_front
#define pof pop_front
#define pob pop_back
#define mp make_pair
#define pll pair<ll,ll>
#define pii pair<int,int>
#define all(s) s.begin(),s.end()
#define vll vector<ll>
#define vi vector<int>
#define vpii vector<pii>
#define vpll vector<pll>
#define vd vector<double>
#define vull vector<ull>
#define vc vector<char>
#define vs vector<string>
#define fi first
#define se second
#define sz(x) x.size()
#define cinarr(n,a) for(int i = 0; i < n; i++) cin >> a[i];
#define coutarr(n,a) for(int i = 0; i < n; i++) cout << a[i] << (i+1==n?'\n':' ');
#define fori(i,a,b,x) for(int i = a; i <= b; i+=x)
#define ford(i,a,b,x) for(int i = a; i >= b; i-=x)
#define tc int tt; cin >> tt; for(int cs = 1; cs <= tt; cs++)
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define ld long double
#define reset(x,y) memset(x,y,sizeof x);
#define sqr(x) 1LL*(x)*(x)
#define cube(x) 1LL*(x)*(x)*(x)
#define ub(v, a) upper_bound(all(v), a)
#define lb(v, a) lower_bound(all(v), a)
#define EPS 1e-10
#define INF 200000
#define mod 1000000007
#define minof(a) min_element(all(a))
#define maxof(a) max_element(all(a))
#define debug(val) cout << "The value of " << #val << " is = " << val << endl;
#define testing cout << "--------------------------\n";

int main() {
	IOS
	int n,k;
	cin>>n;
	ll a[n+5];
	map<ll,ll> freq;
	for(int i = 0; i < n; i++) {
		cin>>a[i];
		freq[a[i]]++;
	}
	ll r=0;
	for(auto x : freq) {
		r+=x.se*(x.se-1)/2;
	}
	for(int i = 0; i < n; i++) {
		ll out=r;
		out-=freq[a[i]]*(freq[a[i]]-1)/2;
		out+=(freq[a[i]]-1)*(freq[a[i]]-2)/2;
		cout<<out<<endl;
	}
}


Measured memory_bytes: 13104
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define RFOR(i,s,e) for(int (i) = (s);(i) >= (e);(i)--)
#define rep(i,n) FOR(i,0,n-1)
#define MOD 1000000007
 
int c[5][100005];
int m[5];
int m2[5];
int idx[5];
int secondIdx[5];
 
signed main(){
	int n;cin>>n;
	rep(i,n)
	{
		int v;cin>>v;
		c[i%2][v]++;
	}
	
	
	rep(i,2) FOR(j,1,100000)
	{
		if(m[i%2]<=c[i%2][j])
		{
			secondIdx[i%2] = idx[i%2];
			idx[i%2] = j;
			m2[i%2] = m[i%2];
			m[i%2] = c[i%2][j];
		}
		else if(m2[i%2]<=c[i%2][j])
		{
			secondIdx[i%2] = j;
			m2[i%2] = c[i%2][j];
		}
	}
	
	int ans;
	if(idx[0] == idx[1])
	{
		int iti = n - m[0] - c[1][secondIdx[1]];
		int ni = n - m[1] - c[0][secondIdx[0]];
		ans = min(iti,ni);
	}
	else
	{
		ans = n - m[0] - m[1];
	}
	cout << ans << endl;
	
}

Measured memory_bytes: 1792
#!usr/bin/env pypy3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)

def main():
    S = input()
    T = input()
    ans = 0
    for (s, t) in zip(S, T):
        ans += 0 if s == t else 1
    print(ans) 

main()


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

W = input()
words = {W}

ans = True
for _ in range(N - 1):
    num = len(words)
    w = input()
    words.add(w)
    if (W[-1] != w[0] or num == len(words)):
        ans = False
        break
    W = w

if (ans):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38384
def merge(A, c, left, mid, right):
    count = 0
    n1 = mid - left
    n2 = right - mid
    L = [0] * (n1+1)
    R = [0] * (n2+1)
    for i in range(n1):
        L[i] = A[left + i]
    for i in range(n2):
        R[i] = A[mid + i]
    L[n1] = 2000000000
    R[n2] = 2000000000
    i = 0
    j = 0
    for k in range(left,right):
        c += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else : 
            A[k] = R[j]
            j += 1
            count += n1 - i
    return count

def mergeSort(A, c, left, right):
    if left+1 < right:
        mid = int((left + right)/2)
        c1 = mergeSort(A, c, left, mid)
        c2 = mergeSort(A, c, mid, right)
        c3 = merge(A, c, left, mid, right)
        return c1 + c2 + c3
    else :
        return 0

if __name__ == '__main__':
    n = int(input())
    A = list(map(int,input().split()))
    c = mergeSort(A, n, 0, n)
    print(str(c))


Measured memory_bytes: 28336
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int A, B, C;
	cin >> A >> B >> C;
	if (A + B < C)
	{
		cout << A + B * 2 + 1 << endl;
	}
	else
	{
		cout << B + C << endl;
	}
	return 0;
}


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

int main(){
    int n,k,now;
    double ans = 0.0;
    double one_n,temp;
    cin >> n >> k;
    one_n = 1.0 / n;

    for (int i = 1; i <= n; i++) {
        now = i;
        temp = one_n;
        while ( now < k ) {
            now *= 2.0;
            temp /= 2.0;
        }
        ans += temp;
    }

    cout << setprecision(15) << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
 
const ll INF = 1e10;

int main(){
    int n, k;
    cin >> n >> k;
    vec<ll> p(n);
    rep(i, n) cin >> p[i];
    ll ans = 0;
    ll tmp = 0;
    rep(i, k) tmp += p[i];
    ans = tmp;
    //cout << ans << endl;
    rep(i, n-k) {
        tmp += p[i+k];
        tmp -= p[i];
        //cout << tmp << endl;
        if (ans < tmp) ans = tmp;
    }
    cout << setprecision(10) << (ans+k)/2.0 << endl;
}

Measured memory_bytes: 1792
/*****include*****/
#include <iostream>
#include <string>
/*****デバッグ定義*****/
//#define DEBUG
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/

/*****その他関数置き場*****/

/*****main関数*****/
int main(){
	/*****変数置き場*****/
	string number;
	string num;
	char c_x;
	char c_y;
	int x;
	int y;
	bool fail;
	char table[6][7] = {
		{'0','0','0','0','0','0','0'},
		{'0','a','f','k','p','u','z'},
		{'0','b','g','l','q','v','.'},
		{'0','c','h','m','r','w','?'},
		{'0','d','i','n','s','x','!'},
		{'0','e','j','o','t','y',' '}
	};
	string answer;
	/*****処理部*****/
	while(1){
		cin >> number;
		if(cin.eof())	break;
		fail = false;
		answer = "";
		if(number.length()%2 != 0){
			fail = true;
		}else{
			for(int i=0;i<number.length();i+=2){
				num = number.substr(i,2);
				c_x = num[0];
				c_y = num[1];
				x = c_x - '0';
				y = c_y - '0';
				if(x<=0 || x>6 || y<=0 || y>5){
					fail = true;
					break;
				}
				answer.append(1,table[y][x]);
				//cout << table[y][x];
			}
		}
		if(fail)	cout << "NA" << endl;
		else
			cout << answer << endl;
	}
	/*****処理終了後*****/
	return 0;
}

Measured memory_bytes: 1192