akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      int[] seq = new int[n];
      for(int i=0; i!=n; i++)
        seq[i] = Integer.parseInt(br.readLine());

      System.out.println( shellSort(seq, n) );

      StringBuilder str = new StringBuilder(n*4);
      for (int i : seq)
        str.append(i).append("\n");

      str.setLength(str.length()-1);
      System.out.println(str);
    }
  }

  public static int shellSort(int a[], int n) {
    int cnt=0;
    int m = 0;
    int[] aG = new int[100];
    for (int g=1,max=n+1; g < max; g=(g*3+1)) {
      aG[m++] = g;
    }
    StringBuilder str = new StringBuilder(m*5);
    str.append(m).append("\n");

    for(int i=(m-1); i!=-1; i--){
      cnt += insertionSort(a, n,aG[i]);
      str.append(aG[i]).append(" ");
    }

    str.setLength(str.length()-1);
    System.out.println(str);

    return cnt;
  }
  
  public static int insertionSort(int a[], final int max, final int g) {
    int cnt=0;

    for (int i=g,j=0,v=0; i < max; i++) {
      for( j=(i-g), v=a[i]; j>=0 && a[j]>v; j-=g ) {
        a[j+g] = a[j];
        cnt++;
      }
      a[j+g] = v;
    }

    return cnt;
  }
}


Measured memory_bytes: 163212
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl
#define dd(x) cout<<#x<<"="<<x<<" "
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define all(a) a.begin(),a.end()
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef double db;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;

const int mod = 1e9+7;
const int N = 6e5+6;
const int M = 2e6+6;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;

bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==0?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=1;a%=mod; if(b<0) return 1; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
    ll x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
int n;
int cnt[N];
bool cmp(int a, int b) { return cnt[a] < cnt[b]; }
int tot = 0;
int ans[N];
ll pre[N], e[N];
inline bool gao(int k, int x) {
	int pos = upper_bound(e + 1, e + tot + 1, x) - e;
	return pre[pos-1] + 1ll*(tot-pos+1)*x >= 1ll*k*x;
}
int main() {
    scanf("%d",&n);
    rep(i, 0, n) {
        int a; scanf("%d", &a);
        cnt[a]++;
    }
    rep(i, 1, n + 1) if(cnt[i]) e[++tot] = cnt[i];
    sort(e + 1,e + tot + 1);
    rep(i, 1, tot + 1) pre[i] = pre[i-1] + e[i];
    int cur = 0;
    repd(k, tot, 1) {
        while(cur < n&&gao(k, cur+1)) ++cur;
        ans[k] = cur;
    }
    rep(i, 1, n + 1) printf("%d\n", ans[i]);
    return 0;
}


Measured memory_bytes: 13696
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define FOR(i, a, b) for(decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
3 1
)");
#define cin input
#endif

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

	if (k == 1)
	{
		cout << (n * n * n) << endl;
		return 0;
	}

	ll r = 0;
	FOR (a, 1, k + 1)
	{
		auto b = k - a;
		if (!b)
			b = k;
		if (abs(a - b) % k)
			continue;
		auto c = min((k - a) ? k - a : k, (k - b) ? k - b : k);
		if (a > n || b > n || c > n)
			continue;
		r += ((n - a) / k + 1) * ((n - b) / k + 1) * ((n - c) / k + 1);
	}

	cout << r << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int k[31],n;
int main(){
for(int i = 0;i< 28;i++){
cin >> n;
k[n] = 1;
}
for(int i = 1;i<=30;i++){
if(k[i]==0){
cout<<i<<endl;
}
}
}



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

int main() {
	int a, b;
	cin >> a >> b;
	
	cout << a / b << '\n';
	
	cout << a % b << '\n';
	
	double c = double(a) / double(b);
	
	cout << fixed << setprecision(6) << c << '\n';
	
	return 0;
}


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

int main() {
    ll a, b, c;
    cin >> a >> b >> c;

    if ((c - a - b) > 0 && (4*a*b < (c - a - b)*(c - a - b))) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


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

using namespace std;

int n;
int arr[110000];
int cnt = 0;

int main() {
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        scanf("%d", &arr[i]);
        if(arr[i] & 1) cnt ++;
    }
    if(cnt & 1) {
        puts("NO");
    } else puts("YES");
    return 0;
}


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

int main() {
	// your code goes here
    int n,i,j,sum=0;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    for(i=0;i<n-1;i++){
        for(j=i+1;j<n;j++){
            sum+=(a[i]*a[j]);
        }
    }
    cout<<sum<<endl;
	return 0;
}


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

int main() {
  int n,sum=0;
  cin>>n;
  int a[n+1];
  vector<int> ans(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(a[i]%2!=0) sum++;
  }
  for(int i=0;i<n;i++){
    int sum=0;
    while(a[i]>0){
      a[i]/=2;
      if(a[i]%2!=0){
        sum++;
        ans[i]=sum;
        break;
      }
      else{
        sum++;
      }
    }
  }
  sort(ans.begin(),ans.end());
  if(sum>0) cout<<0<<endl;
  else cout<<ans[0]<<endl;
  return 0;
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    if(a+b <= 23) cout << a+b << endl;
    else cout << a+b-24 << endl;
}

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

