akhauriyash/Code-Regression huggingface dataset:
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
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            long N = cin.ReadLong;
            var list = new List<string>();
            long ans = 0;
            var dict = new Dictionary<string, int>();
            for(long i = 0; i < N; i++)
            {
                string s = cin.ReadLine;
                var sArray = s.ToArray();
                Array.Sort(sArray);
                s =new string(sArray);
                if (dict.ContainsKey(s))
                {
                    dict[s]++;
                }
                else
                {
                    dict[s] = 0;
                }
                ans += dict[s];
            }
            Console.WriteLine(ans);
        }
            

                
    }  
            


    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; }
        public double[] ReadDoubleArray(long N) { var ret = new double[N]; for (long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; }
    }
}


Measured memory_bytes: 28484
import fractions
a,b,c,d = map(int, input().split())
a = a-1

l = c*d//fractions.gcd(c,d)

count_a = a - (a//c + a//d - a//(l))
count_b = b - (b//c + b//d - b//(l))

print(count_b-count_a)

Measured memory_bytes: 5048
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(a==5&&b==5&&c==7||a==5&&b==7&&c==5||b==5&&c==5&&a==7){
        printf("YES\n");
    }
    else{printf("NO\n");}




}


Measured memory_bytes: 1612
import java.util.*;
public class Main { 
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
      	int n=sc.nextInt();
      	String s=sc.next();
      	if(n%2==1){
          System.out.println("No");
        }else{
        	for(int i=0;i<n/2;i++){
             
            	if(s.charAt(i)==s.charAt(n/2+i)&&i<n/2-1){
                  continue;
                }else if(s.charAt(i)==s.charAt(n/2+i)){
                  	System.out.println("Yes");
                }else {
                	System.out.println("No");
                  	break;
                }
            }
        }
      	
      	
    }
}

Measured memory_bytes: 21840
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

struct Dice {
  int face[6];
  Dice() {}
  bool operator == (const Dice& other) {
    for (int i = 0; i < 6; i++) if (face[i] != other.face[i]) return false;
    return true;
  }
  bool operator != (const Dice& other) {
    return !(*this == other);
  }
  void roll(int a, int b, int c, int d) {
    int tmp = face[a];
    face[a] = face[b];
    face[b] = face[c];
    face[c] = face[d];
    face[d] = tmp;
  }
  void roll(char c) {
    switch (c) {
      case 'N' : roll(0, 1, 5, 4); break;
      case 'S' : roll(0, 4, 5, 1); break;
      case 'E' : roll(0, 3, 5, 2); break;
      case 'W' : roll(0, 2, 5, 3); break;
      case 'R' : roll(1, 2, 4, 3); break;
      case 'L' : roll(1, 3, 4, 2); break;
    }
  }
  bool identical(Dice other) {
    for (int i = 0; i < 6; i++) {
      other.roll(i & 1 ? 'E' : 'N');
      for (int j = 0; j < 4; j++) {
        other.roll('R');
        if (*this == other) return true;
      }
    }
    return false;
  }
};

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  Dice D;
  for (int i = 0; i < 6; i++) {
    cin >> D.face[i];
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    for (int j = 0; j < 6; j++) {
      D.roll(j & 1 ? 'E' : 'N');
      for (int k = 0; k < 4; k++) {
        D.roll('R');
        if (D.face[0] == a && D.face[1] == b) {
          cout << D.face[2] << endl;
        }
      }
    }
  }

  return 0;
}


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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
int v[25],c[21];

int main(){
  cin>>n;
  REP(i,n)cin>>v[i];
  REP(i,n)cin>>c[i];
  int ans = 0;
  REP(i,n)ans += max(0,v[i]-c[i]);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n, m, x = [int(x) for x in input().split()]
C = []
A = []
for _ in range(n):
    c, *a = [int(x) for x in input().split()]
    C.append(c)
    A.append(a)
ans = float("inf")
for i in range(2**n):
    i_bin = bin(i)[2:].zfill(n)
    up = [0]*m
    cost = 0
    for j in range(n):
        if i_bin[j] == "1":
            cost += C[j]
            for k in range(m):
                up[k] += A[j][k]
    flag = 1
    for l in up:
        if l < x:
            flag = 0
            break
    if flag:
        ans = min(ans, cost)
if ans == float("inf"):
    print(-1)
else:
    print(ans)


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

int main() {
  int m,n;
  char from[100],to[100],x;
  while(cin >> n) {
    if(n == 0) break;
  for(int i=0;i<n;i++) {
    cin >> from[i] >> to[i];
  }
  cin >> m;
  for(int i=0;i<m;i++) {
    cin >> x;
    for(int j=0;j<n;j++) {
      if(x == from[j]) {
        x = to[j];
        break;
      }
    }
    cout << x;
  }
  cout << endl;
  }
}

Measured memory_bytes: 856
#include<bits/stdc++.h>
using namespace std;
long long int num[1010];
int main()
{
	long long int n;
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)
	{
        scanf("%lld",&num[i]);
    }
    long long int m=1000;
    for(int i=2;i<=n;i++)
	{
        if(num[i]>num[i-1]) 
			m=m%num[i-1]+(m/num[i-1])*num[i];
    }
    printf("%lld",m);
	return 0;
}
















