akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <math.h>

int comb(int n, int r)
{
    if (r == 0)
        return 1;
    if (n == r)
        return 1;
    return comb(n - 1, r) + comb(n - 1, r - 1);
}

int main()
{
    int N, M;
    scanf("%d %d", &N, &M);
    int ans = 0;
    if (N > 1)
    {
        ans += comb(N, 2);
    }
    if (M > 1)
    {
        ans += comb(M, 2);
    }

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

Measured memory_bytes: 128
s = input()
i = s.count("R")
if i == 0:
    print(0)
elif i == 1:
    print(1)
elif i == 2:
    if s == "RRS" or s == "SRR":
        print(2)
    else:
        print(1)
elif i == 3:
    print(3)

Measured memory_bytes: 9032
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#include<string>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#pragma GCC target("avx")
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC diagnostic error "-std=c++14"

#define isNum(a) (a>='0'&&a<='9')
#define SP putchar(' ')
#define EL putchar('\n')
#define ri register int

template<class T>
inline void in(T&);
template<class T>
inline void out(const T&);

typedef long long ll;
using std::min;
using std::max;
using std::abs;
using std::sort;
using namespace std;

int k,n,m; 

int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    in(k);in(n);in(m);
    for (ri i=1;;++i)
    {
    	if (k*i>=n&&k*i<=m)
    	{
    		puts("OK");
    		return 0;
		}
		if (i*k>m) break;
	}
	puts("NG");
    return 0;
}

template<class T>
void in(T &Re)
{
    T k=0;
    char ch=getchar();
    int flag=1;
    while (!isNum(ch))
	{
        if (ch=='-')
		{
            flag=-1;
        }
        ch=getchar();
    }
    while (isNum(ch))
	{
        k=(k<<1)+(k<<3)+ch-'0';
        ch=getchar();
    }
    Re=flag*k;
}

template<class T>
void out(const T &Wr)
{
    if (Wr<0)
	{
        putchar('-');
        out(-Wr);
    }
	else
	{
        if (Wr<10)
		{
            putchar(Wr+'0');
        }
		else
		{
            out(Wr/10);
            putchar((Wr%10)+'0');
        }
    }
}




Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define vi vector<int>
#define mod 100000007
const int INF=1e9+5;
const int N=1e7+2;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;vector<int> dp(n,INF);vector<int> g;
    fo(i,n){int chap;cin>>chap;
    g.push_back(chap);
        }
           dp[0]=0;
       for(int i=0;i<n;i++){
           for(int j=i+1;j<=(i+k);j++){
               if(j<n){
        dp[j]=min(dp[j],dp[i]+abs(g[j]-g[i]));
               }
    }
}
        cout<<dp[n-1]<<endl;

    return 0;
}

Measured memory_bytes: 1276
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long inf = numeric_limits<long long>::max();
int main()
{
  int n;
  cin >> n;
  int d = n / 100;
  if (n / d == 111 && n % d == 0) {
    cout << n << endl;
  } else {    int c = 100*d + 10*d + d;
    if (c < n) {
      cout << c+111 << endl;
    } else {
      cout << c << endl;
    }
  }
  return 0;
}

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


int main(){
    ll N; cin >> N;
    ll A[N];
    ll cnt[N+1] = {0};
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        cnt[A[i]]++;
    }
    ll ans = 0;
    for (int i = 0; i < N; i++)
    {
        ans += cnt[i+1]*(cnt[i+1]-1)/2;
    }
    for (int i = 0; i < N; i++)
    {
        cout << ans - (cnt[A[i]]-1) << endl;
    }
    
}

Measured memory_bytes: 5760
a,b,k = map(int,input().split())

for i in range(k):
    if i % 2 == 0:
        if a % 2 == 1:
            a -= 1
        
        b += a // 2
        a = a // 2
    else:
        if b % 2 == 1:
            b -= 1

        a += b // 2
        b = b // 2


print(a,b)


Measured memory_bytes: 2940
def main() :
    n = int(input())
    nums = []
    for i in range(n) :
        x = int(input())
        nums.append(x)

    max = float("-inf")
    min = nums[0]
    for i in range(1,n) :
        if nums[i] - min > max :
            max = nums[i] - min

        if nums[i] < min :
            min = nums[i]

    print(max)



if __name__ == '__main__' :
    main()

Measured memory_bytes: 15652
#include <iostream>
#include <string>
#include <unordered_set>
#define int long long
using namespace std;
int n;
unordered_set<string> h_s;
signed main(){
    string opr, word;
    while(cin >> n){
        for(int i=0; i<n; i++){
            cin >> opr >> word;
            if(opr == "insert"){
                h_s.insert(word);
            }else if(opr == "find"){
                cout << ((h_s.count(word)>0)? "yes": "no") << endl;
            }
        }
    }
}


Measured memory_bytes: 32256
#include <iostream>

using namespace std;