int main() {
  // ここにプログラムを追記
  
  int arr[9] = {};
  
  int numbers[10] = {};
  int number = 0;
  int numbers_count = 0;
  
  string result = "No";

  int i;
  
  for (i = 0; i < 9; i++) {
    cin >> arr[i];
  }
  
  for (i = 0; i < 10; i++) {
    cin >> numbers[i];
      
    if (numbers[i] != 0) {
      numbers_count++;
    }
  }
  
  for (i = 0; i < 10; i++) {
      number = numbers[i];
  
    auto itr = std::find(begin(arr), end(arr), number);       //  検索
    if( itr != end(arr) ) {
        // 発見出来た場合
      *itr = 0;
    } else {
        // 発見出来なかった場合
    }
  }
  
      if (arr[0] == 0 && arr[1] == 0 && arr[2] == 0) {
      result = "Yes";
    }
    
    else if (arr[3]== 0 && arr[4]== 0 && arr[5]== 0) {
      result = "Yes";
    }
    
    else if (arr[6]== 0 && arr[7]== 0 && arr[8]== 0) {
      result = "Yes";
    }
    
    else if (arr[0]== 0 && arr[3]== 0 && arr[6]== 0) {
      result = "Yes";
    }
    
    else if (arr[1]== 0 && arr[4]== 0 && arr[7]== 0) {
      result = "Yes";
    }
    
    else if (arr[2]== 0 && arr[5]== 0 && arr[8]== 0) {
      result = "Yes";
    }
    
    else if (arr[0]== 0 && arr[4]== 0 && arr[8]== 0) {
      result = "Yes";
    }
    
    else if (arr[2]== 0 && arr[4]== 0 && arr[6]== 0) {
      result = "Yes";
    }
  
  
  cout << result << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int a, b, c;
    cin >> a >> b >> c;
    bool ans= false;
    if (a <= c && b >= c) ans = true;
    ATYN(ans)

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.rbegin(),a.rend())
#define lb(a,b) lower_bound(a.begin(),a.end(),b)
#define ub(a,b) upper_bound(a.begin(),a.end(),b)
#define MOD ((int)(1e9+7))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double
#define sqrt sqrtl
#define cbrt cbrtl
typedef vector<int> vi;
typedef vector<float> vf;
typedef pair<float,int> fi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<fi> vfi;
typedef vector<vi> vvi;
typedef vector<vf> vvf;
typedef vector<vii> vvii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef priority_queue<fi> pqfi;
typedef priority_queue <int, vector<int>, greater<int> > rpqi; 
typedef priority_queue <ii, vector<ii>, greater<ii> > rpqii; 
typedef priority_queue <fi, vector<fi>, greater<fi> > rpqfi; 

vector<int>dx={0,1,0,-1},dy={1,0,-1,0};
const int N=60,inf=1e18;
int a[N],B[N],S[N];
int G[N][N];

int32_t main()
{
	IOS
	int a,b;cin>>a>>b;
	if(a>=13)cout<<b<<endl;
	else if( a>=6 && a<=12)cout<<b/2<<endl;
	else cout<<0<<endl;
	

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if (A + B > C + D)
    {
        cout << "Left" << endl;
    }
    else if (A + B == C + D)
    {
        cout << "Balanced" << endl;
    }
    else
    {
        cout << "Right" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;

int main(int argc, const char * argv[]) {
  int n;
  cin >> n;
  int count = 0;

  repd(num, 1, n+1){
    if(num % 2 == 0) continue;
    int count2 = 0;
    // while
    repd(i, 1, num+1){
      if(num%i == 0){
        count2++;
      }
    }
    // cout << count2 << endl;
    if(count2 == 8) count++;
  }
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 504
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
	int a,b,c,d,e; scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
	printf("%d\n",min(min(a,b),c)+min(d,e)-50);
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		
		Scanner scan = new Scanner(System.in);
		
		char[] c = {'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'};
		
		String s = scan.next();
		long k = scan.nextLong();
		int[] n = new int[s.length()];
		
		for(int i = 0 ; i < s.length() ; i++){
			for(int j = 0 ; j < c.length ; j++){
				
				if(s.charAt(i) == c[j]){
					n[i] = j;
					break;
				}
			}
		}
		
		for(int i = 0 ; i < n.length ; i++){
			
			if((n[i] != 0)&&((n[i] + k) > 25)){
				k = k - (26 - n[i]);
				n[i] = 0;
			}
			if(i == (n.length - 1)){
				n[i] = (n[i] + (int)(k % 26)) % 26;
			}
			
		}
		for(int i = 0 ; i < n.length ; i++){
			System.out.print(c[n[i]]);
		}
		System.out.println();
	}
}


Measured memory_bytes: 24152
#include <iostream>
#include <cstdio>

using namespace std;

int A, B, C, K;

bool dfs(int k, int a, int b, int c) {
  if (b > a && c > b) return true;
  if (k == 0) return false;
  return dfs(k-1, a*2, b, c) || dfs(k-1, a, b*2, c) || dfs(k-1, a, b, c*2);
}

int main() {
  scanf("%d%d%d%d", &A,&B,&C,&K);

  puts(dfs(K, A, B, C) ? "Yes" : "No");
}


Measured memory_bytes: 3760
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    n = I()
    if n < 1000:
        print("ABC")
    else:
        print("ABD")
    return

#B
def B():
    return

#C
def C():
    n = I()
    ans = float("inf")
    for i in range(n+1):
        m = 0
        k = i
        while k > 0:
            m += k%6
            k //= 6
        k = n-i
        while k > 0:
            m += k%9
            k //= 9
        ans = min(ans,m)
    print(ans)
#D
def D():
    n,C = LI()
    f = LIR(C)
    c = LIR(n)
    d = [defaultdict(int) for i in range(3)]
    for i in range(n):
        for j in range(n):
            d[(i+j+2)%3][c[i][j]-1] += 1
    ans = float("inf")
    for i in range(C):
        for j in range(C):
            if i != j:
                for k in range(C):
                    if k != i and k != j:
                        m = 0
                        for a in d[0].keys():
                            m += d[0][a]*f[a][i]
                        for a in d[1].keys():
                            m += d[1][a]*f[a][j]
                        for a in d[2].keys():
                            m += d[2][a]*f[a][k]
                        ans = min(ans,m)
    print(ans)


#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    A()


Measured memory_bytes: 38640
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1000000007; 
const int INF = 1000000000; //1e9
const int NIL = -1;
const long long LINF = 1000000000000000000; // 1e18
const double EPS = 1E-10;

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



 
 
int main(){
    int X; std::cin >> X;
    std::cout << (X / 500) * 1000 + ((X % 500) / 5) * 5 << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int X, N;
    int p[105] = {0};

    cin >> X >> N;

    if (N == 0) {
        cout << X << endl;
        return 0;
    }
    for (int i = 1; i < 105; i++) {
        p[i] = i;
    }
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        p[a] = 0;
    }

    if (p[X] != 0) {
        cout << X << endl;
        return 0;
    }
    int t1 = -1000, t2 = -1000;
    int s1 = -1000, s2 = -1000;
    for (int i = X; i >= 1; i--) {
        if (p[i] != 0) {
            t1 = i;
            s1 = abs(X - i);
            break;
        }
    }

    for (int i = X; i <= 100; i++) {
        if (p[i] != 0) {
            t2 = i;
            s2 = abs(i - X);
            break;
        }
    }

    if (t1 == -1000) {
        t1 = 0;
        s1 = X;
    }
    if (t2 == -1000) {
        t2 = 101;
        s2 = abs(101 - X);
    }

    if (s1 > s2) {
        cout << t2 << endl;
    } else if (s1 < s2) {
        cout << t1 << endl;
    } else {
        cout << t1 << endl;
    }


    return 0;
}