Measured memory_bytes: 3828
import java.util.Scanner;

public class Main implements Runnable {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Thread(null, new Main(), "", 128 * 1024 * 1024).start();
    }

    public void run() {
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        long cost1 = 0;
        long cost2 = 0;
        int current1 = 0;
        int current2 = 0;
        long[] dp1 = new long[n];
        long[] dp2 = new long[n];
        for (int i = 0, j = n - 1; i < n; i++, j--) {
            cost1 += Math.abs(a[i] - current1);
            current1 = a[i];
            dp1[i] = cost1;
            cost2 += Math.abs(a[j] - current2);
            current2 = a[j];
            dp2[j] = cost2;
        }

        for (int i = 0; i < n; i++) {
            if (i == 0) {
                System.out.println(dp2[i + 1] + Math.abs(a[1]));
            } else if (i == n - 1) {
                System.out.println(dp1[i - 1] + Math.abs(a[i - 1]));
            } else {
                System.out.println(dp1[i - 1] + dp2[i + 1] + Math.abs(a[i - 1] - a[i + 1]));
            }
        }
    }
}

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

int main() {
  int n,k; cin>>n>>k;
  vector<int> p(n);
  for(int &i:p)cin>>i;
  sort(p.begin(),p.end());
  int ans=0;
  for(int i=0;i<k;i++)
    ans+=p[i];
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
def nap(n,cap):
    val = [0]*(cap+1)
    for _ in range(n):
        w,v = map(int,input().split())
        for k in range(cap,w-1,-1):
            nv=val[k-w]+v
            if val[k]<nv:
                val[k]=nv
    return max(val)

n,cap=map(int,input().split())
print(nap(n,cap))


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

ans=[0]*N

for x in range(1,int(N**(1/2))):
    for y in range(1,int(N**(1/2))):
        for z in range(1,int(N**(1/2))):
            cnt=x**2+y**2+z**2+x*y+y*z+z*x
            if cnt>N:
                break
            else:
                ans[cnt-1]+=1
for i in range(N):
    print(ans[i])

Measured memory_bytes: 9396
#include<bits/stdc++.h>
#define mm(a,b) memset(a,b,sizeof(a))
#define ACCELERATE (ios::sync_with_stdio(false),cin.tie(0))
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<long long,long long>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define rush() int T;scanf("%d",&T);while(T--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define sc3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define pf(x) printf("%d\n",x)
#define pf2(x,y) printf("%d %d\n",x,y)
#define pf3(x,y,z) printf("%d %d %d\n",x,y,z)
#define all(x) (x).begin(),(x).end()
#define PI acos(-1.0)
#define E exp(1.0)
#define db double
#define ll long long
#define ld long double
#define ull unsigned long long
//#define io
using namespace std;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
//#define gc getchar
//char buf[1<<21],*p1=buf,*p2=buf;
//inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
//inline int read()
//{
//    int ret=0,f=0;char c=gc();
//    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
//    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
//    if(f)return -ret;return ret;
//}
int t;
int main()
{
    #ifdef io
    freopen("in.txt","r",stdin);
    #endif
    cin>>t;
    t=t*t*t;
    cout<<t<<endl;
    return 0;
}


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

int main()
{
	int k,s;
	int64_t sum,count;

	cin >> k >> s;

	sum=0;
	for (int x=0;x<=k;++x)
	{
		int diff=s-x;
		if ((diff>=0)&&(diff<=2*k))
		{
			count=min( diff+1, 2*k+1-diff );
		}
		else
		{
			count=0;
		}
		//fprintf(stderr,"x: %d, diff: %d, count: %d\n",x,diff,count);
		sum+=count;
	}
	cout << sum << endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define f(i,x,n) for(ll i=x;i<n;i++)
#define fl(i,x,n) for(ll i=n;i>=x;i--)
#define mod (ll)1e9+7
#define print(x) cout<<x<<endl
#define vec vector<ll>
#define pai pair<ll, ll>
#define itr(it) :: iterator it
#define MAX (ll)1e16
#define MIN (ll)-1e16
#define X first
#define Y second
#define up upper_bound
#define lo lower_bound
using namespace std;
       ///////////   ///     ///   ///      ///   ////////////  ///      ///
       ///           ///     ///   ///      ///   ///      ///  ///      ///
       ///           ///     ///   ///      ///   ///      ///  ///      ///
       ///////////   ///////////   ///      ///   ////////////  ////////////
               ///   ///     ///   ///      ///   ///      ///  ///      ///
               ///   ///     ///   ///      ///   ///      ///  ///      ///
       ///////////   ///     ///   ////////////   ////////////  ///      ///
ll minn( ll a , ll b) 
{
    if(a>b)
        return b;
    return a;
}
ll maxx2( ll a , ll b)
{
    if(a>b)
        return a;
    return b;
}
ll maxx(ll a,ll b,ll c)
{
  return maxx2(a,maxx2(b,c));
}
ll gcdd(ll a, ll b)
{
    if(b==0)
        return a;
    else
        return gcdd(b,a%b);
}
ll dsum(ll n)
{
    ll sum=0;
    while(n>0)
    {
        sum+=n%10;
        n/=10;
    }
    return sum;
}
ll poww(ll a,ll b)
{
    if(b<=0)
        return 1;
    if(b==1)
        return a;
    if(b==2)
        return (a*a);
    else
        return poww(poww(a,b/2),2)*(poww(a,b%2));
}
ll sumsq(ll x,ll y,ll z)
{
    return (x-y)*(x-y)+(y-z)*(y-z)+(z-x)*(z-x);
} 
signed main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    IOS;
    ll x,n;
    cin>>x>>n;
    ll a[n];
    set<ll> s;
    ll num[200]={0};
    f(i,0,200)
    {
        num[i]=i;
    }
    f(i,0,n)
    {
        cin>>a[i];
        num[a[i]]=-1;
    }
    ll ans=x,min=100000000;
    f(i,0,150)
    {
        if(num[i]!=-1)
        {
            if(min>(abs(x-i)))
            {
                //cout<<num[i]<<endl;
                ans=i;
                min=abs(x-i);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3656
import sys
from math import *

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]

    for h in  range(1, 3501):
        for n in  range(1, 3501):
            if (4 * h * n - N * n - N * h) > 0:
                w = (N * n * h)/(4 * h * n - N * n - N * h)

                if N * (n *w  + h * w + n * h) == 4 * h * n * w:
                    print h, n, w
                    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 2820
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n, m;
vector<vector<int>> g;
int main() {
  cin >> n >> m;
  g.resize(n + 1);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
  }
  for (int s = 1; s <= n; ++s) {
    queue<int> que;
    que.push(s);
    vector<int> par(n + 1), dist(n + 1);
    i64 dist_min = 1ll << 30;
    par[s] = -1;
    while (!que.empty()) {
      int u = que.front();
      que.pop();
      for (int v : g[u]) {
        if (par[v] == 0) {
          par[v] = u;
          dist[v] = dist[u] + 1;
          que.push(v);
        }
        if (v == s && dist[u] <= dist_min) {
          dist_min = dist[u];
          vector<int> route;
          for (int a = u; a != -1; a = par[a]) {
            route.push_back(a);
          }
          set<int> st;
          for (int u : route) st.insert(u);
          bool ok = true;
          for (int u : route) {
            int cnt = 0;
            for (int v : g[u]) {
              cnt += st.count(v);
            }
            if (cnt != 1) ok = false;
          }
          if (ok) {
            cout << route.size() << '\n';
            for (int u : route) cout << u << '\n';
            return 0;
          }
        }
      }
    }
  }
  cout << -1 << endl;
  return 0;
}


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

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

    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    double sum = 0;
    for (int i = 0; i < n; i++)
    {
        sum += a[i];
    }
    double ave = sum / n;
    double def = INF;
    int pos = 0;
    for (int i = 0; i < n; i++)
    {
        double d = ave - a[i];
        if (d < 0)
            d *= -1;
        if (d < def)
        {
            def = d;
            pos = i;
        }
    }
    cout << pos << endl;
}

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

int main(void){
  char c;
  cin >> c;
  if( c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o' ){
    cout << "vowel\n";
  }
  else{
    cout << "consonant\n";
  }
}

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

using namespace std;

struct route{
	int cost;
  	int time;
};

int main()
{
	int N, limit, min_cost;
  	cin >> N >> limit;
  
  	vector<route> routes;
  	for (int i = 0; i < N; i++){
    	int c, t; cin >> c >> t;
      	route r; r = {c, t};
      	routes.push_back(r);
    }
  	for (int i = 0; i < routes.size();){
    	//cout << "Route " << i << "-> Cost: " << routes[i].cost << "  Time: " << routes[i].time << endl;
    	if (routes[i].time > limit){
        	routes.erase(routes.begin() + i);
        } else {
        	i++;
        }
    }
  	if (routes.size() == 0){
    	cout << "TLE";
    } else {
      	min_cost = routes[0].cost;
    	for (int i = 1; i < routes.size(); i++){
        	if (min_cost > routes[i].cost){
				min_cost = routes[i].cost;
            }
        }
      	cout << min_cost;
    } 	
}

Measured memory_bytes: 256
s=input()
n=len(s)
dic={}
for i in range(n):
    if s[i] in dic:
        dic[s[i]].append(i)
    else:
        dic[s[i]]=[i]
for i in dic.values():
    if len(i)>1:
        for j in range(1,len(i)):
            if i[j]-i[j-1]<=2:
                print(i[j-1]+1,i[j]+1)
                exit()
print(-1,-1)

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

int main() {
int64_t n,k,p,q,m;
  cin>>n>>k;
  vector<int64_t> vec(n);
  for(int64_t i=0;i<n;i++){cin>>vec.at(i);}
  vector<int64_t> ans(n+1);
  vector<int64_t> a(n+1);
  ans.at(0)=1;
  for(int64_t i=1;i<=n;i++){
  ans.at(i)=vec.at(ans.at(i-1)-1);
  }
  for(int64_t i=0;i<=n;i++){a.at(i)=ans.at(i);}
   sort(ans.begin(), ans.end()); 
  for(int64_t i=0;i<n;i++){if(ans.at(i)==ans.at(i+1)){
    m=ans.at(i); break;}}
  for(int64_t b=0;b<=n;b++){if(a.at(b)==m){p=b; break;}}
    for(int64_t l=p+1;l<=n;l++){if(a.at(l)==m){q=l; break;}}
  if(k<p){cout<<a.at(k)<<endl;} 
 else { cout<<a.at(((k-p)%(q-p))+p)<<endl;}
}

Measured memory_bytes: 7976
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll tot = 0, need = 0;
  vector<ll> plus;
  int cnt = 0;
  rep(i, n){
    int b; cin >> b;
    tot += a[i] - b;
    a[i] -= b;
    if(a[i] < 0){
      need -= a[i];
      cnt++;
    }else plus.push_back(a[i]);
  }
  if(tot < 0) cout << -1 << endl;
  else{
    sort(all(plus));
    ll total = 0;
    if(need){
      for(int i = plus.size() - 1; i >= 0; i--){
        total += plus[i];
        cnt++;
        if(total >= need) break;
      }
    }
    cout << cnt << endl;
  }
}

Measured memory_bytes: 4972
N = int(input())
c = 0
tail_A = 0
head_B = 0
B_A = 0
def count(S):
    if len(S) == 1:
        return 0
    c = 0
    for i in range(len(S)-1):
        if S[i] == 'A' and S[i+1] == 'B':
            c += 1
    return c

for _ in range(N):
    s = input()
    c += count(s)
    if s[-1] == 'A':
        if s[0] == 'B':
            B_A += 1
        else:
            tail_A += 1
    else:
        if s[0] == 'B':
            head_B += 1

if tail_A > 0 and head_B > 0:
    c = c + B_A + 1
    tail_A -= 1
    head_B -= 1
elif tail_A == 0 and head_B > 0:
    c = c + B_A
    head_B -= 1
elif tail_A > 0 and head_B == 0:
    c = c + B_A
    tail_A -= 1
else:
    if B_A >= 2:
        c = c + B_A - 1

c += min(tail_A, head_B)
print(c)


Measured memory_bytes: 3064
import java.util.*;

public class Main {

      public static HashMap map = new HashMap<Integer, Integer>();

      public static void main(String[] args) {

            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            long ans = 0;
            //n - 1 1 までの、掛け算の仕方の総和
            //1 * 2 と２ * 1 は区別、1 * 1 は区別しない
            for (int i = 1; i <= Math.ceil(Math.sqrt(n - 1)); i++) {
                  for (int j = 1; j <= n-1; j++) {
                        if (i * j <= n - 1 && i <=j) {
                              if (i == j) {
                                    ans++;
                              } else {
                                    ans += 2;
                              }
                        }

                  }
            }
            System.out.println(ans);
      }


}


Measured memory_bytes: 36248
import { readFileSync } from "fs";

const { cin, nCin, biCin } = (() => {
  const inputs = readFileSync("/dev/stdin", "utf-8").split(/[\n|\s]+/);
  let count = 0;
  const cin = () => inputs[count++];
  return { cin: cin, nCin: () => Number(cin()), biCin: () => BigInt(cin()) };
})();

const range = (n: number | bigint) => [...Array(Number(n))].map((_, i) => i);

{
  const N = nCin();
  const ans = N % 1000 === 0 ? 0 : 1000 - (N % 1000);
  console.log(ans);
}


Measured memory_bytes: 29632
// Increment Decrement
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int n;
string s;

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

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

int main(){
    int N; cin >> N;
    vector<int> V(N);
    for(int i = 0; i < N; i++) cin >> V[i];
    map<int,int> mp1,mp2;
    set<int> st1,st2;
    for(int i = 0; i < N; i++){
        if(i % 2 == 0){
            mp1[V[i]]++;
            st1.insert(V[i]);
        }else{
            mp2[V[i]]++;
            st2.insert(V[i]);
        }
    }
    vector<pair<int,int>> vec1,vec2;
    for(auto s:st1){
        vec1.push_back(make_pair(mp1[s],s));
    }
    for(auto s:st2){
        vec2.push_back(make_pair(mp2[s],s));
    }
    sort(vec1.begin(),vec1.end(),greater<pair<int,int>>());
    sort(vec2.begin(),vec2.end(),greater<pair<int,int>>());
    
    if(vec1[0].second != vec2[0].second) cout << N - vec1[0].first - vec2[0].first << endl;
    else if(vec1[0].first + vec2[1].first > vec1[1].first + vec2[0].first) cout << N - vec1[0].first - vec2[1].first << endl;
    else cout << N - vec1[1].first - vec2[0].first << endl;
    
}

Measured memory_bytes: 14004
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n;
    cin >> n;
    map<string, ll> word_count;
    vector<string> vec(n);
    REP(i, n) cin >> vec.at(i);
    string previous_word = "";
    REP(i, n) {
        string key;
        key = vec.at(i);
        if (previous_word != "" && key.front() != previous_word.back()) {
            cout << "No" << endl;
            return 0;
        }
        if (word_count[key] >= 1) {
            cout << "No" << endl;
            return 0;
        }
        word_count[key]++;
        previous_word = key;
    }
    cout << "Yes" << endl;
    return 0;
}

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

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

  for(int i=0; i<A; i++){
   if(!('0'<=S[i] && S[i]<='9')){cout<<"No"; return 0;}
  }
  
  if(S[A]!='-'){cout<<"No"; return 0;}
  
  for(int i=A+1; i<A+B+1; i++){
   if(!('0'<=S[i] && S[i]<='9')){cout<<"No"; return 0;}
  }
  
  cout<<"Yes"; return 0;
}


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

