akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int N,M;
int S,T;

vector<tuple<int,int,ll>> edges;
vector<pair<int,ll>> g[100010];
ll dist[2][100010];
const ll INF=1e18;

ll dp[2][100010];

void dijkstra(int c){
    for(int i=0;i<=N;i++) dist[c][i]=INF;
    priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> PQ;
    if(c==0){
        dist[c][S]=0;
        PQ.push(mkp(0,S));
    }else{
        dist[c][T]=0;
        PQ.push(mkp(0,T));
    }

    while(!PQ.empty()){
        int now;
        ll cost;
        tie(cost,now)=PQ.top();
        PQ.pop();

        if(dist[c][now]<cost) continue;
        for(int i=0;i<g[now].size();i++){
            int nex;
            ll neco;
            tie(nex,neco)=g[now][i];
            if(dist[c][nex]>dist[c][now]+neco){
                dist[c][nex]=dist[c][now]+neco;
                PQ.push(mkp(dist[c][nex],nex));
            }
        }
    }
}

void add(ll &a,ll b){
    a=(a+b)%MOD;
}

void setRoutes(int c){
    priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> PQ;
    vector<int> used(N+1,0);
    if(c==0){
        dp[c][S]=1;
        PQ.push(mkp(0,S));
        used[S]=1;
    }else{
        dp[c][T]=1;
        PQ.push(mkp(0,T));
        used[T]=1;
    }

    while(!PQ.empty()){
        int now;
        ll cost;
        tie(cost,now)=PQ.top();
        PQ.pop();

        for(int i=0;i<g[now].size();i++){
            int nex;
            ll neco;
            tie(nex,neco)=g[now][i];
            int tar=T;
            if(c==1) tar=S;
            if(dist[c][now]+neco+dist[1-c][nex]==dist[c][tar]){
                add(dp[c][nex],dp[c][now]);
                if(used[nex]==0){
                    used[nex]=1;
                    PQ.push(mkp(dist[c][nex],nex));
                }
            }
        }
    }
}

void mul(ll &a,ll b){
    a=a*b%MOD;
}

int main(){
  cin>>N>>M;
  cin>>S>>T;
  rep(i,M){
      ll a,b,c;
      cin>>a>>b>>c;
      edges.push_back(mkt(a,b,c));
      g[a].push_back(mkp(b,c));
      g[b].push_back(mkp(a,c));
  }

  dijkstra(0);
  dijkstra(1);

  setRoutes(0);
  setRoutes(1);

  ll ans=dp[0][T];
  mul(ans,dp[1][S]);
  for(int i=1;i<=N;i++){
      if(dist[0][i]+dist[1][i]==dist[0][T]&&dist[0][i]==dist[1][i]){
          ll res=dp[0][i];
          mul(res,dp[1][i]);
          mul(res,res);
          add(ans,MOD-res);
      }
  }

  for(int i=0;i<M;i++){
      ll a,b,c;
      a=get<0>(edges[i]);
      b=get<1>(edges[i]);
      c=get<2>(edges[i]);

      if(dist[0][a]>dist[0][b]) swap(a,b);
      if(dist[0][a]+c+dist[1][b]==dist[0][T]){
          if(abs(dist[0][a]-dist[1][b])<c){
              ll res=dp[0][a];
              mul(res,dp[1][b]);
              mul(res,res);
              add(ans,MOD-res);
          }
      }
  }
  
  add(ans,MOD);
 
  cout<<ans<<endl;


  return 0;
}


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

