akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]
#![allow(non_snake_case)]
use proconio::{input, fastout};
use proconio::marker::{Chars, Bytes, Usize1};

use std::cmp::Ordering;
use std::collections::BinaryHeap;

#[derive(Copy, Clone)]
struct State {
    cost: usize,
    y: usize,
    x: usize
}

impl Ord for State {
    fn cmp(&self, other: &State) -> Ordering {
        other.cost.cmp(&self.cost)
    }
}

impl PartialOrd for State {
    fn partial_cmp(&self, other: &State) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}

impl PartialEq for State {
    fn eq(&self, other: &State) -> bool {
        self.cost == other.cost
    }
}

impl Eq for State {}

#[fastout]
fn main() {
    input!{
        H:usize, W:usize,
        ch:Usize1, cw:Usize1,
        dh:Usize1, dw:Usize1,
        g: [String; H]
    }
    let mut G: Vec<Vec<char>> = Vec::new();
    for x in g {
        G.push(x.chars().collect());
    }
    let arr: Vec<(i32, i32)> = vec![(0, 1), (1, 0), (0, -1), (-1, 0)];
    let mut dist = vec![vec![H*W; W]; H];
    dist[ch][cw] = 0;
    let mut q = BinaryHeap::new();
    q.push(State{cost:0, y:ch, x:cw});
    while let Some(State{cost, y, x}) = q.pop() {
        if cost > dist[y][x] { continue; };
        for &(du, dv) in &arr {
            let nu = y.wrapping_add(du as usize);
            let nv = x.wrapping_add(dv as usize);
            if nu < H && nv < W && G[nu][nv] == '.' && dist[nu][nv] > cost {
                dist[nu][nv] = cost;
                q.push(State{cost, y:nu, x:nv});
            }
        }
        for du in -2i32..3 {
            for dv in -2i32..3 {
                let nu = y.wrapping_add(du as usize);
                let nv = x.wrapping_add(dv as usize);
                if nu < H && nv < W && G[nu][nv] == '.' && dist[nu][nv] > cost + 1 {
                    dist[nu][nv] = cost + 1;
                    q.push(State{cost:cost + 1, y:nu, x:nv});
                }
            }
        }
    }
    let ans = dist[dh][dw];
    println!("{}", if ans == H * W {-1} else {ans as i32});
}


Measured memory_bytes: 15300
n = int(input())
a = list(map(int,input().split()))
a.insert(0,0)
a.append(0)

default= 0
tmp = 0
for i in range(n+2):
    default += abs(a[i]-tmp)
    tmp = a[i]

for i in range(1,n+1):
    if a[i-1] <= a[i] <= a[i+1] or a[i-1] >= a[i] >= a[i+1]:
        print(default)
    else:
        distance = abs(a[i] - a[i-1]) + abs(a[i+1] - a[i])
        sa = distance - abs(a[i+1] - a[i-1])
        print(default-sa)


Measured memory_bytes: 14048
import java.util.Scanner;
class Main{
  public static void main(String[] args){
  	
    Scanner scan = new Scanner(System.in);
    
    int n = scan.nextInt();
    int r = scan.nextInt();
    int res = 0;
    int k = 0;
    if(n<10){
     k = 100*(10-n);
     res = r + k;
    }else if(n>=10){
      res = r;
    }
    System.out.println(res);
  }
}

Measured memory_bytes: 21844
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()
#define pb push_back

#define error(x) cout << #x << " = " << x << endl

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

const int N = 1e5 + 20, mod = 998244353;
int n, d[N];
int cnt[N];

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

	cin >> n;
	for (int i = 0; i < n; i++) cin >> d[i], cnt[d[i]]++;

	if (d[0] || cnt[0] > 1) return cout << "0\n", 0;

	int ans = 1;
	int last = 0;
	for (int i = 1; i < n; i++)
		ans = 1ll * ans * cnt[d[i] - 1] % mod;

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


Measured memory_bytes: 1024
MOD = 10**9 + 7
N, K = map(int, input().split())
if K - N == 1:
    print(1)
    exit()
ans = 1
left = 0
right = 0
for i in range(1,K):
    left += i
for i in range(N-K+1,N+1):
    right += i
ans += right - left + 1
ans %= MOD
for i in range(K+1,N+1):
    left += i - 1
    right += N - (i-1)
    ans += right - left + 1
    ans %= MOD
print(ans)

Measured memory_bytes: 9184
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define all(x) (x).begin() , (x).end()
#define f first
#define s second
#define pr(x) cout<<x<<endl;
#define pr2(x,y) cout<<x<<" "<<y<<endl;
#define pr3(x,y,z) cout<<x<<" "<<y<<endl;
#define prv(v) for(auto x:v) cout<<x<<" ";
using namespace std;
 
const ll N =(1e5+5);
const ll MOD = 1e9+7;
const ll INF = 1e16;
const ll LOG = 29;

long long binpow(long long a, long long b) {
     a %= MOD;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a)%MOD ;
        a = (a * a)%MOD ;

        
        b >>= 1;
    }
    res%=MOD;
    return res;
}
ll dp2[404][404];
ll dp[404][404];
void solve(){
    ll n;
    cin>>n;
    vll a(n);
    for(int i= 0;i<n;i++){
        cin>>a[i];
    }
    ll l,q;
    cin>>l>>q;
    ll dp[25][n];
    for(int i= 0;i<n;i++){
        auto it = upper_bound(all(a),a[i]+l);
        it--;
        dp[0][i] = distance(a.begin(),it);   
    }
    for(int i = 1;i<25;i++){
        for(int j = 0;j<n;j++){
            dp[i][j] = dp[i-1][dp[i-1][j]];
        }
    }

    while(q--){
        ll a,b;
        cin>>a>>b;
        --a;
        --b;
        if(a>b)swap(a,b);
        ll ans = 0;
        for(ll i =24;i>=0;i--){
            if(dp[i][a] < b){
                ans |= (1ll<<i);
                a = dp[i][a];
            }
        }
        ans++;
        cout<<ans<<endl;
    }
}