int main() {
    string s;
    cin >> s;
    ll ans = 0;
    for(auto e : s) {
        ans += e - '0';
    }
    if(ans % 9) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 3736
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
  int n;cin >> n;
  string s;cin >> s;
  vector<int> a(s.size(),0);
  int flag = 0;
  int ans = 0;
  char f;
  f = s[0];
  REP(i,0,s.size()){
    if(s[i]==f){
      continue;
    }
    else {
      ans++;
      f = s[i];
    }
  }
  cout << ans+1 << endl;

}


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

int main()
{
    int x,a,b;
    cin>>x>>a>>b;
    if(a>=b)
    {
        cout<<"delicious"<<endl;
    }
    else if(a+x>=b)
    {
        cout<<"safe"<<endl;
    }
    else
    {
        cout<<"dangerous"<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static char line[];
	static int res;
	public static void main(String[] args) {
		while(read()){
			solve();
		}
		System.out.println(res);
	}
	static boolean read(){
		if(!sc.hasNext())return false;
		line = sc.next().toCharArray();
		return true;
	}
	static void solve(){
		for(int i = 0; i < line.length; i++){
			if(Character.isDigit(line[i])){
				int x = 0;
				while(i < line.length && Character.isDigit(line[i])){
					x *= 10;
					x += line[i] - '0';
					i++;
				}
				res += x;
			}
		}
	}
}

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

int main(){
  int n;
  cin >> n;
  map<string, int> mp;
  
  for(int i = 0; i < n; i++) {
  	string s;
  	cin >> s;
    sort(s.begin(), s.end());
  	mp[s]++;
  }
  
  long long ans = 0;
  
  for(auto p : mp) {
  	long long s = p.second;
  	ans += s*(s-1)/2;
  }
  cout << ans << endl;
  
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

  ll N; cin >> N;
  ll M; cin >> M;
  ll K; cin >> K;
  vector<ll> A(N); for (ll i = 0; i < N; i++) cin >> A[i];
  vector<ll> B(M); for (ll i = 0; i < M; i++) cin >> B[i];
  
  vector<ll> sumA(N + 1, 0);
  vector<ll> sumB(M + 1, 0);
  for (ll i = 0; i < N; i++) sumA[i + 1] = sumA[i] + A[i];
  for (ll i = 0; i < M; i++) sumB[i + 1] = sumB[i] + B[i];

  ll ans = 0;
  ll b = 0;
  for (ll i = N; i >= 0; i--) {
    while (sumA[i] + sumB[b] <= K) {
      ans = max(ans, i + b);
      b++;
      if (b > M) {
        b = M;
        break;
      }
    }
  }

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 9532
#include<bits/stdc++.h>
using namespace std;
char s[200005];
int main(){
	scanf("%s",s);
	int len = strlen(s);
	long long ans = 0;
	
		int A = 0,f = 0;
		for(int i = 0; i < len-1; i++){
			if(s[i] == 'A') A++;
			else if(s[i-1] == 'A'&&s[i] == 'B'&&s[i+1] == 'C'){
				s[i-1] = 'B';
				s[i] = 'C';
				s[i+1] = 'A';
				ans += A;
				i++;
			}
			else A = 0;
		}
 
	printf("%lld\n",ans);
} 

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
const int INT_INF = 2147483647;
//stoi(s) : string→int stoll(s) :string→longlong  int→string to_string(i)
const double PI = acos(-1.0);
//小数点の表し方 cout << fixed << setprecision(5);
const ll LLMAX = 9223372036854775805;

int main(){
    char s;
    cin >> s;
    if(s <= 'z' && s>='a'){
        cout << 'a' << endl;
    }else{
        cout << 'A' << endl;
    }

}

Measured memory_bytes: 3620
X,Y,A,B,C=map(int, input().split())
plist=list(map(int, input().split())) 
qlist=list(map(int, input().split())) 
rlist=list(map(int, input().split())) 
plist.sort(reverse=True)
qlist.sort(reverse=True)

redlist = plist[:X]
greenlist = qlist[:Y]
RandG = redlist+greenlist+rlist
RandG.sort(reverse=True)
print(sum(RandG[:X+Y]))

Measured memory_bytes: 111852
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const int NINF = -1*INF;
const long long LLINF = 1ll << 60;
const long long LLNINF = -1*LLINF;

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef vector<vld> vvld;
 
#define mp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()
#define revAll(x) x.rbegin(), x.rend()
#define gcd(a, b) __gcd(a, b)
#define popcount(x) __builtin_popcount(x)
#define isize(x) (int)(x.size())
#define rep(i,n) for(int i = 0; i < n; i++)
#define exists(x,m) m.find(x) != m.end()
#define umap unordered_map
#define uset unordered_set
#define pq priority_queue

const ll MOD = 1e9 + 7;

vll primes_up_to(ll lim) {
	vll primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37,
					41, 43, 47, 53, 59, 61, 67, 71};
	if (lim <= 71) return {primes.begin(), upper_bound(all(primes), lim)};
	for (int num = 73; num <= lim; num++) {
		bool is_prime = true;
		for (int i = 0; primes[i]*primes[i] <= num; i++) {
			if (num % primes[i] == 0) {
				is_prime = false;
				break;
			}
		}
		if (is_prime) primes.pb(num);
	}	
	return primes;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	int n; cin >> n;
	vi A = vi();
	int maxx = 0;
	rep(i, n) {
		int x; cin >> x;
		A.pb(x);
		maxx = max(maxx, x);
	}	
	vll primes = primes_up_to(1e6);
	umap<int, int> prime_freq = umap<int, int>();
	for (const int& a : A) {
		int b = a;
		for (int i = 0; primes[i]*primes[i] <= b; i++) {
			if (b % primes[i] == 0) prime_freq[primes[i]]++;
			while(b % primes[i] == 0) b /= primes[i];
		}
		if (b != 1) prime_freq[b]++;
	}
	int max_freq = 0;
	for (const auto& [p, freq] : prime_freq) {
		max_freq = max(max_freq, freq);
	}
	if (max_freq <= 1) {
		cout << "pairwise coprime";
	} else {
		cout << (max_freq < n ? "setwise coprime" : "not coprime");
	}
}

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

 
int main()
{
    
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int cnt=1;
    while(a>0 && c>0)
    {
        if(cnt%2!=0)
           c=c-b;
           
        else
          a=a-d;
          
          cnt++;
    }
    
    if(a<=0)
      printf("No");
      
    else
       printf("Yes");
       
       
    
    
    
     return 0;   
         
  
  
}

Measured memory_bytes: 3688
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	int N = sc.nextInt();
      	int M = sc.nextInt();
      	if(N == M){
      		System.out.println("Yes");
      	} else {
        	System.out.println("No");
      	}
    }
}

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