int main(void){
    int x1, x2, y1, y2, x3, y3, x4, y4;

    cin >> x1 >> y1 >> x2 >> y2;

    int d_x = abs(x1 - x2);
    int d_y = abs(y1 - y2);

    if(x1 >= x2 && y1 >= y2){
        // cout << "1" << endl;
        x3 = x2 + d_y;
        y3 = y2 - d_x;

        x4 = x1 + d_y;
        y4 = y1 - d_x;
    }else if(x2 >= x1 && y1 >= y2){
        // cout << "2" << endl;
        x3 = x2 + d_y;
        y3 = y2 + d_x;

        x4 = x1 + d_y;
        y4 = y1 + d_x;
    }else if(x2 >= x1 && y2 >= y1){
        // cout << "3" << endl;
        x3 = x2 - d_y;
        y3 = y2 + d_x;

        x4 = x1 - d_y;
        y4 = y1 + d_x;
    }else if(x1 >= x2 && y2 >= y1){
        x3 = x2 - d_y;
        y3 = y2 - d_x;

        x4 = x1 - d_y;
        y4 = y1 - d_x;
    }

    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define ljc 1000000007
using namespace std;
/*
C_{a_i+b_i+a_j+b_j}^{a_i+a_j}
等价于(-a_i,-b_i)->(a_j,b_j)的方案数（只能上右移）
\sum_{i=1}^n\sum_{j=i+1}^n C_{a_i+b_i+a_j+b_j}^{a_i+a_j}
=\sum_{i=1}^n([i+1,n])点到(a_i,a_j)的距离
直接 dp
最后容斥。 
*/
#ifdef Fading
#define gc getchar
#endif
#ifndef Fading
inline char gc(){
    static char now[1<<16],*S,*T;
    if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
    return *S++;
}
#endif
inline ll read(){
    register ll x=0,f=1;char ch=gc();
    while (!isdigit(ch)){if(ch=='-')f=-1;ch=gc();}
    while (isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=gc();}
    return (f==1)?x:-x;
}
int n,MX,dp[4003][4003];
inline ll fast_pow(ll a,ll b,ll p){
	ll t=1;a%=p;
	while (b){
		if (b&1) t=t*a%p;
		b>>=1;a=a*a%p;
	}	
	return t;
}
ll inv[100001],a[200201],b[200201],fac[100001];
inline void init(int n){
	inv[0]=inv[1]=fac[0]=fac[1]=1;
	for (ll i=2;i<=n;i++) fac[i]=fac[i-1]*i%ljc;
	for (ll i=2;i<=n;i++) inv[i]=(ljc-(ljc/i)*inv[ljc%i]%ljc)%ljc;
	for (ll i=1;i<=n;i++) inv[i]=inv[i-1]*inv[i]%ljc;
}
signed main(){
	n=read();
	init(8000);
	for (int i=1;i<=n;i++){
		a[i]=read(),b[i]=read();MX=max(MX,max(a[i],b[i]));
	}
	for (int i=1;i<=n;i++){
		dp[-a[i]+MX][-b[i]+MX]++;
	}
	for (int i=0;i<=2*MX;i++){
		for (int j=0;j<=2*MX;j++){
			dp[i+1][j]=(dp[i+1][j]+dp[i][j])%ljc;
			dp[i][j+1]=(dp[i][j+1]+dp[i][j])%ljc;
		}
	}
	ll ans=0;
	for (int i=1;i<=n;i++){
		ans=(ans+dp[a[i]+MX][b[i]+MX])%ljc;
	 	ans=(ans-fac[2*a[i]+2*b[i]]*inv[2*b[i]]%ljc*inv[2*a[i]]%ljc+ljc)%ljc;
	}
	ans=ans*fast_pow(2,ljc-2,ljc)%ljc;
	cout<<ans<<endl;
	return 0;
}

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

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int INF = pow(2,29);
const int MOD = 1000000007;

int main() {
  double W, H, x, y; cin >> W >> H >> x >> y;
  double S = W*H/2;
  int type = (W/x==2 && H/y==2) ? 1 : 0;
  cout << S << " " << type << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

int main () {
  string S;cin>>S;
  int N = S.size();
  reverse(S.begin(),S.end());
  vector<int> mod(N+1,0);
  mod[0] = 0;
  map<int,ll> dic;
  ll ten = 1;
  dic[0]++;
  rep(i,N) {
    int now = S[i] - '0';
    mod[i+1] = (ten * now % 2019 + mod[i]) % 2019;
    ten = ten * 10 % 2019;
    dic[mod[i+1]]++;
  }
  ll ans = 0;
  for (auto it = dic.begin() ; it != dic.end() ; it++) {
    //    cout << it->first << " " << it->second << endl; 
    ans = (ans + (it->second) * (it->second - 1) / 2 % MOD) % MOD;
  }
  cout << ans << endl;
}


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

int main(void){
    int n, x = 0, ans = 0;
    string s;
    cin >> n >> s;
    for (int i=0; i<n; i++){
        if (s[i] == 'I') x++;
        else x--;
        ans = max(ans, x);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3564
#include <iostream>
using namespace std; 
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ll long long
int a[200005],b[200005];
int main(int argc, char** argv) {
	int n;
	scanf("%d",&n);
	rep(i,1,n)
	scanf("%d%d",&a[i],&b[i]);
	ll ans=0,mx=1e18,fg=0;
	rep(i,1,n)
	{
		if(a[i]<=b[i])
		{
		
		ans+=a[i];
		if(a[i]<b[i])fg=1;
	}
		else if (a[i]>b[i])
		{
			if(a[i]>b[i])fg=1;
			ans+=1ll*a[i];
			mx=min(mx,1ll*b[i]);
		}
	}
	if(fg)
	cout<<ans-mx;
	else cout<<0;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
void show(vector<int> a,int x){
  rep(i,x) cout << a[i] << " ";
  cout  << "\n";
}
int main()
{
  int n;cin >> n;
  string s;cin >> s;  
  vector<int> a(n);
  bool in1 = false;
  rep(i,n){
    a[i] = (int)s[i] - '1';
    if(a[i] == 1) in1 = true;
  }

  int x = 0;
  rep(i,n){
    if(a[i] == 1 && (n-1 == (i | (n-1-i)))) x = (x+1)%2;
  }
  if(x%2 == 1) cout << 1 << "\n";
  else if(in1) cout << 0 << "\n";
  else{
    x = 0;
    rep(i,n){
      if(a[i] == 2 && (n-1 == (i | (n-1-i)))) x = (x+1)%2;      
    }
    if(x%2 == 0) cout << 0 << "\n";
    else cout << 2 << "\n";
  }
  
  
  return 0;
}


Measured memory_bytes: 5252
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<list>
#include<stack>
using namespace std;
#define ll long long 
#define dd cout<<endl
const int mod=1e9+7;
const int inf=1e9+7;

const int maxn=1e5+10;

int main()
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	
	ll int k,num;
	
	while(cin>>k>>num)
	{
		vector<int>v;
		
		
		
		k--;
		
		ll int t=k;
		ll int tnum=num;
		while(t)
		{
			tnum--;
			v.push_back(tnum);
			t--;
		}
		
		v.push_back(num);
		
		t=k;
		tnum=num;
		while(t<2*k)
		{
			tnum++;
			v.push_back(tnum);
			t++;
		}
		
		sort(v.begin(),v.end());
		
		for(int i=0;i<v.size();i++)
		{
			if(i==v.size()-1)
				cout<<v[i]<<endl;
			else
				cout<<v[i]<<" ";
		}
		
		
	}
	
	return 0;
}

Measured memory_bytes: 256
def solve(N, M, P, X):
    if X[M-1] == 0:
        return 0

    return sum(X) * (100-P) / X[M-1]

while True:
    N, M, P = map(int, raw_input().split(" "))
    if N == M == P == 0:
        break
    X = [int(raw_input()) for _ in range(N)]

    print solve(N, M, P, X)


Measured memory_bytes: 4212
/// @file up.cc
/// @brief up の実装ファイル
/// @author Yusuke Matsunaga (松永 裕介)
///
/// Copyright (C) 2019 Yusuke Matsunaga
/// All rights reserved.


#include <iostream>
#include <vector>
#include <list>

using namespace std;

class MFSetCell
{
public:

  long mId;

  MFSetCell* mParent;

  long mRank;

};

class MFSet
{
public:

  MFSet(long num);

  ~MFSet() = default;

  long
  find(long id);

  long
  merge(long id1,
	long id2);


private:

  MFSetCell*
  _find_top(MFSetCell* cell);

  vector<MFSetCell> mArray;

};


MFSet::MFSet(long num) :
  mArray(num)
{
  for ( long i = 0; i < num; ++ i ) {
    MFSetCell& cell = mArray[i];
    cell.mId = i;
    cell.mParent = &cell;
    cell.mRank = 0;
  }
}

long
MFSet::find(long id)
{
  auto tmp = &mArray[id];
  auto top = _find_top(tmp);
  return top->mId;
}

MFSetCell*
MFSet::_find_top(MFSetCell* cell)
{
  auto parent = cell->mParent;
  while ( parent->mParent != parent ) {
    cell = cell->mParent = parent->mParent;
    parent = cell->mParent;
  }
  return parent;
}

long
MFSet::merge(long id1,
	     long id2)
{
  auto cell1 = &mArray[id1];
  auto cell2 = &mArray[id2];

  if ( cell1->mParent != cell1 ) {
    cell1 = _find_top(cell1);
  }
  if ( cell2->mParent != cell2 ) {
    cell2 = _find_top(cell2);
  }
  if ( cell1 == cell2 ) {
    return cell1->mId;
  }

  if ( cell1->mRank > cell2->mRank ) {
    cell2->mParent = cell1;
    return cell1->mId;
  }
  else if ( cell1->mRank == cell2->mRank ) {
    ++ cell1->mRank;
    cell2->mParent = cell1;
    return cell1->mId;
  }
  else {
    cell1->mParent = cell2;
    return cell2->mId;
  }
}

void
no()
{
  cout << "No" << endl;
  exit(0);
}

void
yes()
{
  cout << "Yes" << endl;
  exit(0);
}

int
main(int argc,
     char** argv)
{
  cin.tie(0);
  ios::sync_with_stdio(0);

  long N;
  long M;
  long Q;
  cin >> N
      >> M
      >> Q;

  if ( Q == 0 ) {
    abort();
  }
  if ( M > ((N * (N - 1)) / 2) ) {
    abort();
  }

  MFSet mfset(N);

  vector<pair<long, long>> single_pair_list;
  vector<pair<long, long>> multi_pair_list;
  bool has_single = false;
  for ( long i = 0; i < Q; ++ i ) {
    long a, b, c;
    cin >> a >> b >> c;
    if ( c == 0 ) {
      single_pair_list.push_back(make_pair(a, b));
      mfset.merge(a, b);
      has_single = true;
    }
    else {
      multi_pair_list.push_back(make_pair(a, b));
    }
  }

  if ( M == N - 1 ) {
    // M = N - 1 の時は木構造のグラフとなる．
    if ( multi_pair_list.size() > 0 ) {
      // その場合複数経路はありえない．
      no();
    }
    else {
      yes();
    }
  }

  if ( !has_single ) {
    yes();
  }

  for ( auto p: multi_pair_list ) {
    long a = p.first;
    long b = p.second;
    if ( mfset.find(a) == mfset.find(b) ) {
      no();
    }
  }

  long K = 0;
  for ( long i = 0; i < N; ++ i ) {
    if ( mfset.find(i) == i ) {
      ++ K;
    }
  }

  long M_max = N - K + (K * (K - 1)) / 2;
  if ( M > M_max ) {
    no();
  }

  yes();

  return 0;
}


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

void chmax(string &a, string b) {
  if (a.size() < b.size() || a < b)
    a = b;
  return;
}

int main() {
  int N, M;
  cin >> N >> M;
  int cost[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
  vector<int> m(M);
  rep(i, M) cin >> m[i];
  vector<string> dp(N + 10, "0");
  dp[0] = "";
  rep(i, N + 1) rep(j, M) {
    if (dp[i] != "0")
      chmax(dp[i + cost[m[j] - 1]], dp[i] + to_string(m[j]));
  }
  cout << dp[N] << endl;
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> num(N);
  
  for(int i=0; i<N; i++){
   cin >> num.at(i);
  }
  
  sort(num.begin(),num.end());
  reverse(num.begin(),num.end());//大きい順の配列
  
  int count=0;
  
  if(N/2 *2 ==N){ //N:even
    for(int i=0; i<N; i +=2){
     count += num.at(i);
      count -= num.at(i+1);
    }
  }
  else{ //N:odd
    for(int i=0; i<N-1; i +=2){
     count += num.at(i);
      count -= num.at(i+1);
    }
    count += num.at(N-1);
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}
int main(){
    ll n;cin >> n;
    vl v(n);rep(i,n)cin >> v[i];
    map<ll,ll> mp;
    ll now=0;mp[0]++;
    ll res=0;
    rep(i,n){
        now+=v[i];
        res+=mp[now];
        mp[now]++;
    }
    cout << res <<endl;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N+1);
    vector<int> B(N+1);
    for (int i=0; i<=N; i++){
        cin >> A[i];
    }
    for (int i=0; i<N; i++){
        cin >> B[i];
    }

    long int count = 0;
    for (int i=0; i<N; i++){
        if (A[i] >= B[i]){
            count += B[i];
        }else{
            B[i] -= A[i];
            count += A[i];

            if (A[i+1] >= B[i]){
                count += B[i];
                A[i+1] -= B[i];
            }else{
                count += A[i+1];
                A[i+1] = 0;
                
            }
        }
    }

    cout << count;
}


Measured memory_bytes: 1024
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b, a%b);
}
int main(){
    int n;
    cin >> n;
    vi v;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        v.pb(x);
    }
    sort(rall(v));
    int gcdN = v[0];
    for(int i = 1; i < v.size(); i++){
        gcdN = gcd(max(gcdN, v[i]), min(gcdN, v[i]));
    }
    cout << gcdN;
}

Measured memory_bytes: 892
#pragma region Macros
#include <bits/stdc++.h>

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

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#pragma endregion

void solve() {
    int n;
    cin >> n;
    vector<string> a(n);
    for (int i=0; i<n; i++) {
        cin >> a.at(i);
    }
    int cnt = 0;
    for (int i=0; i<n; i++) {
        bool ok = true;
        for (int j=0; j<n; j++) {
            for (int k=j+1; k<n; k++) {
                if (a.at((i+j)%n).at(k) != a.at((i+k)%n).at(j)) {
                    ok = false;
                    break;
                }
            }
            if (!ok) break;
        }
        if (ok) cnt++;
    }
    cout << cnt * n << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) {
        is >> x;
    }
    return is;
}

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;

    ll ans = 0;
    map<string, int> m;
    REP(i, n) {
        string str;
        cin >> str;
        sort(all(str));
        ans += m[str];
        m[str]++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 11264
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            int n = cin.ReadInt;
            int m = cin.ReadInt;

            List<int[]> pList = new List<int[]>();

            for(int i = 0; i < m; i++)
            {
                // P_i, Y_i, i, rank
                pList.Add(new int[] {cin.ReadInt, cin.ReadInt, i, 1 });
            }

            List<int[]> orderdList = pList.OrderBy(x => x[0]).ThenBy(x => x[1]).ToList<int[]>();

            int tempP = -1;
            int beforeRank = 1;
            foreach(int[] item in orderdList)
            {
                if(item[0] != tempP)
                {
                    tempP = item[0];
                    beforeRank = 1;
                }
                else
                {
                    item[3] = beforeRank + 1;
                    beforeRank++;
                }
            }

            foreach(int[] item in pList)
            {
                Console.WriteLine(String.Format("{0:D6}", item[0]) + String.Format("{0:D6}", item[3]));
            }
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;

        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }

        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }

        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


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





