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

#define fa(x,v) for(auto x:v)
#define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define spc " "
#define endl '\n'
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(s) (ll)int(s.length())
#define sz(v) (ll)int(v.size())
#define MOD 1000000007

void Fast_IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    freopen("debug.out","w",stderr);
    #endif
} 

// Code Here

const ll maxcost = 2500;
const ll INF = 1e15;

ll n, m, s;
vector < vector < pair< ll, pair<ll,ll> > > > adj;
ll c[51], d[51];
ll dist[51][2501];

int main()
{
    Fast_IO();
    cin >> n >> m >> s;
    adj.resize(n);
    f(_,1,m) {
    	ll ui, vi, ai, bi;
    	cin >> ui >> vi >> ai >> bi;
    	ui--; vi--;
    	adj[ui].pb(mp(vi,mp(ai,bi)));
    	adj[vi].pb(mp(ui,mp(ai,bi)));
    }
    f(i,0,n-1) cin >> c[i] >> d[i];
    s = min(s, maxcost);
    priority_queue <
    	pair <ll, pair<ll,ll> >,
    	vector < pair <ll, pair<ll,ll> > >,
    	greater < pair <ll, pair<ll,ll> > >
    > pq;
    pq.push(mp(0LL,mp(0LL,s)));
    f(i,0,n-1) f(j,0,maxcost) dist[i][j] = INF;
    dist[0][s] = 0;
    while(!pq.empty()) {
    	pair <ll, pair<ll,ll> > Top = pq.top(); pq.pop();
    	ll Time = Top.ff, u = Top.ss.ff, cost = Top.ss.ss;
    	fa(edge,adj[u]) {
    		ll v = edge.ff, ai = edge.ss.ff, bi = edge.ss.ss;
    		if(cost >= ai) {
    			if(dist[v][cost-ai] > Time + bi) {
    				dist[v][cost-ai] = Time + bi;
    				pq.push(mp(dist[v][cost-ai],mp(v,cost-ai)));
    			}
    		}
    	}
    	if(cost != maxcost) {
    		ll new_cost = cost + c[u];
    		new_cost = min(new_cost, maxcost);
    		if(dist[u][new_cost] > Time + d[u]) {
    			dist[u][new_cost] = Time + d[u];
    			pq.push(mp(dist[u][new_cost],mp(u,new_cost)));
    		}
    	}
    }
    ll ans[n];
    f(i,1,n-1) {
    	ans[i] = INF;
    	f(j,0,maxcost) ans[i] = min(ans[i], dist[i][j]);
    }
    f(i,1,n-1) cout << ans[i] << endl;
    return 0;
}

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

const int N=100005;

int n,m,ans;
bool tag;
int a[N],b[N];

int main(){
	int i,j;
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	for (i=1;i<=n;i=j+1){
		j=i;
		b[++m]=a[i];
		for (;j<n&&a[j+1]==a[i];j++);
	}
	for (i=1;i<=m;i=j+1){
		j=i+1; ans++;
		if (b[j]>b[i]) tag=1;
		else tag=0;
		for (;j<m&&(b[j+1]>b[j])==tag;j++);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = Integer.parseInt(sc.next());
		int X = Integer.parseInt(sc.next());
		sc.close();

		int left = X - K + 1;
		int right = X + K - 1;

		for(int i = left; i <= right; i++) {
			if(i != right) {
				System.out.print(i + " ");
			}else {
				System.out.print(i);
			}
		}
	}

}

Measured memory_bytes: 23764
import sys
a, b, c = [int(x) for x in input().split()]
k = int(input())
i = 0
while b<=a:
  i += 1
  b *= 2
if(k<i):
  print('No')
  sys.exit()
else:
  k -= i
  j = 0
  while c<=b:
    j += 1
    c *= 2
  if(k<j):  
    print('No')
    sys.exit()
  else:
    print('Yes')

Measured memory_bytes: 9192
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;


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

    if (A <= 5)
        cout << "0" << endl;
    else if (6 <= A && A <= 12)
        cout << B / 2 << endl;
    else
        cout << B << endl;


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof a) ;
#define vi vector<int>
#define ull unsigned long long
#define ll long long 
#define db double 
#define ldb long double
#define fl float
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lrep(i,a,b) for(ll i=a;i<b;i++)
//#define mod 1000000007
#define mpr make_pair
#define pb push_back
#define fr first
#define sn second
#define bpp(x) __builtin_popcountll(x)
const ldb PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899863;
const int INF = 1e9+7;
bool ok(string &s ,int l ,int r)
{
while(s[l]==s[r]) l++,r--;
return l>=r; 
}/*
ll por(ll a,int b)
{
ll res=1,M=998244353;
while(b)
{
if(b&1)
res=(res*a)%M;
a=(a*a)%M;
b/=2;
}
return res;
}
void rev(vector<int>&arr,int l,int r)
{
    for(;l<r;l++,r--) swap(arr[l],arr[r]);
}
*/
int prime[]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89,97,101,103};
int add(int a,int b) // integer range
{
long x=a+b;
if(x>=INF)
x-=INF;
return x;
}
/*
goto e;


e:
;
*/
void solve()
{
int m,n; cin>>n>>m;
double a[n];
double sum=0;
rep(i,0,n)
{
cin>>a[i];
sum+=a[i];
}
sum/=(4*m);
int ct=0;
rep(i,0,n)
{
if(a[i]>=sum)
ct++;
}
if(ct>=m)
cout<<"Yes\n";
else
cout<<"No\n";
return;
}
int main()
{
ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
//	cin>>t;
while(t--)
{
solve();
}
return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n[101];
  int i;
  int num;
  cin >> num;
  for(i=0;i<num;i++) cin >> n[i];
  cout << n[num-1];
  for(i=1;i<num;i++) cout <<" "<< n[num-i-1];
  cout << endl;
  return 0;
}


