akhauriyash/Code-Regression huggingface dataset:
// hmmmm ...coool
#include<bits/stdc++.h>
using namespace std;	
#pragma GCC optimize("Ofast") 
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;	i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
# define PI  3.14159265358979323846
#define MOD 1000000007
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
const int N = 2e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int done[N];
map<int,int>mp;
void pre(){
	for(int i=1;i<=N;i++){
		if(mp[i]){
			if(mp[i]>=2)done[i]=1;
			for(int j=2*i;j<=N;j+=i)done[j]=1;
		}
	}
}
signed main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		int n;
		cin >> n;
		fn{
			cin >> ar[i];
			mp[ar[i]]++;
		}
		pre();
		int ans =0;
		fn{
			ans+=(!done[ar[i]]);
		}	
		cout<<ans;
	
	}
	return 0;
}

Measured memory_bytes: 145740
#include <bits/stdc++.h>
#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()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

ll solve(ll n){
    return (n-1)*n /2;
}

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

    ll ans = solve(n);

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


Measured memory_bytes: 256
import collections

s=list(input())

c = collections.Counter(s)

score_sorted = sorted(c.items(), key=lambda x:-x[1])

val = []

for i, j in score_sorted:
    val.append(j)

if len(val) == 2:
    val.append(0)
elif len(val) == 1:
    val.append(0)
    val.append(0)
    
val.sort()

if 0<= val[2]-val[0] <=1:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 77824
n, m = map(int, input().split())
s = []
k = []
for i in range(m):
    s.append(list(map(int, input().split())))
    k.append(s[i].pop(0))
p = list(map(int, input().split()))

# 全点灯パターンの個数
ans = 0

# 点灯している電球の数
cnt_s_on = 0

# 電球jに繋がるONのスイッチの数
cnt_switch = 0

for i in range(2**n):
    # print(bin(i))
    # print(bin(i>>1))
    # print("----")

    # print("i: "+str(bin(i)))
    tmpS=[0]*m
    cnt_s_on = 0
    
    # すべての電球に対して調べる
    for j in range(m):
        cnt_switch = 0
        
        # 電球jに繋がるすべてのスイッチに対してON/OFFを調べる
        for K in range(k[j]):
            if ((i >> (s[j][K]-1)) & 1):
                # スイッチがONならONカウントに＋する
                cnt_switch += 1
        
        # print("cnt_switch: " + str(cnt_switch))
        # print("cnt_switch%2: " + str(cnt_switch%2))
        # print("p[j]: " + str(p[j]))
        if cnt_switch%2 == p[j]:
            # 電球jは点灯している
            cnt_s_on += 1
            tmpS[j] = 1
    
    # print("電球状況："+str(tmpS))
    # print("cnt_s_on: " + str(cnt_s_on))
    if cnt_s_on == m:
        ans += 1

    # print("----------")
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007 
#define int long long
#define ll long long
#define pb push_back
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define vp vector<pair< int,int> >
#define mpi map<pair<int,int> ,int>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repi(i,a,b) for(int i=a;i>=b;i--)
#define fill(a,i) memset(a,i,sizeof a);


void solve()
{ 
  int k;cin>>k;
     int k1=7,flag=0,ans=0;
    while(1)
    {
        if(k1%k==0)
        {
            cout<<ans+1<<endl;
            flag=1;
            break;
        }
        ans++;
        k1=k1*10;
        k1+=7;k1%=k;
        if(ans>=10000000)break;
    }
    if(flag==0)cout<<"-1";
}

signed main()
{ 
    boost
    int test=0,t;
    //cin >> t ;
    t=1;
    while(test++ <t){
    //cout<<"Case #"<<test<<": ";
    solve();}
  
}

Measured memory_bytes: 3616
// テ・ツ淞コテヲツ慊ャテ」ツδ?」ツδウテ」ツδ療」ツδャテ」ツδシテ」ツδ?

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int hash_num = 0;
map< vector<int>, int > hash_s;