Measured memory_bytes: 3576
import sys

def chk(i,j):
    tmp=[p[i][k] for k in range(M)]
    tmp[j]=p[i][j]+1
    for k in range(M-1,-1,-1):
        if tmp[k] > p[i+x[j]][k] :
            p[i+x[j]]=[tmp[k] for k in range(M)]

N,M=map(int,input().split())
x=[0,2,5,5,4,5,6,3,7,6]
a=list(map(int,input().split()))
a.sort()
b=[]
for i in range(M):
    for j in range(M):
        if x[a[j]]==x[a[i]]: tmp=j
    b.append(a[tmp]) 

a=list(set(b))
a.sort()
M=len(a)
x=[ x[a[i]] for i in range(M) ]

p=[-100 for i in range(N+10)]
p[0]=0
for i in range(N):
    if p[i]>-1:
        for j in range(M):
            p[i+x[j]]=max(p[i+x[j]],p[i]+1)

ans=""
while N>0:
    for j in range(M-1,-1,-1):
        if p[N]==p[N-x[j]]+1:
            ans+=str(a[j])
            N-=x[j]
            break
print(ans)




Measured memory_bytes: 3436
let is_palin s =
    let rec aux s lindex rindex =
        if lindex > rindex then false
        else if lindex = rindex then true
        else if s.[lindex] = s.[rindex] && aux s (lindex + 1) (rindex - 1) then true
        else false
    in aux s 0 (String.length s - 1)

let rec solve a b =
    if a > b then 0
    else if is_palin (string_of_int a) then
        1 + solve (a + 1) b
    else
        solve (a + 1) b

let () =
    Scanf.scanf "%d %d" (fun a b ->
        Printf.printf "%d\n" (solve a b)
    )


Measured memory_bytes: 1792
#include <stdio.h>
#define Max 1000000

int gyou[101], m[101][101];

void martixCM(int n){
  int i,j,t,l;
  for(i=0; i<n; i++){
    m[i][i] = 0;
  }
  for(l=2; l<=n; l++){
    for(i=1; i<=n-l+1; i++){
      j=i+l-1;
      m[i][j] = Max;
      for(t=i; t<=j-1; t++){
      if(m[i][j] > m[i][t]+m[t+1][j]+(gyou[i-1]*gyou[t]*gyou[j])){
	m[i][j] = m[i][t]+m[t+1][j]+(gyou[i-1]*gyou[t]*gyou[j]);
      }
      else{
	m[i][j] = m[i][j];
      }
      }
    }
  }
}

int main(){
  int i,n;
  scanf("%d",&n);
  
  for(i=1; i<=n; i++){
    scanf("%d%d",&gyou[i-1],&gyou[i]);
  }
  
  martixCM(n);
  
  printf("%d\n",m[1][n]);
  
  return 0;
}

Measured memory_bytes: 636
#include <stdio.h>
#include <stdlib.h>