using namespace std;

vector<long long> enum_divisors(long long N){
    vector<long long> res;
    for(long long i=1; i*i <= N; ++i){
        if(N % i == 0){
            res.push_back(i);

            //重複しないならそれも入れる
            if(N/i != i) res.push_back(N/i);
        }
    }
    //小さい順に並べる
    //sort(res.begin(), res.end());
    return res;
}

// bool can_be_one( long long N, long long K){
//     if(K == 1) return false;

//     while( N % K == 0){
//         N /= K;
//     }

//     if(N == 1 || N % K == 1) return true;
//     else return false;
// }

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

    // debug
    // for(long long i=2; i<=N; ++i){
    //     long long n = N;
    //     while(n >1){
    //         if(n %i == 0){
    //             n /= i;
    //         }else{
    //             n = n -i;
    //         }
    //     }
    //     if( n == 1) cout << i << endl;
    // }

    long long cnt = 0;
    for(long long x : enum_divisors(N)){
        if( x == 1) continue;
        long long tmp = N;
        while(tmp%x == 0)tmp /= x;
        tmp %= x;
        if(tmp == 1) cnt++;
    }

    vector<long long> nums_mod1 = enum_divisors(N-1);
    cnt += nums_mod1.size() - 1;

    cout << cnt << endl;

}

