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

long long d;
long long dp[10005][2][105] = {0};
string k;

long long solve();

int main() {
  cin >> k >> d;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  for(int i = 0; '0' + i < k[0]; ++i) dp[0][1][i % d] += 1;
  dp[0][0][(k[0] - '0') % d] += 1;
  for(int i = 1; i < k.size(); ++i)
    for(int j = 0; j < 10; ++j)
      for(int l = 0; l < d; ++l) {
        if('0' + j < k[i]) {
          dp[i][1][(l + j) % d] +=
              (dp[i - 1][1][l] + dp[i - 1][0][l]) % N;
          dp[i][1][(l + j) % d] %= N;
        }
        else if('0' + j == k[i]) {
          dp[i][1][(l + j) % d] += dp[i - 1][1][l];
          dp[i][1][(l + j) % d] %= N;
          dp[i][0][(l + j) % d] += dp[i - 1][0][l];
          dp[i][0][(l + j) % d] %= N;
        }
        else {
          dp[i][1][(l + j) % d] += dp[i - 1][1][l];
          dp[i][1][(l + j) % d] %= N;
        }
      }
  return (N + dp[k.size() - 1][1][0] +
          dp[k.size() - 1][0][0] - 1) %
         N;
}

Measured memory_bytes: 16640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int dp[2][120010];
int p[15],c[15];
int main(){
	int D,G;
	scanf("%d%d",&D,&G);
	G/=100;
	memset(dp,0x3f,sizeof dp);
	int *f=dp[0],*g=dp[1];
	f[0]=0;
	ll tot=0;
	for(int i=1;i<=D;i++){
		scanf("%d%d",p+i,c+i);
		c[i]/=100;
		tot+=p[i]*i+c[i];
	}
	tot=min(tot,120000ll);
	for(int i=1;i<=D;i++){
		for(int j=0;j<=G;j++) g[j]=f[j];
		for(int j=0;j<=p[i];j++){
			int add=j*i;
			if(j==p[i]) add+=c[i];
			for(int k=0;k+add<=tot;k++)
				g[k+add]=min(g[k+add],f[k]+j);
		}
		swap(f,g);
	}
	int ans=0x3f3f3f3f;
	for(int i=G;i<=tot;i++)
		ans=min(ans,f[i]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;
int main(){

  int a,b,c,n,x,t;
  cin >> n >> x >> t;

  a=n/x;
  b=n%x;

  c=a*t;

  if(b!=0){
    c+=t;
  }

  cout << c << endl;

}


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

int main()
{
	int N;cin>>N;
	int sum = 0;
	for(int i = 1;i<=N;++i)
	{
		int x,y;
		cin>>x>>y;
		if(x == y) sum++;
		else sum = 0;
		if(sum == 3) return cout<<"Yes",0; 
	}
	cout<<"No";
	return 0;
 } 

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

# define rep(i, n) for(int(i)=0;(i)<(n);(i)++)
# define reps(i, n) for(int(i)=1;(i)<=(n);(i)++)
# define rrep(i, n) for(int i=((int)(n)); i>0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>=0; --i)
# define ALL(v) v.begin(), v.end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<typename T> void dump(T e){std::cout << e << std::endl;}
template<typename T> void dump(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void dump(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ dump(v); } }
typedef long long ll;


int main() {
  vector<vector<int>> g(3, vector<int>(3));
  rep(i, 3) {
    rep(j, 3) {
      cin >> g[i][j];
    }
  }
  int a1=0;
  int b1=g[0][0];
  int b2=g[0][1];
  int b3=g[0][2];
  int a2=g[1][0]-b1;
  int a3=g[2][0]-b1;
  
  vector<int> a = {a1,a2,a3};
  vector<int> b = {b1,b2,b3};
  rep(i, 3) {
    rep(j, 3) {
      if (a[i]+b[j] != g[i][j]) {
        dump("No");
        return 0;
      }
    }
  }
  dump("Yes");
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
using namespace std;
#define MAX_LIST 1000000 



int main(){
	bool *prime=(bool *)malloc(sizeof(bool)*MAX_LIST);
	for(int i=0;i<MAX_LIST;i++){
		prime[i]=1;
	}
	prime[0]=prime[1]=0;
	for(int i=0;i*i<MAX_LIST;i++){
		if(prime[i]==1){ 
			for(int j=i*2;j<MAX_LIST;j=j+i){
				prime[j]=0;
			}
		}
	}
	int a,d,n;
	while(cin>>a>>d>>n,a){
		int ans=0;
		for(int i=a;n;i=i+d){
			if(prime[i]==1){
				n--;
			}
			if(n==0){
				ans=i;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 2156
#include "bits/stdc++.h"
using namespace std;

int main() {
	int A,B;
	cin >> A >> B; 
	if (A >= 10 || B>=10) {
		cout << -1 <<endl;
	}
	else {
		cout <<  A * B<<endl;
	}
	return 0;
}

Measured memory_bytes: 3596
import java.util.*;
import java.util.concurrent.SynchronousQueue;

public class Main {
	static final long MODULO = 1_000_000_000 + 7;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();

		long[] inv = new long[1001];
		inv[1] = 1;
		for (int i = 2; i < inv.length; ++i) {
			inv[i] = MODULO - inv[(int) (MODULO % i)] * (MODULO / i) % MODULO;
		}
		long[] fac = new long[1001];
		long[] invfac = new long[1001];
		fac[0] = 1;
		invfac[0] = 1;
		for (int i = 1; i <= 1000; ++i) {
			fac[i] = (fac[i - 1] * i) % MODULO;
			invfac[i] = (invfac[i - 1] * inv[i]) % MODULO;
		}

		long[] dp = new long[1001];
		dp[0] = 1;
		for (long i = A; i <= B; ++i) {
			long[] ndp = Arrays.copyOf(dp, dp.length);
			for (int j = 0; j < 1000; ++j) {
				if (dp[j] == 0)
					continue;
				for (long k = C; i * k + j <= N && k <= D; ++k) {
					ndp[(int) (i * k + j)] += dp[j] * fac[(int) (N - j)] % MODULO * invfac[(int) (N - j - i * k)]
							% MODULO * invfac[(int) k] % MODULO * pow(invfac[(int) i], k) % MODULO;
					ndp[(int) (i * k + j)] %= MODULO;
				}
			}
			dp = ndp;
		}
		System.out.println(dp[(int) N]);
	}

	static long pow(long a, long n) {
		long ret = 1;
		for (; n > 0; n >>= 1, a = (a * a) % MODULO) {
			if (n % 2 == 1) {
				ret = (ret * a) % MODULO;
			}
		}
		return ret;
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


Measured memory_bytes: 18380
S = input()

if S == '?' * (10 ** 5):
    print(590369788)

else:
    dp = [0, 0, 0, 1]
    for s in S[::-1]:
        tmp = dp[:]

        dp[3] = tmp[3] * 3 if s == '?' else tmp[3]

        for j in range(2, -1, -1):
            dp[j] = tmp[j] * 3 + tmp[j + 1] if s == '?' else \
                    tmp[j] + tmp[j + 1] if s == 'ABC'[j] else \
                    tmp[j]

    print(dp[0] % (10**9 + 7))


Measured memory_bytes: 3316
#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);
  }
  

  

  int res = 0;
  
  while (true) {
    bool exist_odd = false;
    for (int i = 0; i < N; i++) {
      if (num.at(i) % 2 != 0) {
        exist_odd = true;
      }}
      
      if (exist_odd){break;}
      
      for (int i = 0; i < N; i++) {
        num.at(i) /= 2;
      }
      res++;
    }
    
    cout << res << endl;
    
  }
  


Measured memory_bytes: 256
D=int(input())
c=list(map(int,input().split()))
s=[]
t=[]
v=0
lastday=[0 for i in range(26)]

for i in range(D):
  tmp=list(map(int,input().split()))
  s.append(tmp)
for i in range(D):
  tmp=int(input())-1
  t.append(int(tmp))

for i in range(1,D+1):
  v+=s[i-1][t[i-1]]
  lastday[t[i-1]]=i
  for j in range(26):
    v-=c[j]*(i-lastday[j])
  print(v)

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

using namespace std;

using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;

// 入力
int N;
Graph G;

// res は答え
vector<int> res;

// v を c に塗る。p は v の親
void dfs(int v, int p, int c) {
  res[v] = c;
  for (auto e : G[v]) {
    if (e.first == p) continue;
    if (e.second & 1)
      dfs(e.first, v, 1 - c);
    else
      dfs(e.first, v, c);
  }
}

int main() {
  cin >> N;
  G.assign(N, vector<Edge>());
  for (int i = 0; i < N - 1; ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    --u, --v;
    G[u].push_back(Edge(v, w));
    G[v].push_back(Edge(u, w));
  }
  res.assign(N, 0);
  dfs(0, -1, 1);
  for (auto v : res) cout << v << endl;
}

Measured memory_bytes: 8960
import collections
def main():
	n, m = map(int, input().split())
	count = collections.defaultdict(int)
	for _ in range(n):
		nums = list(map(int, input().split()))
		for i in range(nums[0]):
			count[nums[i+1]] += 1
	ans = 0
	for v in count.values():
		if v == n:
			ans += 1

	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+10;
ll n,m,a,b,cnt;
ll head[N],bl[N];
struct Edge{ll nxt,to;}edge[N<<1];
inline void add(ll u,ll v){edge[++cnt]=(Edge){head[u],v};head[u]=cnt;}
void dfs(ll u,ll col){
	bl[u]=col;
	for(ll i=head[u];i;i=edge[i].nxt){
		ll v=edge[i].to;
		if(bl[v]==-1) dfs(v,!col);
		if(bl[v]!=!col){printf("%lld",n*(n-1)/2-m);exit(0);}
	}
}
int main(){
	scanf("%lld%lld",&n,&m);
	for(ll i=1;i<=m;i++) scanf("%lld%lld",&a,&b),add(a,b),add(b,a);
	memset(bl,-1,sizeof(bl));
	dfs(1,0);
	ll s1=0,s2=0;
	for(ll i=1;i<=n;i++) if(bl[i]==0) s1++; else if(bl[i]==1) s2++;
	printf("%lld",s1*s2-m);
}

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

using namespace std;

double distance(vector<int> a, vector<int> b) {
    int sum = 0;
    for(int i = 0; i < a.size(); i++) {
        sum += (a[i] - b[i])*(a[i] - b[i]);
    }
    return sqrt(sum);
}

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

   // vector<int> x(D, 0);
    vector<vector<int>> v(N, vector<int>(D,0));

    for(int i = 0; i < N; i++) {
        for(int j = 0; j < D; j++) {
            cin >> v[i][j];
        }
    }

    int count = 0;
    for(int i = 0; i < N; i++) {
        for(int j = i+1; j < N; j++) {
            double dist = distance(v[i], v[j]);
            if (ceil(dist) == floor(dist)) count++;
        }
    }

    cout << count << endl;

}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    P = [int(x) for x in input().split()]

    ans = 0
    for i in range(N):
        if i + 1 == P[i]:
            ans += 1
            if i == N - 1:
                break
            P[i + 1] = P[i]

    print(ans)
    
    

if __name__ == '__main__':
    main()



Measured memory_bytes: 13876
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
const long double eps = 1e-12;
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*2
#define REP(a,b) for(long long a = 0;a < b;++a)
long long dp[200000][3];
int main() {
	long long n;
	cin >> n;
	REP(i, n) {
		long long geko[3];
		REP(q, 3) {
			cin >> geko[q];
		}
		REP(q, 3) {
			REP(j, 3) {
				if (q != j) {
					dp[i + 1][j] = max(dp[i + 1][j], dp[i][q] + geko[j]);
				}
			}
		}
	}
	cout << max({ dp[n][0],dp[n][1],dp[n][2] }) << endl;
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <iomanip>

using namespace std;

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

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

    double ans = 0;
    for( auto elm: v ){
        ans += 1/elm;
    }

    cout << setprecision(10) << 1/ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int ban;
	double tai,shin,bmi;
	while(scanf("%d,%lf,%lf",&ban,&tai,&shin)!=EOF){
		bmi=tai/(shin*shin);
		if(bmi>=25){
			printf("%d\n",ban);
		}
	}
	return 0;
}

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

using namespace std;

typedef vector<int> per;

int n, k;
per a[7], A, p, q; // A = qp^{-1}q^{-1}

per mul(per a, per b) {
	per c;
	c.resize(n);
	for (int i = 0; i < n; ++i) c[i] = a[b[i]];
	return c;
}

per inv(per a) {
	per b;
	b.resize(n);
	for (int i = 0; i < n; ++i) b[a[i]] = i;
	return b;
}

int cir[100005];
bool is[100005];

per power(per a, int t) { // return a^t
	per b;
	b.resize(n);
	for (int i = 0; i < n; ++i) is[i] = 0;
	for (int i = 0; i < n; ++i)
		if (!is[i]) {
			if (a[i] == i) {
				b[i] = i;
				continue;
			}
			int p = i, l = 0;
			do {
				cir[l++] = p;
				is[p] = 1;
				p = a[p];
			} while (p != i);
			for (int j = 0; j < l; ++j)
				b[cir[j]] = cir[(j + t) % l];
		}
	return b;
}

int main() {
	scanf("%d%d", &n, &k);
	p.resize(n);
	q.resize(n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &p[i]);
		--p[i];
	}
	for (int i = 0; i < n; ++i) {
		scanf("%d", &q[i]);
		--q[i];
	}
	a[1] = p;
	a[2] = q;
	if (k <= 6) {
		for (int i = 3; i <= k; ++i) a[i] = mul(a[i - 1], inv(a[i - 2]));
		for (int i = 0; i < n; ++i)
			printf("%d ", a[k][i] + 1);
		return 0;
	}
	for (int i = 3; i <= 6; ++i) a[i] = mul(a[i - 1], inv(a[i - 2]));
	A.resize(n);
	for (int i = 0; i < n; ++i) A[i] = i;
	A = mul(A, q);
	A = mul(A, inv(p));
	A = mul(A, inv(q));
	A = mul(A, p);
	A = power(A, (k - 1) / 6);
	per ans = mul(mul(A, a[(k - 1) % 6 + 1]), inv(A));
	for (int i = 0; i < n; ++i) {
		printf("%d ", ans[i] + 1);
	}
}

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

public class Main
{
	PrintWriter out = new PrintWriter(System.out);
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok = new StringTokenizer("");
    String next() throws IOException {
        if (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); }
        return tok.nextToken();
    }
    int ni() throws IOException { return Integer.parseInt(next()); }
    long nl() throws IOException { return Long.parseLong(next()); }
    
    void solve() throws IOException {
        for (int tc=1;tc>0;tc--) {
            int n=ni(),x=ni(),t=ni();
            int ans=n/x;
            if (n%x>0) ans++;
            out.println(ans*t);
        }
        out.flush();
    }
    
    public static void main(String[] args) throws IOException {
        new Main().solve();
    }
}

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

using namespace std;

using ll = long long;
constexpr int mo = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n;
    vector<vector<int>> v(3,vector<int>(3));
    vector<vector<bool>> f(3,vector<bool>(3,false));
    for(int i=0;i<3;++i)for(int j=0;j<3;++j)cin>>v[i][j];
    cin>>n;
    vector<int> b(n);
    for(auto &a : b) cin>>a;
    for(int i=0;i<n;++i){
        for(int y=0;y<3;++y)for(int x=0;x<3;++x){
            if(b[i] == v[y][x])f[y][x] = true;
        }
    }
    
    bool ok = false;
    if((f[0][0] and f[1][1] and f[2][2]) or (f[2][0] and f[1][1] and f[0][2])) ok = true;
    for(int i=0;i<3;++i){
        if((f[0][i] and f[1][i] and f[2][i]) or (f[i][0] and f[i][1] and f[i][2])) ok = true;
    }
    if(ok) cout  << "Yes" << endl;
    else cout  << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
typedef struct{
    int x;
    int y;
}pair;
int main()
{   int n;
    scanf("%d",&n);
    pair a[n];
    for(int i=0;i<n;i++){
        scanf("%d%d",&a[i].x,&a[i].y);
    }
    int frac=1;
    for(int i=1;i<n;i++){
        frac*=i;
    }
    double ans=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            ans+=(sqrt((a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y)))*frac;
        }
    }
    printf("%.8lf",ans/(n*frac));
    return 0;
}


Measured memory_bytes: 128
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

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;
}