int main() {
    long long A[100000],answer = 1,max = 1000000000000000000;
    int n,i;
    scanf("%d",&n);
    
    for (i = 0;i < n;i++){
        scanf("%lld",&A[i]);
    }
    
    for (i = 0;i < n;i++){
        if (A[i] == 0){
            printf("0");
            return 0;
        }
    }
        
    for (i = 0;i < n;i++){
        if(max / A[i] < answer){
            printf("-1\n");
            return 0;
        }
        answer *= A[i];
    }
    
    printf("%lld\n",answer);
    
    return 0;
}


Measured memory_bytes: 2512
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RREP(i,x) for(int i=(x)-1;i>=0;i--)
#define RFOR(i,c) for(auto i=(c).rbegin();i!=(c).rend();++i)
#define ALL(container) container.begin(), container.end()
#define SZ(container) ((int)container.size())
 
const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;
 
string s;
vector<pii> stdb;
vector< set<int> > sts;
vector<double> sim;
 
double Jaccard(set<int> &a, set<int> &b){
	int t = 0;
	FOR(it, a) if(b.count(*it)) t++;
	return (double)t / (a.size() + b.size() - t);
}
 
int dfs(int &p){
//  printf("dfs(%d, %d)\n", p, l);
	if(s[p] == 'x'){
		p++;
		return 0;
	}
	pii t;
	if(s[p++] != '('){
		cout << "not (" << endl;
	}
	t.first = dfs(p);
	if(s[p++] != ' '){
		cout << "not space" << endl;
	}
	t.second = dfs(p);
	if(s[p++] != ')'){
		cout << "not )" << endl;
	}
	if(t.first > t.second) swap(t.first, t.second);
	auto ret = find(stdb.begin(), stdb.end(), t);
	if(ret == stdb.end()){
		int p = stdb.size();
		stdb.push_back(t);
		sts.push_back(sts[t.first]);
		sts.back().insert(sts[t.second].begin(), sts[t.second].end());
		sts.back().insert(p);
		sim.push_back(1 - Jaccard(sts[t.first], sts[t.second]));
		return p;
	}else return ret - stdb.begin();
}

int comp(int r1, int r2){
	if(r1 == r2) return 0;
	if(abs(sim[r1] - sim[r2]) > 1e-10) return sim[r1] > sim[r2] ? 1 : -1;
	if(!r1 || !r2) return 0;
	pii c1 = stdb[r1];
	pii c2 = stdb[r2];
	if(sim[c1.first] < sim[c1.second]) swap(c1.first, c1.second);
	if(sim[c2.first] < sim[c2.second]) swap(c2.first, c2.second);
	int ret = comp(c1.first, c2.first);
	if(ret) return ret;
	return comp(c1.second, c2.second);
}

void printTree(int st, int l){
	if(!st) printf("x");
	else{
		pii t = stdb[st];
		if(l ^ (comp(t.first, t.second) == -1)) swap(t.first, t.second);
		printf("(");
		printTree(t.first, 0);
		printf(" ");
		printTree(t.second, 1);
		printf(")");
	}
}
main(){
	while(getline(cin, s), s[0] !='0'){
		stdb.clear();
		stdb.push_back(pii(-1, -1));
		sts.clear();
		sts.push_back(set<int>());
		sts.back().insert(0);
		sim.clear();
		sim.push_back(1.0);

		int p = 0;
		printTree(dfs(p), 0);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 1308
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <vector>
using namespace std;
static const int max_n = 200000;
static const int INF = 1e8;
static long long x,a,b,m,n,h,D=0,amax=1;
typedef pair<long long, long long> p;
static long long s[max_n],d[max_n];
static const int mod =1e9 + 7;
static int dist[111];//出発地からの最短距離
static long long cnt[111];//cnt[i] : 出発地からiまでの最短距離の回数
static vector<vector<int> > G;
static long long dp[max_n];
long long k = 0;
void solve(){
    long long sum = 0;
    for(int i=1 ; i<n ; i++){
        if(a * (s[i] - s[i-1]) > b ){
            sum += b;
        }else{
            sum += a * (s[i] - s[i-1]);
        }
    }
    cout << sum << endl;
}
int main(){
    cin >> n >> a >> b;
    for(int i=0 ; i<n ; i++){
        cin >> s[i];
    }
    solve();
    return 0;
}


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

public class Main {
	static final int like = 753;
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		
		String s = sc.next();
		int min = 1000;
		for(int i = 0; i < s.length() - 2; i++) {
			String sub = s.substring(i, i + 3);
			int n = Integer.valueOf(sub);
			int m = Math.abs(like - n);
			if (min > m) min = m;
		}
				
		out.println(min);
		
		out.close();
	}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}



Measured memory_bytes: 21204
from collections import deque, Counter, defaultdict
from itertools import chain, combinations
import json
# import numpy as np
import bisect
import sys
import math
import bisect
from functools import lru_cache

sys.setrecursionlimit(10 ** 8)

M = 10 ** 9 + 7
INF = 10 ** 17


def main():
    N = int(input())
    # A = [int(a) for a in input().split()]
    print(2*N*math.pi)

    # @lru_cache(None)
    # def f(i, j):
    #     if i < 0 or j < 0:
    #         return -INF
    #     if i == 0:
    #         return -INF
    #     if abs(j - i // 2 - 1) >= 2:
    #         return -INF
    #     if j == 0:
    #         return 0
    #     if j == 1:
    #         return max(A[:i])
    #     return max(A[i - 1] + f(i - 2, j - 1), f(i - 1, j))
    #
    # print(f(N, math.floor(N / 2)))


if __name__ == "__main__":
    main()


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

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  int n;cin>>n;

  ll ans=0;
  for(ll i=1;i<=n;i++){
    if(i%3==0||i%5==0){}else{ans+=i;}
  }

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


Measured memory_bytes: 3652
N,L=map(int,input().split())
ringos = [ L+i-1 for i in range(1,N+1)]

abs_ringos=[abs(i) for i in ringos]

min_key=0
amin_ringo=99999
for i in range(len(abs_ringos)):
    if amin_ringo != min(amin_ringo,abs_ringos[i]):
        amin_ringo = abs_ringos[i]
        min_key=i

print(sum(ringos)-ringos[min_key])

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int x; cin>>x;
    int ans=1;
    for(int sum=0;sum<x;++ans)sum+=ans;
    cout<<--ans<<endl;
}


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