int main() 
{
  ll L,R; cin>>L>>R;
  if(R-L+1>=2019) {cout<<0<<endl; return 0;}
  vector<ll> vec(0);
  for(ll i=L;i<=R;i++)
  {
    vec.push_back(i%2019);
  }
  ll ans=10000;
  for(ll i=0;i<R-L+1;i++)
  {
    for(ll j=i+1;j<R-L+1;j++)
    {
      ans=min(ans,vec.at(i)*vec.at(j)%2019);
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int X, Y;
cin >> X;
cin >> Y;
if(X*4>=Y&&X*2<=Y){
  if(Y%2==0){
    cout << "Yes" << endl;}
  else{
    cout << "No" << endl;}}
else{
  cout << "No" << endl;}
return 0;
}


Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n+1],b[n+1],c[n];
	int ans=0;
	for (int i=1;i<=n;i++)
	{
	    cin>>a[i];
	}
	for (int i=1;i<=n;i++)
	{
	    cin>>b[i];
	    ans+=b[i];
	}
	for (int i=1;i<n;i++)
	{
	    cin>>c[i];
	}
	for (int i=1;i<n;i++)
	{
	    if (a[i]+1==a[i+1])
	    ans+=c[a[i]];
	}
	
	cout<<ans;
	
}

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

int main(){
    int x=0, maxX=0;
    int N;
    string S;
    cin >> N >> S;
    for(int i=0; i<N; i++){
        if(S[i] == 'I'){
            x++;
        }else {
            x--;
        }
        maxX = x > maxX ? x : maxX;
    }
    cout << maxX << '\n';
}