//想定解答との絶対誤差または相対誤差が 10−6以下の場合+1以上だしておく。適当に15とかでもおｋ．
//cout << fixed << setprecision(15);

template <typename Iterator>
inline bool next_combination(const Iterator first, Iterator k, const Iterator last)
{
   /* Credits: Thomas Draper */
   if ((first == last) || (first == k) || (last == k))
      return false;
   Iterator itr1 = first;
   Iterator itr2 = last;
   ++itr1;
   if (last == itr1)
      return false;
   itr1 = last;
   --itr1;
   itr1 = k;
   --itr2;
   while (first != itr1)
   {
      if (*--itr1 < *itr2)
      {
         Iterator j = k;
         while (!(*itr1 < *j)) ++j;
         std::iter_swap(itr1,j);
         ++itr1;
         ++j;
         itr2 = k;
         std::rotate(itr1,j,last);
         while (last != j)
         {
            ++j;
            ++itr2;
         }
         std::rotate(k,itr2,last);
         return true;
      }
   }
   std::rotate(first,k,last);
   return false;
}

int main() {
// 5-choose-3 
    vector<pair<int, int> > a;
    while(true) {
        int n, x;
        cin >> n >> x;
        if (n == 0 && x == 0) break;
        pair<int, int> p = make_pair(n, x);
        a.push_back(p);
    }

    rep(i, 0, a.size()) {
        int count = 0;
        int n = a[i].first;
        int k = 3;

        std::vector<int> ints;
        for (int j = 1; j <= n; ints.push_back(j++));
        do {
            int res = 0;
            for (int l = 0; l < k; ++l) {
                res += ints[l];
            }
            if (res == a[i].second) ++count;
        }
        while(next_combination(ints.begin(),ints.begin() + k,ints.end()));
        cout << count << endl;
    }
    return 0;
}




Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll n, cnt, ans;
vector<ll> s, v;
int main(){
    cin >> n;
    REP(i, n){
        ll a;
        cin >> a;
        a--;
        s.push_back(a);
        v.push_back(a);
    }
    sort(ALL(v));
    REP(i, n){
        if (v[i] != s[i]) cnt++;
    }
    ll q;
    cin >> q;
    if(cnt == 0){
        cout << 0 << endl;
        return 0;
    }
    REP(i, q){
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        if (s[a] != v[a]) cnt--;
        if (s[b] != v[b]) cnt--;
        swap(s[a], s[b]);
        if (s[a] != v[a]) cnt++;
        if (s[b] != v[b]) cnt++;
        if(cnt == 0){
            cout << i + 1 << endl;
            return 0;
        }   
    }
    cout << -1 << endl;
}