Measured memory_bytes: 3608
#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()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

bool e[2010][2010];

int main() {
	int t = 41;
	int K = t + 1;
	int N = K * (K - 1) + 1;

	printf("%d %d\n", N, K);
	rep(i, t + 1) {
		printf("%d", N);
		rep(j, t) {
			printf(" %d", i * t + j + 1);
		}
		puts("");
	}

	rep(d, t) {
		rep(i, t) {
			printf("%d", t * t + 1 + d);
			rep(j, t) {
				printf(" %d", t * j + (i + d * j) % t + 1);
			}
			puts(" ");
		}
	}

	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		sc.next();
		String s = sc.next();

		int max = 0;
		int sum = 0;
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == 'I') {
				sum++;
			} else {
				sum--;
			}
			if (max < sum) {
				max = sum;
			}
		}
		System.out.println(max);

		sc.close();
	}
}

Measured memory_bytes: 23764
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int M = sc.nextInt();
		
		int[] map = new int[N];
		for (int i = 0; i < M; i++) {
			map[sc.nextInt()-1]++;
			map[sc.nextInt()-1]++;
		}
		
		for (int i = 0; i < N; i++) {
			System.out.println(map[i]);
		}
	}
	
	
}


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

int w, h, cnt;
char cmp;
char field[50][50];
int dx[] = { -1, 0, 1, 0 };
int dy[] = { 0, -1, 0, 1 };