Measured memory_bytes: 3160
#include<iostream>
#include<vector>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;

int main(){
	char c;
	cin>>c;
	if(c<='Z')cout<<'A'<<endl;
	else cout<<'a'<<endl;
	return 0;
}

Measured memory_bytes: 3564
N = int(input())
A = [int(i) for i in input().split()]
A.insert(0, 0)

ans = []
for i in reversed(range(1, N + 1)):
    if sum(A[i::i]) % 2 != A[i]:
        A[i] = (A[i] + 1) % 2
    if A[i] == 1:
        ans.append(i)

print(len(ans))
print(*ans)


Measured memory_bytes: 12580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

int main() {
    int N, K, R, S, P;
    cin >> N >> K >> R >> S >> P;
    string T;
    cin >> T;
    map<char, int> points = {{'r', P}, {'s', R}, {'p', S}};

    int minusPoint = 0;
    rep(i, K){
        char prev = 'n';
        bool hasToMinusNext = true;
        for(int j = i; j < N; j = j + K){
            char now;
            now = T[j];
            if(now == prev && hasToMinusNext){
                minusPoint += points[now];
                hasToMinusNext = false;
            } else {
                hasToMinusNext = true;
            }
            prev = now;
        }
    }
    int ans = 0;
    rep(i, N){
        ans += points[T[i]];
    }
    cout << ans - minusPoint << endl;
    
    return 0;
}


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