Measured memory_bytes: 3072
#include <stdio.h>

int is_leap(int y)
{
    if ((y % 4 == 0 && y % 100 != 0) || (y % 400 == 0)){
        return (1);
    }
    else {
        return (0);
    }
}

int day_count(int y, int m, int d)
{
    int cnt = 0;

    cnt += d;
    m--;
    while (m > 0){
        if (m == 2){
            if (is_leap(y) == 1){
                cnt += 29;
            }
            else {
                cnt += 28;
            }
        }
        else if (m == 4 || m == 6 || m == 9 || m == 11){
            cnt += 30;
        }
        else {
            cnt += 31;
        }
        m--;
    }
    y--;
    while (y > 0){
        if (is_leap(y) == 1){
            cnt += 366;
        }
        else {
            cnt += 365;
        }
        y--;
    }

    return (cnt);
}

int main(void)
{
    int y1, m1, d1;
    int y2, m2, d2;
    int cnt1, cnt2;

    while (scanf("%d %d %d %d %d %d", &y1, &m1, &d1, &y2, &m2, &d2)){
        if (y1 < 0 || m1 < 0 || d1 < 0 || y2 < 0 || m2 < 0 || d2 < 0){
            break;
        }

        cnt1 = day_count(y1, m1, d1);
        cnt2 = day_count(y2, m2, d2);
        printf("%d\n", cnt2 - cnt1);
    }

    return (0);
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
    cin.tie(0);
    cout << fixed << setprecision(10);
    int n, k; cin >> n >> k;
    vector<int> h(n);
    for(int i=0;i<n;++i) {
      cin >> h[i];
    }
    vector<int> dp(n, INF);
    dp[0] = 0;
    for(int i=0;i<n;++i) {
      for(int j=1;j<=k;++j) {
        if(i+j >= n) break;
        dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i+j]));
      }
    }
    cout << dp[n-1] << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
    string s;
    cin >> s;
    bool ans=false;
    int ans1=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='C'&&ans1==0){
            ans1++;
        }else if(ans1>=1&&ans1==1&&s[i]=='F'){
            ans1++;
        }
    }
    if(ans1==2)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 384
def getInput():
    (n, unit) = (int(i) for i in input().split(" "))
    q = []
    for i in range(n):
        tmp = [i for i in input().split(" ")]
        q.append([tmp[0], int(tmp[1])])
    return n, unit, q

def initQtable(Len_q):
    Q = [0 for i in range(Len_q+1)]
    return Q

def initPointer():
    head = tail = 0
    return head, tail

def isEmpty(head, tail):
    return head == tail

def isFull(head, tail, Len_q):
    return head == (tail+1)%Len_q

def enqueue(head, tail, Q, qname):
    Len_q = len(Q)
    if isFull(head, tail, Len_q):
        print("Error: Full Qtable")
        return
    tail = incrementPointer(tail, Len_q)
    Q[tail] = qname
    return tail
    
def dequeue(head, tail, Q):
    if isEmpty(head, tail):
        print("Error: Empty Qtable")
        return
    head = incrementPointer(head, Len_q+1)
    q = Q[head]
    return head, q

def incrementPointer(ptr, Len_q):
    ptr += 1
    if ptr >= Len_q:
        ptr = 0
    return ptr

n, unit, Jobs = getInput()
head, tail = initPointer()
Len_q = len(Jobs)
Q = initQtable(Len_q)
for i in range(Len_q):
    q = Jobs[i]
    tail = enqueue(head=head, tail=tail, Q=Q, qname=q)
total_time = 0
while not isEmpty(head, tail):
    head, [qname, time] = dequeue(head=head, tail=tail, Q=Q)
    progress = min(time, unit)
    total_time += progress
    time -= progress
    if time > 0:
        tail = enqueue(head=head, tail=tail, Q=Q, qname=[qname, time])
    else:
        print(qname, total_time, sep=" ")



Measured memory_bytes: 18948
import math
from itertools import accumulate

def is_prime(n):
    if n == 1:
        return 0
    for k in range(2,int(math.sqrt(n))+1):
        if n % k == 0:
            return 0
    return 1
    
Q = int(input())    
L = [0]*Q
R = [0]*Q

for i in range(Q):
    L[i], R[i] = list(map(int, input().split()))

min_L = min(L)
max_R = max(R)

check = []
for i in range(min_L,max_R+ 1):
    if (i%2 ==1):
        flg = (is_prime(i) and is_prime((i+1)/2))
    else:
        flg = 0
    check.append(flg)
    
#print(check)

check = [0] + check
check = list(accumulate(check))
#print(check)
#print(R,L,min_L)

for i in range(Q):
    print(check[R[i]-min_L+1]-check[L[i]-min_L])

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