Measured memory_bytes: 9228
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int n; string s;
  cin >> n >> s;
  int cnt=0;
  rep(i,n-2){
    if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')cnt++;
  }
  cout << cnt << endl;
  return 0;
}


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

int main(){
  long long N, M;
  cin >> N >> M;
  vector<bool> aac(N+1, false);
  vector<int> mon(M);
  vector<string> woa(M);
  for(int i=0; i<M; ++i){
    cin >> mon.at(i) >> woa.at(i);
  }
  
  vector<int> WAbA(N+1);
  int WA=0, AC=0;
  for(int i=0; i<M; ++i){
    if(aac.at(mon.at(i)) == true) continue;
    else if(woa.at(i)== "AC"){
      ++AC;
      WA += WAbA.at(mon.at(i));
      aac.at(mon.at(i)) = true;
    }
    else if(woa.at(i)== "WA") ++WAbA.at(mon.at(i));
  }
  cout << AC << " " << WA << endl;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int> >;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mk make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
typedef unsigned int uint;
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  std::cin >> n;
  std::vector<string> s(n);
  std::vector<int> t(n);
  rep(i,n)std::cin >> s[i]>>t[i];
  string x;
  std::cin >> x;
  int p;
  rep(i,n)if(s[i]==x)p=i;
  std::cout << sum(t.begin()+p+1,t.end(),0) << std::endl;
  
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if (a == b) {
			System.out.println("Draw");
		} else if (a == 1) {
			System.out.println("Alice");
		} else if (b == 1) {
			System.out.println("Bob");
		} else if (a > b) {
			System.out.println("Alice");
		} else {
			System.out.println("Bob");
		}
	}
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  
  long long int X = 0, Y = 0;
  for (int i = 0; i < N; i++) X += A.at(i);
  
  long long int ans = 1000000000000000;
  for (int i = N - 1; i > 0; i--) {
    X -= A.at(i);
    Y += A.at(i);
    ans = min(ans, abs(X - Y));
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()

using namespace std;

namespace Dump {
#define dump(...) Dump::print(#__VA_ARGS__, __VA_ARGS__)
static std::vector<string> dumpKey;
static string dumpKeyBuf;

void print() { cerr << endl; }
template <class Head, class... Tail> void print(Head &&head, Tail &&... tail) {
  if (dumpKey.empty()) {
    dumpKeyBuf = head;
    dumpKeyBuf.erase(std::remove_if(dumpKeyBuf.begin(), dumpKeyBuf.end(),
                                    [](char c) { return c == ' '; }),
                     dumpKeyBuf.end());

    std::istringstream stream(dumpKeyBuf);
    string field;
    while (std::getline(stream, field, ','))
      dumpKey.push_back(field);

    reverse(dumpKey.begin(), dumpKey.end());
  } else {
    cerr << dumpKey.back() << ":" << head << "  ";
    dumpKey.pop_back();
  }
  Dump::print(std::move(tail)...);
}
}

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef vector<unsigned long long> vull;
typedef pair<int, int> pii; // p.first p.second

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

void solve(long long N, long long Y) {

  Y /= 1000;

  for (int i = 0; i <= N; ++i) {
    for (int j = 0; (i + j) <= N; ++j) {

      int _N = N - i - j;
      if (10 * i + 5 * j + _N == Y) {
        cout << i << " " << j << " " << _N << endl;
        return;
      }
    }
  }

  cout << "-1 -1 -1" << endl;
}

int main() {
  ios::sync_with_stdio(false);
  long long N;
  long long Y;
  cin >> N;
  cin >> Y;
  solve(N, Y);
  return 0;
}


Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let p: Vec<i32> = (0..n).map(|_| input()).collect();

    let cnt = p
        .iter()
        .enumerate()
        .filter(|&(i, &p)| i + 1 != p as usize)
        .count();
    println!("{}", if cnt < 3 { "YES" } else { "NO" });
}


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