int main() {
	char s[1024];
	scanf("%s", s);

	int counter_x = 0;
	for (int i = 0; s[i] != '\0'; i++) {
		if (s[i] == 'x') counter_x++;
	}

	if (counter_x >= 8) {
		cout << "NO" << endl;
		return 0;
	}

	cout << "YES" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

int getMinIndex(int *array, int length) {
	int min = 0;
	for (int i = 0; i < length; i++) {
		if (array[min] > array[i]) {
			min = i;
		}
	}
	return min;
}

int getMaxIndex(int *array, int length) {
	int max = 0;
	for (int i = 0; i < length; i++) {
		if (array[max] < array[i]) {
			max = i;
		}
	}
	return max;
}

int abs(int a, int b) {
	return a > b ? a : b;
}

int main() {
	using namespace std;
	
	int n = 0;
	int *a;
	int max_index = 0;
	int min_index = 0;
	
	cin >> n;
	a = new int[n];

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	
	min_index = getMinIndex(a, n);
	max_index = getMaxIndex(a, n);
	
	cout << abs(a[max_index] - a[min_index]) << endl;
	
	delete[] a;
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

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

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a,b;
  cin >> a >> b;
  cout << max(a+b,max(a-b,a*b)) << endl;
  return 0;
}
  

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

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

int main(){
    char ch; cin>>ch;
    if(ch=='A') cout<<"T"<<endl;
    if(ch=='T') cout<<"A"<<endl;
    if(ch=='G') cout<<"C"<<endl;
    if(ch=='C') cout<<"G"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int l[200005],r[200005];

int main(void){
	scanf("%d",&n);
	ll ans=0;
	for(int i=1;i<=n;i++){
		ans+=(ll)i*(n+1-i);
	}
	for(int i=0;i<n-1;i++){
		scanf("%d%d",&l[i],&r[i]);
		if(l[i]>r[i]){
			swap(l[i],r[i]);
		}
		ll val=(ll)l[i]*(n-r[i]+1);
		ans-=val;
	}
	printf("%lld\n",ans);
	return 0;
}


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

template <typename Monoid>
struct SegmentTree
{
  using F = function<Monoid(Monoid, Monoid)>;

  int sz;
  vector<Monoid> seg;

  const F f;
  const Monoid M1;

  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1)
  {
    sz = 1;
    while (sz < n)
      sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  void set(int k, const Monoid &x)
  {
    seg[k + sz] = x;
  }

  void build()
  {
    for (int k = sz - 1; k > 0; k--)
    {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int k, const Monoid &x)
  {
    k += sz;
    seg[k] = x;
    while (k >>= 1)
    {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  Monoid query(int a, int b)
  {
    Monoid L = M1, R = M1;
    for (a += sz, b += sz; a < b; a >>= 1, b >>= 1)
    {
      if (a & 1)
        L = f(L, seg[a++]);
      if (b & 1)
        R = f(seg[--b], R);
    }
    return f(L, R);
  }

  Monoid operator[](const int &k) const
  {
    return seg[k + sz];
  }

  template <typename C>
  int find_subtree(int a, const C &check, Monoid &M, bool type)
  {
    while (a < sz)
    {
      Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
      if (check(nxt))
        a = 2 * a + type;
      else
        M = nxt, a = 2 * a + 1 - type;
    }
    return a - sz;
  }

  template <typename C>
  int find_first(int a, const C &check)
  {
    Monoid L = M1;
    if (a <= 0)
    {
      if (check(f(L, seg[1])))
        return find_subtree(1, check, L, false);
      return -1;
    }
    int b = sz;
    for (a += sz, b += sz; a < b; a >>= 1, b >>= 1)
    {
      if (a & 1)
      {
        Monoid nxt = f(L, seg[a]);
        if (check(nxt))
          return find_subtree(a, check, L, false);
        L = nxt;
        ++a;
      }
    }
    return -1;
  }

  template <typename C>
  int find_last(int b, const C &check)
  {
    Monoid R = M1;
    if (b >= sz)
    {
      if (check(f(seg[1], R)))
        return find_subtree(1, check, R, true);
      return -1;
    }
    int a = sz;
    for (b += sz; a < b; a >>= 1, b >>= 1)
    {
      if (b & 1)
      {
        Monoid nxt = f(seg[--b], R);
        if (check(nxt))
          return find_subtree(b, check, R, true);
        R = nxt;
      }
    }
    return -1;
  }
};

int main()
{
  i64 n, m;
  string s;
  cin >> n >> m >> s;
  SegmentTree<pair<i64, i64>> seg(n + 1, [](pair<i64, i64> a, pair<i64, i64> b) { return min(a, b); }, {1e9, 1e9});
  for (i64 i = 0; i < (i64)s.size(); i++)
    seg.set(i, {s[i] - '0', i});
  seg.build();
  vector<i64> ans;
  for (i64 i = n; 0 < i;)
  {
    pair<i64, i64> st = seg.query(max(0LL, i - m), i);
    if (st.first == 1)
    {
      cout << -1 << endl;
      return 0;
    }
    ans.push_back(i - st.second);
    i = st.second;
  }
  for (i64 i = ans.size() - 1; - 1 < i; i--)
    cout << ans[i] << (i == 0 ? "\n" : " ");
  return 0;
}


Measured memory_bytes: 5624
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N=sc.nextLong();
        long K=sc.nextLong();
        long maxd=1L;
        int kurai=0;
        while(true){
            if(maxd-1L < N){        //2進数だったら15より大きい17は5桁
                maxd*=K;
                kurai++;
            }
            else {
                break;
            }
        }
        pl(kurai);
    }
    public static void pl(Object o){
        System.out.println(o);
    }
    public static void p(Object o){
        System.out.println(o);
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define ll long long int
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod 1000000007
using namespace std;
const ll c=1000009;
ll fact[c],inv[c],finv[c],num[c];

int main()
{ 
    fast;
    ll n,k,x;
    cin>>n>>k;

    memset(num,0,sizeof(num));
    num[0]=1;
    cin>>x;
    num[x+1]=-1;

    for(ll j=1;j<n;j++)
    {
        cin>>x;
        x++;
        for(ll i=k;i>-1;i--)
            if(x+i<=k)
            num[x+i]=(num[x+i] -num[i])%mod;
    }
    
    ll ans=0;
    fact[0]=fact[1]=inv[0]=inv[1]=finv[0]=finv[1]=1;

    for(ll i=2;i<c;i++)
    {
        fact[i]=fact[i-1]*i%mod;
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
  
   ll dr[k+1];
   for(ll i=0;i<=k;i++)
          dr[i]=fact[n+i-1]*finv[i]%mod*finv[n-1]%mod;
        
    for(ll i=0;i<=k;i++)
    {
        ll add=dr[k-i]*num[i]%mod;
        ans=(ans+add+mod)%mod;
    }
    cout<<ans<<endl;
  }

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

bool revp2(const pair<ll,ll>&a,const pair<ll,ll>&b){return a.first>b.first;}
bool revp3(const pair<ll,ll>&a,const pair<ll,ll>&b){if(a.first==b.first)return a.second<b.second;
return a.first>b.first;}

int main()
{
//    ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
    ll l1[4],s=0;
    cin>>l1[1]>>l1[2]>>l1[3];
    sort(l1+1,l1+3+1);
    ll jo=0,bij=0;
    for(int i=1;i<=3;i++)if(l1[i]&1)bij++;
    jo=3-bij;//cout<<jo<<endl;
    if(jo==3||bij==3)cout<<((l1[2]-l1[1])/2)+l1[3]-l1[2];
    else if(jo==2){
        for(int i=1;i<=3;i++){
            if(l1[i]%2==0)l1[i]++;
            //cout<<l1[i]<<endl;
        }
        s+=1;
        s+=((l1[2]-l1[1])/2)+l1[3]-l1[2];
        cout<<s;
    }
    else if(bij==2){
        for(int i=1;i<=3;i++){
            if(l1[i]%2!=0)l1[i]++;
        }
        s++;
        s+=((l1[2]-l1[1])/2)+l1[3]-l1[2];
        cout<<s;
    }
}


Measured memory_bytes: 3600
<?php
// From https://qiita.com/yoshikyoto/items/6924478283dbdd549e4b
class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}
// From https://qiita.com/yoshikyoto/items/6924478283dbdd549e4b
list($N)=sscanf(trim(fgets(STDIN)),"%d");
$sc = new Scanner();
$sum=0;
for($i=0;$i<$N;$i++){
    $n = $sc->nextInt();
    $sum +=1/$n;
}
print(1/$sum);

//

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

int main() {
  string s;
  cin >> s;

  for (int i = 0; i < s.size() - 1; ++i) {
    if (s[i] == s[i + 1]) {
      cout << i + 1 << ' ' << i + 2 << endl;
      return 0;
    }
  }
  for (int i = 0; i < s.size() - 2; ++i) {
    if (s[i] == s[i + 2]) {
      cout << i + 1 << ' ' << i + 3 << endl;
      return 0;
    }
  }
  cout << -1 << ' ' << -1 << endl;
}


Measured memory_bytes: 512
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
#include <numeric>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <stack>

using namespace std;

#define INFint (1<<30)
#define BOUND 27182818284
#define MAT 2

typedef long long ll;
typedef long long int lli;
typedef pair<ll, ll> P;

ll MOD = 1000000007;
const ll INF = (1ll<<60);
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for(int i=int(a);i<int(b);++i)

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

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

// gcd
template<typename T>
T gcd(T a, T b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int findGCD(vector<int> arr) {
    int result = arr[0];
    for (auto a: arr) {
        result = gcd(a, result);
    }
    return result;
}

template<typename T>
T lcm(T m, T n) {
    // 引数に0がある場合は0を返す
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    fill((T *) array, (T *) (array + N), val);
}


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

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};


int main() {
    int N; cin >> N;
    string S; cin >> S;

    for(char a: S){
        char c= (a-'A' + N)%26+'A';

        cout << (char)c;
    }

    cout << endl;
    return 0;
}


Measured memory_bytes: 888
#include <stdio.h>

int main()
{
    int n;
    char s[10001];
    scanf("%d",&n);
    scanf("%s",s);
    for(int i=0;;i++)
    {
        if(s[i]=='\0') break;
        printf("%c",(s[i]-'A'+n)%26+'A');
    }
    printf("\n");
}

Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;

class Program {

    static void Main (string[] args) {
        string[] str = Console.ReadLine ().Split (' ');
        long a = long.Parse (str[0]);
        long b = long.Parse (str[1]);
        long c = long.Parse (str[2]);
        long k = long.Parse (str[3]);
        if (a + b >= k) {
            Console.WriteLine (Math.Min (a, k));
        } else {
            Console.WriteLine (2 * a - k + b);
        }
    }
}

Measured memory_bytes: 27484
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    int b;
    while(cin >> b,b){
        int left=1,right=1,tmp=1;
        for(left=1;;left++){
            while(tmp<b){
                right++;
                tmp+=right;
            }
            if(tmp==b)break;
            tmp-=left;
        }
        cout << left << " " << right-left+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3068
import collections
n = int(input())
s = [0] * n
c = [0] * n

count = 0
for i in range(n):
    s[i] = input()
    c[i] = ''.join(sorted(s[i]))
for i in collections.Counter(c).values():
    count += i*(i-1)//2
print(count)

Measured memory_bytes: 26856
#include <bits/stdc++.h>
using namespace std;
const int dx[]={0,1,0,-1,1,-1,-1,1};
const int dy[]={-1,0,1,0,1,1,-1,-1};
const int INF = 1<<30;
const double EPS = 1e-15;
#define PB push_back
#define mk make_pair
#define fi first
#define se second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
typedef pair<int,int> Pii;
typedef pair<int,Pii> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
struct Point{
    double x,y;
    Point(){}
    Point(double _x,double _y){
        x = _x;
        y = _y;
    }
    Point operator + (Point p){
        return Point(x+p.x,y+p.y);
    }
 
    Point operator - (Point p){
        return Point(x-p.x,y-p.y);
    }
 
    Point operator * (double k){
        return Point(k*x,k*y);
    }
 
 	Point operator / (double k){
 		return Point(x/k,y/k);
 	}

    bool operator<(const Point &p)const{
        return x!=p.x?x<p.x:y<p.y;
    }
 
};
double dot(Point p, Point q){
    return p.x*q.x+p.y*q.y;
}
 
double cross(Point p,Point q){
    return p.x*q.y-q.x*p.y;
}
 
double norm(Point p){
    return p.x*p.x+p.y*p.y;
}
 
double pabs(Point p){
    return sqrt(norm(p));
}
typedef vector<Point> Polygon;
struct Line : Polygon{
    Line(){}
    Line(Point p,Point q){
        PB(p);
        PB(q);  
    }
};
struct Circle{
    Point p; //中心点
    double r; //半径
    Circle(){}
    Circle(Point _p,double _r){
        p = _p;
        r = _r;
    }
};
int ccw(Point a,Point b,Point c){
    b = b-a;
    c = c-a;
    if(cross(b,c) > 0)return +1; //a→b で反時計に折れてc ccw
    if(cross(b,c) < 0)return -1; //a→b で時計に折れてc ccw
    if(dot(b,c) < 0)return +2; // c--a--b;
    if(pabs(b)<pabs(c))return -2; //a--b--c
    return 0; //a--c--b
}
bool intersectSS(Line l,Line m){
    //lとmが交差してるかどうか
    return (ccw(l[0],l[1],m[0])*ccw(l[0],l[1],m[1])<=0)&&
            (ccw(m[0],m[1],l[0])*ccw(m[0],m[1],l[1])<=0);
}

double TriangleArea(Point a,Point b,Point c){
	b = b - a;
	c = c - a;
	return fabs(cross(b,c))*0.5;
}

double VertexArea(Polygon v){
	double subArea = 0.0;
	rep(i,v.size()-1){
		subArea += TriangleArea(v[0],v[i],v[i+1]);
	}
}

Point crosspoint(Line l,Line m){
	if(intersectSS(l,m) == false)return Point(INF,INF);
	return m[0]+(m[1]-m[0])*cross(l[1]-l[0],l[1]-m[0])/cross(l[1]-l[0],m[1]-m[0]);
}

int main(){
	int Q;
	cin >> Q;
	while(Q--){
		Line l[2];
		rep(i,2){
			double x1,y1,x2,y2;
			cin >> x1 >> y1 >> x2 >> y2;
			l[i].PB(Point(x1,y1));
			l[i].PB(Point(x2,y2));
		}
		Point ans = crosspoint(l[0],l[1]);
		printf("%.10lf %.10lf\n",ans.x,ans.y);
	}
	return 0;
}

Measured memory_bytes: 1256
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("YES") if fl else print("NO")
import collections
import math
import itertools
import heapq as hq
n = ni()
ab = []
for i in range(n):
    ab.append(lma())
ab.sort(key=lambda x:x[1],reverse=True)
ab.sort(reverse=True)
cd = []
for i in range(n):
    cd.append(lma())
cd.sort()
cd.sort(key=lambda x:x[1])
cnt=0
INF=10**9
for a,b in ab:
    #print("ab",a,b)
    for i in range(n):
        c,d = cd[i]
        if a<c and b<d:
            #print("cd",c,d)
            cnt+=1
            cd[i][0]=-INF
            cd[i][1]=-INF
            break
print(cnt)
#print(cd)


Measured memory_bytes: 9472
// see https://gist.github.com/LumaKernel/ff55d49ee1af69b7388f15b707e75c15
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <complex>
#include <random>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<P> VP;

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

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

#define LFOR(i,a,b) for(ll i=(a);i<(b);++i)
#define RLFOR(i,b,a) for(ll i=(b)-1;i>=(a);--i)

#define ALL(a) (a).begin(),(a).end()
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end())
#define MP make_pair
#define PB push_back
#define EACH(i,c) REP(i,(int)(c).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define dump(x) cerr << "[L " << __LINE__ << "] " << #x << " = " << (x) << "\n";
#define dump2(x,y) cerr << "[L " << __LINE__ << "] " << #x << " = " << (x)\
			<< " , " << #y << " = " << (y) << "\n";

const int INF = 1e9;
const double EPS = 1e-10;
const int _N = 1e5;

ll n,m,a[_N],b[_N],c[_N];
ll bToC[_N], aToB[_N];
ll k;
string s;

int main() {
	cin >> n;
//	REP(i, n){
//	}
	REP(i, n){
		cin >> a[i];
	}
	REP(i, n){
		cin >> b[i];
	}
	REP(i, n){
		cin >> c[i];
	}
	sort(a, a + n);
	sort(b, b + n);
	sort(c, c + n);



	ll ans = 0;

	// b to c
	REP(i, n){
		int k = upper_bound(c, c+n, b[i]) - c;
		bToC[i] = n - k;
	}

	RREP(i, n-1) bToC[i] += bToC[i+1];

	// a to b
	REP(i, n){
		int k = upper_bound(b, b+n, a[i]) - b;
		if(k<n)ans += bToC[k];
	}

	cout << ans;
	cout << endl;
}


Measured memory_bytes: 3328
#include<iostream>
using namespace std;
int main(){
	int W;
	int H;
	int x;
	int y;
	int r;
	cin >> W >> H >> x >> y >> r;
	if (W<x + r){
		cout << "No\n";
	}else if (0>x - r){
		cout << "No\n";
	}else if (H<y + r){
		cout << "No\n";
	}
	else if (0>y - r){
		cout << "No\n";
	}
	else { cout << "Yes\n"; }
	return 0;
}

Measured memory_bytes: 3088
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
const long long MOD = (ll)1e9+7;
// const long long MOD = (ll)1e6+3;
const long long MAX = (ll)1e5+10;


bool IsPrime(int num)
{
   if (num < 2) return false;
   else if (num == 2) return true;
   else if (num % 2 == 0) return false;
   double sqrtNum = sqrt(num);
   for (int i = 3; i <= sqrtNum; i += 2) {
      if (num % i == 0) return false;
   }
    return true;
}

ll N,K,R,S,P;
string T;
vector<ll> Tn;
vector<ll> dp(3);
void Update(ll modk, ll i) {
   vector<ll> dp1(3,0);
   ll ind = i*K+modk;
      if (Tn[ind] == 0) dp1[2] = max(dp[0],dp[1]) + P;
      else dp1[2] = max(dp[0],dp[1]);
      if (Tn[ind] == 1) dp1[0] = max(dp[1],dp[2]) + R;
      else dp1[0] = max(dp[1],dp[2]);
      if (Tn[ind] == 2) dp1[1] = max(dp[0],dp[2]) + S;
      else dp1[1] = max(dp[2],dp[1]);
   swap(dp,dp1);
   return;
}


int main(void) {
   // ll X;
   // cin>>X;
   // while(1) {
   //    if (IsPrime(X)) break;
   //    else X++;
   // }
   // cout<<X<<endl;

   cin>>N>>K;
   cin>>R>>S>>P;
   cin>>T;
   Tn.resize(N);
   rep(i,0,N) {
      if (T[i]=='r') Tn[i] = 0;
      if (T[i]=='s') Tn[i] = 1;
      if (T[i]=='p') Tn[i] = 2;
   }

   ll ans = 0;
   rep(modk,0,K) {
      ll i = 0;
      dp[0] = 0;
      dp[1] = 0;
      dp[2] = 0;
      while(i*K+modk<N) {
         Update(modk,i);
         i++;
      }
      // cout<<dp[0]<<" "<<dp[1]<<" "<<dp[2]<<endl;
      ans += max(max(dp[0],dp[1]),dp[2]);
   }
   cout<<ans<<endl;



   return 0;
}

Measured memory_bytes: 1280