bool search( int sx, int sy ){
    cnt++;
    field[sy][sx] = '#';
    bool ans = true;
    for( int i = 0; i < 4; i++ ){
        int x = sx + dx[i];
        int y = sy + dy[i];
        if( 0 <= x && x < w && 0 <= y && y < h && field[y][x] != '#' ){
            if( field[y][x] == 'B' || field[y][x] == 'W' ){
                if( cmp == '.' ) cmp = field[y][x];
                else if( cmp != field[y][x] ) ans =  false;
            }else if( !search( x, y ) ) ans = false;
        }
    }
    return ans;
}

int main(){
    while( cin >> w >> h && w ){
        for( int i = 0; i < h; i++ ){
            for( int j = 0; j < w; j++ ){
                cin >> field[i][j];
            }
        }
        int cnt_b = 0, cnt_w = 0;
        for( int i = 0; i < h; i++ ){
            for( int j = 0; j < w; j++ ){
                cnt = 0;
                cmp = '.';
                if( field[i][j] == '.' ){
                    if( search( j, i ) ){
                        if( cmp == 'B' ) cnt_b += cnt;
                        else if( cmp == 'W' ) cnt_w += cnt;
                    }
                }
            }
        }
        cout << cnt_b << ' ' << cnt_w << endl;
    }
}