const int N = 100100;
int n, m, q;
int a[N];
int pos[N];
int len[N];
int cnt[N];
int b[N];

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);


	scanf("%d%d%d", &n, &m, &q);
	for (int i = 0; i < q; i++)
		scanf("%d", &a[i]);
	reverse(a, a + q);
	for (int i = 1; i <= m; i++)
		pos[i] = -1;
	for (int i = 0; i < q; i++)
	{
		int x = a[i];
		if (pos[x] == -1)
		{
			pos[x] = len[0];
			b[len[0]] = x;
			len[0]++;
			cnt[x] = 1;
		}
		else
		{
			int y = cnt[x];
			if (y >= n) continue;
			if (len[y] < pos[x]) continue;
			len[y]++;
			cnt[x]++;
		}
	}
	/*
	for (int i = 0; i < n; i++)
		printf("%d ", len[i]);
	printf("\n");
	for (int i = 0; i < len[0]; i++)
		printf("%d ", b[i]);
	printf("\n");
	*/
	int minUnused = m + 1;
	for (int x = 1; x <= m; x++)
		if (pos[x] == -1)
		{
			minUnused = x;
			break;
		}
	int L = len[0];
	while(L > 0 && b[L - 1] < minUnused)
	{
		L--;
		minUnused = b[L];
	}
	bool ok = 1;
	for (int i = 0; i < n; i++)
		ok &= len[i] >= L;
	if (ok)
		printf("Yes\n");
	else
		printf("No\n");

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int MOD = 1000000007;
int INF = numeric_limits<int>::max() / 2;

class UnionFind {
public:
    vector <int> par; // 各元の親を表す配列
    vector <int> siz; // 素集合のサイズを表す配列(1 で初期化)

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

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