signed main() {
    string s, t; cin >> s >> t;
    int len = min(s.length(), t.length());

    int ans = 0;
    repq(i,1,len) {
        hash_s.clear();
        hash_num = 0;

        int cnt = 0;
        vector<int> app_s(26), app_t(26);
        rep(k,0,s.length()) {
            int val = s[k] - 'a';
            app_s[val]++;

            cnt++;
            if(cnt == i) {
                if(!hash_s.count(app_s)) {
                    hash_s[app_s] = hash_num++;
                }

                int prev = k - i + 1;
                int prev_val = s[prev] - 'a';
                app_s[prev_val]--;
                cnt--;
            }
        }

        cnt = 0;
        rep(k,0,t.length()) {
            int val = t[k] - 'a';
            app_t[val]++;
            cnt++;
            if(cnt == i) {
                if(hash_s.count(app_t)) chmax(ans, i);

                int prev = k - i + 1;
                int prev_val = t[prev] - 'a';
                app_t[prev_val]--;
                cnt--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

typedef pair<long long,int> P;

int n;
vector<long long> bit(200010,0);
void add(int a, int w) {
	for (int x = a;x <= n;x += x&-x) bit[x] += w;
}
int sum(int a) {
	int ret = 0;
	for (int x = a;x > 0;x -= x&-x) ret += bit[x];
	return ret;
}

int main() {
	int k;
	long long ans = 0;
	vector<int> s;
	cin >> n >> k;
	vector<P> a(n+1);
	for (int i = 1;i <= n;++i) {
		cin >> a[i].first;
		a[i].first -= k;
		a[i].second = i;
	}
	a[0] = P(0,0);
	for (int i = 0;i < n;++i) a[i+1].first += a[i].first;
	
	sort(a.begin(),a.end());

	n++;
	for (int i = n;i > 0;--i) {
		ans += sum(n)-sum(a[i-1].second+1);
		add(a[i-1].second+1,1);
	}

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

Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
const int MOD = 1e9+7;
const int MOOD = 998244353;
#define PI 3.14159265359
typedef long long ll;
using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	vector<ll> a(n);
	vector<ll> sum(n+1);
	map<ll, ll> mp;
	for (int i = 0; i < n; i++){
		cin >> a[i];
		sum[i+1] = sum[i] + a[i];
		sum[i+1] %= m;
		mp[sum[i+1]]++;
	}

	ll ans = 0;
	for (auto x : mp){
		if (x.first % m == 0) ans += x.second;
		ans += x.second*(x.second-1)/2;
	}

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

Measured memory_bytes: 8732
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
using namespace std;

int main()
{
    int n;
    string s;

    cin >> n;
    cin >> s;

    if(n % 2 == 1)
    	cout << "No" << endl;
    else
    {
    	int count = 0;
    	for(int i = 0; i < n / 2; i ++)
    	{
    		if(s[i] == s[i + n / 2])
    			count ++;
    	}
    	if(count == n / 2)
    		cout << "Yes" << endl;
    	else
    		cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int n, a;
  	cin >> n;
  
  	for (int i = 0; i<n ; i++){
		string s;
      	cin >> s;
      	if (s == "Y"){
        	a = 0;
          	break;
        }
      	else{
			a = 1;        	
        }
    }
 
  	if (a == 0){
      cout << "Four" << endl;
    }
  	else{
      cout << "Three" << endl;
    }
}

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


int main() {
  int n;
  string s;
  cin >> n >> s;
  map<char, int> chars = {
    {'A', 0}, {'B', 1}, {'C', 2}, {'D', 3}, {'E', 4}, {'F', 5},
    {'G', 6}, {'H', 7}, {'I', 8}, {'J', 9}, {'K', 10}, {'L', 11},
    {'M', 12}, {'N', 13}, {'O', 14}, {'P', 15}, {'Q', 16}, {'R', 17},
    {'S', 18}, {'T', 19}, {'U', 20}, {'V', 21}, {'W', 22}, {'X', 23},
    {'Y', 24}, {'Z', 25}
  };
  vector<char> vec = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
                      'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
                      'U', 'V', 'W', 'X', 'Y', 'Z'};
  int ss = s.size();
  rep(i, ss){
    int nn;
    nn = chars.at(s.at(i));
    int n3 = nn + n;
    if(n3 > 25){n3 -= 26;};
    cout << vec.at(n3);
  }
  
  cout << endl;
  return 0;
}

Measured memory_bytes: 764
import scala.io.Source.stdin

object Main extends App {
  var b = new StringBuilder

  def integral(i:Int,s:Int,d:Int):Unit = if(i*d >= 600-d) b.append((s + i*i*d*d*d)+"\n") else integral (i+1, s + i*i*d*d*d, d)

  for(i<-stdin.getLines)
    integral(0,0,i.toInt)

  print(b.result)
}

Measured memory_bytes: 43888
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>

ll n,cnt,ans,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

//------ 自分を天才だと信じる ------

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

    cin>>n;
    rep(i,3*n)cin>>a[i];
    sort(a,a+3*n);
    rrep(i,n,3*n){
        ans+=a[i];
        i++;
        cnt++;
        if(cnt==n)break;
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
typedef long long ll;
const int MAX = 999999999;

bool graph[50][50] = {false};
bool visited[50] = {false};

void bfs(int n){
    visited[n] = true;

    rep(i, 50){
        if(graph[n][i] && !visited[i]) bfs(i);
    }
}

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

    vector<pair<int, int>> ways;
    rep(i, m){
        int s, g;
        cin >> s >> g;
        s --;
        g --;
        ways.push_back(pair<int, int>(s, g));
        graph[s][g] = true;
        graph[g][s] = true;
    }

    int cnt = 0;
    rep(i, m){
        // 無効化する道を選ぶ
        graph[ways[i].first][ways[i].second] = false;
        graph[ways[i].second][ways[i].first] = false;

        // 全て未探索に
        rep(i, n) visited[i] = false;

        bfs(0);

        // 全到達失敗でカウント
        rep(i, n) if(!visited[i]){ cnt ++; break; }

        // 再初期化
        graph[ways[i].first][ways[i].second] = true;
        graph[ways[i].second][ways[i].first] = true;
    }

    cout << cnt << endl;
}

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

using namespace std;



int main(){


    int n,l;
    string s;
    cin>>n>>l;
    vector<string> v;
    while(cin>>s){
        v.push_back(s);
        if(n==1){
            break;
        }
        n--;

    }

    sort(v.begin(),v.end());

    for(auto x:v){
        cout<<x;
    }




}


Measured memory_bytes: 256
import itertools
 
N, X, Y = map(int, input().split())
 
n_iter = itertools.combinations(list(range(1,N+1)), 2)
 
count_list = [0]*(N-1)
 
for i, j in n_iter:
  #1. abs(X - i) + abs(Y - j) + 1
  #2. abs(Y - i) + abs(X - j) + 1
  #3. abs(j - i)
  x = min(
    abs(X - i) + abs(Y - j) + 1,
    abs(j - i)
  )
  count_list[x-1] += 1
 
for i in count_list:
  print(i)

Measured memory_bytes: 3572
import heapq
N = int(input())
A = [0]*N

maxVal = -1
for i in range(N):
    A[i] = int(input())
    maxVal = max(maxVal, A[i])

secondMax = -1
maxIndex = A.index(maxVal)
A[maxIndex] = -1
secondMax = max(A)
A[maxIndex] = maxVal

for i in range(N):
    if A[i] == maxVal:
        print(secondMax)
    else:
        print(maxVal)


Measured memory_bytes: 79044
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 2000000000;
using namespace std;

int main(){
    double a, b;
    cin >> a >> b;

    double p = (b - a) / 2 + a;
    if(abs(a - b) > 180){
        if(p - 180 < 0) cout << fixed << setprecision(8) << p + 180<< endl;
        else cout <<fixed << setprecision(8) <<  p - 180 << endl;
    }else{
        if(p < 0) cout << fixed << setprecision(8) << p + 360 << endl;
        else cout <<fixed << setprecision(8) <<  p << endl;
    }
}

Measured memory_bytes: 3272
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

// type
#include <cstdint>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    string str;
    cin >> str;
    int N = str.size();
    string ret;
    for (int i = 0; i < N; i++) ret += 'x';
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
// 2014/08/30 Tazoe

#include <iostream>
#include <algorithm>
using namespace std;

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

		if(n==0)
			break;

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

		int DP[5000];
		DP[0] = a[0];
		int s_max = DP[0];

		for(int i=1; i<n; i++){
			DP[i] = max(DP[i-1]+a[i], a[i]);

			s_max = max(s_max, DP[i]);
		}

		cout << s_max << endl;
	}

	return 0;
}

Measured memory_bytes: 1192
let _ =
    let a, b, c = Scanf.scanf "%d %d %d" (fun a b c -> a, b, c) in
    let swap a b =
        if a < b then (a, b)
        else (b, a) in
    let a, b = swap a b in
    let b, c = swap b c in
    let a, b = swap a b in
    if a mod 2 = 1 && b mod 2 = 1 && c mod 2 == 1 then
        Printf.printf "%d\n" (a*b)
    else
        Printf.printf "0\n";;


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	string s; cin>>s;
	vector<int>v(26,0);
	for(int i=0;i<4;++i){
		++v.at(s.at(i)-'A');
	}
	cout<<(count(v.begin(),v.end(),2)==2?"Yes"s:"No"s)<<"\n"s;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         sort(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  ll n; cin >> n;
  vector<ll> a(n + 1);
  for (int i = 1; i <= n; i++) {
    ll ai; cin >> ai;
    a[i] = ai;
  }
  vector<ll> mins(n + 1);
  for (int i = 1; i <= n; i++) mins[i] = -1;

  ll step = 0, now = 1;
  mins[now] = 0;
  while (now != 2) {
    ll next = a[now];
    if (mins[next] != -1) break;
    mins[next] = ++step;
    now = next;
  }

  outl(mins[2]);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


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

using namespace std;

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

    vector<vector<int>> dp1(N, vector<int>(T, 0)), dp2(N, vector<int> (T, 0));
    for(int i = 0; i < N; i++){
        if(i > 0){
            for(int j = 0; j < T; j++){
                dp1[i][j] = dp1[i - 1][j];
            }
        }
        for(int j = T - A[i] - 1; j >= 0; j--){
            dp1[i][A[i] + j] = max(dp1[i][A[i] + j], dp1[i][j] + B[i]);
        }
    }
    for(int i = N - 1; i >= 0; i--){
        if(i < N - 1){
            for(int j = 0; j < T; j++){
                dp2[i][j] = dp2[i + 1][j];
            }
        }
        for(int j = T - A[i] - 1; j >= 0; j--){
            dp2[i][A[i] + j] = max(dp2[i][A[i] + j], dp2[i][j] + B[i]);
        }
    }

    // for(int i = 0; i < N; i++){
    //     for(int j = 0; j < T; j += 10) cout << dp1[i][j] << "\t";
    //     cout << endl;
    // }
    // cout << endl;
    // for(int i = 0; i < N; i++){
    //     for(int j = 0; j < T; j += 10) cout << dp2[i][j] << "\t";
    //     cout << endl;
    // }

    int ans = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < T; j++){
            int l, r;
            if(i == 0) l = 0;
            else l = dp1[i - 1][j];
            if(i == N - 1) r = 0;
            else r = dp2[i + 1][T - j - 1];
            ans = max(ans, l + r + B[i]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 70784
#include <iostream>
#include <cmath>
using namespace std;
#define N 4
#define PN 16

int MDT[PN][PN];
int dx[4] = {0,-1,0,1};
int dy[4] = {1,0,-1,0};
int limit;

struct Puzzle{ int f[PN], space, MD;};
Puzzle state;

int sumMD(Puzzle p){
    int sum = 0;
    for(int i = 0; i < PN; i++){
        if(p.f[i] == PN) continue;
        sum += MDT[i][p.f[i]-1];
    }
    return sum;
}

bool dfs(int depth, int prev){
    if(state.MD == 0) return true;
    if(depth+state.MD > limit) return false;

    int sx = state.space/N;
    int sy = state.space%N;
    Puzzle tmp = state;

    for(int r = 0; r < 4; r++){
        int tx = sx + dx[r];
        int ty = sy + dy[r];
        if(tx < 0 || ty < 0 || tx >= N || ty >= N) continue;
        if((r+2)%4 == prev) continue;
        tmp = state;
        state.MD -= MDT[tx*N+ty][state.f[tx*N+ty]-1];
        state.MD += MDT[sx*N+sy][state.f[tx*N+ty]-1];
        swap(state.f[tx*N+ty],state.f[sx*N+sy]);
        state.space = tx*N+ty;
        if(dfs(depth+1,r)) return true;
        //if(dfs(depth+1,r)){path[depth] = r; return true;}
        state = tmp;
    }

    return false;
}

int main(){
    Puzzle p;

    for(int i = 0; i < PN; i++){
        cin >> p.f[i];
        if(p.f[i] == 0){
            p.f[i] = PN;
            p.space = i;
        }
    }

    for(int i = 0; i < PN; i++){
        for(int j = 0; j < PN; j++){
            MDT[i][j] = abs(i/N - j/N) + abs(i%N - j%N);
        }
    }

    p.MD = sumMD(p);

    for(limit = 0; limit < 45; limit++){
        state = p;
        if(dfs(0,-1)){
            cout << limit << endl;
            return 0;
        }
    }
    cout << 45 << endl;

    return 0;
}


Measured memory_bytes: 3108
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

void addPath(string &path, int n, char direction) {
	for(int i = 0; i < n; ++i) {
		path += direction;
	}
}

int main(void) {
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	
	string ans = "";
	addPath(ans, ty - sy, 'U');
	addPath(ans, tx - sx, 'R');
	addPath(ans, ty - sy, 'D');
	addPath(ans, tx - sx, 'L');
	
	ans += 'L';
	
	addPath(ans, ty - sy + 1, 'U');
	addPath(ans, tx - sx + 1, 'R');
	
	ans += "DR";
	
	addPath(ans, ty - sy + 1, 'D');
	addPath(ans, tx - sx + 1, 'L');
	
	ans += 'U';
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
# arc091_a.py
# def canGo(y,x):
#     if x>=0 and y>=0 and x<W and y<H:
#         return True
#     return False

# def operate(h,w):
#     dx = [-1,0,1]
#     dy = [-1,0,1]
#     for x in dx:
#         for y in dy:
#             if canGo(h+y,w+x):
#                 print("can go",h+y,w+x)
#                 glid[h+y][w+x] += 1


H,W = map(int,input().split())
h = H-2
w = W-2
if H==1:
    h=1
if W==1:
    w=1
print(h*w)
# glid = [[0]*W for _ in range(H)]
# print(glid)
# print("#######")
# for i in range(H):
#     for j in range(W):
#         print(i,j)
#         operate(i,j)
# print(glid)


Measured memory_bytes: 2940
def main():
    n = int(input())
    print(b(n))


def b(n: int) -> int:
    m = 100
    i = 0
    while True:
        m = m * 101 // 100
        i += 1
        if m >= n:
            break

    return i


if __name__ == '__main__':
    main()


Measured memory_bytes: 9176
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define double long double
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
ll linf=(1LL<<31)-1LL;
ll n;
vector<ll>seg(1<<21);
void init(ll n_){
    n=1;
    while(n<n_){
        n*=2;
    }
    rep(i,n*2-1){
        seg[i]=0;
    }
}
void update(ll k,ll a){
    k+=n-1;
    seg[k]=a;
    while(k>0){
        k--;
        k/=2;
        seg[k]=max(seg[2*k+1],seg[2*k+2]);
    }
}
//半開区間
ll query(ll a,ll b,ll k,ll l,ll r){
    if(r<=a||l>=b)return 0;
    if(l>=a&&r<=b)return seg[k];
    else {
        return max(query(a,b,k*2+1,l,(l+r)/2),query(a,b,k*2+2,(l+r)/2,r));
    }
}
int main(){
    ll n_;cin>>n_;
    init(n_);
    vector<ll>h(n_),a(n_);
    rep(i,n_)cin>>h[i];
    rep(i,n_)cin>>a[i];
    ll ans=0;
    for(int i=n_-1;i>=0;i--){
        ll sc=query(h[i]+1,n_+1,0,0,n);
        update(h[i],sc+a[i]);
        ans=max(ans,sc+a[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 19840
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
int main(){
  int N;
  cin>>N;
  int a[200000];
  int b[200000];
  for(int i=0;i<N;i++){
    b[i]=0;
  }
  for(int i=0;i<N-1;i++){
    cin>>a[i];
    b[a[i]-1]++;
  }
  for(int i=0;i<N;i++){
    cout<<b[i]<<endl;
  }
  
  return 0;
}

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

int main() {
    int N;
    std::cin >> N;
    std::vector<int> A;
    A.reserve(N);
    for (int i = 0; i < N; i++) {
        int t;
        std::cin >> t;
        A.push_back(t);
    }
    unsigned int alice = 0;
    unsigned int bob = 0;
    std::sort(A.begin(), A.end(), [](const int& a, const int& b){return a > b;});
    for (int i = 0; i < N; i++) {
        if(i % 2) {
            bob += A[i];
        }else{
            alice += A[i];
        }
    }
    std::cout << alice - bob << std::endl;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int> tako(N);
    for (int i= 0;i < N;i++){
        cin >> tako.at(i);
    }

    int times = N * (N - 1) / 2;
    int sum = 0;
    int ti = 0;
  	//cout << times << endl;
  
    for (int j = 0;j < N - 1;j++){
        for (int i = 0;i < N - ti;i++){
            sum = sum + tako.at(j) * tako.at(ti+i);
            //cout << sum << endl;
        }
        ti = ti + 1;
    }

    for (int l = 0;l < N;l++){
        sum = sum - tako.at(l) * tako.at(l);
    }

    sum = sum + tako.at(N - 1) * tako.at(N - 1);
  
  	

    cout << sum << endl;



}


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

void solve(){
    map<string, ll> mp;
    ll n; string x;
    cin >> n;
    for(ll i = 0; i < n; i++) cin >> x, mp[x]++;
    cout << mp.size() << endl;
}
   

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  //int t;scanf("%d", &t);while(t--)
  solve();
  return 0;
}


Measured memory_bytes: 19252
# -*- coding: utf-8 -*-
N = int(input())
f = [0] * (N+1)
for i in range(1, N+1):
  for j in range(i, N+1, i):
    f[j] += 1

ans = 0
for i in range(1, N+1):
  ans += f[i] * i
print(ans)

Measured memory_bytes: 151392
#include<bits/stdc++.h>
using namespace std;
int main ()
{
    char a[200000];
    scanf("%s",a);
    int n=strlen(a);
    int count=0;
    for(int i=0;i<n;i++)
        count+=a[i]-'0';
    if(count%9==0)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 3844
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int GCD(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   if(_a % _b == 0){
      return _b;
   }
   else{
      return GCD(_b, _a % _b);
   }
}

int LCM(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   return (_a*_b)/(GCD(_a, _b));
}

int main(){
   int n, k;
   cin >> n >> k;
   vector<int> l(n);
   for(int i = 0; i < n; i++){
      cin >> l[i];
   }

   sort(l.begin(), l.end(), greater<int>());

   int ans = 0;
   for(int i = 0; i < k; i++){
      ans += l[i];
   }

   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
  int N, A, B;
  if (scanf("%d%*c", &N) == -1) return -1;
  if (N == 1) printf("Hello World\n");
  else {
    if (scanf("%d%*c%d", &A, &B) == -1) return -1;
    printf("%d\n", A + B);
  }
  return 0;
}

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

int main() {
    string s;
    cin >> s;
    bool ans = false;
    for(int i=0;i<3;i++){
        if(s[i]=='7')ans = true;
    }
    if(ans)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3628
#include <iostream>

int main ()
{
  int a, b;
  std::cin >> a >> b;

  if (b>a)
    {
      auto temp = a;
      a = b;
      b = temp;
    }

  for (int i=0; i<a; i++)
    std::cout << b;
  std::cout << std::endl;


  return 0;
}


Measured memory_bytes: 256
import math

K = int(input())
res=0
for a in range(1,K+1):
    for b in range(1,K+1):
        tmp = math.gcd(a,b)
        for c in range(1,K+1):
            #print(a,b,c)
            res += math.gcd(tmp,c)
print(res)

Measured memory_bytes: 9184
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n);i++)
#define rep1(i,n) for(int i=1; i<(n); i++)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
const int INF = 1e9;
const LL LLINF = 1e16;
const int mod = 1e9+7;

int W, H;
char mas[1010][1010];
int min_cost[1010][1010];

void bfs()
{
  const int vx[] = {0, 1, 0, -1}, vy[] = {1, 0, -1, 0};
  memset(min_cost, -1, sizeof(min_cost));

  queue< pair< int, int > > que;
  rep(y, H)rep(x, W){
      if(mas[y][x] == '#'){
          que.emplace(x, y);
          min_cost[x][y] = 0;
      }
  }
  while(!que.empty()) {
    auto p = que.front(); que.pop();
    for(int i = 0; i < 4; i++) {
      int nx = p.first + vx[i], ny = p.second + vy[i];
      if(nx < 0 || ny < 0 || nx >= W || ny >= H) continue;
      if(min_cost[nx][ny] != -1) continue;
      if(mas[ny][nx] == '#') continue;
      min_cost[nx][ny] = min_cost[p.first][p.second] + 1;
      que.emplace(nx, ny);
    }
  }
}


int main(){
    cin >> H >> W;

    rep(i, H)rep(j, W) cin >> mas[i][j];
    bfs();
    int ans = 0;
    rep(y, H)rep(x, W){
        ans = max(ans, min_cost[x][y]);
    }
    cout << ans << endl;


}

Measured memory_bytes: 13456
#!/usr/bin/env python3
from itertools import*
n, m, x = map(int, input().split())
d = [list(map(int, input().split())) for k in range(n)]
INF = float("inf")
mi = INF
for i in range(1, n+1):
    for j in combinations(range(n), i):
        if all(sum(d[p][q] for p in j) >= x for q in range(1, m+1)):
            mi = min(mi, sum(d[c][0] for c in j))
print(mi if mi != INF else -1)


Measured memory_bytes: 9208
//Compiler optimization
#pragma GCC optimize("Ofast")

//include
#include <bits/stdc++.h>
using namespace std;

//typedef
typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef string S;
typedef queue<int> qi;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<vl> mat;

//macro
//#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define fr(i,n)for(ll i=0;i<(n);i++)
#define ifr(i,n)for(ll i=(n)-1;i>=0;i--)
#define all(x) x.begin(),x.end()

//abbreviation
#define pb push_back
#define elif else if
#define mp make_pair
#define endl '\n'

//debug
#define debug(x) cerr << #x << ": " << x << endl

//const
const  ll INF = 1e18;

//FenwickTree
template <typename T>struct BinaryIndexedTree { //1-indexed
    vector<T> data;

    BinaryIndexedTree(int sz){
        data.assign(++sz, 0);
    }
    void add(int i, T x){
        for(;i<data.size();i+=i&-i)data[i]+=x;
    }
    T sum(int i){
        T res = 0;
        for(;i>0;i-=i&-i)res += data[i];
        return (res);
    }
    T rangesum(int i,int j){//[i,j]
        return (sum(j))-(sum(i-1));
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    ll n,q;cin >> n >> q;
    vl a(n);
    fr(i,n)cin>>a[i];
    vl left(q), right(q), ids(q);
    fr(i,q){
        cin >> left[i] >> right[i];
        ids[i] = i;
    }
    sort(all(ids), [&](int i,int j){return right[i] < right[j];}); // クエリの処理順をrの昇順にソート
    BinaryIndexedTree<ll> bit(n+5);
    vi good(1100000, 0); // good[i]: i種類目の玉の良い位置
    vl res(q, 0);
    ll i = 0;
    fr(r,n){ //rは今見ている右の位置
        if(good[a[r]]>0)bit.add(good[a[r]], -1);
        bit.add(r+1, +1);
        good[a[r]] = r+1;
        for(;right[ids[i]] == r+1;++i){
            res[ids[i]] = bit.rangesum(left[ids[i]], r+1);
        }
        
    }
    fr(i,q)cout << res[i] << endl;
}

Measured memory_bytes: 31516
#include<bits/stdc++.h>
#define maxn 200000
using namespace std;

long long int heights[maxn+5];
long long int values[maxn+5];
long long int tree[(4*maxn)+5]={0};
long long int n;

long long int getMax(long long int l,long long int r,long long int crr_l,long long int crr_r,long long int si)
{
    if(crr_l>r||crr_r<l)
        return -1e15;

    if(crr_l>=l&&crr_r<=r)
        return tree[si];

    long long int mid=(crr_l+crr_r)/2;

    return max(getMax(l,r,crr_l,mid,(2*si)+1),getMax(l,r,mid+1,crr_r,(2*si)+2));
}

void update(long long int idx,long long int value,long long int l,long long int r,long long int si)
{
    if(l==r)
    {
        tree[si]=value+getMax(0,idx-1,0,n,0);
        return;
    }

    long long int mid=(l+r)/2;

    if(idx<=mid)
        update(idx,value,l,mid,(2*si)+1);
    else
        update(idx,value,mid+1,r,(2*si)+2);

    tree[si]=max(tree[(2*si)+1],tree[(2*si)+2]);
}

int main()
{
    cin>>n;
    long long int i;
    for(i=0;i<n;i++)
        cin>>heights[i];
    for(i=0;i<n;i++)
        cin>>values[i];

    long long int ans=0;
    for(i=0;i<n;i++)
    {
        update(heights[i],values[i],0,n,0);
        ans=getMax(0,n,0,n,0);
    }

    cout<<ans;
}


Measured memory_bytes: 9600
#include <stdio.h>
int a[1000001];
int main(){
    int K;
    scanf("%d",&K);
    a[1]=7%K;
    for(int i=2;i<=K;i++)a[i]=(a[i-1]*10+7)%K;

    for(int i=1;i<=K;i++)if(a[i]==0){
        printf("%d\n",i);
        return 0;
    }
    printf("-1\n");
}

Measured memory_bytes: 5976
#include <bits/stdc++.h>
#ifdef DEBUG
  #include "debug.hpp"
#else
  #define DUMP(var)
#endif

using namespace std;
template< class T1, class T2 > inline istream &
operator>>( istream & fin, pair< T1, T2 > & pr )
{ fin >> pr.first >> pr.second; return fin; }
template< class T0, class T1, class T2 > inline istream &
operator>>( istream & fin, tuple< T0, T1, T2 > & t )
{ fin >> get<0>(t) >> get<1>(t) >> get<2>(t); return fin; }
template< class T > inline istream &
operator>>( istream & fin, vector< T > & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class T, size_t n> inline istream &
operator>>( istream & fin, array<T, n> & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class FwdIter> inline auto
dump(FwdIter first, FwdIter last, const char * dlm = " ") -> void {
using value_type = typename iterator_traits<FwdIter>::value_type;
copy(first, last, ostream_iterator<value_type>(cout, dlm)); }
template<typename T> vector<T> & operator--(vector<T> & a)
{ for(auto & i: a) --i; return a; }
/* @@@ ----------------------------------- */


int main(const int /*argc*/, char ** /*argv*/) {
  ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

  size_t n;
  cin >> n;
  cout << n * n * n;

  return EXIT_SUCCESS;
}


Measured memory_bytes: 256
from collections import deque

import numpy as np
import sys
#input = sys.stdin.readline

sys.setrecursionlimit(5000)

def bfs(point, field, target, H, W):
    visited = [[-1 for _ in range(W+2)] for _ in range(H+2)]
    visited[point[0]][point[1]] = 1
    que = deque()
    que.append(point)

    while True:
        v = que.popleft()
        depth = visited[v[0]][v[1]]
        for a in [(v[0]-1, v[1]), (v[0]+1, v[1]), (v[0], v[1]-1), (v[0], v[1]+1)]:
            if field[a[0]][a[1]] == 0 and visited[a[0]][a[1]] == -1:
                visited[a[0]][a[1]] = 1 + depth
                if a == target:
                    return visited[a[0]][a[1]]
                else:
                    que.append(a)
        if len(que) == 0:
            return 0

def main():
    H, W = list(map(int, input().split()))
    target = (H, W)
    field = [[-1] * (W+2)]
    number_of_whites = 0
    for _ in range(H):
        s = input()
        number_of_whites += s.count('.')
        field.append([-1] + [0 if c=='.' else -1 for c in s] + [-1])
    field += [[-1] * (W+2)]

    shortest_path = bfs((1, 1), field, target, H, W)
    if shortest_path > 0:
        print(number_of_whites - shortest_path)
    else:
        print(-1)
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 19916
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N;
  cin >> N;
  int D[N][2];
  int C = 0, Mx = 0;
  for (int i = 0; i< N; i++){
    cin >> D[i][0] >> D[i][1];
    if (D[i][0] == D[i][1]) {
      C++;
      Mx = max(Mx, C);
    }else {
      Mx = max(C, Mx);
      C = 0;
    }
  }
  if (Mx >= 3){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define R cin>>
#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 1e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long unsigned int ll;

ll solve(ll n, ll c, ll d) {
    ll ret = n;
    ll l = (c * d) / __gcd(c, d);
    ret -= n / c;
    ret -= n / d;
    ret += n / l;
    return ret;
}

int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans;
    ans = solve(b, c, d) - solve(a-1, c, d);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
const int INF = 1e6;
using namespace std;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
char marking(int n){
    if(n==0) return 'S';
    if(n==1) return 'H';
    if(n==2) return 'C';
    if(n==3) return 'D';
}
int main(){
    vector<vector<bool>> tramp(4,vector<bool>(13, false));
    int n;
    cin >> n;
    rep(i,n){
        char c; int k;
        cin >> c >> k;
        int mark;
        if(c=='S') mark = 0;
        if(c=='H') mark = 1;
        if(c=='C') mark = 2;
        if(c=='D') mark = 3;
        k--;
        tramp[mark][k] = true;
    }
    rep(i,4){
        rep(j,13){
            if(!tramp[i][j]){
                cout << marking(i) << ' ' << j+1 << endl;
            }
        }
    }
}


Measured memory_bytes: 3088
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){

    int n;
    cin >> n;
    string s[n];
    inrep(n,s);
    rep(i,0,n)sort(s[i].begin(),s[i].end());

 
    map<string,int> m;
    rep(i,0,n)m[s[i]]++;

    ll ans = 0;
    rep(i,0,n){
	ans += m[s[i]] - 1;
    }
    P(ans/2);
    return  0;
}


Measured memory_bytes: 18176
/*
[abc133] B - Good Distance
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 10;
const int MAX_D = 10;

int N, D;
int x[MAX_N][MAX_D];

bool is_ok(int p, int q) {
    int dist = 0;
    for (int d = 0; d < D; d++) {
        dist += (x[p][d] - x[q][d]) * (x[p][d] - x[q][d]);
    }
    int n = 0;
    while (n * n < dist) {
        n++;
    }
    return n * n == dist;
}

ll solve() {
    int ans = 0;
    for (int p = 0; p < N; p++) {
        for (int q = p + 1; q < N; q++) {
            if (is_ok(p, q)) {
                ans++;
            }
        }
    }
    return ans;
}

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

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::iter;
#[allow(unused_imports)]
use std::mem::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::usize;

#[allow(unused_macros)]
macro_rules! read_cols {
    ($($t:ty),+) => {{
        let mut line = String::new();
        stdin().read_line(&mut line).unwrap();

        let mut it = line.trim()
            .split_whitespace();

        ($(
            it.next().unwrap().parse::<$t>().ok().unwrap()
        ),+)
    }}
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();
    line.trim().to_string().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();

    line.trim()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn main() {
    let (a, b, q) = read_cols!(usize, usize, usize);

    let s = {
        let mut s = vec![];
        s.push(-100000000000);
        for _ in 0..a {
            s.push(read::<i64>());
        }
        s.push(100000000000);
        s.sort();
        s
    };
    let t = {
        let mut t = vec![];
        t.push(-100000000000);
        for _ in 0..b {
            t.push(read::<i64>());
        }
        t.push(100000000000);
        t.sort();
        t
    };

    for _ in 0..q {
        let x = read::<i64>();
        let is = s.binary_search(&x);
        let it = t.binary_search(&x);

        let ls = s[is.unwrap_or_else(|i| i - 1)];
        let lt = t[it.unwrap_or_else(|i| i - 1)];

        let rs = s[is.unwrap_or_else(|i| i)];
        let rt = t[it.unwrap_or_else(|i| i)];

        let p1 = x - min(ls, lt);
        let p2 = 2 * (x - ls) + (rt - x);
        let p3 = 2 * (x - lt) + (rs - x);
        let p4 = 2 * (rt - x) + (x - ls);
        let p5 = 2 * (rs - x) + (x - lt);
        let p6 = max(rs, rt) - x;

        let m = min(p1, min(p2, min(p3, min(p4, min(p5, p6)))));
        println!("{}", m);
    }
}


Measured memory_bytes: 7420
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?9e18:1e9;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};
int main(){
	ll n,a,b;
	cin>>n>>a>>b;
	vi in(n);
	rep(i,n)cin>>in[i];
	ll l=0,r=1000000010;
	while(r-l>1){
		ll h=(l+r)/2;
		ll co=0;
		rep(i,n)if(in[i]-h*b+a-b-1>0)co+=(in[i]-h*b+a-b-1)/(a-b);
		if(co<=h)r=h;
		else l=h;
	}
	cout<<r<<endl;
}








Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  sort(s.begin(), s.end());
  s.erase(unique(s.begin(), s.end()), s.end());
  if (s.size() == 26)
    cout << "None" << endl;
  else {
    int i = 0;
    while (i < s.size()) {
      if (s[i] != char('a'+i))
        break;
      i++;
    }
    cout << char('a'+i) << endl;
  }
  return 0;
}

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

int main(){

    int n; cin >> n;
    int counter = 0;
    for(int i = 0; i < n; i++){
        int input; cin >> input;
        if(input % 2 == 1) counter++;
    }

    if(counter % 2 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256