Measured memory_bytes: 1272
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define int long long

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

int h, w;
vector<vector<char>> field;
vector<vector<bool>> used;
int cntb, cntw;

void dfs(int x, int y, char c) {
    used[x][y] = true;
    if(c == '#') cntb ++;
    else cntw ++;
    rep(i, 4) {
        int nx = x + dx[i], ny = y + dy[i];
        char d = (c == '#'? '.': '#');
        if(0 <= nx && nx < h && 0 <= ny && ny < w && field[nx][ny] == d && !used[nx][ny]) {
            dfs(nx, ny, d);
        }
    }
}

void solve() {
	cin >> h >> w;
    field.assign(h, vector<char>(w));
    used.assign(h, vector<bool>(w));
    rep(i, h) {
        rep(j, w) {
            cin >> field[i][j];
            used[i][j] = false;
        }
    }
    int ans = 0;
    rep(i, h) {
        rep(j, w) {
            cntb = 0; cntw = 0;
            if(!used[i][j]) {
                dfs(i, j, field[i][j]);
            }
            ans += cntb * cntw;
        }
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 10496
import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();

		long ans = 0;
		for (int i = 0; i < n; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();

			ans += r - l + 1;
		}

		pr.println(ans);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 25172
#include <bits/stdc++.h>
typedef long long ll;

#define pll pair<ll,ll>
#define ff first
#define snd second
#define pb push_back
#define vll vector<ll>
#define vpll vector<pll>
#define endl "\n"
#define MOD 1000000007
using namespace std;

ll const N = 1e5+1;


void solve()
{
   ll n;
   cin>>n;
   ll a;
   map<ll,ll>m;
   ll sum = 0;
   for(int i=0;i<n;i++)
   {
           cin>>a;
           m[a]++;
           sum+=a;
   }
   
   ll q;
   cin>>q;
   
   for(int i=0;i<q;i++)
   {
           ll b,c;
           cin>>b>>c;
           if(m.find(b)==m.end())
           {
                cout<<sum<<endl;   
                continue;
           }
           else
           {
                ll k = m[b];
                sum-=(k*b);
                sum+=(k*c);
                m[c]+=k;
                m[b]-=k;
                cout<<sum<<endl;
           }
   }
}
 
int main() {
            ios_base::sync_with_stdio(false);
            cin.tie(NULL);
	    int t=1;
	    //cin>>t;
	    while(t--)
	    {
	            solve();
	    }
	    return 0;
}

Measured memory_bytes: 8792
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>

#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define vsort(v) sort(v.begin(),v.end())
#define asort(a,n) sort(a, a + n)
#define vi vector<int>
#define vd vector<double>

//ここからAtCoder向けdefine
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    int N, A, B;
    cin >> N >> A >> B;
    if(N * A < B)
        cout << N * A << endl;
    else
        cout << B << endl;
    
    return 0;
}

Measured memory_bytes: 256
/*====Corycle====*/
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<vector>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<map>
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const int N=1e7+5;
const int M=1e6+5;
int read(){
	int s=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){s=s*10+c-'0';c=getchar();}
	return s*f;
}
int n,p[M],m[N];
ll ans,d[N];
bool vis[N];
int main(){
//	freopen("_.in","r",stdin);
//	freopen("_.out","w",stdout);
	n=read();
	d[1]=1;
	for(int i=2;i<=n;i++){
		if(!vis[i])p[++p[0]]=i,d[i]=2,m[i]=2;
		for(int j=1;j<=p[0]&&i*p[j]<=n;j++){
			vis[i*p[j]]=1;
			if(!(i%p[j])){
				d[i*p[j]]=d[i]/m[i]*(m[i]+1);
				m[i*p[j]]=m[i]+1;
				break;
			}
			d[i*p[j]]=d[i]*2,m[i*p[j]]=2;
		}
	}
	for(int i=1;i<=n;i++)ans+=i*d[i];
	cout<<ans;
	return 0;
}


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