const ll INF = 1LL << 60;

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    sort(A.rbegin(), A.rend());

    double sum = accumulate(A.begin(), A.end(), 0LL);
    // cout << (double)A[M - 1] << endl;
    // cout << (double)sum / (4 * M) << endl;
    if ((double)A[M - 1] < (double)sum / (4 * M)) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
//itp1_4-d
#include <iostream>
#include <vector>
using namespace std;

int main(){
 int n;
 cin>>n;
 vector<long> a(n);
 for(int i=0;i<n;i++){
  cin>>a[i];
 }
 long rmax=-1000001;
 long rmin=1000001;
 long rsum=0;
 for(int i=0;i<n;i++){
  rsum+=a[i];
  rmax=max(a[i],rmax);
  rmin=min(a[i],rmin);
 }
 cout<<rmin<<" "<<rmax<<" "<<rsum<<endl;
 return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
#define endl '\n'
#define pb push_back
#define ll long long
#define lli long long int
#define li long int
#define ld long double
#define vi vector<int>
#define vlli vector<lli>
#define vii vector<pair<int, int>>
#define pii pair<int, int>
#define mp(a, b) make_pair(a, b)
#define all(arr) arr.begin(), arr.end()
using namespace std;
const lli mod = 1e9 + 7;
const lli mod_ = 998244353;
const int INF = 1000000000;
const lli INF64 = (lli)1E18;
const int MAX = 1e5 + 5;

int main() {
	// ifstream cin("input.in");
	// ofstream cout("output.out");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n, capacity, weight, value;
	cin >> n >> capacity;
	vlli dp(capacity+1);
	for(int item = 0; item < n; item++) {
		cin >> weight >> value;
		for(int weight_remaining = capacity; weight_remaining >= weight; weight_remaining--) {
			dp[weight_remaining] = max(dp[weight_remaining], value+dp[weight_remaining-weight]);
		}
	}
	cout << *max_element(all(dp));
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include<algorithm>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int main(){
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i,n) cin >> d[i];
  ll ans = 0;
  rep(a,n){
    rep(b,a){
      ans += d[a]*d[b];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
A=list(map(int,input().split()))
from collections import defaultdict
d=defaultdict(list)
for i,a in enumerate(A):
    d[a].append(i)
x=0
k=1
from bisect import bisect
while True:
    i=bisect(d[A[x]],x)
    if i==len(d[A[x]]):
        if k==K:
            break
        i=0
        k+=1
    x=d[A[x]][i]+1
    if x==N:
        if K%k==0:
            break
        K=K%k
        k=1
        x=0
t=[]
while x<N:
    i=bisect(d[A[x]],x)
    if i==len(d[A[x]]):
        t.append(A[x])
        x+=1
    else:
        x=d[A[x]][i]+1
print(*t)

Measured memory_bytes: 58164
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
int A, B, C, X, Y;
cin >> A >> B >> C >> X >> Y; 
int ans = A * X + B * Y; 
for(int i = 0; i <= max(X, Y); i++){
int T = A * max(X - i, 0) + B * max(Y - i, 0) + C * i * 2; 
ans = min(ans, T); 
}
cout << ans << endl; 
}

Measured memory_bytes: 256
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define all(v) ((v).begin(),(v).end())
#define Sort(v) sort(all(v))
#define INF 1000000000
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};


int main(){
    int x;
    cin>>x;
    if(x<1200)cout<<"ABC"<<endl;
    else if(x<2800)cout<<"ARC"<<endl;
    else cout<<"AGC"<<endl;

}



    

Measured memory_bytes: 256
/*
  In The Name Of GOD
  author: amirhoseinatari
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define pp() pop_back()
#define mp make_pair
#define fir first
#define sec second
#define momaz(x) cout.precision(x);cout<<fixed
#define _ ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define debug(x) cout<<string(20,'#')<<endl<< #x <<"--> "<<x<<endl<<string(20,'-')<<endl
#define debug1(x) cout<<string(20,'#')<<endl<< #x <<"--> "<<x<<endl<<string(20,'-')<<endl
#define debug2(x,y) cout<<string(20,'#')<<endl<< #x <<"--> "<<x<<endl<< #y <<"--> "<<y<<endl<<string(20,'-')<<endl
#define debug3(x,y,z) cout<<string(20,'#')<<endl<< #x <<"--> "<<x<<endl<< #y <<"--> "<<y<<endl<< #z <<"--> "<<z<<endl<<string(20,'-')<<endl
#define debug4(x,y,z,t) cout<<string(20,'#')<<endl<< #x <<"--> "<<x<<endl<< #y <<"--> "<<y<<endl<< #z <<"--> "<<z<<endl<< #t <<"--> "<<t<<endl<<string(20,'-')<<endl
///freopen("input.txt","r",stdin);   add to main()
///freopen("output.txt","w",stdout);     //

/*
</head>
<body>
*/

const ll maxn = 100050 ;
vi a[maxn];

int dfs(int v,int par)
{
    int ans=0;
    for(auto i:a[v])
    {
        if(i!=par)
            ans^=dfs(i,v)+1;
    }
    return ans;
}
int main()
{_
	int n,q1,q2;
	cin>>n;
	for(int i=1;i<n;i++)
        cin>>q1>>q2,a[q1].pb(q2),a[q2].pb(q1);
    if(dfs(1,-1)==0)
        cout<<"Bob";
    else
        cout<<"Alice";

    return 0;
}
///Attar81 :)

Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
ll power( ll b, ll e)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b,e/2);
	return power(b*b,e/2);
}
ll power(ll b,ll e,ll m)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b%m,e/2,m)%m;
	return power(b*b%m,e/2,m);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    ll int a,b;
    cin>>a>>b;
    if(b>=a)
        cout<<"unsafe";
    else
        cout<<"safe";
    return 0;
}