    // Union(Unite, Merge)
    bool unite(int x, int 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(int x, int y) { // 連結判定
        return root(x) == root(y);
    }

    int size(int x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    int N, M;
    cin >> N >> M;
    pair<int,int> P[M];
    rep(i,M){
      int a, b;
      cin >> a >> b;
      --a; --b;
      P[i].first = a;
      P[i].second = b;
    }

    UnionFind uf(N);
    int ans = 0;
    rep(i,M){
      uf.init(N);
      rep(j,M){
        if(j == i) continue;
        uf.unite(P[j].first, P[j].second);
      }
      if(uf.size(0) < N) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long int ll;

string N;
ll ans;

ll Pow(int x,int n){
    int res=1;
    for(int i=0;i<n;++i)res*=x;
    return res;
}


ll calc(int n,int isupper,int f,int l){
    //cout<<s<<" "<<isupper<<endl;
    if(n==N.size()-1){
        //cout<<s+(char)(l+'0')<<" "<<isupper<<endl;
        if(isupper==1)return 0;
        if(isupper==2&&N[N.size()-1]-'0'<l)return 0;
        else return 1;
    }
    ll res=0;
    for(int i=0;i<=9;++i){
        if(n==0)if(i!=f)continue;
        int _isupper;
        if(isupper==0)_isupper=0;
        else if(isupper==2&&i==N[n]-'0')_isupper=2;
        else if(isupper==2&&i<N[n]-'0')_isupper=0;
        else _isupper=1;
        if(i==l)res+=calc(n+1,_isupper,f,l)+1;
        else res+=calc(n+1,_isupper,f,l);
    }
    return res;
}

int main(){
    //for(int i=0;i<10;++i)for(int j=0;j<3;++j)for(int k=0;k<10;++k)for(int l=0;l<10;++l)
    cin>>N;
    for(int a1=1;a1<=9;++a1){
        for(int a2=1;a2<=9;++a2){
            ans+=calc(0,2,a1,a2)*calc(0,2,a2,a1);
        }
    }
    //cout<<calc(0,2,2,1,"")<<endl;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
n = int(input())
box = []
for _ in range(n):
    a,b = map(int,input().split())
    box.append([a,b])
box.sort(key=lambda x: x[1])
cnt = 0
for a,b in box:
    cnt += a
    if cnt > b:
        print("No")
        exit()
print("Yes")

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

int main(){
	/*input*/
	string s;	cin >> s;
	/*calculation*/
	vector<bool>flag(3, false);
	if(s.at(0) == 'A')flag.at(0) = true;
	int i = 2;
	for(; i < s.size() - 1; i++){
		if(s.at(i) == 'C'){
			flag.at(1) = true; 
			break;
		}
	}
	for(int j = 1; j < s.size(); j++){
		if(j == i)continue;
		if((s.at(j) >= 'a')&&(s.at(j) <= 'z')){
			flag.at(2) = true;
		}else{
			flag.at(2) = false;
			break;
		}
	}
	/*output*/
	if(flag[0]&&flag[1]&&flag[2]){
		cout << "AC" << endl;
	}else{
		cout << "WA" << endl;
	}
}


Measured memory_bytes: 256
#こんな筋肉みたいなコード書いたけど、考察深めればO(1)で解けます
#n,p = map(int,input().split())
#a  = list(map(int,input().split()))
#cnt = 0
#for x in a:
#   if x%2:cnt+=1
#if cnt == 0:
#    if p:ans = 0
#    else:ans = 2**n
#else:
#    ans = 2**(n-1)
#print(ans)

n,p = map(int,input().split())
a = list(map(int,input().split()))
cnt = 0
ans = 0
fact = [1]*(n+1)

for i in range(1,n+1):
    fact[i] = fact[i-1]*i
def C(x,y):
    return fact[x]//fact[y]//fact[x-y]
    
    
for x in a:
    if x %2 == 1:
        cnt += 1
if p :
    for i in range(1,n+100,2):
        if i >cnt:break
        ans += C(cnt,i)*(2**(n-cnt))
else:
    for i in range(0,n+100,2):
        if i > cnt:break
        ans += C(cnt,i)*(2**(n-cnt))
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;

ll n,a,b;
vector<ll> h(100010);

bool c(ll t){
  ll sum=0;
  rep(i,n){
    ll x=h[i]-b*t;
    if(x<=0) continue;
    if(x%(a-b)==0){
      sum+=x/(a-b);
    }else{
      sum+=x/(a-b)+1;
    }
  }
  if(sum<=t) return true;
  else return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>a>>b;
    rep(i,n) cin>>h[i];
    ll l=0,r=1e10,mid;
    while(r-l>1){
      mid=(l+r)/2;
      if(c(mid)) r=mid;
      else l=mid;
    }
    cout<<r<<endl;
}

Measured memory_bytes: 1024
<?php
$input = explode(" ",trim(fgets(STDIN)));
$a = intval($input[0]);
$b = intval($input[1]);
$c = intval($input[2]);
$cnt = 0;
for($i=$a;$i<=$b;$i++){
    if($c%$i===0){
        $cnt++;
    }
}
echo $cnt;?>

Measured memory_bytes: 15380
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  ll N;
  cin >> N;
  vector<ll> L(N);
  REP(i, N) cin >> L.at(i);
  sort(L.begin(), L.end());
  ll ans = 0;
  for (ll mid = N - 1; mid >= 0; mid--) {
    for (ll low = mid - 1; low >= 0; low--) {
      auto itr = lower_bound(L.begin(), L.end(), L[mid] + L[low]);
      ll ng = distance(itr, L.end());
      ans += (N - 1 - mid) - ng;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>

using namespace std;

bool solve(){ 
	int p[8];
	for(int i= 0 ;i < 8; i++) if(!(cin>>p[i])) return false;
	static int s[8][8] = {
		{1,2,1,2,1,4,1,4},
		{1,2,1,4,1,4,1,2},
		{1,4,1,2,1,2,1,4},
		{1,4,1,4,1,2,1,2},
		{2,1,2,1,4,1,4,1},
		{2,1,4,1,4,1,2,1},
		{4,1,2,1,2,1,4,1},
		{4,1,4,1,2,1,2,1},
	};

	int min_i = -1;
	int mn = INT_MAX;
	for (int i = 0; i < 8; i++){
		int a = 0;
		for (int j = 0; j < 8; j++)	a += max(0,p[j] - s[i][j]);
		if(a < mn){
			min_i = i;
			mn = a;
		}
	}
	for(int i = 0; i < 8; i++) printf("%d%c",s[min_i][i],(i == 7) ? '\n' : ' ');
	return true;
}

int main(){

	while(solve());
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int n;
int a[100100];

int main(){
	cin>>n;
	REP(i,n)
		cin>>a[i];
	
	
	sort(a,a+n);
	int co=1;
	int ans=0;
	for(int i=0;i<=n;i++){
		if(i==n){
				
					if(a[i-1]<=co){
						ans+=(co-a[i-1]);
					}else{
						ans+=co;
					}
					break;
		}
		if(i!=0){
			if(a[i]==a[i-1]){
				co++;
			}else{
				if(a[i-1]<=co){
					ans+=(co-a[i-1]);
				}else{
					ans+=co;
				}
				co=1;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(){
  int a,b,c,d; cin >> a>> b >> c >>d;
  if(a * b > c * d)
    cout << a * b << endl;
  else if(a * b < c * d)
    cout << c * d << endl;
  else
    cout << a * b <<endl;
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;

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

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

  vector<int> vc(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> vc[i];
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += vb[va[i]];
    if (i >= 1 && va[i - 1] == va[i] - 1) {
      ans += vc[va[i - 1]];
    }
  }

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll cnt=0;
ll rec(ll n)
{
    if(n==1)
    {
        return 1;
    }
    return rec(n/2)*2 + 1;
}
int main()
{
   ll n,res;
   cin>>n;
   res=rec(n);
   printf("%lld\n",res);
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>
#include <functional>

using namespace std;
#define ALL(x)              (x).begin(),(x).end()
#define REP(i, n)           for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)       for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF                 (int)2e9
#define MOD                 (1000 * 1000 * 1000 + 7)
#define Ceil(x, n)          (((((x))+((n)-1))/n))
#define CeilN(x, n)         (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)        ((x)-(x)%(n))
#define IsOdd(x)            (((x)&0x01UL) == 0x01UL)
#define IsEven(x)           (!IsOdd((x)))
#define M_PI                3.14159265358979323846
typedef long long           ll;
typedef pair<ll, ll>        P;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main()
{
	string S;
	int Q;
	cin >> S >> Q;

	bool isTop = true;
	string top;
	string end;
	REP(i, Q) {
		int t;
		cin >> t;
		if (t == 1) {
			isTop = !isTop;
		} else {
			int f;
			string c;
			cin >> f >> c;
			if (f == 1 && isTop || f == 2 && !isTop) {
				top += c;
			} else {
				end += c;
			}
		}
	}

	reverse(ALL(top));
	string ans = top + S + end;
	if (!isTop) {
		reverse(ALL(ans));
	}

	cout << ans << endl;

	return 0;
}


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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main()
{
    int n;
    cin >> n;
    map<string, int> m;
    REP(i,n){
        string s;
        cin >> s;
        m[s] = 1;
    }
    int ans = 0;
    for(auto s:m){
        ans++;
    }
    cout << ans <<"\n";

    return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;
using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "YES" << '\n'; exit(0); }
inline void no() { cout << "NO" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline bool isprime(i32 n) { if (n < 2) return 0; for (i32 i = 2; i * i <= n; i++) if (n % i == 0) return 0; return 1; }
inline vi32 plist(i32 n) { vi32 f(n, 1); f[0] = f[1] = 0; repi(i, 2, n) for (int j = i * 2; j < n; j += i) f[j] = 0; return f; }
inline void ioinit() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); }
template<class T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<class T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<class T> inline bool amax(T &x, T y) { if (x >= y) return 0; x = y; return 1; }
template<class T> inline bool amin(T &x, T y) { if (x <= y) return 0; x = y; return 1; }
template<class T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<class T> vector<T> make_v(int n, T v) { return vector<T>(n, v); }
template<class... Ts> auto make_v(int n, Ts... ts) { return vector<decltype(make_v(ts...))>(n, make_v(ts...)); }

int main() {
  ioinit();
  int h, w, n;
  cin >> h >> w >> n;
  int sr, sc;
  cin >> sr >> sc;
  string s, t;
  cin >> s >> t;
  {
    int ll = 0, rr = w + 1;
    rrep(i, n) {
      if (ll > 0 && t[i] == 'R') ll--;
      if (rr < w + 1 && t[i] == 'L') rr++;
      if (s[i] == 'L') ll++;
      if (s[i] == 'R') rr--;
      if (ll == w) no();
      if (rr == 1) no();
      if (ll >= rr - 1) no();
    }
    if (ll >= sc || rr <= sc) no();
  }
  {
    int ll = 0, rr = h + 1;
    rrep(i, n) {
      if (ll > 0 && t[i] == 'D') ll--;
      if (rr < h + 1 && t[i] == 'U') rr++;
      if (s[i] == 'U') ll++;
      if (s[i] == 'D') rr--;
      if (ll == h) no();
      if (rr == 1) no();
      if (ll >= rr - 1) no();
    }
    if (ll >= sr || rr <= sr) no();
  }
  yes();
  return 0;
}


Measured memory_bytes: 920
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;
	  ll gcd (ll a , ll b ){ return b ? gcd(b,a%b) : a;}
  ll lcm (ll a , ll b ){ return a/gcd(a,b)*b ;}

int main() {

  ll N , M ;
  cin >> N >> M ;
  ll ans = N%M ;
  ll ans2 = abs(N%M - M ) ;
  cout << min(ans,ans2) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 2e5+1;
int n, k;
string s;
int _v[N+1], *v=_v+1;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> k >> s;
  Fill(_v, n);
  char p='1';
  int idx=0;
  v[-1] = 0;
  FOR(i, 0, sz(s)){
    if(s[i] != p){
      v[idx++] = i;
      p = s[i];
    }
  }
  int ma = 0;
  for(int i=k*2; i<N; i+=2) maxs(ma, v[i]-v[i-k*2-1]);
  cout << ma << endl;
}

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

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

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

int A, B;
int d[11][11];
pair<pii, int> info[11][11];

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

	for (int i = 1; i <= A; ++i) {
		for (int j = 1; j <= B; ++j) {
			cin >> d[i][j];
		}
	}

	int maxi = 0;
	int u = 0;

	for (int i = 1; i <= A; ++i) {
		for (int j = 1; j <= B; ++j) {
			vector<pii> cand;

			for (int k = 0; k <= 100; ++k) {
				for (int l = 0; l <= 100; ++l) {
					if (k * i + l * j > d[i][j]) continue;
					int c = d[i][j] - k * i - l * j;
					bool ok = 1;

					for (int p = 1; p <= A; ++p) {
						for (int q = 1; q <= B; ++q) {
							if (p * k + q * l + c < d[p][q]) {
								ok = 0;
							}
						}
					}

					if (ok) {
						cand.eb(k, l);
					}
				}
			}

			if (cand.size() == 0) {
				puts("Impossible");
				return 0;
			} else {
				pii la = cand[0];
				u = max(u, la.fi);
				maxi = max(maxi, la.se);
				int zan = d[i][j] - la.fi * i - la.se * j;
				info[i][j] = mp(la, zan);
			}
		}
	}

	puts("Possible");

	vector<pair<pii, int>> vec;

	int S = 0;
	int now = u + 1;

	rep(i, u) {
		vec.eb(mp(i, i + 1), -1);
	}

	int T = now;

	rep(i, maxi) {
		++now;
		vec.eb(mp(now, now - 1), -2);
	}
	++now;

	for (int i = 1; i <= A; ++i) {
		for (int j = 1; j <= B; ++j) {
			pii p = info[i][j].fi;
			int c = info[i][j].se;
			vec.eb(mp(p.fi, now), c);
			vec.eb(mp(now, T + p.se), 0);
			++now;
		}
	}

	cout << now << " " << vec.size() << endl;
	for (auto e : vec) {
		printf("%d %d ", e.fi.fi + 1, e.fi.se + 1);
		if (e.se == -1) {
			putchar('X');
		} else if (e.se == -2) {
			putchar('Y');
		} else {
			printf("%d", e.se);
		}
		puts("");
	}

	cout << S + 1 << " " << T + 1 << endl;

	return 0;
}

Measured memory_bytes: 384
S = input()
Q = int(input())
mae_usiro = [[],[]]
rev = 0
for _ in range(Q):
    temp = input().split()
    T = temp[0]
    if T =="1":
        rev += 1
    else:
        F = temp[1]
        C = temp[2]
        if F == "1": #前
            mae_usiro[rev % 2].append(C)
        else: # 後ろに付ける
            mae_usiro[(rev + 1) % 2].append(C)

# print(mae_usiro)
mae =  mae_usiro[0]
usiro= mae_usiro[1]
if rev % 2 == 1: #奇数回の反転なら
    S = S[::-1] #元の文字列は反転
    usiro.reverse()
    ans = "".join(usiro) + S + "".join(mae)
else:
    mae.reverse()
    ans = "".join(mae) + S + "".join(usiro)

print(ans)

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
const long double PI = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679;
const int    INF = 1000000007;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> D;

int n;
P pos[100001];
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
map<P,int> m;
map<P,int>::iterator it;
vector<P> v;
vector<D> d;

int main(){
    cin >> n;
    pos[0] = P(0,0);
    rep(i,2) rep(j,2) m[P(i,j)] = 1;
    for(int i = 1; i < n; i++){
        int p, d;
        cin >> p >> d;
        pos[i] = P(pos[p].first+dx[d],pos[p].second+dy[d]);
        rep(j,2) rep(k,2) m[P(pos[i].first+j,pos[i].second+k)]++;
    }
    for(it = m.begin();it != m.end(); it++){
        if((*it).second > 1) continue;
        v.push_back((*it).first);
    }
    rep(i,v.size()) d.push_back(P((double)v[i].first,(double)v[i].second));
    double ans = 1000000000000.0;
    rep(u,100){
        double r = (PI/100.0)*u, l = (PI/100.0)*(u+1), mr, ml;
        rep(i,1000){
            mr = (r*2+l)/3;
            ml = (r+l*2)/3;
            double sr, sl;
            double X = 0, x = 0, Y = 0, y = 0;
            double sinr = sin(mr), cosr = cos(mr);
            double sinl = sin(ml), cosl = cos(ml);
            rep(j,d.size()){
                X = max(X,d[j].first*cosr-d[j].second*sinr);
                x = min(x,d[j].first*cosr-d[j].second*sinr);
                Y = max(Y,d[j].first*sinr+d[j].second*cosr);
                y = min(y,d[j].first*sinr+d[j].second*cosr);
            }
            sr = (X-x)*(Y-y);
            X = 0; x = 0; Y = 0; y = 0;
            rep(j,d.size()){
                X = max(X,d[j].first*cosl-d[j].second*sinl);
                x = min(x,d[j].first*cosl-d[j].second*sinl);
                Y = max(Y,d[j].first*sinl+d[j].second*cosl);
                y = min(y,d[j].first*sinl+d[j].second*cosl);
            }
            sl = (X-x)*(Y-y);
            if(sr < sl){
                ans = min(ans,sr);
                l = ml;
            } else{
                ans = min(ans,sl);
                r = mr;
            }
        }
    }
    printf("%.9f\n",ans);
}

Measured memory_bytes: 14508
//
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define MOD 1000000007
#define PI 3.14159265
#define EPS 1e-9
#define Pi acos(-1.0)
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define forr(i,a,b) for(int i=(a); i<(b); i++)
#define clean(arr,val) memset(arr,val,sizeof(arr))
#define forn(i,n) forr(i,0,n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;

/*CODE START HERE*/

int a, b;

int main(){
    ios::sync_with_stdio(0);
    cin >> a >> b;

    int digits = 0;
    int aux = b;

    while(aux){
        digits++;
        aux/=10;
    }

    aux = 1;
    forn(i,digits){
        aux *= 10;
    }

    a = a * aux;

    a += b;

    aux = sqrt(a);

    if(aux*aux == a){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (int) 1e9+7
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define vi vector<int>
ll xpow(ll a, ll b)
{
	if (b == 0)
		return 1;
	if (b % 2 == 0)
	{
		ll k = pow(a, b / 2);
		return k * k;
	}
	if (b % 2 != 0)
		return a * pow(a, b - 1);
}
int main()
{

#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	fio;
	ll x;
	cin >> x;
	for (int i = -200; i <= 200; i++)
	{
		for (int j = -200; j <= 200; j++)
		{
			if (xpow(i, 5) - xpow(j, 5) == x)
			{
				cout << i << " " << j;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 4120
#include<bits/stdc++.h>
#define ll long long
#define mod (ll)1000000007
using namespace std;

int main()
{
    unordered_map<string,int> f;
    string s,t;
    cin>>s>>t;
    int a,b;
    cin>>a>>b;
    f[s] = a;
    f[t] = b;
    string u;
    cin>>u;
    f[u]--;

    cout<<f[s]<<" "<<f[t]<<"\n";
    return 0;
}


Measured memory_bytes: 256
import math
a, b, C = map(float, input().split())
print('{:.5f}'.format(a*b*math.sin(math.radians(C))/2))
print('{:.5f}'.format(a+b+(a**2+b**2-2*a*b*math.cos(math.radians(C)))**0.5))
print('{:.5f}'.format(b*math.sin(math.radians(C))))



Measured memory_bytes: 5708
N,K,Q = map(int, input().split())
A = []
for _ in range(Q):
    A.append(int(input()))

p = [0] * N
for a in A:
    p[a-1] += 1

for i in range(N):
    p[i] = K-(Q-p[i])
    if p[i] <= 0:
        print('No')
    else:
        print('Yes')


Measured memory_bytes: 16792
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;

ll gcd(ll a, ll b)
{
    for (;;)
    {
        if (a == 0) return b;
        b %= a;
        if (b == 0) return a;
        a %= b;
    }
}

ll lcm(ll a, ll b)
{
    ll temp = gcd(a, b);

    return temp ? (a / temp * b) : 0;
}

int main(int argc, const char * argv[]) {
  ll a, b;
  cin >> a >> b;
  cout << lcm(a, b) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>
#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222






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



  cin >> n;
  map<string, ll> mp;
  rep(i, n) {
    cin >> s;
    sort(all(s));
    mp[s]++;
  }
  for (auto it : mp) {
    ans += it.second*(it.second - 1) / 2;
  }
  cout << ans << endl;



  return 0;
}


Measured memory_bytes: 11264
#include <stdio.h>

int main (void)
{
    unsigned int n, i;
    unsigned long a, b, a_top, a_last, b_top, b_last;

    scanf("%u", &n);

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

    a_top = a_last = a;
    b_top = b_last = b;

    for (i = 1; i < n; i++) {
        scanf("%lu", &a);
        scanf("%lu", &b);
        if (a < a_top) {
            a_top = a;
            b_top = b;
        } else if (a > a_last) {
            a_last = a;
            b_last = b;
        }
    }

    printf("%d\n", a_top + (a_last - a_top) + b_last);
}

Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstring>
#include <string>
#include <string.h>
#include <cmath>
#include <math.h>
#include <iterator>
#include <iomanip>
#include <set>
#include <bitset>
#include <algorithm>
#include <map>
#include <queue>
#include <deque>
#include <vector>
#include <stack>
#include <climits>
#include <limits>
#include <functional>
#include <ctime>
#include <cctype>
#include <cstdlib>
#include <cstdio>
#define fore(i,a,b) for(ll i = (a),_b = (b); i < (_b); i++)
#define fort(i,a,b) for(ll i = (a),_b = (b); i <= (_b); i++)
#define ford(i,a,b) for(ll i = (a),_b = (b); i >= (_b); i--)
#define fi first
#define se second
#define sz(x) ((ll)(x).size())
#define pb push_back
#define pf push_front
//#define LOCAL
using namespace std;

template<class A,class B> bool maxi(A&a,const B b){return a < b ? (a = b,true):false;};
template<class A,class B> bool mini(A&a,const B b){return a > b ? (a = b,true):false;};

typedef long long ll;

const ll maxN = 3e3 + 5;
const ll inf = 1e10;

ll n,m;
string s,t,res;
ll dp[maxN][maxN];
int trace[maxN][maxN];

int main(){
    #ifdef LOCAL
        freopen("f.INP","r",stdin);
    #endif // LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> s >> t;
    n = sz(s);
    m = sz(t);
    s = ":" + s;
    t = ":" + t;
    fort(i,1,n)
        fort(j,1,m)
            if(s[i] == t[j]){
                dp[i][j] = dp[i - 1][j - 1] + 1;
                //trace[i][j] = 0;
            }else{
                dp[i][j] = dp[i - 1][j - 1];
                if(maxi(dp[i][j],dp[i - 1][j]))
                    trace[i][j] = 1;
                if(maxi(dp[i][j],dp[i][j - 1]))
                    trace[i][j] = -1;
            }
    while(n && m){
        if(s[n] == t[m])
            res = s[n] + res;
        if(!trace[n][m]){
            n--;
            m--;
        }else if(trace[n][m] < 0)
            m--;
        else
            n--;
    }
    cout << res << '\n';
    return 0;
}


Measured memory_bytes: 105856
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>
#include <functional>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
const ll inf = (1LL << 60);
const ll mod = 1000000007;
ll max(ll a, ll b) {
	if (a < b)
		return b;
	else
		return a;

}
ll min(ll a, ll b) {
	if (a < b)
		return a;
	else
		return b;

}




ll ans[100005];
ll flag[100005];
vector<ll> a;
int main() {

	ll N, M;

	cin >> N >> M;

	a.resize(M);

	rep(i, M) {
		cin >> a[i];
		a[i]--;
		flag[a[i]] = 1;
	}

	ans[0] = 1;
	ans[1] = (flag[0] == 0) * ans[0] + 1;
	for(int i = 2;  i < N; i++) {
		
		ans[i] = (flag[i-1] == 0) * (ans[i - 1] % mod) + (flag[i-2] == 0) * (ans[i-2] % mod);
		ans[i] %= mod;
	}


	cout << ans[N - 1] << endl;

	return 0;
}


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





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

	vector<int>t(N+2);
	vector<int>x(N+2);
	vector<int>y(N+2);

	string ans="Yes";

	t[0]=0;
	x[0]=0;
	y[0]=0;
	for(int i=1;i<N+2;i++) cin>>t[i]>>x[i]>>y[i];
	
	
	
	for(int i=1;i<N+1;i++){
		if(abs(x[i]-x[i-1])+abs(y[i]-y[i-1])<=t[i]-t[i-1] && (t[i]-t[i-1]-(abs(x[i]-x[i-1])+abs(y[i]-y[i-1])))%2==0){

		}else{
			ans="No";
		}
	}
	cout<<ans;
	
}


Measured memory_bytes: 1408
s = input()
if    1 <=int(s[0:2]) <= 12 and 1<= int(s[2:4]) <= 12:
    print("AMBIGUOUS")
elif  1<= int(s[2:4]) <= 12:
    print("YYMM")
elif  1<= int(s[0:2]) <= 12:
    print("MMYY")
else :
    print("NA")

Measured memory_bytes: 9176
#include <stdio.h>
#include <stdlib.h>


typedef struct{
	int left;
	int right;
}TREE_T;

typedef struct{
	int num;
	int h;
}STRUCT;


TREE_T *TREE;
STRUCT *IN_ORDER;
int *MEM;

int COUNT = 0;


void Make_tree(int left, int right)
{
	int id;
	int soeji;
	int l_max, l_pos, r_max, r_pos;
	int i;

	soeji = MEM[COUNT++];
	id = IN_ORDER[soeji].num;

	l_max = r_max = -1;
	for(i = left; i < soeji; i++){
		if(l_max < IN_ORDER[i].h){
			l_max = IN_ORDER[i].h;
			l_pos = i;
		}
	}
	if(l_max == -1)
		TREE[id].left = -1;
	else
		TREE[id].left = IN_ORDER[l_pos].num;

	for(i = soeji + 1; i <= right; i++){
		if(r_max < IN_ORDER[i].h){
			r_max = IN_ORDER[i].h;
			r_pos = i;
		}
	}
	if(r_max == -1)
		TREE[id].right = -1;
	else
		TREE[id].right = IN_ORDER[r_pos].num;

	// 左側の処理
	if(l_max != -1)
		Make_tree(left, soeji - 1);

	// 右側の処理
	if(r_max != -1)
		Make_tree(soeji + 1, right);
}


// 帰りがけなぞり
int WALK_COUNT = 0;
void Walk_tree(int soeji)
{
	if(TREE[soeji].left != -1)
		Walk_tree(TREE[soeji].left);

	if(TREE[soeji].right != -1)
		Walk_tree(TREE[soeji].right);


	printf("%d", soeji);
	WALK_COUNT++;
	if(WALK_COUNT != COUNT)
		printf(" ");
	else
		printf("\n");
}


int main()
{
	int n;
	int *pre_order;
	int i, j;

	scanf("%d", &n);

	// 初期化
	pre_order = (int *)malloc(sizeof(int) * n);
	IN_ORDER = (STRUCT *)malloc(sizeof(STRUCT) * n);

	TREE = (TREE_T *)malloc(sizeof(TREE_T) * (n + 1));
	MEM = (int *)malloc(sizeof(int) * n);

	// データ入力
	for(i = 0;i < n; i++)
		scanf("%d", &pre_order[i]);
	for(i = 0; i < n; i++)
		scanf("%d", &IN_ORDER[i].num);

	//　必要なデータの前準備
	for(i = 0; i < n; i++){
		for(j = 0; j < n; j++){
			if(pre_order[i] == IN_ORDER[j].num){
				//printf("●");
				MEM[i] = j;
				IN_ORDER[j].h = n - i;
			}//else
				//printf("×");
		}
		//printf("\n");
	}

	// 木の作成
	Make_tree(0, n - 1);

/*	for(i = 1; i < n + 1; i++)
		printf("%d l:%d r:%d\n", i, TREE[i].left, TREE[i].right);
*/
	// 帰りがけなぞり
	Walk_tree(IN_ORDER[MEM[0]].num);

	return 0;
}


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

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int N,P; cin >> N >> P;
    ll sum = 0;
    vector<tuple<double,int,int>> hyou(N);
    rep(i,N){
        int w,b; cin >> w >> b;
        ll k = (ll)(100-P)*w+(ll)P*b;
        hyou[i] = tie(k,w,b);
        sum += b;
    }
    sort(hyou.rbegin(),hyou.rend());
    int ans = 0;
    ll white = 0;
    rep(i,N){
        int a,b,c;
        tie(a,b,c) = hyou[i];
        sum += b-c;
        white += b;
        if(white*100 >= P*sum){
            ans = i+1;
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
arguments = input().split()

array = []

for word in arguments:
    if word == '-':
        s1 = array.pop()
        s2 = array.pop()
        array.append(s2-s1)
    elif word == '*':
        s1 =array.pop()
        s2 = array.pop()
        array.append(s1*s2)
    elif word == '+':
        s1 = array.pop()
        s2 = array.pop()
        array.append(s1+s2)
    else:
        array.append(int(word))


print(array.pop())

Measured memory_bytes: 7652
#include <iostream>

#include <set>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(NULL);

   int N, M;
   cin >> N >> M;

   vector<int> freq(N+1, 1);
   set<int> X;
   X.insert(1);

   for (int m = 0; m < M; ++m) {
      int u, v;
      cin >> u >> v;
      if (X.count(u)) {
         if (freq[u] == 1)
            X.erase(u);
         X.insert(v);
      }
      --freq[u];
      ++freq[v];
   }

   cout << X.size() << endl;

   return 0;
}


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

A = [int(input()) for i in range(N)]

ans = 0
for i in range(N-1):
    ans += A[i]//2
    if A[i]%2==1 and A[i+1]>0:
        A[i+1] -= 1
        ans += 1

print(ans+(A[N-1]//2))

Measured memory_bytes: 7072
#include <iostream>
#include <vector>
#include <tuple>
#include <map>
#include <algorithm>
using namespace std;

struct team_data {
    int id;
    int solved;
    int time;
    map<int, int> wrong;
};

int main() {
    int T, P, R;
    while(cin >> T >> P >> R, T) {
        vector<team_data> v(T);
        for(int i=0; i<T; ++i) {
            v[i].id = i+1;
        }

        for(int i=0; i<R; ++i) {
            int tID, pID, time;
            string message;
            cin >> tID >> pID >> time >> message;
            if(message == "CORRECT") {
                v[tID-1].time += time + v[tID-1].wrong[pID]*1200;
                v[tID-1].solved += 1;
            } else {
                v[tID-1].wrong[pID] += 1;
            }
        }

        stable_sort(v.begin(), v.end(), [](auto const& t1, auto const& t2) {
            if(t1.solved == t2.solved) {
                return t1.time < t2.time;
            } else {
                return t1.solved > t2.solved;
            }
        });

        for(auto& t : v) {
            cout << t.id << " " << t.solved << " " << t.time << endl;
        }
    }
}


Measured memory_bytes: 3228