int const N = 200000;
char s[N + 2];

void no() { printf("No\n"); exit(0); }

int main(){
	int n, a, b, c, d;
	scanf("%d%d%d%d%d%s", &n, &a, &b, &c, &d, s + 1);
	f(i, a, c)if (s[i] == '#' && s[i - 1] == '#')no();
	f(i, b, d)if (s[i] == '#' && s[i - 1] == '#')no();
	if (c > d){
		bool ok = false;
		f(i, b + 1, d + 2)if (s[i] == '.' && s[i - 1] == '.' && s[i - 2] == '.') { ok = true; break; }
		if (!ok)no();
	}
	printf("Yes\n");
}

Measured memory_bytes: 384
#include"bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
const long long mod = 1000003;
int kj[1000006], kji[1000006];
int modpow(int a, int x) {
	int res = 1;
	while (x) {
		if (x & 1)res = res*a%mod;
		a = a*a%mod;
		x >>= 1;
	}
	return res;
}

void setkj() {
	kj[0] = 1;
	for (int i = 1; i <= mod; i++)kj[i] = kj[i - 1] * i%mod;
	kji[0] = kji[1] = 1;
	for (int i = 2; i < mod; i++) {
		kji[i] = mod - (kji[mod%i] * (mod / i)) % mod;
	}
	for (int i = 1; i < mod; i++)kji[i] = kji[i] * kji[i - 1] % mod;
}

signed main() {
	setkj();
	int q; cin >> q;
	rep(i, q) {
		int x, d, n; cin >> x >> d >> n;
		if (!d || !x) {
			cout << modpow(x,n) << endl;
		}
		else {
			int L = x*modpow(d, mod - 2) % mod;
			int R = L + n - 1;
			if (L > R%mod)cout << 0 << endl;
			else if (R - L >= mod - 1)cout << 0 << endl;
			else {
				R %= mod;
				int ans = kj[R] * kji[L - 1] % mod;
				ans *= modpow(d, n);
				ans %= mod;
				cout << ans << endl;
			}
		}
	}
}


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

typedef long long ll;
typedef unsigned long long ull;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main()
{
    int n=0; cin>> n;
    while(n!=0){
        if(n%10==7){
            cout << "Yes\n"; return 0;
        }
        n/=10;
    }
    cout << "No\n";
}


Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000

using namespace std;


int main(void) {
	int h, w;
	char s[51][51];
	int count[51][51];

	cin >> h >> w;
	FOR(i, 1, h) {
		FOR(t, 0, w - 1) {
			count[i][t] = 0;
		}
	}
	FOR(i, 1, h) {
		cin >> s[i];
	}
	
	FOR(i, 1, h) {
		FOR(t, 0, w - 1) {
			if (s[i][t] == '#') {
				count[i][t] = -1;
				FOR(p, i - 1, i + 1) {
					FOR(q, t - 1, t + 1) {
						if (s[i][t] == '#') {
							count[i][t] = -1;
						}
						if (p >= 1 && p <= h&&q >= 0 && q <= w - 1 && count[p][q] != -1) {
							count[p][q]++;
						}
					}
				}
			}
		}
	}
	FOR(i, 1, h) {
		FOR(t, 0, w - 1) {
			if (count[i][t] == -1) {
				cout << "#";
			}
			else {
				cout << count[i][t];
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
class katana
{
	public:
	int a,b;
	katana()
	{
		a=b=0;
	}
	bool operator < (const katana &kb) const
	{
		return this->b>kb.b;
	}
};
int main()
{
	int n,h;
	cin>>n>>h;
	vector<katana> wsd(n);
	int maxd=n-1;
	for(int i=0;i<n;i++)
	{
		cin>>wsd[i].a>>wsd[i].b;
	}
	sort(wsd.begin(),wsd.end());
	for(int i=n-2;i>=0;i--)
	{
		if(wsd[maxd].a<wsd[i].a)
			maxd=i;
	}
	int t=0;
	for(int i=0;i<n&&wsd[i].b>wsd[maxd].a;i++)
	{
		if(i==maxd)
			continue;
		h-=wsd[i].b;
		t++;
		if(h<=0)
			break;
	}
	int maxy=wsd[maxd].a;
	if(h >	0)
	{
		if(maxy<wsd[maxd].b)
		{
			t++;
			h-=wsd[maxd].b;
		}
		if(h>0)
		{
			t+=h/maxy;
			if(h%maxy)
				t++;
		}
	}
	cout<<t;
	return 0;
}

Measured memory_bytes: 1152