int main()
{
    ios_base::sync_with_stdio(0);
     cin.tie(NULL);
     
    ll t=1;
    while(t--){
        solve();
    }
     
 
 
    return 0;     
    
        
}

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

using namespace std;

#define int long long 
#define INF 1e9
#define LINF 1e18

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[] = { 0, 0, 1, -1 };
const int dx[] = { 1, -1, 0, 0 };

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int imos[102];

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

    int N;
    int p[100];
    cin >> N;
    int res = 1;
    for(int i = 0; i < N; ++i) {
        cin >> p[i];
        ++imos[1]; --imos[p[i] + 1];
    }
    for(int i = 1; i <= 100; ++i) imos[i + 1] += imos[i];
    for(int i = 1; i <= 100; ++i) {
        if(i <= imos[i]) res = i;
    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 3212
import math
N=int(input())

def isPrime(n):
  for k in range(2,int(math.sqrt(n))+2):
    if n%k==0:
      return False
  else:
    return True

plist=[2]
p=11
while(len(plist)<N):
  if p%5==1 and isPrime(p):
    plist.append(p)
  p+=10
    
print(" ".join(map(str,plist)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<pair<int, int>> vp(n);
  rep(i, n){
    int a, b;
    cin >> a >> b;
    vp.at(i) = {a-b, a+b};
  }
  sort(vp.begin(), vp.end(), 
  [](const auto &l, const auto &r){
    return l.second < r.second;
  });
  int ans = 0;
  int bf = -2e9;
  rep(i, n){
    if(bf <= vp.at(i).first){
      ans++;
      bf = vp.at(i).second;
    }
  }
  cout << ans << endl;
  return 0;
}

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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, k;
  cin >> n >> k;
  
  vector<vector<ll>> x(n, vector<ll>(2));
  for(int i = 0; i < n; i++) cin >> x.at(i).at(1) >> x.at(i).at(0);
  
  sort(x.rbegin(), x.rend());
  
  ll oisisa = 0;
  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
  vector<ll> t(n + 1);
  for(int i = 0; i < k; i++){
    oisisa += x.at(i).at(0);
    t.at(x.at(i).at(1))++;
    pq.push(make_pair(x.at(i).at(0), x.at(i).at(1)));
  }
  
  ll count = 0;
  for(int i = 1; i <= n; i++){
    if(t.at(i) > 0) count++;
  }
  
  ll ans = oisisa + count * count;
  
  for(int i = k; i < n; i++){
    if(t.at(x.at(i).at(1)) > 0) continue;
    pair<ll, ll> p;
    while(!pq.empty()){
      p = pq.top();
      pq.pop();
      if(t.at(p.second) > 1){
        t.at(p.second)--;
        t.at(x.at(i).at(1))++;
        count++;
        oisisa -= p.first;
        oisisa += x.at(i).at(0);
        pq.push(make_pair(x.at(i).at(0), x.at(i).at(1)));
        break;
      }
    }
    ans = max(ans, oisisa + count * count);
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 8692
#AtcoderABC081 #2

def div(A,N):
	for n in range(N):
		A[n] = A[n]//2

N = int(input())
A = list(map(int, input().split(' ')))
f = 1
cnt = 0
ans = 0

while True:
	for a in A:
		if(a%2 == 0): cnt += 1
	if cnt == N: 
		div(A,N)
		ans += 1
		cnt = 0
	else: break

print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

void f(int n){
	if(n>=8)f(n/8);
	n%=8;
	if(n<4)cout<<n;
	else if(n==4)cout<<5;
	else cout<<n+2;
}

int main() {
	int n;
	while(n=in()){
		f(n);
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 884
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);

	int a, b, c, k; cin >> a >> b >> c >> k;

	int ans = 0;
	if (k < a)
		ans = k;
	else if (k >= a && k <= a + b)
		ans += a;
	else
		ans = a - (k - a - b);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
#define int long long

int f(int b, int n) {
  if (n < b) return n;
  return f(b, n / b) + (n % b);
}

signed main() {
  int n, s;
  cin >> n >> s;
  if (n < s) {
    cout << -1 << endl;
    return 0;
  }
  if (n == s) {
    cout << n + 1 << endl;
    return 0;
  }
  for (int i = 2; i <= sqrt(n); i++) {
    if (f(i, n) == s) {
      cout << i << endl;
      return 0;
    }
  }
  vector<int> v;
  for (int i = 1; i <= sqrt(n); i++) {
    if ((n - s) % i) continue;
    int b = (n - s) / i + 1;
    if (f(b, n) == s) {
      v.push_back(b);
    }
  }
  if (v.size() == 0) {
    cout << -1 << endl;
  } else {
    sort(v.begin(), v.end());
    cout << v[0] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;

int main() {
	int y, m, d;
	scanf("%d/%d/%d", &y, &m, &d);
	bool heisei = 0;
	if (y < 2019) heisei = 1;
	else if (y == 2019) {
		if (m < 4) heisei = 1;
		else if (m == 4 && d <= 30) heisei = 1;
	}
	if (heisei) cout << "Heisei" << endl;
	else cout << "TBD" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N=100010;
int main(){
	ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
	int i,j,n,a[N],dp[N];
	cin>>n;
	for(i=0;i<n;++i) cin>>a[i];
	dp[0]=0; dp[1]=abs(a[1]-a[0]);
	for(i=2;i<n;++i){
		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	}
	cout<<dp[n-1];
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define PI acos(-1.0)
#define mod 1e9+7
using namespace std;
bool dp[100005];
int arr[110];
int main()
{
    int n, k;
    cin>>n>>k;
    for(int i=0; i<n; i++) scanf("%d", &arr[i]);
    for(int stone=1; stone<=k; stone++)
    {
        for(int i=0;i<n; i++)
        {
            if(stone>=arr[i])
            {
                if(!dp[stone-arr[i]])
                    dp[stone]=true;
            }
        }
    }
    if(dp[k])
        printf("First\n");
    else printf("Second\n");
    return 0;
}


Measured memory_bytes: 384
from sys import stdin
di = {}
n = int(stdin.readline())
a = [0] + map(int,stdin.readline().split())
ans = 0
for i in xrange(1,n):
    if a[i]==i:
        x = a[i]
        a[i] = a[i+1]
        a[i+1] = x
        ans+=1
if a[n]==n:
    ans+=1
print ans

Measured memory_bytes: 11328
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)
import Data.List

solve :: String -> String
solve n
    | n1 == n3 = "Yes"
    | otherwise = "No"
    where
        n1 = n!!0
        n3 = n!!2


main :: IO ()
main = do
    n <- getLine
    putStrLn $ solve n


Measured memory_bytes: 380
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define EPS 1e-10
using namespace std;
typedef long long llong;
int main() {
	int n;
	while (cin >> n, n) {
		vector<int>v(n);
		for (int i = 0; i < n; i++)cin >> v[i];
		sort(v.begin(), v.end());
		int a = 100000000;
		for (int i = 1; i < n; i++) {
			a = min(a, abs(v[i] - v[i - 1]));
		}
		cout << a << endl;
	}
	return 0;
}

Measured memory_bytes: 3140
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n;
	cin >> n;
	int a[200001];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int Mi = a[0];
	int count = 0;
	for (int i = 0; i < n; i++) {
		Mi = min(Mi, a[i]);
		if (Mi == a[i]) {
			count += 1;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 1024
import itertools
n, m = map(int, input().split())

edges = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    edges[a - 1].append(b - 1)
    edges[b - 1].append(a - 1)
cnt = 0
for path in itertools.permutations(range(1, n)):
    # 0はじまり
    path = [0] + list(path)
    flg = True
    for i in range(1, n):
        if path[i] not in edges[path[i-1]]:
            flg = False
            break
    if flg:
        cnt += 1

print(cnt)

Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;

int main(){
  double x, h;
  while(cin >> x >> h && x != 0 || h != 0) {
    printf("%f\n", 1.0 * x * ( x + sqrt(4.0 * h * h + x * x)));
  }
  
  return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 998244353;
int gcd(int a, int b)
{
	int c;
	while (a != 0) {
		c = a; a = b%a;  b = c;
	}
	return b;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	res = A[0];
	for (int i = 1; i < N; i++) {
		res = (res * gcd(A[i], i)) % MOD;
	}
	cout << res << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
using namespace std;
int main(){
	string s;
	cin >> s;
	if(s == "SSS") printf("0\n");
	if(s == "RSS" || s == "RSR" || s == "SRS" || s == "SSR") printf("1\n");
	if(s == "RRS" || s == "SRR") printf("2\n");
	if(s == "RRR") printf("3\n");
	return 0;
}

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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

const lli e5 = 1 << 20;
const lli mod = 1000000007;
const lli e3 = 1 << 13;
const lli INF = 1ll << 62;

lli n,x;
lli p[e5];
lli b[e5];

lli dfs(lli l,lli x){
  if(x == 0) return 0;
  if(p[l]+b[l] == x) return p[l];
  if(p[l-1]+b[l-1]+2 < x) return dfs(l-1,x-(p[l-1]+b[l-1])-2) + p[l-1] + 1;
  if(p[l-1]+b[l-1]+2 == x) return p[l-1] + 1;
  if(p[l-1]+b[l-1]+1 == x) return p[l-1];
  return dfs(l-1,x-1);
}

int main(){
  cin >> n >> x;
  p[0] = 1;
  b[0] = 0;
  for(lli i = 0;i < n;i++){
    p[i+1] = 0 + p[i] + 1 + p[i] + 0;
    b[i+1] = 1 + b[i] + 0 + b[i] + 1;
  }
  cout << dfs(n,x) << endl;
}


Measured memory_bytes: 2304
#import math
#import bisect
#import numpy as np
#import itertools
#import copy
import sys

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    a = int(input())
    s = input()

    if a >= 3200:
        print(s)
    else:
        print('red')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
using System;

public class hello
{
    public static void Main()
    {
        var w = Console.ReadLine().Trim();
        var count = 0;
        while (true)
        {
            string[] s = Console.ReadLine().Trim().Split(' ');
            if (s[0] == "END_OF_TEXT") break;
            for (int i = 0; i < s.Length; i++)
                if (w.ToUpper() == s[i].ToUpper())
                    count++;
        }
        Console.WriteLine(count);

    }
}


Measured memory_bytes: 17876
#include <bits/stdc++.h>
using namespace std;
// flow from KACTL
typedef long long LL;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef ll Flow;

struct Edge {
	int dest, back;
	Flow f, c;
};
typedef vector<vector<Edge> > graph;

struct PushRelabel {
	graph g;
	vector<Flow> ec;
	vector<Edge*> cur;
	vector<vi> hs; vi H;
	PushRelabel(int n) : g(n), ec(n), cur(n), hs(2*n), H(n) {}

	void add_edge(int s, int t, Flow cap, Flow rcap=0) {
		if (s == t) return;
		Edge a = {t, sz(g[t]), 0, cap};
		Edge b = {s, sz(g[s]), 0, rcap};
		g[s].push_back(a);
		g[t].push_back(b);
	}

	void add_flow(Edge& e, Flow f) {
		Edge &back = g[e.dest][e.back];
		if (!ec[e.dest] && f) hs[H[e.dest]].push_back(e.dest);
		e.f += f; e.c -= f; ec[e.dest] += f;
		back.f -= f; back.c += f; ec[back.dest] -= f;
	}
	Flow maxflow(int s, int t) {
		int v = sz(g); H[s] = v; ec[t] = 1;
		vi co(2*v); co[0] = v-1;
		rep(i,0,v) cur[i] = g[i].data();
		trav(e, g[s]) add_flow(e, e.c);

		for (int hi = 0;;) {
			while (hs[hi].empty()) if (!hi--) return -ec[s];
			int u = hs[hi].back(); hs[hi].pop_back();
			while (ec[u] > 0)  // discharge u
				if (cur[u] == g[u].data() + sz(g[u])) {
					H[u] = 1e9;
					trav(e, g[u]) if (e.c && H[u] > H[e.dest]+1)
						H[u] = H[e.dest]+1, cur[u] = &e;
					if (++co[H[u]], !--co[hi] && hi < v)
						rep(i,0,v) if (hi < H[i] && H[i] < v)
							--co[H[i]], H[i] = v + 1;
					hi = H[u];
				} else if (cur[u]->c && H[u] == H[cur[u]->dest]+1)
					add_flow(*cur[u], min(ec[u], cur[u]->c));
				else ++cur[u];
		}
	}
};
int main(){
	int n;
	cin >> n;
	int z[n];
	map<int,int> f;
	for(int i = 0; i < n; i++){
		cin >> z[i];
		f[z[i]]++;
		f[z[i]+1]++;
	}
	vector<int> r;
	vector<int> odd, even;
	for(map<int,int>::iterator it = f.begin(); it != f.end(); it++){
		if(it->second == 1){
			r.push_back(it->first);
			if(it->first % 2){
				odd.push_back(it->first);
			} else {
				even.push_back(it->first);
			}
		}
	}
	PushRelabel s(300);
	for(int i = 0; i < 100; i++){
		s.add_edge(200,i,1);
		s.add_edge(i+100,201,1);
	}
	for(int i = 0; i < odd.size(); i++){
		for(int j = 0; j < even.size(); j++){
			int a = odd[i];
			int b = even[j];
			//cout << a << " " << b << endl;
			int p = abs(a-b);
			int ok = 1;
			if(p <= 1) ok = 0;
			for(int c = 2; c*c <= p; c++){
				if(p % c == 0){
					ok = 0;
					break;
				}
			}
			if(ok){
				s.add_edge(i,j+100,1);
			}
		}
	}
	int flow = (int)s.maxflow(200,201);
	int o1 = (int)odd.size() - flow;
	int e1 = (int)even.size() - flow;
	int ans = flow;
	ans += (o1/2)*2;
	ans += (e1/2)*2;
	o1 %= 2;
	e1 %= 2;
	if(o1 >= 1){
		ans += 3;
	}
	cout << ans << endl;
}



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

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

	vector<int> vec(n * d);

	for (int i = 0; i < n * d; i++) {
		cin >> vec.at(i);
	}

	int out = 0;

	for (int i = 0; i < n - 1; i++) {
		for (int j = i + 1; j < n; j++) {
			int distance = 0;
			for (int k = 0; k < d; k++) {
				distance += (vec.at(i * d + k) - vec.at(j * d + k)) * (vec.at(i * d + k) - vec.at(j * d + k));
			}
			double distance2 = sqrt(distance);
			if (ceil(distance2) == floor(distance2)) {
				out++;
			}
		}
	}

	cout << out << endl;

	return 0;
}


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

int main(){
    int n, i;
    cin >> n;
    set<string> st;
    for(i=0; i<n; i++){
        string s;
        cin >> s;
        st.insert(s);
   }
    cout << st.size() << endl;;
    
}

Measured memory_bytes: 19124
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1 << 30;

using namespace std;

using ll = long long;
using P = tuple<int, int>;
using iarr = valarray<int>;

int main()
{
    int N;
    cin >> N;
    vector<string> s(N);
    map<string, ll> m;
    for(int i = 0; i < N; ++i){
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
        m[s[i]]++;
    }
    ll cnt = 0;
    for(auto& pair : m){
        cnt += pair.second * (pair.second - 1) / 2;
    }

    cout << cnt << endl;

    return 0;
}



Measured memory_bytes: 18176
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <list>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <math.h>

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

using namespace std;

/*
int main(){
	int n;

	cin >> n;

	while(n--){
		int input = 0;
		int left = 0, right = 0;
		bool achieve = true;
		REP(i, 10){
			cin >> input;
			if(left > input && right > input){
				//両方入らなかったら
				achieve = false;
				break;
			}
			else{
				//どっちかにしか入らない場合
				
				if(left > input || right > input){
					//入る方探して入れる
					if(input > left){
						left = input;
					}
					else{
						right = input;
					}
				}
				//どっちにも入る場合
				else{
					//先に入ってる数字が大きい方に入れる
					if(left > right){
						left = input;
					}
					else{
						right = input;
					}
				}
			}
		}
		cout << (achieve ? "YES" : "NO") << endl;
	}
	return 0;
}
*/
int main(){
    int n;
 
    cin >> n;
    while(n--){
        int a;
        bool p = true;
        int b = 0, c = 0;
        for(int i = 0; i < 10; i++){
            cin >> a;
            if(p){
                if(a > b){
                    b = a;
                }else if(a > c){
                    c = a;
                }else{
                    p = false;
                }
            }
        }
         
        if(p){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
 
    return 0;
}

Measured memory_bytes: 1152
import numpy as np
n=int(input())
l=np.array(list(map(int,input().split())))
c=0
for i in range(n):
  for j in range(n-i):
    if 0 in l[i:n-j]:
      pass
    else:
      c+=min(l[i:n-j])
      l[i:n-j]=l[i:n-j]-np.array([min(l[i:n-j])]*(n-j-i))
print(c)

Measured memory_bytes: 12396
s = input()
t = input()

s_counter = []
t_counter = []
for c in 'abcdefghijklmnopqrstuvwxyz':
    s_counter.append(s.count(c))
    t_counter.append(t.count(c))

s_counter.sort()
t_counter.sort()

ans = 'Yes' if s_counter == t_counter else 'No'
print(ans)

Measured memory_bytes: 3632
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef unsigned int uint;

int temp[22], temq[22];
int *pp = temp + 10;
int *qq = temq + 10;
int ok[20];

vector <ll> S;

ll dfs(vector <ll> &V, int x, ll D, ll now, ll cc = 1) {
	if(x && abs(D-now) > S[x-1]) return 0;
	if(x == sz(V)){
		if(D == now) return cc;
		return 0;
	}
	int *rr = (x ? pp : qq);
	ll res = 0;
	for(int i=-9;i<=9;i++) {
		res += dfs(V, x + 1, D, now + V[x] * i, cc * rr[i]);
	}
	return res;
}

ll Do(vector <ll> V, ll D) {
	int m = sz(V);
	S.resize(m);
	for(int i=m-1;i;i--) {
		S[i-1] = S[i] + 9 * V[i];
	}
	return dfs(V, 0, D, 0);
}

void solve(){
	ll D; cin >> D;
	ll P[19] = {1};
	rep(i, 10)rep(j, 10) pp[i-j]++;
	rep(i, 10)rep(j, 10) if(j != 0) qq[i-j]++;
	for(int i=1;i<=18;i++) P[i] = P[i-1] * 10;
	ll ans = 0;
	for(int L=2;L<=18;L++){
		vector <ll> V;
		for(int i=0;i<L/2;i++) {
			V.pb(P[L-i-1] - P[i]);
		}
		if(L % 2 == 0) ans += Do(V, D);
		else ans += Do(V, D) * 10;
	}
	printf("%lld\n", ans);
}

int main(){
	int Tc = 1; //scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int n,m,cnt=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&m);
        if(i%2==1&&m%2==1)cnt++;
    }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 1732
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k  = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        int[] a = new int[q];
        for(int i=0;i<q;i++){
            a[i] = Integer.parseInt(sc.next());
        }    
        int[] point = new int[n];
        for(int i=0;i<q;i++){
            int ans = a[i]-1;
            point[ans]++;
        }
        for(int i=0;i<n;i++){
            if(k - q + point[i]>0){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }
        }
    }
}

Measured memory_bytes: 67544
#include <stdio.h>
#include <string>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;
const static int MAX = 10;

int n, k;
char S[MAX], r;
string s;

int main() {
    scanf("%d", &n);
    scanf("%s", S);
    s = S;
    scanf("%d", &k);
    r = s[k-1];

    for ( int i = 0; i < n; i++ ) {
        if ( s[i] != r ) {
            s[i] = '*';
        }
    }
    
    printf("%s\n", s.c_str());
    return 0;
}



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

int main(){
  int n,x;
  cin >> n >> x;
  int m[n];
  int minm = 10000;
  int ans;
  int all = 0;
  for(int i = 0;i < n;i++){
    cin >> m[i];
    if(minm > m[i]){
      minm = m[i];
    }
    all += m[i];
  }

  ans = n;
  x -= all;
  ans += x/minm;

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

Measured memory_bytes: 256
#include<iostream>
#define rep(i,n)for(int i=0;i<n;i++)
#define l long long
using namespace std;l q,x,y,f[99]={0,1},m=1e9+7;main(){cin>>q;rep(i,97)f[i+2]=f[i]+f[i+1];rep(i,q){cin>>x>>y;if(x>y)swap(x,y);if(y<=2){cout<<1<<" "<<(y==1?1:x==1?2:4)<<" ";continue;}rep(j,99){if(x<f[j]||y<f[j+1]){l a=x==1?2:1;rep(k,j-2){l n=f[j-1]+f[j-3-k]*f[k+2],m=f[j]+f[j-2-k]*f[k+2];if(n<=x&&m<=y)a+=(y-m)/n+1;}if(f[j]<=x){a++;rep(k,j-2)a+=(x-f[j])/(f[j-2-k]*f[k+2]);}cout<<j-2<<" "<<a%m<<" ";j=99;}}}}

Measured memory_bytes: 4320
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    x, k, d = map(int, input().split())
    cnt = abs(x) // d
    if cnt >= k:
        res = abs(x) - d * k
        print(res)
    else:
        now = abs(x) - cnt * d
        k -= cnt
        if k % 2 == 0:
            print(now)
        else:
            print(abs(now - d))


if __name__ == '__main__':
    resolve()


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
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; }
//end



int main(){
   int n,x; scanf("%d%d",&n,&x);
   vector<int> a(n),mi(n);
   rep(i,0,n)scanf("%d",&a[i]),mi=a;
   ll res=INF;
   rep(k,0,n){
      ll sub=1LL*k*x;
      rep(i,0,n)chmin(mi[i],a[(i-k+n)%n]);
      rep(i,0,n)sub+=mi[i];
      chmin(res,sub);
   } printf("%lld\n",res);
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
bool bucket[4];

int main() {
  int A, B; cin >> A >> B;
  bucket[A] = true;
  bucket[B] = true;
  for(int i = 1; i <= 3; i++) {
    if(!bucket[i]) cout << i << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

x,a,b = map(int,input().split())

if(abs(a-x) < abs(b-x)):
    print("A")
else:
    print("B")

Measured memory_bytes: 3572
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int C = sc.nextInt();
		char[] s = sc.next().toCharArray();
		int[] L = new int[N], R = new int[N];
		int sum = 0;
		for(int i = 0; i < N; i++) {
			if(s[i] == 'o') {
				L[sum] = i;
				sum++;
				i += C;
			}
			if(sum == K)
				break;
		}
		for(int i = N-1; i >= 0; i--) {
			if(s[i] == 'o') {
				sum--;
				R[sum] = i;
				i -= C;
			}
			if(sum == 0)
				break;
		}
		for(int i = 0; i < K; i++)
			if(L[i] == R[i])
				System.out.println(L[i]+1);
	}
}


Measured memory_bytes: 55088
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

set<pair<int, int>> E[100001];
int D[100001];
queue<pair<int, int>> que;
void sagasu(int p, int d, int c) {
	D[p] = min(D[p], d);
	que.push(mp(p, d));

	auto itr1 = E[p].lower_bound(mp(c, 0));
	auto itr2 = E[p].lower_bound(mp(c + 1, 0));

	while (itr1 != itr2) {
		int j = (*itr1).second;
		E[p].erase(itr1);
		sagasu(j, d, c);

		itr1 = E[p].lower_bound(mp(c, 0));
		itr2 = E[p].lower_bound(mp(c + 1, 0));
	}
}

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


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

	rep(i, M) {
		int p, q, c;
		cin >> p >> q >> c;
		E[p].insert(mp(c, q));
		E[q].insert(mp(c, p));
	}

	rep1(i, N) D[i] = 1e9;
	D[1] = 0;
	que.push(mp(1, 0));
	while (que.size()) {
		auto p = que.front();
		que.pop();
		int i = p.first;
		int d = p.second + 1;
		
		auto e = E[i].begin();
		while (E[i].size()) {
			e = E[i].begin();
			int j = (*e).second;
			int c = (*e).first;
			E[i].erase(e);
			sagasu(j, d, c);
		}
	}

	if (D[N] == 1e9) co(-1);
	else co(D[N]);

	Would you please return 0;
}

Measured memory_bytes: 56576
_, k = map(int, input().split())
s = input()

a = []
cnt_one = 0
cnt_zero = 0

if s[0] == "0":
    a.append(0)

for i in s:
    if i == "1":
        cnt_one += + 1
        if cnt_zero != 0:
            a.append(cnt_zero)
            cnt_zero = 0
    else:
        cnt_zero += 1
        if cnt_one != 0:
            a.append(cnt_one)
            cnt_one = 0

a.append(max(cnt_zero, cnt_one))

if s[-1] == "0":
    a.append(0)

n = len(a)
right = 2 * k + 1
up = sum(a[:right])
max_up = up

for i in range((n - right) // 2):
    new_up = up + a[right + i * 2] + a[right + i * 2 + 1] - a[i * 2] - a[i * 2 + 1]
    max_up = max(max_up, new_up)
    up = new_up

print(max_up)

Measured memory_bytes: 4480
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <climits>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << -1; return;}
#define yes {cout << "Yes"; return;}
#define mkp make_pair
#define mkt make_tuple
#define cerr if(0) cerr

void solve() {
    int n; cin >> n; cout << n * n;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
#define lli long long int
#define pb push_back
#define mod2 1000000007
#pragma GCC optimize ("-O3")
#define mod 998244353
#define MAXN 1000000000
#define v32 vector<int>
#define v64 vector<lli>
#define v1024 vector <vector <int>>
#define v4096 vector <vector <lli>>
#define vt vector
#define f(x, y, z) for (lli x = y; x < z; x++)
#define fd(x, y, z) for (lli x = y; x > z; x--)
#define lb lower_bound
#define ld long double
#define m64 map<lli,lli>
#define m32 map<int,int>
#define m64it map<lli,lli>::iterator
#define m32it map<int,int>::iterator
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ist insert
#define endl "\n"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define p_q priority_queue 
#define min_p_q priority_queue <int,vt <int>,greater <int>>
using namespace std;
using namespace __gnu_pbds; 

template <typename T> 
void DEBUG_ARR(vt<T> a,char c)
{
	f(i,0,a.size())cout<<a[i]<<c;
	cout<<"\n";
}

lli tmod(lli x,lli m=mod){return (x%m+m)%m;}//USE AT YOUR OWN RISK
lli power(lli x, lli y,lli m=mod) 
{
    lli res = 1;  
   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x)%m; 
        y = y>>1; 
        x = (x*x)%m;  
    }
    if(res<0)
       res+=m; 
    return res; 
}

// lli fact[2000009];
// lli ncr(lli n,lli r){
//     lli ans=fact[n];
//     if(r>n)return 0;
//     ans=(ans*power(fact[n-r],mod-2))%mod;
//     ans=(ans*power(fact[r],mod-2))%mod;
//     return ans;
// }

int main() 
{ 
    // fact[0]=1;
    // f(i,1,2000001)fact[i]=(i*fact[i-1])%mod;
    fastio;
    int t;
    // cin>>t;	
    t=1;
	while(t--){
        lli k,n;cin>>k>>n;
        lli a[n];f(i,0,n)cin>>a[i];
        sort(a,a+n);
        lli ans=(a[n-1]-a[0]);
        f(i,1,n){
            ans=min(ans,k-(a[i]-a[i-1]));
        }
        cout<<ans<<"\n";
    }   
    return 0; 	
}


Measured memory_bytes: 1792
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        int n=Integer.parseInt(br.readLine());
        int mx=(int)1e7+1;
        int arr[]=new int[mx];
        Arrays.fill(arr,1);
        for(long i=2;i<=mx-1;i++)
        {
            for(long j=i;j<=mx-1;j+=i)
            arr[(int)j]++;
        }
        long sum=1;
        for(int i=2;i<=n;i++)
        sum=sum+(1L*arr[i]*i);
        pw.println(sum);
        pw.flush();
        pw.close();
    }
}

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

int main() {
  
  int N,M;
  cin >> N >> M;
  
  vector<int> A(M);
  vector<int> B(M);
  
  for(int i=0; i<M; i++){
    cin >> A.at(i) >> B.at(i);
  }
    
  
  for(int i=1; i<N+1; i++){
    int cnt = 0;
    for(int j=0; j<M; j++){
      if(A.at(j) == i){
        cnt++;
      }
     
      if(B.at(j) == i){
        cnt++;
      }
       
    }
    
    cout << cnt << endl;
  }
  
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// __uint128_t
const ll MOD = 1e9+7;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


struct edge{
    ll v;
    ll u;
};

bool operator< (const edge &edge1, const edge &edge2){
    return edge1.v < edge2.u;
};

int main(){
    ll N; cin >> N;
    priority_queue<pair<ll, edge>, vector<pair<ll, edge>>, greater<pair<ll, edge>>> Q;
    UnionFind tree(N);
    vector<pair<ll, ll>> X(N), Y(N);

    for(int i = 0; i < N; i++){
        ll x, y; cin >> x >> y;
        X[i] = {x, i}, Y[i] = {y, i};
    }
    sort(X.begin(), X.end());
    sort(Y.begin(), Y.end());
    for(int i = 0; i < N-1; i++){
        ll d = X[i+1].first - X[i].first;
        ll v = X[i].second, u = X[i+1].second;
        edge e; e.u=u, e.v=v;
        Q.push({d, e});
    }

    for(int i = 0; i < N-1; i++){
        ll d = Y[i+1].first - Y[i].first;
        ll v = Y[i].second, u = Y[i+1].second;
        edge e; e.u=u, e.v=v;
        Q.push({d, e});
    }


    ll ans = 0;
    while(!Q.empty()){
        auto p = Q.top();
        Q.pop();
        ll d = p.first;
        ll v = p.second.v, u = p.second.u;
        if(tree.root(v) != tree.root(u)){
            ans += d;
            tree.unite(v, u);
        }
    }
    cout << ans << endl;
    



}


Measured memory_bytes: 13296
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>
using namespace std;
#define All(v) (v).begin(),(v).end()
const long long mod = 1000000007;
const long long inf = mod*mod;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
signed main(){
    int n;
    cin>>n;
    map<string,long long> d;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        sort(All(s));
        d[s]++;
    }
    long long  res = 0;
    for(auto it:d){
        res+=it.second*(it.second-1)/2;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)

int main() {
    ll A, B, N; cin >> A >> B >> N;
    ll k, ans;
    if (N + 1 >= B) {
        k = (N + 1) / B;
        ans = A * (B * k - 1) / B - A * ((B * k - 1) / B);
        cout << ans << endl;
        return 0;
    }

    ans = A * N / B - A * (N / B);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#include <numeric>
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)




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

	ll A, B, C, K;
	cin >> A >> B >> C >> K;
	if (K <= A)puts(K);
	else if (A < K && K <= A + B)puts(A);
	else puts(2LL*A + B - K);
	return 0;
}

Measured memory_bytes: 3640
#include<cstdio>

int search(int *A,int n,int key){
  int i=0;
  A[n]=key;
  while(A[i]!=key)i++;
  
  return i!=n;
}

int main() {
  int n;
  scanf("%d",&n);
  
  int A[10001];
  for(int i=0;i<n;i++){
    scanf("%d",A+i);
  }
  
  int q;
  scanf("%d",&q);
  
  int key,sum=0;
  for(int i=0;i<q;i++){
    scanf("%d",&key);
    if(search(A,n,key)){
      sum++;
    }
  }
  
  printf("%d\n",sum);
  
  return 0;
}

Measured memory_bytes: 2760
//Dirichlet's Theorem on Arithmetic Progressions
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

int p[1000000];
vector<ll> prime;

int main(){
  memset(p, 0, sizeof(p));
  prime.push_back(2); p[2]=1;
  for(ll i=3; i<1000000; i+=2){
    bool flag=true;
    for(ll j=0; j<prime.size() && i>=prime[j]*prime[j]; j++){
      if(i%prime[j]==0){flag=false; break;}
    }
    if(flag){p[i]=1; prime.push_back(i);}
  }

  while(true){
    ll a, d, n;
    cin>>a>>d>>n;
    if(a==0&&d==0&&n==0)break;
    int cnt=0;
    ll ans=a-d;
    do{
      ans+=d;
      cnt+=p[ans];
    }while(cnt!=n);
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 5888
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
	int n,s=0,i;
	scanf("%d",&n);
	for(i=1;i*i<=n;i++)
	{
		if(i*i==n){s=i*i;break;}
	}
	if(i*i>n)s=(i-1)*(i-1);
	printf("%d\n",s);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int sol;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, x;
    cin >> n >> x;
    int a[100];
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a, a + n);
    for (int i = 0; i < n; ++i)
    {
        if (a[i] <= x)
            x -= a[i], a[i] = 0, sol++;
    }
    if (x > 0 && a[n - 1] == 0)
        sol--;
    cout << sol;
}


Measured memory_bytes: 256
# 先頭から見ていく
# A_i // 2個は自分同士でペアを作ってよい
# 1枚余ったら、A_i+1が0でなければA_i+1から1減らしてペアを作る。
# この貪欲でOK

import sys
readline = sys.stdin.readline

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

ans = 0
for i in range(N):
  pair, mod = divmod(A[i],2)
  ans += pair
  if mod == 1 and i != N - 1 and A[i + 1] > 0:
    ans += 1
    A[i + 1] -= 1
  
print(ans)

Measured memory_bytes: 7072
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;

    long* A = new long[X];
    for (int i = 0; i < X; i++) {
        cin >> A[i];
    }
    
    long* B = new long[Y];
    for (int i = 0; i < Y; i++) {
        cin >> B[i];
    }
    
    long* C = new long[Z];
    for (int i = 0; i < Z; i++) {
        cin >> C[i];
    }

    long* E = new long[X*Y];
    for (int i = 0; i < X; i++) {
        for (int j = 0; j < Y; j++) {
            E[i*Y + j] = A[i] + B[j];
        }
    }

    sort(E, E+X*Y, greater<long>());
    
    long* F;
    if (X*Y > K) {
        F = new long[K*Z];
        for (int i = 0; i < K; i++) {
            for (int j = 0; j < Z; j++) {
                F[i*Z + j] = E[i] + C[j];
            }
        }
        sort(F, F+K*Z, greater<long>());
    } else {
        F = new long[X*Y*Z];
        for (long i = 0; i < X*Y; i++) {
            for (long j = 0; j < Z; j++) {
                F[i*Z + j] = E[i] + C[j];
            }
        }
        sort(F, F+X*Y*Z, greater<long>());
    }

    for (int i = 0; i < K; i++) {
        cout << F[i] << endl;
    }
    cout << endl;

    return 0;
}


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

int main(void) {
	int N;
	cin >> N;
	int finalans = 1000;

	for (int i = 0; i < N; i++) {
		int ans = 0;
		int A;
		cin >> A;
		while (A % 2 == 0) {
			A /= 2;
			ans++;
		}
		if (ans < finalans) {
			finalans = ans;
		}
	}

	cout << finalans << endl;
}

Measured memory_bytes: 256
open Batteries
open BatPrintf

let scan fmt f =
  Scanf.sscanf (read_line ()) fmt f

let scan_list cnv =
  read_line ()
  |> String.split_on_char ' '
  |> List.map cnv

let scan_listn n cnv =
  if n = 0 then []
  else List.range 1 `To n |> List.map (fun _ -> (cnv % read_line) ())

let bsearch_ge arr a =
  let l = Array.length arr in
  match Array.bsearch Int.ord arr a with
  | `All_lower -> l
  | `All_bigger -> 0
  | `Just_after n -> l - n -1
  | `At n -> l - n
  | `Empty -> 0

let rec zip xs ys =
  match xs, ys with
  | [], _ -> []
  | _, [] -> []
  | x::xs, y::ys ->
    (x, y) :: zip xs ys

let square x = x * x

let dbg n = Printf.eprintf "%s\n" @@ dump n; n

let (n, m) = scan "%d %d" Tuple.Tuple2.make
let l = scan_listn m (fun s -> Scanf.sscanf s "%d %d" Tuple.Tuple2.make)

let () =
  let arr = Array.make n None in
  List.fold_left (fun r (s, c) ->
      r && match arr.(s-1) with
      | None -> arr.(s-1) <- Some c; true
      | Some n -> n = c
    ) true l
  |> (fun ans -> printf "%s\n"
         (if ans then
            match arr.(0) with
            | Some 0 when n <> 1 -> "-1"
            | _ -> if arr.(0) = None && n > 1 then arr.(0) <- Some 1;
              Array.map (function | None -> "0" | Some c -> String.of_int c) arr
              |> Array.to_list
              |> String.concat ""
          else "-1"))


Measured memory_bytes: 3072
import numpy as np
import math
n,d = map(int, input().split())
x = np.array(list(input().split() for _ in range(n)), dtype=int)
ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        s = math.sqrt(sum((x[i]-x[j])**2))
        if s.is_integer():
            ans += 1
print(ans)

Measured memory_bytes: 27144