void solve(string S, string T) {
    vector<vector<int>> dp(S.size() + 1, vector<int>(T.size() + 1, 0));
    REP(i, S.size() + 1) REP(j, T.size() + 1) {
        if (S[i - 1] == T[j - 1]) dp[i][j] = max({dp[i - 1][j - 1] + 1, dp[i - 1][j], dp[i][j - 1]});
        else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
    }
    cout << dp[S.size()][T.size()] << endl;
    return;
}

int main() {
    int q;
    cin >> q;
    rep(i, q) {
        string X, Y;
        cin >> X >> Y;
        solve(X, Y);
    }
    return 0;
}



Measured memory_bytes: 6852
function Main(input) {
  input = input.split("\n");
  var s = input[0];
  if(s.match(/BW/g)){
  var l1 = s.match(/BW/g).length;
  }else{
    l1=0;
  }
  if(s.match(/WB/g)){
  var l2 = s.match(/WB/g).length;
  }else{
    l2=0;
  }
  console.log('%s', l1+l2);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(){
  int MAX = 1000000;
  int n;
  int cnt=0;
  vector<bool> num(n);
  
  for(int i=0; i<MAX; i++){
    num[i] = true;
  }
  num[0] = false;
  num[1] = false;

  for(int i=2; i*i<=MAX; i++){
    if(num[i]){
      for(int j=i*2; j<MAX; j+=i){
	num[j] = false;
      }
    }
  }

  while(cin >> n){
    cnt = 0;
    for(int i=0; i<=n; i++){
      if(num[i]) cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 16000
#include<stdio.h>
#include<stdlib.h>
#define N 100005
int a[N],n,m,i,count=0,j,min,k,flag;
int cmp(const void*a,const void *b)
{
    return *(int *)a-*(int *)b;
}
int main()
{
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    qsort(&a[1],n,sizeof(a[1]),cmp);
    for(i=1;i<=n;i++)
    {
        if(a[i]!=a[1])
        {
            k=i;
            flag=1;
            break;
        }
    }
    if(!flag)
    {
        count=0;
    }
    else
    {
    if(k<m)
     {
       count=1;
       if((n-m)%(m-1)!=0)
       {
           count+=(n-m)/(m-1)+1;
       }
       else
       {
           count+=((n-m)/(m-1));
       }
    }
    else
    {
            n=n-(k-1);
           count+=(n/(m-1)+n%(m-1));
    }
}
        printf("%d\n",count);
}


Measured memory_bytes: 892
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;

// Bellman-Ford O(|V| * |E|)
class Program
{
    static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        new Program().solve();
        Console.Out.Flush();
    }
    Scanner cin = new Scanner();

    struct Edge
    {
        public int from, to, cost;
        public Edge(int from, int to, int cost)
        {
            this.from = from;
            this.to = to;
            this.cost = cost;
        }
    }

    void solve()
    {
        int V = cin.nextint;
        int E = cin.nextint;
        int r = cin.nextint;

        var G = new Edge[E];
        for (int i = 0; i < E; i++)
        {
            G[i] = new Edge(cin.nextint, cin.nextint, cin.nextint);
        }

        var D = Enumerable.Repeat(int.MaxValue, V).ToArray();

        D[r] = 0;
        for (int i = 0; i < V; i++)
        {
            for (int j = 0; j < E; j++)
            {
                var e = G[j];
                if (D[e.from] != int.MaxValue && D[e.to] > D[e.from] + e.cost)
                {
                    D[e.to] = D[e.from] + e.cost;

                    if (i == V - 1)
                    {
                        Console.WriteLine("NEGATIVE CYCLE");
                        return;
                    }
                }          
            }
        }

        foreach (var v in D)
        {
            Console.WriteLine(v == int.MaxValue ? "INF" : v + "");
        }
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return Console.ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 9680
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;
#define RET(ans) {cout<<ans<<endl;return 0;} 

    // 二次元ベクターの基本
    /*
    vector<vector<int>> dp; // 宣言
    dp.resize(n); // 1次元めの要素数決定
    dp[i].push_back(int); // プッシュバック
    rep(i,n){
        sort(dp[i].begin(),dp[i].end()); // 二次元めを昇順ソート
    }
    */

    // 整数スキャン（複数）
    /*
    int x,y,z;
    scanf("%d%d%d",&x,&y,&z);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s; cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s; cin >> s;
        slist.push_back(s);
    }
    */

int main() {
    int n;
    scanf("%d",&n);
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    ll b[n] = {};
    ll c[n] = {};
    rep(i,n){
        b[i] = 20001*i;
        c[i] = 20001*(n-1-i);
    }
    rep(i,n){
        b[a[i]-1] += i+1;
        c[a[i]-1] += i+1;
    }
    rep(i,n){
        cout << b[i] << ' ';
    }
    cout << endl;
    rep(i,n){
        cout << c[i] << ' ';
    }
    cout << endl;

    

    return 0;
}
 
 


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

using namespace std;

typedef long long ll;

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

	string s;
	cin >> s;

	sort(s.begin(), s.end());
	cout << (s == "abc" ? "Yes" : "No") << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>

using namespace std;

#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

int main() {
    int N, M;
    cin >> N >> M;
    int g = (N * (N-1)) / 2;
    int k = (M * (M-1)) / 2;
    cout << g+k << endl;
    return 0;
}

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

#define ll long long int
#define str string
#define sec .second

ll MOD = 1000000007,INFL = 1ll << 60,INF = 1 << 30;
ll A[10000000] = {};
ll X[1000000] = {};
ll aiti[10000];
int dy[]={0, 0, 1, -1},dx[]={1, -1, 0, 0};
vector <ll> v;
ll a = 0,b = 0,c = 0,n = 0,sum = 0, max = INF;
str S;
bool an = false,bn = false;

int findDigits(int n) {
        int i = 0;
        while (n > 0) {

                X[i] = n%10;
                n /= 10;
                i++;
        }
        return i;
}


int main(){
        cin.tie(0);
        ios::sync_with_stdio(false);
        //Code Line
cin >> a >> b >> c;
for(int i = 0;i < 10;i++){
  cout << a * c - b << endl;
  c =  a * c - b;
}
cin >> n;
  //Code Line
        return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main( void )
{
	int i;
	int j;
	
	for( i = 0; i < 9; i++ )
	{
		for( j = 0; j < 9; j++ )
		{
			printf( "%dx%d=%d\n", i + 1, j + 1, ( i + 1 ) * ( j + 1 ) );
		}
	}
	
	
	return (0);
}

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

ll dp[101][5][5][5];

void solve() {

    int N;
    cin >> N;
    const int mod = 1e9 + 7;

    dp[0][4][4][4] = 1;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 5; j++) {
            for (int k = 0; k < 5; k++) {
                for (int l = 0; l < 5; l++) {
                    for (int m = 0; m < 4; m++) {
                        vector<int> I = {j, k, l, m};
                        if (I[1] == 0 && I[2] == 1 && I[3] == 2) continue;
                        if (I[1] == 0 && I[2] == 2 && I[3] == 1) continue;
                        if (I[1] == 1 && I[2] == 0 && I[3] == 2) continue;
                        
                        if (I[0] == 0 && I[2] == 1 && I[3] == 2) continue;
                        if (I[0] == 0 && I[1] == 1 && I[3] == 2) continue;
                        
                        dp[i + 1][k][l][m] += dp[i][j][k][l];
                        dp[i + 1][k][l][m] %= mod;
                        
                    }
                }
                
            }
        }
    }

    ll ans = 0;
    for (int j = 0; j < 5; j++) {
        for (int k = 0; k < 5; k++) {
            for (int l = 0; l < 5; l++) {
                ans += dp[N][j][k][l];
                ans %= mod;
            }
        }
    }

    cout << ans << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)

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

    string a_s;
    string b_s;
    while (cin >> a_s >> b_s)
    {
        string c_s = a_s + b_s;
        double c = stoi(c_s);
        double c_root = sqrt(c);
        if (pow(floor(c_root), 2) == c)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }

        return 0;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) #x "=" << x << " "
#define fore(i,a,b) for(int i=a,gon=b;i<gon;++i)
#define pb push_back
#define F first
#define S second
typedef double lf;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif
    int R[] = {1, 400, 800, 1200, 1600, 2000, 2400, 2800, 3200};
    int n, r, dif = 0;
    cin >> n;
    bitset<8> mark;
    while (n--) {
        cin >> r;
        int i = upper_bound(R, R+9, r)-R-1;
        if (i < 8) mark[i] = 1;
        else dif++;
    }
    int cnt = mark.count();
    cout << max(1, cnt) << " " << cnt+dif << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;
 
const ll MOD = 1e9+7;
string s[100000];
int main()
{
	int n;
	ll ans=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>s[i];
		sort(s[i].begin(),s[i].end());
	}
	sort(s,s+n);
	int ind=0;
	while(ind<n)
	{
		string t=s[ind];
		ll cnt=1;
		ind++;
		while(ind<n && s[ind]==t)
		{
			cnt++;
			ind++;
		}
		ans+=cnt*(cnt-1)/2;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 7296
from collections import defaultdict

if __name__ == '__main__':
    mod = 10**9 +7
    N = int(input())
    S = str(input())

    letter = defaultdict(int)
    letter_count = defaultdict(int)
    count = 0
    for i in range(N):
        new_count = count + 1
        new_count -= letter[S[i]] #今まで追加文字が使われている組み合わせはNG
        count += new_count
        letter[S[i]] += new_count #追加文字が追加されたことによる組み合わせ増分を増やす
        #追加文字による、他のある文字が使われる組み合わせの増加は
        #今まである文字が使われていた組み合わせの数-ある数が使われていてかつ追加文字が含まれている組み合わせ
        for key in letter:
            if key != S[i]:
                letter[key] += letter[key]//(1 + letter_count[S[i]])
        letter_count[S[i]] += 1
    print(count%mod)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pii;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie();
	
	ll n;
	string s;
	cin >> n >> s;
	if (n % 2) {
		cout << "No";
	}
	else {
		for (ll i = 0; i < n/2; i++) {
			if (s[i] != s[n/2 + i]) {
				cout << "No";
				return 0;
			}
		}
		cout << "Yes\n";
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int l;
    cin>>l;
    
    int a=1,b=1,c=1;
    int sum=0;
    for(int i=0;i<n;i++)
    {
    	if(l+i<0) a=0;
    	if(l+i==0) b=0;
    	if(l+i>0) c=0;
    	sum+=l+i;
	}
	
	
	if(b==0) cout<<sum;
	else if(a==0) cout<<sum-(l+n-1);
	else cout<<sum-(l);
	
	
}

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

def VI(N, init=0):
  return [init for _ in range(N)]
def VVI(N, M, init=0):
  return [[init for _ in range(M)] for _ in range(N)]

def VD(N, init=0.0):
  return [init for _ in range(N)]
def VVD(N, M, init=0.0):
  return [[init for _ in range(M)] for _ in range(N)]

def Decimal(x):
  print("{0:.10f}".format(x))

class Pair:
  def __init__(self, x=0, y=0):
    self.first = x
    self.second = y

  def __repr__(self):
    return '{0} {1}'.format(self.first, self.second)

  def __lt__(self, pi):
    return self.first < pi.second

def POW(x, n):
  ret = 1
  while n:
    if n&1:
      ret *= x
    x *= x
    n >>= 1
  return ret

N = int(input().rstrip())
if N < 1000:
  print("ABC")
else:
  print("ABD")


Measured memory_bytes: 38256
#include "bits/stdc++.h"5 7 5
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans = 0;
int main() {
	string S;
	cin >> S;
	n = S.length() / 2;
	rep(i, n) {
		if (S[i] != S[S.length() - 1 - i])ans++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

fn main() {
    input! {
        d: usize,
        g: usize,
        pc: [(usize, usize); d],
    }

    let mut ans = 1 << 50;

    for i in 0..1 << d {
        let mut solved = 0;
        let mut score = 0;
        let mut unsolved = vec![true; d];
        for j in 0..d {
            if i >> j & 1 == 1 {
                solved += pc[j].0;
                score += pc[j].1 + 100 * pc[j].0 * (j + 1);
                unsolved[j] = false;
            }
        }

        if score >= g {
            ans = min(ans, solved);
            continue;
        }

        for j in (0..d).rev() {
            if unsolved[j] {
                let t = (g - score + (j + 1) * 100 - 1) / ((j + 1) * 100);
                if t < pc[j].0 && score + t * (j + 1) * 100 >= g {
                    ans = min(ans, solved + t);
                }
            }
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
using System;
using System.Linq;

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int ret = 0;
            for (int i = 0; i < n; i++) if (x[i] % 2 == 0) ret++;
            Console.WriteLine(ret);
        }
    }
}



Measured memory_bytes: 18308
#include<cstdio>
#include<algorithm>
using namespace std;
struct ben
{
    int x;
    int y;
}a[1000000];
int cmp(const ben &xx,const ben &yy)
{
    return xx.x>yy.x;
}

int main()
{
    int n,h;
    int c=0;
    scanf("%d%d",&n,&h);
    for(int i=1;i<=n;i++)
    {
    	c++;
        scanf("%d",&a[c].x);
        c++;
        a[c].y=1;
        
        scanf("%d",&a[c].x);
    }
    sort(a+1,a+c+1,cmp);
    int sum=0;
    for(int i=1;i<=c;i++)
    {
        if(a[i].y==1)
        {
            sum++;
            h-=a[i].x;
            if(h<=0)
            {
                printf("%d",sum);
                return 0;
            }
        }
        else if(a[i].y!=1)
        {
            if(h%a[i].x==0) 
				sum+=h/a[i].x;
            else
			 	sum+=h/a[i].x+1;
            printf("%d",sum);
            return 0;

        }
    }
	return 0; 
}

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

int main(void){
	int n;
	cin>>n;
	int a[3]={0};
	for(int i=0;i<n;i++){
		int tmp;
		cin>>tmp;
		a[tmp-1]++;
	}
	double ***DP=new double**[n+1];
	for(int i=0;i<=n;i++){
		DP[i]=new double*[n+1];
		for(int j=0;j<=n;j++){
			DP[i][j]=new double[n+1];
		}
	}

	for(int i=0;i<=n;i++){
		for(int j=0;j<=n-i;j++){
			for(int k=0;k<=n-i-j;k++){
				DP[i][j][k]=0;
				if(i>0)DP[i][j][k]+=i*DP[i-1][j+1][k];
				if(j>0)DP[i][j][k]+=j*DP[i][j-1][k+1];
				if(k>0)DP[i][j][k]+=k*DP[i][j][k-1];
				if(i+j+k>0)DP[i][j][k]=(DP[i][j][k]+n)/(i+j+k);
			}
		}
	}
	printf("%.10f\n",DP[a[2]][a[1]][a[0]]);
}


Measured memory_bytes: 214784
def main():
    x, a, b = (int(input()) for _ in range(3))
    print((x - a) % b)


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()


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

int main()
{
	string S;
    cin >> S;
	ll N = S.length();
	ll cnt(0);
	for(ll i(0);i<N;++i){
		if(S[i] == '0'){
			cnt++;
		}
	}
	if(N-cnt >= cnt){
		cout << 2*cnt << endl;
	}else{
		cout << 2*(N-cnt) << endl;
	}
	return 0;
}

Measured memory_bytes: 512