int main(){
 int N,M,Q,a[50],b[50],c[50],d[50];
  cin >> N >> M >> Q;
  for(int i = 0; i<Q; i++){
   cin >> a[i] >> b[i] >> c[i] >> d[i]; 
  }
  int A[11]= {0,1,1,1,1,1,1,1,1,1,1};
  int max = 0;
  while(A[0]==0){
    int sum = 0;
   
  	for(int i = 0; i<Q; i++){
    	if(A[b[i]]-A[a[i]]==c[i])
          sum+=d[i];
 	}
    if(max<sum)
      max = sum;
   
   A[N]++;
    for(int j=N;j>=1;j--){
     if(A[j]>M){
      A[j-1]++;
     }else{
      for(int k = j+1; k<=N; k++){
       A[k] = A[j]; 
      }
       break;
     }
    }
  }
  cout<< max <<endl;
  return 0;
}

Measured memory_bytes: 3624
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

int main() {
  int k;
  int s[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

  std::cin >> k;


  std::cout << s[k-1] << std::endl;

  return 0;
}


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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

// bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
//     return arg1.first > arg2.first;
// }

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

    vector<int> a(n);
    for(int i=0;i<n;i++) {
        cin >> a.at(i);
    }

    int hmax = a.at(0), ans=1;

    for(int i=1;i<n;i++) {
        if(hmax<=a.at(i)) {
            ans++;
            hmax = a.at(i);
        }
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() 
{
  int N;
  int A;
  int B;
  
  cin >> N >> A >> B;
  if(N * A < B)
  {
    cout << N * A << endl;
  }
  else if(N * A > B)
  {
    cout << B << endl;
  }
  else if(N * A == B)
  {
    cout << B << endl;
  }
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, l;
    cin >> n >> l;
    vector<string> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a.begin(), a.end());
    for (int i = 0; i < n; ++i)
        cout << a[i];
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;

const int N=4e5+5;
int n,k,now,c[N],b[N];
ll s,ans;
struct A{ ll x; int id; }a[N];

bool cmp(A i,A j) {
    return i.x<j.x;
}

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

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

int main() {
    scanf("%d%d",&n,&k);
    a[0]=(A){0,0};
    for(int i=1;i<=n;i++) {
        int x; scanf("%d",&x);
        s+=x;
        a[i]=(A){s-(ll)k*i,i};
    }
    sort(a,a+n+1,cmp);
    b[a[0].id]=now=1;
    for(int i=1;i<=n;i++) {
        if(a[i].x!=a[i-1].x) {
            now++;
        }
        b[a[i].id]=now;
    }
    for(int i=0;i<=n;i++) {
        ans+=ask(b[i]),add(b[i]);
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 6656
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

int main()
{
	int N,M;
	cin>>N>>M;
	vector<vector<int>> path(N);

	for(int i=0; i<M; i++)
	{
		int s,t;
		cin>>s>>t;
		s--;
		t--;
		path[s].push_back(t);
	}

	int S,T;
	cin>>S>>T;
	S--;
	T--;
	
	vector<vector<bool>> dp(N);
	for(int i=0; i<N; i++)
	{
		dp[i].resize(3,false);
	}
	dp[S][0] = true;
	queue<pair<int,int>> q;
	q.push(make_pair(S,0));
	//int result = 0;
	while(!q.empty())
	{
		//pathを開く
		int point = q.front().first;
		int mod = q.front().second;

		if(point == T && mod % 3 == 0)
		{
			cout<<(mod/3)<<endl;
			return 0;
		}

		q.pop();



		int pp_size = path[point].size();
		for(int i=0; i<pp_size; i++)
		{
			if(dp[path[point][i]][(mod+1)%3]==false)
			{
				dp[path[point][i]][(mod+1)%3]=true;
				q.push(make_pair(path[point][i],mod+1));
			}
		}
	}

	if(dp[T][0]==false)
	{
		cout<<-1<<endl;
	}
	return 0;
}

Measured memory_bytes: 12800
import sys
from heapq import heappush, heappop


N, Q = map(int, input().split())
P = []
for i in range(1, N + 1):
    s, t, x = map(int, sys.stdin.readline().split())
    P.append((s - x, t - 1 - x, x))
P.sort()


q = []
cur = 0
ans = [-1] * Q
for i, d in enumerate(map(int, sys.stdin)):
    while cur < N and P[cur][0] <= d:
        s, t, x = P[cur]
        heappush(q, (x, t))
        cur += 1
    while q and q[0][1] < d:
        heappop(q)
    if q:
        ans[i] = q[0][0]

print(*ans, sep='\n')

Measured memory_bytes: 109532
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 998244353
pair<int,int> a[100005];
int n,m;
signed main(){
	cin >> n >> m;
	for(int i = 1 ; i <= m ; i ++)
		cin >> a[i].first >> a[i].second;
	sort(a + 1, a + m + 1);
	int ans = 0;
	int L = a[1].first, R = a[1].second;
	a[m + 1] = {LLONG_MAX, LLONG_MIN};
	int req = 2;
	while(req <= m){
		//cout << req << endl;
		L = max(L, a[req].first);
		R = min(R, a[req].second);
		if(L < R) req ++;
		else ans ++, L = a[req].first, R = a[req].second;	
	}
	cout << ans + 1;
}


Measured memory_bytes: 1792
#include<stdio.h>

int main()
{
	char ch;
	int count[26] = {0};
	int i;
	
	while(scanf("%c",&ch) != EOF){
		if (ch >='A' && ch <='Z')
		{
			i = ch - 'A';
			count[i]++;
		}
		else if(ch >='a' && ch <='z')
		{
			i = ch - 'a';
			count[i]++;
		}
	}
	ch = 'a';
	for(i = 0;i < 26;i++){
		printf("%c : %d\n" ,ch,count[i]);
		ch++;
	}
	return 0;
}


Measured memory_bytes: 2144
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x;
    cin>>x;
    int a=x/1000;
    int b=-10*a+x/100;
    int c=-100*a-10*b+x/10;
    int d=-1000*a-100*b-10*c+x;
    int jc[2]={1, -1};
    int jk[2]={1, -1};
    int jd[2]={1, -1};
    char s[2]={'+', '-'};
    bool h =false;
    for(int i=0;i<2;i++){
        for(int j=0;j<2;j++){
            for(int k=0;k<2;k++){
                if(a+jc[i]*b+jk[j]*c+jd[k]*d==7){
                    cout<<a<<s[i]<<b<<s[j]<<c<<s[k]<<d<<"=7";
                    h=true;
                    break;
                }
            }
            if(h){
                break;
            }
        }
        if(h){
            break;
        }
    }
}


Measured memory_bytes: 256
H, W, K = map(int, input().split())
HW = [0] * H
for i in range(H):
  HW[i] = str(input())
ans = 0

for i in range(2 ** (H + W)):
  now = 0
  hh = [0] * H
  ww = [0] * W
  for j in range(H):
    if ((i >> j) & 1):
      hh[j] = 1
  for k in range(W):
    if (i >> (k + H)) & 1:
      ww[k] = 1
   
  for j in range(H):
    for k in range(W):
      if (hh[j] == 1) and (ww[k] == 1):
        if HW[j][k] == "#":
          now += 1
  #print(i, hh, ww, now)
  if now == K:
    ans += 1
    
print(ans)
          
      
      

Measured memory_bytes: 9156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
ll D, G;
vector<ll> p(11, 0);
vector<ll> c(11, 0);
//vector<ll> dp(10550010, LLONG_MAX);
vector<vector<ll>> dp(20, vector<ll>(10010, -1));
 
int main(void){
	
	cin >> D >> G;
	for(int i = 0; i < D; ++i) cin >> p[i] >> c[i]; 
    
    dp[0][0] = 0;
    for(int i = 0; i < D; ++i){
        for(int j = 0; j < 10010; ++j){
            if(~dp[i][j]){
                for(int q = 0; q <= p[i]; ++q){ // 解いた問題数
                    ll point = q * 100 * (i + 1) + (q == p[i] ? c[i] : 0);
                    dp[i + 1][j + q] = max(dp[i + 1][j + q], dp[i][j] + point);
                }
            }
        }
    }
    for(int i = 0; i < 10010; ++i) if(dp[D][i] >= G){ cout << i << endl; break; }
    
	return 0;
}

Measured memory_bytes: 1920
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll>Q;


int main(void){
    string s;
    cin>>s;
    int n = s.length();
    int plus=0,minus=0;
    for(int i=0;i<n;i++){
        if(s[i]=='+')plus++;
        else minus++;
    }
    cout<<plus-minus<<endl;
    return 0;
}

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

using namespace std;

struct Card {
    char suit, value;
};

void bubbleSort(struct Card c[], int n) {
    rep(i, n) {
        for (int j = n - 1; j > i; j--) {
            if (c[j].value < c[j - 1].value) {
                swap(c[j], c[j - 1]);
            }
        }
    }
}

void selectionSort(struct Card c[], int n) {
    rep(i, n) {
        int minj = i;
        for (int j = i; j < n; j++) {
            if (c[j].value < c[minj].value) {
                minj = j;
            }
        }
        swap(c[i], c[minj]);
    }
}

void printC(struct Card c[], int n) {
    rep(i, n) {
        if (i > 0)
            cout << " ";
        printf("%c%c", c[i].suit, c[i].value);
    }
    printf("\n");
}

int main() {
    int n;
    cin >> n;
    Card bubble[n], selection[n];

    rep(i, n) {
        cin >> bubble[i].suit >> bubble[i].value;
        selection[i] = bubble[i];
    }

    bubbleSort(bubble, n);
    selectionSort(selection, n);

    printC(bubble, n);
    printf("Stable\n");

    bool isStable = true;
    rep(i, n) {
        if (bubble[i].suit != selection[i].suit)
            isStable = false;
    }

    printC(selection, n);
    if (isStable)
        printf("Stable\n");
    else
        printf("Not stable\n");
}


Measured memory_bytes: 3208
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;

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

  int a[26] = {};
  string s;
  
  cin >> s;
  
  REP(i,s.size()){
    a[s[i]-'a']++;
  }
  
  bool f = true;
  REP(i,26){
    if(a[i] >= 2) f = false;
  }
  
  if(f) cout << "yes" << endl;
  else  cout << "no" << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vll vector<ll>
#define ub upper_bound
#define lb lower_bound
#define all(v) ((v).begin()),((v).end())
#define ff first
#define ss second
#define mp make_pair
#define pll pair<ll,ll> 
#define fo(i,n) for(ll i=0;i<n;i++)
ll mod1 = 1e9 + 7;
ll mod2 = 998244353;

ll power(ll x,ll y){ll z=1;while(y>0){if(y%2)z=(z*x);x =(x*x) ;y/=2;}return z;}
ll gcd(ll a,ll b){if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);} 
ll min(ll a,ll b){if(a<b)return a;return b;}
ll max(ll a,ll b){if(a>b)return a;return b;}







int main(){
	ll n,k;
	cin>>k>>n;
	ll a[n];
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	ll m1 = a[n-1]-a[0];
	ll mini = 10000000;
	for(ll i=1;i<n;i++){
		ll temp = k - a[i] + a[i-1];
		mini = (mini<temp)?mini:temp;

	}
	cout<<min(mini,m1)<<endl;
	

    
	
}

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

int main(void) {

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	while (1) {
		c -= b;
		if (c <= 0) {
			cout << "Yes";
			return 0;
		}
		a -= d;
		if (a <= 0) {
			cout << "No";
			return 0;
		}
	}
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define nl ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
using namespace std;

int main() {
    nl // Lofi songs		

    int a, b, h;
    cin >> a >> b >> h;
    cout << (a+b) * h/2;
}	


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int R, G, B, N;
    cin >> R >> G >> B >> N;
    lint ans = 0;
    for(int i = 0; i <= N; i += R){
        for(int j = 0; i + j <= N; j += G){
            ans += ((N - i - j) % B == 0);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! test {
    ($($input:expr => $expected_output:expr),*) => {
        #[test]
        fn solve_test() {
            let mut i = 0;
            println!("");
            $(
                i += 1;
                println!("Case {}:", i);
                println!("[in]\n{}", $input);
                println!("[out]\n{}", solve($input));
                println!("[expected out]\n{}", $expected_output);
                println!("");
                assert_eq!(solve($input), $expected_output);
             )*
        }
    }
}

test! {
r"8 3 4
" => r"4",

r"8 0 4
" => r"0",

r"6 2 4
" => r"2"
}

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        N: i64,
        A: i64,
        B: i64,
    }
    let ans: i64 = A*(N/(A+B)) + std::cmp::min(A, N%(A+B));
    return ans.to_string();
}


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

using namespace std;
#define ll long long
#define ld long double

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    string s;
    cin >> s;
    if(s[2] ==s[3] && s[4] == s[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP2(i, a, b) for(int i = a;i <= b;i++)
#define REPR(i, a, b) for(int i = a; i >= b; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define PI 3.14159265358979323846
#define vi vector<int>
#define vll vector<ll>
#define vi2 vector<vector<int>>
#define eb emplace_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
using P = pair<ll,ll>;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
#define INT(name) int name;cin >> name;
#define VEC(type,name,n) vector<type> name(n);REP(i,n) cin >> name[i];

template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
class UnionFind {
public:
    vector < ll > par; // 各元の親を表す配列
    vector < ll > siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1);
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};
int main()
{
  ll N,M;
  cin >> N >> M;
  vector<P> A(M);
  REP(i,M){
    cin >> A[i].first >> A[i].second;
    A[i].first--;
    A[i].second--;
  }
  UnionFind UF(N);
  vector<ll> ans(M);
  ans[M-1]=N*(N-1)/2;
  REPR(i,M-1,1){
    if(UF.issame(A[i].first,A[i].second)){
      ans[i-1]=ans[i];
    }else{
      ans[i-1]=ans[i]-UF.size(A[i].first)*UF.size(A[i].second);
    }
    UF.merge(A[i].first,A[i].second);
  }

  REP(i,M){
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 7204
N,Q=map(int,input().split())
S=input()
A=[0]*N
for i in range(1,N+1):
	if S[i-1:i+1]=="AC":
		A[i]+=1
for i in range(1,N):
	A[i]=A[i]+A[i-1]
for i in range(Q):
	l,r=map(int,input().split())
	print(A[r-1]-A[l-1])

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);


inline LL in() { LL in; scanf("%lld", &in); return in; }
inline void outLL(LL out, bool endl = 1) { printf("%lld%c", out, " \n"[endl]); }

int main() {
	int N = in();
	VL a(N), b(N);
	FOR(i, 0, N)a[i] = in();
	FOR(i, 0, N)b[i] = in();
	LL ans = 0;
	auto A = a;
	auto B = b;
	auto LRsum = [&](int L, int R) {
		return lower_bound(ALL(B), R) - lower_bound(ALL(B), L);
	};
	FOR(k, 0, 30) {
		const int base2 = 1 << k;
		const int base22 = 1 << (k + 1);
		FOR(i, 0, N) {
			A[i] = a[i] % base22;
			B[i] = b[i] % base22;
		}
		SORT(B);
		LL cnt = 0;
		FOR(i, 0, N) {
			if (A[i] <= base2) {
				cnt += LRsum(base2 - A[i], base22 - A[i]);
			}
			else {
				cnt += LRsum(0, base22 - A[i]);
				cnt += LRsum(base2 + base22 - A[i], base2 + base22 - A[i] + base2);
			}
		}
		ans += base2 * (cnt & 1);
	}
	cout << ans << "\n";

}

Measured memory_bytes: 6528
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <set>
#include <functional>
#include <cmath>
#include <set>
#include <map>


//マクロ
#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 RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
#define All(a) (a).begin(),(a).end()
#define RAll(a) (a).rbegin(),(a).rend()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF 1e9
#define INFL 1e18
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
using Graph = vector<vector<int>>;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数

//使用する関数
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;
}

//numまでの素数を求める
int prime[500000] = { 0 };
int idx;
void getPrime(ll num) {
	if (num < 2) {
		idx = -1;
		return;
	}
	prime[0] = 2;
	if (num < 3) {
		idx = 0;
		return;
	}
	idx = 1;
	prime[0] = 2;
	prime[1] = 3;
	ll i, j;
	int flag;
	for (i = prime[idx] + 2; i * i <= num; i += 2) {
		//cout << i << endl;
		flag = 1;
		for (j = 0; prime[j] <= (int)sqrt(i); j++) {
			if (i%prime[j] == 0) {
				flag = 0;
				break;
			}
		}
		if (flag)prime[++idx] = (int)i;
	}
}

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

	ll n;
	cin >> n;
	getPrime(n);
	ll ans = 0;

	REP(i, idx + 1) {
		ll tar = prime[i];
		while(n%tar==0){
			ans++;
			n /= tar;
			if (tar*prime[i] <= (ll)1e12) {
				tar *= prime[i];
				continue;
			}
			break;
		}
		while (n%prime[i] == 0) {
			n /= prime[i];
		}
	}
	if (n != 1)ans++;
	cout << ans << endl;
}

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define rtr(ds, it) for(auto it=ds.rbegin(); it!=ds.rend(); it++)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
typedef priority_queue <ll> pq;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define graph vector<vi>

const ll mod = 1000000007;
ll po(ll x, ll n ){ 
    ll ans=1;
     while(n>0){
         if(n&1) ans=(ans*x)%mod;
         x=(x*x)%mod;
         n/=2;
     }
     return ans;
}



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    int T=1;
    //cin >> T;
    while(T--){
        ll n;
        cin>>n;

       ll lp[n+1]={0};
       vi pr;

       ll ans[n+1]={0};
       ans[1]=1;

       rep_a(i,2,n+1){
            if(lp[i]==0){
                lp[i]=i;
                pr.pb(i);
            }
            for(int j=0;j<(int)(pr.size()) && pr[j]<=lp[i] && i*pr[j]<=n;j++){
                lp[i*pr[j]]=pr[j];
            }
    }
    int cnt, z;
    ll sum=1;
    rep_a(i,2,n+1){
        cnt=0;
        z=i;
        
        while(z%lp[i]==0){
            z/=lp[i];
            cnt++;
        }

        ans[i] = ans[z]*(cnt+1);
        sum += (i*ans[i]);
        
    }
    cout<<sum<<el;
 
   
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}

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

;;

int main(){
  ;;
    int n, a;
    cin >> n >> a;
    ;
    cout << (n*n-a) << endl;;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int n, r;
int p[300000];
bool saw[300001];
vector<int> v;
bool dp[300001];
int d_m = 0;

int main() {
    cin >> n >> r;
    rep(i,n) cin >> p[i];
    rep(i,n) p[i]--;
    rep(i,n) {
        if (saw[i]) continue;
        saw[i] = true;
        int cnt = 1;
        int j = p[i];
        while (true) {
            if (saw[j]) break;
            saw[j] = true;
            j = p[j];
            cnt++;
        }
        v.push_back(cnt);
    }
    sort(v.begin(), v.end());
    dp[0] = true;
    rep(i,v.size()) {
        int con = 1;
        while (i != v.size()-1) {
            if (v[i] == v[i+1]) {
                i++;
                con++;
            } else {
                break;
            }
        }
        for (int k = d_m; k >= 0; k--) {
            if (!dp[k]) continue;
            rep(_,con) {
                dp[k+v[i]*(_+1)] = true;
                d_m = max(d_m, k+v[i]*(_+1));
            }
        }
    }
    if (dp[r]) cout << "Yes" << endl;
    else cout << "No" << endl;
}



Measured memory_bytes: 6432
n = int(input())
s = input()
max1 = -100
n = 0
for i in range(len(s)):
    if s[i] == "I":
        n += 1
    elif s[i] =="D":
        n -= 1
    max1 = max(max1,n)
print(max(max1,0))
            

Measured memory_bytes: 3060
#include <stdio.h>
#define N 40
void Postorder(int *,int *,int);
int n,post[N],count=0;

void Postorder(int *pre,int *in,int n)
{
  int k,p;

  for(k=0;k<n;k++){
    if(pre[0]==in[k]){
      p=k;
      break;
    }
  }

  if(p!=0) Postorder(pre+1,in,p);

  if(p!=n-1) Postorder(pre+p+1,in+p+1,n-p-1);

  post[count]=pre[0];
  count++;
}
    

int main()
{
  int i,pre[N],in[N];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&pre[i]);
  }

  for(i=0;i<n;i++){
    scanf("%d",&in[i]);
  }

  Postorder(pre,in,n);

  for(i=0;i<n;i++){
    if(i==n-1) printf("%d\n",post[i]);
    else printf("%d ",post[i]);
  }

  return 0;
}

Measured memory_bytes: 2760
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << "No"; return;}
#define mkp make_pair
#define mkt make_tuple
#define cerr if (0) cerr

const int N = 2e5 + 7, INF = 1e18;

int a[N], dp2[3][N], dp3[2][N];

int solve0(int n) {
    int odd = 0, even = 0, ans = 0;
    for (int i = 1; i <= n; ++++i) {
        even += a[i]; odd += a[i + 1];
    }
    ans = max(odd, even);
    for (int i = 3; i <= n; ++i) {
        dp2[0][i] = dp2[0][i - 2] + a[i];
        dp2[1][i] = max(dp2[0][i - 3], dp2[1][i - 2]) + a[i];
    }
    ans = max(ans, dp2[1][n]);
    return ans;
}

int solve1(int n) {
    int ans = 0;
    for (int i = 2; i <= n; ++++i)
        ans += a[i];
    dp3[0][0] = 0;
    dp3[0][1] = a[1];
    dp3[0][2] = a[2];
    dp3[0][3] = a[3];
    for (int i = 3; i <= n; ++i) {
        dp2[0][i] = dp2[0][i - 2] + a[i];
        dp2[1][i] = max(dp2[0][i - 3], dp2[1][i - 2]) + a[i];
        dp2[2][i] = max(dp2[1][i - 3], dp2[2][i - 2]) + a[i];
        dp3[0][i] = dp3[0][i - 2] + a[i];
        if (i > 3)
            dp3[1][i] = max(dp3[1][i - 2], dp3[0][i - 4]) + a[i];
    }
    ans = max({ ans, dp2[1][n], dp2[1][n - 1], dp2[2][n], dp3[1][n] });
    return ans;
}

void solve() {
    loop(i, N)
        dp2[0][i] = dp2[1][i] = dp2[2][i] = dp3[0][i] = dp3[1][i] = -INF;
    int n; cin >> n;
    loop1(i, n)
        cin >> a[i];
    dp2[0][0] = 0;
    dp2[0][1] = a[1];
    dp2[0][2] = a[2];
    if (n % 2 == 0)
        cout << solve0(n);
    else
        cout << solve1(n);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}


Measured memory_bytes: 13000
#include<iostream>
using namespace std;
int main(){
  int n,ans;
  while(cin>>n){
    if(n==0) break;
    ans = 0;
    while(n!=1){
      if(n%2==0){
	n /= 2;
	ans++;
      }else{
	n *= 3;
	n += 1;
	ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
} 

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

int main() {
  int n,k,x;
  int ans=0;
  cin >> n;
  cin >> k;
  for(int i=0;i<n;i++){
    cin >> x;
    ans+=min(x,k-x);
  }
  cout << ans*2 << "\n";
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

int main() {
	llong N;
	vector<P> v;

	cin >> N;
	v.resize(N);
	for (int i = 0; i < N; ++i)
		cin >> v[i].first >> v[i].second;

	map<P, llong> m;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			if (i == j) continue;
			P dis = P(v[i].first - v[j].first, v[i].second - v[j].second);
			m[dis]++;
		}
	}

	llong maxi = 0;
	for (auto it : m) {
		maxi = max(maxi, it.second);
	}

	cout << N-maxi << endl;

	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FR first
#define SC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;


signed main(){
  int n;
  while(cin>>n,n){
    vector<char> vote(n);
    set<char> can;
    REP(i,n){
      cin>>vote[i];
      can.insert(vote[i]);
    }
    vector<int> cm(26);
    REP(i,n)cm[vote[i]-'A']++;
    int mx=*max_element(ALL(cm));
    int win=0;
    for(auto x:cm)if(mx==x)win++;
    if(win>=2)cout<<"TIE"<<endl;
    else{
      map<char,int> mp;
      for(auto x:can){
        mp[x]=0;
      }
      if(mp.size()==1){
        cout<<vote[0]<<' '<<n/2+1<<endl;
      }else{
        int maxi=-1;
        char ans;
        REP(i,n){
          int rem=n-i-1;
          mp[vote[i]]++;
          if(maxi<mp[vote[i]]){
            maxi=mp[vote[i]];
            ans=vote[i];
          }
          bool flag=true;
          for(auto t:mp){
            if(t.FR==ans)continue;
            if(t.SC+rem>=maxi)flag=false;
          }
          if(flag){
            cout<<ans<<' '<<n-rem<<endl;
            break;
          }
        }
      }
    }
  }
  return 0;
}



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

#define int long long int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define endl "\n"

int32_t main()
{
	IOS;
	float r;
	cin >> r;
	double ans = 2 * 3.141592 * r;
	cout << ans << endl;



	return 0;
}

Measured memory_bytes: 3796
// ABC060
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

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

typedef long long ll;


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

    if(A[A.size()-1] == B[0] && B[B.size()-1] == C[0])
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
apple = list(map(int, input().split()))
apple.reverse()
count = 0
for i in range(n - 1):
    if apple[i] >= apple[i + 1]:
        pass
    elif apple[i] + 1 == apple[i + 1]:
        apple[i + 1] = apple[i + 1] - 1
    else:
        count = 1
        break
print("Yes" if count == 0 else "No")

Measured memory_bytes: 63856
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()

int const N = 100001;
int n, k, v[N];

int main(){
    int an = 0;
    scanf("%d%d", &n, &k);
    for(int i = 0; i<n; ++i){
        scanf("%d", v+i);
        an += (v[i]>=k);
    }
    printf("%d\n",an);
    
} 


Measured memory_bytes: 640
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
    long long int N;
    cin >> N;
    
    vector<long long int> A(N);
    map<long long int, long long int> mp;
    vector<long long int> B(N+1, 0);
    for(long long int n=0; n<N; n++) {
        cin >> A[n];
        
        mp[A[n]]++;
        B[n+1] = (n+1)*n/2;
    }
    
    long long int sum=0;
    for(auto itr=mp.begin(); itr!=mp.end(); itr++) {
        sum += B[itr->second];
    }
    
    for(long long int n=0; n<N; n++) {
        cout << sum - B[mp[A[n]]] + B[mp[A[n]]-1] << endl;
    }

    return 0;
    
}

Measured memory_bytes: 14336
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <set>
#include <map>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)

using namespace std;
typedef long long ll;

int N,A,B;

int main(){
    int N;
    cin>>N;
    vector<pair<int,int> > vec;
    if(N%2==1){
        for(int i=1;i<=N-1;i++){
            int no = N-i;
            for(int j=i+1;j<=N;j++){
                if(j!=no){
                    vec.push_back(make_pair(i,j));
                }
            }
        }
    }else{
        for(int i=1;i<=N;i++){
            int no = N+1-i;
            for(int j=i+1;j<=N;j++){
                if(j!=no){
                    vec.push_back(make_pair(i,j));
                }
            }
        }
    }
    cout<<vec.size()<<endl;
    for(int i = 0;i < vec.size();i++){
        cout<<vec[i].first<<" "<<vec[i].second<<endl;
    }
}


Measured memory_bytes: 384
n = int(input())
t,a= map(int, input().split())
l = list(map(int, input().split()))

x = t - l[0] * 0.006
ans = []
for x in l:
    x = t - x * 0.006
    y = a - x
    ans.append(abs(y))

print(ans.index(min(ans)) + 1)


Measured memory_bytes: 9192
// inputに入力データ全体が入る
function Main(input) {
	
	var Input = input.split(" ");
	
	var a = parseInt(Input[0], 10);
	var b = parseInt(Input[1], 10);
	
  	var ans = a - 2 * b
    var ans = ans < 0 ? 0:ans
  
	//出力
	console.log(ans);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

const ll INF = 1001001001;

int main(){
  ll n; cin>>n;
  ll a= n*(n+1);
  ll b= 3*(n/3)*(n/3+1);
  ll c= 5*(n/5)*(n/5+1);
  ll d= 15*(n/15)*(n/15+1);
  ll ans = a-b-c+d;
  cout<<ans/2<<endl;
}



Measured memory_bytes: 3636
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n),e1(n),e2(n),o1(n),o2(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }

  for(int i = 0; i < n;i++){
    if(i%2==0){
      e1[i] = a[i];
      o1[i] = -a[i];
    }else{
      e1[i] = -a[i];
      o1[i] = a[i];
    }

  }
  e2 = e1;
  o2 = o1;
  for(int i = 0; i < n -1;i++){
    e1[i+1] = e1[i] + e1[i+1];
    o1[i+1] = o1[i] + o1[i+1];
  }
  for(int i = n-2; i >= 0 ;i--){
    e2[i] = e2[i] + e2[i+1];
    o2[i] = o2[i] + o2[i+1];
  }
  
//  for(int i = 0; i < n;i++){
//    cout << e1[i] << "," << e2[i] << "," << o1[i] << "," << o2[i] << endl;;
//  }
//  cout << endl;
  for(int i = 0 ; i < n-1; i++){
    if(i==0){
      cout << e1[n-1] << endl;
    }
    if(i%2==1){
      cout << (o1[i] + e2[i+1]) << endl;
    }else{
      cout << (e1[i] + o2[i+1]) << endl;
    }
  }
  return 0;
} 


Measured memory_bytes: 3328
N,K = map(int, input().split())
A = list(map(int, input().split())) 
A.sort()
A.reverse() 
x = A[0]   
for i in range (1, N):
  while A[i] != 0:
    x , A[i] = A[i] , x % A[i]
if K > A[0]:
  print('IMPOSSIBLE')
else:
  print('POSSIBLE' if K%x == 0 else 'IMPOSSIBLE')

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

long long int sum[100000 + 500];
long long int a[100000 + 500];
map<long long int,long long int> mod_counter;

int main() {

    int n,m;

    cin >> n >> m;

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

    sum[0] = 0;
    for(int i=1; i<n+1; i++){
        if(i != 0) {
            sum[i] = (sum[i - 1] + a[i-1])%m;
        }
        else {
            sum[i] = a[i-1] % m;
        }
    }

    long long int count = 0;

    for(int i=0; i<n+1; i++){
        count += mod_counter[sum[i]];
        mod_counter[sum[i]]++;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 5760
a = list()
for _ in range(3):
    data = input().split(' ')
    a.append([int(d) for d in data])
n = int(input())
b = list()
for _ in range(n):
    b.append(int(input()))
# check data
matched_flag = list()
for i in range(3):
    matched_flag.append([1 if elem in b else 0 for elem in a[i]])
# check rows
for row in matched_flag:
    if sum(row) == 3:
        print('Yes')
        exit(0)
# check cols
for j in range(3):
    if sum([matched_flag[i][j] for i in range(3)]) == 3:
        print('Yes')
        exit(0)
# check diags
if (sum([matched_flag[i][i] for i in range(3)]) == 3) or \
    (sum([matched_flag[i][2-i] for i in range(3)]) == 3):
    print('Yes')
    exit(0)
print('No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
char s[10001];
int main()
{
	long long n,ans=0,max1=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>s[i];
	}
	for(int i=1;i<=n;i++)
	{
		if(s[i]=='I')
		{
			ans++;
		}
		if(s[i]=='D')
		{
			ans--;
		}
		if(ans>max1)
		{
			max1=ans;
		}
	}
	cout<<max1<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
def input():
    return sys.stdin.readline()[:-1]

S = list(input())
flag = False
dp = {}
out = [0]*(len(S))
cnt = 0
S.append('R')
leng = len(S)

for i in range(leng):
    s = S[i]
    r = 0
    if flag:
        if s=='R':
            if cnt%2==0:
                out[right-1] = cnt//2
                out[right] = cnt//2
            else:
                if right_2:
                    out[right-1] = cnt//2 + 1
                    out[right] = cnt//2
                else:
                    out[right-1] = cnt//2
                    out[right] = cnt//2 + 1
            flag = False
            cnt = 1
        else:
            cnt += 1
    else:
        cnt += 1
        if s=='R':
            pass
        else:
            right = i
            if cnt%2==0:
                right_2 = True
            else:
                right_2 = False
            flag = True
print(' '.join(map(str, out)))

Measured memory_bytes: 11176
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

void solve(){
  int a[3];
  rep(i,3)cin>>a[i];
  if(a[0]==a[1]&&a[1]==a[2])cout<<"Yes\n";
  else cout<<"No\n";
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 256
t = int(input())
for t in range(t):
    N,K = map(int, input().strip().split(" "))
    X = list(map(int,input().strip().split(" ")))
    L = [X[i+1] - X[i] for i in range(0,N-1)]
    L.sort()
    s = 0
    for i in range(0,N-K):
        s = s + L[i]
    print(s)


Measured memory_bytes: 21764
import java.util.*;
import java.lang.*;
 
public class Main {
    public static void main(String[] args) {

        Scanner sc  = new Scanner(System.in);

        int N = Integer.parseInt(sc.next());
        Long[] a = new Long[N];
        long t = 0;
        for(int i=0; i < N; i++){
            a[i] = Long.parseLong(sc.next());
            t+=a[i];
        }
        
        // Arrays.sort(a);
        long inf = 2147000009;
        
        long x = 0;
        long y = t;
        long min = inf;
        
        for(int i=0; i < N; i++){
            
            x += a[i];
            y -= a[i]; 
            
            if(i<N-1)min = Math.min( min, Math.abs(x-y)  );
           
           
        }

  

        System.out.print( min );

        System.out.println();
    }

}

Measured memory_bytes: 68528