Measured memory_bytes: 3592
/*
[ ( ^ _ ^ ) ]
*/
// problem: atc/abc165_b
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1000000000



int main() {
    ll x;
    scanf("%lld", &x);
    int i = 1;
    long double lhs = x, rhs = 100;
    while(true) {
        // lhs *= 100;
        rhs *= 1.01;
        rhs = (ll)rhs;
        if(lhs <= rhs) {
            printf("%d\n", i);
            return 0;
        }
        i++;
    }
}


Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 111111
int n,i,j;
double pw,vw[N],pf[N],vf[N],th[N],l,r,m1,m2,ans,res;
double calc(double x){
  res=pw*x;
  for(j=0;j<n;j++) res+=max(0.0,(th[j]-vw[j]*x)*pf[j]/vf[j]);
  ans=min(ans,res);
  return res;
}
int main(){
  while(cin>>n,n){
    cin>>pw;
    for(i=0;i<n;i++) scanf("%lf%lf%lf%lf",vw+i,pf+i,vf+i,th+i);
    l=0,r=1e9,ans=calc(0);
    for(i=0;i<100;i++){
      m1=l+(r-l)/3,m2=l+(r-l)*2/3;
      (calc(m1)>calc(m2))?l=m1:r=m2;
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

int main(){
  string S;
  cin >> S;
  if(S[0]==S[1]&&S[1]==S[2]){
    cout << "Yes" << endl;
  } else if(S[1]==S[2]&&S[2]==S[3]){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const int MAX=2e5+5;

//i桁目についてj番目までの和
int sum[20][MAX];

int main(){
	int N;
	cin>>N;
	rep1(j,N){
		int a;
		cin>>a;
		rep(i,20)sum[i][j]=sum[i][j-1]+((a>>i)&1);
	}
	//尺取り
	int l=0,r=1;
	ll ans=0;
	while(r<=N){
		bool ok=true;
		rep(i,20)if(sum[i][r]-sum[i][l]>1)ok=false;
		if(ok){
//         	cout<<l<<" "<<r<<endl;
          	r++;
        }
		else{
			ans+=(ll)r-l-1;
			l++;
			if(l==r)r++;
		}
	}
  	while(l<=N){
  		ans+=(ll)r-l-1;
      	l++;
   	}
	cout<<ans<<endl;
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll;
vector<ll> check ;
bool v[200005] ;
vector<ll> G[200005] ;
ll beg[200005] , last[200005] ;
void dfs(ll s);
void solve () {
  ll N , Q ;
  cin >> N >> Q ;
  for(ll i=0 ;i<=N;i++)
    v[i] = false; 
  for(ll i = 1 ; i < N ;i++){
    
    ll u , v ;
    cin >> u >> v ;
    G[u].push_back(v) ;
    G[v].push_back(u) ;
  }
  dfs(1) ;
  ll siz = (ll)check.size() + 10; 
  ll calc[siz] ;
  
  for(ll i =0 ; i < (ll)check.size() + 10 ;i++)
    calc[i] =0 ;

  while(Q--) {
    
    ll p , x ;
    cin >> p >> x ;
    calc[beg[p]] += x ;
    calc[last[p]] -= x;

  }

  for(ll i=1 ; i < check.size() ;i++)
    calc[i] = calc[i - 1] + calc[i] ;

  for(ll i = 1 ; i <= N ;i++)
    cout << calc[beg[i]] << " ";

}
  
 void dfs(ll s){

    v[s] = true ;
  beg[s] = (ll)check.size() ;
  check.push_back(s) ;
  for(ll i =0 ;i < G[s].size() ;i++)
    if(v[G[s][i]] == false)
      dfs(G[s][i]) ;
  last[s] = (ll)check.size() ;
} 
  
  int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t=1;
	//cin >> t;
	while(t--)
	{
		solve();
	}
		return 0;
}


Measured memory_bytes: 24564
#include <iostream>

using namespace std;

int main()
{	
	int a1, a2, a3, buff;
	
	cin >> a1 >> a2 >> a3;

	if (a1 > a2) {
		buff = a1;
		a1 = a2;
		a2 = buff;
	}

	if (a2 > a3) {
		buff = a2;
		a2 = a3;
		a3 = buff;
	}

	if (a1 > a2) {
		buff = a1;
		a1 = a2;
		a2 = buff;
	}

    cout << a1 << " " << a2 << " " << a3 << endl; 
}


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

#define ll long long int
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define repm(i, a, n) for (ll i = a; i >= n; i--)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define mod (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vd vector<double>
#define vb vector<bool>
#define vs vector<string>
#define vii vector<vector<int>>
#define vllll vector<vector<ll>>
#define ALL(a) (a).begin(), (a).end()

int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};

void print(bool f)
{
    cout << (f ? "Yes" : "No") << endl;
}

void Print(bool f)
{
    cout << (f ? "YES" : "NO") << endl;
}

int main(void)
{
    string s, t;
    cin >> s >> t;

    ll scnt = 1, tcnt = 1;
    map<char, int> mps, mpt;
    rep(i, 0, s.size())
    {
        if (mps[s[i]] == 0)
            mps[s[i]] = scnt++;
        s[i] = mps[s[i]] + '0';
        if (mpt[t[i]] == 0)
            mpt[t[i]] = tcnt++;
        t[i] = mpt[t[i]] + '0';
    }
    print(s == t);
}

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

int main(){
  string first,second;
  
  cin >> first >> second;
  int len = second.size();
  char add = second.at(len-1);
  
  first.push_back(add);
  if(first == second){
    cout << "Yes" <<endl;
  }
  else{
    cout << "No" << endl;
  }
  
}


Measured memory_bytes: 3632
#!/usr/bin/env python3
import sys
try: from typing import Any, Union, List, Tuple, Dict
except ImportError: pass
sys.setrecursionlimit(10**6)
def debug(*args): print(*args, file=sys.stderr)
def exit(): sys.exit(0)


x, y = map(int, input().split())


ans = -1

if y > 0:
    if y < x:
        ans = 1 + (-y) - (-x) + 1
    elif 0 <= x < y:
        ans = y - x
    elif -y <= x < 0:
        ans = 1 + y - (-x)
    elif x < -y:
        ans = (-y) - x + 1
    else:
        raise Exception("hoge")
elif y == 0:
    if x > 0:
        ans = 1 + x
    else:
        ans = -x
elif y < 0:
    if x < y:
        ans = y - x
    elif y < x < 0:
        ans = 1 + (-y) - (-x) + 1
    elif 0 <= x <= -y:
        ans = (-y) - x + 1
    elif -y < x:
        ans = 1 + y - (-x)
    else:
        raise Exception("fuga")

print(ans)


Measured memory_bytes: 38384
# -*- coding: utf-8 -*-


def main():
    x, y = map(int, input().split())
    ans = 0

    if x == 1:
        ans += 300000
    elif x == 2:
        ans += 200000
    elif x == 3:
        ans += 100000

    if y == 1:
        ans += 300000
    elif y == 2:
        ans += 200000
    elif y == 3:
        ans += 100000

    if x == 1 and y == 1:
        ans += 400000

    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;

using ll = long long;

#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define repn(i,n)  rep(i,0,n)

const double EPS = 1e-5;
const int MOD = 1e9+7;


int main(){
  int a, p;

  cin >> a >> p;

  int particles = a * 3 + p;

  int pie = particles / 2;

  cout << pie << endl;

  return 0;


}


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

int main() {

    long long n;

    cin >> n;
    int cnt = 0;
    while(n > 3) {
        if(n % 3) n = n / 3 + 1;
        else n /= 3;
        cnt++;
    }
    cout << cnt + 1 << endl;
}



Measured memory_bytes: 3088
N, K = [ int(n) for n in input().split() ]
A    = [ int(n) for n in input().split() ]

count = 0
for i in range(N):
    for j in range(i,N):
        if A[i] < A[j]:
            count += ( (K-1)*K//2 ) % (10**9 + 7)
            count %= (10**9 + 7)
        elif A[i] > A[j]:
            count += ( K*(K+1)//2 ) % (10**9 + 7)
            count %= (10**9 + 7)

print( count )

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef long double ld;
 
//****************************************************                
#define f(var,start,end) for(ll var = start; var <end ; ++var)
#define rf(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define vvll vector<vector<ll>>
#define mtp make_tuple
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define nl cout<<"\n"
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define OC freopen("input.txt" , "r", stdin); freopen("output.txt" , "w", stdout) 
#define MOD (ll)1e9+7; //change it for other mods
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions
void solve();

int binary(int a[],int l,int r,int find)
{
    if(l>r)
    {
        return -1; 
    }else
    {
        int mid=(l+r)/2;
        if(a[mid]==find)
        {
            return mid+1;
        }else if(a[mid]>find)
        {
            binary(a,l,mid-1,find);
        }else
        {
            binary(a,mid+1,r,find);
        }   
    }   
    return 0;
}

int main()
{
    FAST_IO;
    ll testcases = 1;
    // cin >> testcases; //comment for 1 test case
    while(testcases--)
    {
        solve();
    }
    return 0;
}

void solve()
{
	ll k,n;
	cin>>k>>n;
	vll a(n);
	vll mp(102,0);
	f(x,0,n)
	{
		cin>>a[x];
		mp[a[x]]++;
	}
	ll ans=0;
	ll mn=k;
	f(x,0,102)
	{
		if(mp[x]==0)
		{
			ll vl=abs(k-x);
			if(vl<mn)
			{
				mn=vl;
				ans=x;
			}
		}
	}
	cout<<ans;
	nl;
}

Measured memory_bytes: 3608
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read_<T: FromStr>(&mut self) -> Option<T> {
        let token = self
            .cin
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read_().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let n: i32 = sc.read();
    let mut array: Vec<i32> = vec![0; n as usize];
    for i in 0..n {
        array[i as usize] = sc.read();
    }

    let mut result: Vec<i32> = vec![];
    for el in array {
        if result.len() == 0 || result[result.len() - 1] >= el {
            result.push(el);
        } else {
            let mut left = 0;
            let mut right = result.len();
            while left < right {
                let current = (left + right) / 2;
                if result[current as usize] < el {
                    right = current;
                } else {
                    left = current + 1;
                }
            }
            result[left as usize] = el;
        }
    }

    println!("{}", result.len());
}


Measured memory_bytes: 4352
N = int(input())
d = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
for i in range(N):
    inp = input()
    if inp[0] in d:
        d[inp[0]] += 1
import itertools
cnt = 0
for c in itertools.combinations(d.keys(), 3):
    cnt += d[c[0]] * d[c[1]] * d[c[2]]
print(cnt)


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

class Main{
    public static void main(String[] args){
        solve();
    }

    public static void solve(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        long count = 0;
        for(int i=0;i<n;i++){
        	a[i] = sc.nextLong();
        	count += a[i];
        }
        long min = Long.MAX_VALUE/2;

        long counter = 0;
        for(int i=0;i<n-1;i++){
        	counter += a[i];
        	min = Math.min(min, (long)Math.abs((count-counter) - counter));
        }

        System.out.println(min);
    }
}

Measured memory_bytes: 63984
use std::io::*;
use std::cmp::Ordering;

fn solve() -> u32{
    0
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();

    let n:usize = iter.next().unwrap().parse().unwrap();
    let mut v: Vec<(String, i32, usize)> = (0..n)
        .map(|i| {
            (
                iter.next().unwrap().parse().unwrap(),
                iter.next().unwrap().parse().unwrap(),
                i+1,
            )
        }).collect();
    v.sort_by(|v0,v1| {
        let result = v0.0.cmp(&v1.0);
        if result != Ordering::Equal {
            return result;
        }
        if v0.1 < v1.1 {
            return Ordering::Greater;
        }
        Ordering::Less
    });
    for item in v {
        println!("{}", item.2);
    }
}


Measured memory_bytes: 4352
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v){
    if(v.empty()){
        os<<"{ }";
        return os;
    }
    os<<"{"<<v.front();
    for(auto itr=++v.begin();itr!=v.end();itr++){
        os<<", "<<*itr;
    }
    os<<"}";
    return os;
}

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n; cin>>n;
    vector<int> a(n,0),b(n,0);
    rep(i,n){
        cin>>a[i];
    }
    rep(i,n){
        cin>>b[i];
    }
    set<int> st;
    vector<set<int>> sts(n+1);
    rep(i,n){
        if(a[i]==b[i]){
            st.insert(a[i]);
            sts[a[i]].insert(i);
        }
    }
    while(!(st.empty())){
        if(st.size()>=2){
            int l=*st.begin();
            int r=*(++st.begin()); 
            int p1=*sts[l].begin();
            int p2=*sts[r].begin();
            swap(b[p1],b[p2]);
            sts[l].erase(p1);
            sts[r].erase(p2);
            if(sts[l].empty()) st.erase(l);
            if(sts[r].empty()) st.erase(r);

        }
        else{
            int l=*st.begin();
            int idx=0;
            while(!(sts[l].empty())){
                int p1=*sts[l].begin();
                while(1){
                    if(idx==n){
                        cout<<"No"<<endl;
                        return 0;
                    }
                    if(idx!=p1 && a[idx]!=l && b[idx]!=l) break;
                    idx++;
                }
                swap(b[idx],b[p1]);
                sts[l].erase(p1);
            }
            st.erase(l);
        }
    }
    cout<<"Yes"<<endl;
    rep(i,n) cout<<b[i]<<" ";
    cout<<endl;
}

Measured memory_bytes: 33076
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y) -> int: return pow(x, y, DVSR)
def INV(x, d=DVSR) -> int: return pow(x, d - 2, d)
def DIV(x, y, d=DVSR) -> int: return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

S=II()
DV=10**9
A=DV
B=(DV-(S%DV)) if S%DV else 0
C=1
D=(S+B)//A
# print(A*D-B*C)
print('0 0 {} {} {} {}'.format(A,B,C,D))


Measured memory_bytes: 3064
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
  
def main():
  n,a,b = map(int,input().split())
  ans = n//(a+b) * a
  rem = n % (a+b)
  ans += min(rem,a)
  print(ans)
if __name__ == '__main__':
  main()

Measured memory_bytes: 2940