akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>

using namespace std;

struct Node {
	bool leaf;
	char op;
	int leafnum;
	union {
		int mask;
		Node* children[2];
	};
};

vector<int> leafmask(9);
vector<Node*> mids;

void skip(const string &str, int &pos, char c) {
	if(str[pos] != c) {
		cerr << "Error at " << pos << ": expected " << c << " but " << str[pos] << endl;
	}
	++pos;
}

Node *node(const string &str, int &pos) {
	Node *n = new Node;
	if(isdigit(str[pos])) {
		n->leaf = true;
		n->mask = 0;
		//leaves[str[pos]-'0'-1] = n;
		n->leafnum = str[pos]-'0'-1;
		++pos;
	}
	else {
		n->leaf = false;
		skip(str, pos, '(');
		n->children[0] = node(str, pos);
		skip(str, pos, ' ');
		n->children[1] = node(str, pos);
		skip(str, pos, ')');
		mids.push_back(n);
	}
	return n;
}

int calc(Node *n) {
	if(n->leaf) return leafmask[n->leafnum];

	int l = calc(n->children[0]);
	int r = calc(n->children[1]);
	if(n->op == 'A') return l&r;
	else if(n->op == 'O') return l|r;
	else return l^r;
}

int main() {
	while(true) {
		string tree;
		getline(cin, tree);
		if(tree == "END") break;

		mids.clear();
		int pos = 0;
		Node *root = node(tree, pos);

		int N;
		cin >> N;
		for(int i = 0; i < N; ++i) {
			leafmask[i] = 0;
			for(int j = 0; j < 4; ++j) {
				int flag;
				cin >> flag;
				//if(flag) leaves[i]->mask |= (1<<j);
				if(flag) leafmask[i] |= (1<<j);
			}
		}
		int limit = 1;
		int cnt = 0;
		for(int i = 0; i < mids.size(); ++i) limit *= 3;
		for(int i = 0; i < limit; ++i) {
			int tmp = i;
			for(int j = 0; j < mids.size(); ++j) {
				mids[j]->op = "AOX"[tmp%3];
				tmp /= 3;
			}
			if(calc(root) == 0x0f) ++cnt;
		}
		cout << cnt << endl;
		cin.ignore();
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.*;
import java.lang.Math;
public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        boolean flag = false;
        int counter = 0;
        char[] work = new char[S.length()];
        for(int i = 0; i < S.length(); i++){
            work[i] = S.charAt(i);
            if(work[i] == 'R'){
                counter++;
                flag = true;
            }
            if(work[i] == 'S' && flag){
                break;
            }
        }
        System.out.println(counter);
    }
}


Measured memory_bytes: 35384
S = str(input())
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])
if A+B+C+D == 7:
    print(str(A) + "+" + str(B) + "+" + str(C) + "+" + str(D) + "=" + "7")
elif A+B+C-D == 7:
     print(str(A) + "+" + str(B) + "+" + str(C) + "-" + str(D) + "=" + "7")
elif A+B-C+D == 7:
     print(str(A) + "+" + str(B) + "-" + str(C) + "+" + str(D) + "=" + "7")
elif A+B-C-D == 7:
     print(str(A) + "+" + str(B) + "-" + str(C) + "-" + str(D) + "=" + "7")
elif A-B+C+D == 7:
     print(str(A) + "-" + str(B) + "+" + str(C) + "+" + str(D) + "=" + "7")
elif A-B+C-D == 7:
     print(str(A) + "-" + str(B) + "+" + str(C) + "-" + str(D) + "=" + "7")
elif A-B-C+D == 7:
     print(str(A) + "-" + str(B) + "-" + str(C) + "+" + str(D) + "=" + "7")
elif A-B-C-D == 7:
     print(str(A) + "-" + str(B) + "-" + str(C) + "-" + str(D) + "=" + "7")

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

void trace(int A[], int n) {
    for (int i = 0; i < n; i++) {
        if (i > 0) {
            cout << ' ';
        }
        cout << A[i];
    }
    cout << endl;
}

void insertionSort(int A[], int n) {
    for (int i = 1; i < n; i++) {
        int v = A[i];
        int j = i - 1;
        while (j >= 0 && A[j] > v) {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        trace(A, n);
    }
}

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

    int A[n];
    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }
    trace(A, n);
    insertionSort(A, n);

    return 0;
}

Measured memory_bytes: 3096
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0139

"""
import sys
from sys import stdin
import re
input = stdin.readline


def identify_snake(snake):
    # ????????????>`???????¶???????1?????\?????????=]??????#??????????????§1?????\?????????=??????????????????~??????????????¨?????????=?????°?????????
    patternA = re.compile("^>'(=+)#(=+)~")
    resultA = patternA.search(snake)
    if resultA:
        pre, post = resultA.groups()
        if pre == post:
            return 'A'

    # ????????????>^???????¶???????1?????\?????????Q=]???????????????????????????~~???
    patternB = re.compile("^>\^(Q=)+~~")
    resultB = patternB.search(snake)
    if resultB:
        return 'B'

    return 'NA'


def main(args):
    n = int(input())
    for _ in range(n):
        snake = input()
        result = identify_snake(snake)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 7904
n=int(input())
a = tuple(map(int,input().split()))
dp = [0]*(n*max(a)+1)
dp[0] = 1
for i in range(n):
    past = list(dp)
    for m in range(n*max(a)+1):
        if m-a[i]>=0:
            dp[m] = max(dp[m],past[m-a[i]])
        else:
            dp[m] = past[m]
q = int(input())
for s in tuple(map(int,input().split())):
    if s > max(a)*n:
        print('no')
    elif dp[s]:
        print('yes')
    else:print('no')


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

int main(){
  int N;
  string A,B,C;
  cin >> N >> A >> B >> C;
  int ans=0;
  for (int i=0;i<N;i++){
    if (A[i]==B[i] or B[i]==C[i] or C[i]==A[i]){
      ans+=1;
    }
    else{
      ans+=2;
    }
    if (A[i]==B[i] and B[i]==C[i]){
      ans-=1;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

int i_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int i_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}

int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}
// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
ll _pfact(ll a);
static ll pf[100000000];
static ll pc;

ll _pfact(ll a) {
	long i, r;
	if (a % 2 == 0) {
		pf[pc] = 2; pc++;
		return(_pfact(a / 2));
	}
	r = sqrt(a);
	for (i = 3; i <= r; i += 2) {
		if (a % i == 0) {
			pf[pc] = i; pc++;
			return(_pfact(a / i));
		}
	}
	if (a != 1) {
		pf[pc] = a; pc++;
	}
	return 0;

}


#pragma endregion


//ABC  120-C Unification
#define MAX 100000

int main(void) {
	char c[MAX+1];
	int  len = 0, c0 = 0,c1=0;

    scanf("%s", c);
	len = strlen(c);

	for (int i = 0; i < len; i++) 
		if (c[i] == '0') c0++;
		else c1++;
	
	printf("%d\n", (c0 < c1) ? c0*2:c1*2);
	return 0;
	
}





Measured memory_bytes: 2208
#include<iostream>
#include<algorithm>
#include<string> 
#include<map>
#include<set>
#include<vector>
#include<string.h> 
#include<math.h>
#include<stdio.h> 
#include<queue>
using namespace std;  
int main()
{int a,b,c,d;cin>>a>>b>>c>>d;
cout<<min(a,b)+min(c,d);
system("pause");
return 0;
}

Measured memory_bytes: 504
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<list>
#include<set>
#include<map>
#include<stack>
# define PI 3.14159265358979323846
using namespace std;
typedef long long ll;
const int maxn = 1e5+10;
ll node[maxn];

int main()
{
	int n;
	cin>>n;
	int index = 1;
	for(index;index<=9;index++)
	{
		node[index] = index;
	}
	int i=1;
	while(index<=n)
	{
		if(node[i]%10==0)
		{
			node[index++] = node[i]*10;
			node[index++] = node[i]*10+1; 
		}
		else if(node[i]%10==9)
		{
			node[index++] = node[i]*10+8;
			node[index++] = node[i]*10+9;
		}
		else
		{
			node[index++] = node[i]*10+node[i]%10-1;
			node[index++] = node[i]*10+node[i]%10;
			node[index++] = node[i]*10+node[i]%10+1;
			
		}
		i++;
	}
	cout<<node[n]<<endl;
	
	return 0;
}


Measured memory_bytes: 1024
while True:
    h,m,s = map(int, raw_input().split())
    if h == -1:
        break
    ls = 7200 - (3600*h + 60*m + s)
    ls3 = 3*ls
    print "%02d:%02d:%02d" % (ls/3600,ls%3600/60,ls%3600%60)
    print "%02d:%02d:%02d" % (ls3/3600,ls3%3600/60,ls3%3600%60)

Measured memory_bytes: 4204
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long long int x[2000];
long long int y[2000];
long long int z[2000];
long long int xa,ya,za;

bool comp(int a, int b) {
    return x[a]*xa+y[a]*ya+z[a]*za>x[b]*xa+y[b]*ya+z[b]*za;
}



int main(void){
    int N,M;
    scanf("%d %d",&N,&M);
    for(int i=0;i<N;i++){
        scanf("%lld %lld %lld",&x[i],&y[i],&z[i]);
    }
    long long int ans=0;
    for(int i=-1;i<2;i+=2)for(int j=-1;j<2;j+=2)for(int k=-1;k<2;k+=2){
        xa=(long long int)i;
        ya=(long long int)j;
        za=(long long int)k;
        vector<int> po;
        for(int h=0;h<N;h++)po.push_back(h);
        sort(po.begin(),po.end(),comp);
        long long int karians=0;
        for(int l=0;l<M;l++)karians+=x[po[l]]*xa+y[po[l]]*ya+z[po[l]]*za;
        if(karians>ans)ans=karians;
    }
    printf("%lld",ans);
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{
    int n, k, i, j, max;
    char s[101];
    int h1[26], h2[26];

    scanf("%d%s", &n, s);

    max = 0;
    for (i=1; i<n-1; i++) {
        memset(h1, 0, sizeof(h1));
        memset(h2, 0, sizeof(h2));
        k = 0;

        for (j=0; j<i; j++) h1[s[j]-'a']++;
        for (j=i; j<n; j++) h2[s[j]-'a']++;

        for (j=0; j<26; j++) {
            if (h1[j] && h2[j]) k++;
        }

        if (k>max)  max = k;
    }

    printf("%d\n", max);

    return 0;
}

Measured memory_bytes: 128
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int x = a - (b + c);
    if (x <= 0) {
      System.out.println(Math.abs(x));
    } else {
      System.out.println(0);
    }
  }
}

Measured memory_bytes: 22868
#include <iostream>
using namespace std;
int main(){
  int c ,a ,n ,team=0 ,year;
  cin >> year;
  while( year > 0 ){
    cin >> c >> a >> n;

    if( c >= 1 && a >= 1 && n >= 1 ){ // CAN型
      while( c >= 1 && a >= 1 && n >= 1 ){
	team++;
	c--;
	a--;
	n--;
      }
    }
    
    if( c >= 2 && a >= 1 ){ // CCA型
      while( c >= 2 && a >= 1 ){
	team++;
	c -= 2;
	a -= 1;
      }
    }
    
    if( c >= 3 ){ // CCC型
      while( c >= 3 ){
	team++;
	c -= 3;
      }
    }
   
    cout << team << endl;
    team = 0;
    year--;
  }
}

Measured memory_bytes: 1160
//@formatter:off
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<P>
#define vvp vector<vector<P>>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << '\n'; }
void YES(bool b) { cout << (b ? "YES" : "NO") << '\n'; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    string s;
    cin >> s;
    if (s.back() == 's') s.pb('e');
    cout << s << 's' << endl;
}

Measured memory_bytes: 3664
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String ans = "Yes";
        int[] H = new int[n];
        Arrays.setAll(H, i -> Integer.parseInt(sc.next()));
        for(int i = n-1; i > 0; i--) {
            if(H[i-1] > H[i]) H[i-1]--;
            if(H[i-1] > H[i]) {
                ans = "No"; break;
            }
        }
        System.out.println(ans);
    }
}


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

using namespace std;

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    ll x, y;
    cin >> x >> y;
    ll cnt = 0;
    if(abs(x) - abs(y) > 0) {
        if(x > 0) {
            cnt++;
            x *= -1;
        }
        cnt += abs(x) - abs(y);
        if(y > 0) {
            cnt++;
        }
    } else if(abs(x) - abs(y) < 0) {
        if(x < 0) cnt++;
        cnt += abs(y) - abs(x);
        if(y < 0) cnt++;
    } else {
        if(x != y) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

using namespace std;
#define ll long long

int main()
{
    string s1,s2;
    cin >> s1 >> s2;
    if(s1=="H")
    {
        cout << s2 << endl;
    }
    else
    {
        if(s2=="H")
        cout << "D" << endl;
        else cout << "H" << endl;

    }
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, k;
    cin >> a >> b >> k;
    for(int i = 0; i < k; i++){
        if(i % 2 == 0){
            a = a / 2;
            b += a;
        }else{
            b = b / 2;
            a += b;
        }
    }
    cout << a << ' ' << b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
typedef long long int lli;
#define tc int t;cin>>t;while(t--)
#define f first
#define s second
#define pb push_back
#define vi vector<int>
#define vll vector<lli>


int n;

void dfs(string s,char mx)
{
    if(s.length()==n)
    {
        cout<<s<<"\n";
        return;
    }
    for(char c='a';c<=mx;c++)
    {
        if(c==mx)
            dfs(s+c,mx+1);
        else
            dfs(s+c,mx);
    }

}

int main() {
   cin>>n;
   dfs("",'a');
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using M = map<string,ll>;


int main(){
    ll N;
    cin >> N;
    ll M;
    cin >> M;
    vector<ll> A(N,0);
    for(int i=0;i<N;i++){
        cin>>A[i]
    ;}
    ll sum=0;
    for(int i=0;i<N;i++){
        sum+=A[i]
    ;}
    sort(A.begin(), A.end());
    if(4*M*A[N-M]>=sum)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

return 0;
}  



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int ans = 0;
		for (int i = 0; i < n; i++) {
			ans += (sc.nextInt() >= k) ? 1 : 0;
		}
		System.out.println(ans);	
	}
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main(){
    int c[3][3];
    REP(i, 3) REP(j, 3) cin >> c[i][j];

    for(int a1 = -100; a1 <= 200; a1++){
        int b[3];
        REP(i, 3) b[i] = c[0][i] - a1;

        int a2 = c[1][0] - b[0];
        int a3 = c[2][0] - b[0];

        bool flag = true;
        REP1(i, 3) {
            if(c[1][i] !=  a2 + b[i] || c[2][i] != a3 + b[i]){
                flag = false;
                break;
            }
        }

        if(!flag) continue;
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <typeinfo>
#include <math.h>
#include <iomanip>
#include <limits>

using namespace std;
using ll = long long;
const ll res = 1000000007;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

int main() {
	bool f=false;
	string n;
	cin >> n;
	rep(i, 3) {
		if (n[i] == '7') {
			f = true;
		}
	}
	if (f == true) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (int i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (int i = x.size()-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define fst first
#define scd second
#define nextline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

map<string, int> mp;

int main()
{
    int n;
    cin>>n;
    REP(i,n) {
        string s;
        cin>>s;
        SORT(s);
        mp[s]++;
    }
    ll ans = 0ll;
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
        int n = itr->scd;
        //cout<<itr->fst<<" "<<itr->scd<<endl;
        ans += n * (n - 1ll) / 2;
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mid ((x + y) / 2)
#define left (ind * 2)
#define right (ind * 2 + 1)
#define mp make_pair
#define timer ((double)clock() / CLOCKS_PER_SEC)
#define endl "\n"
#define spc " "
#define d1(x) cerr<<#x<<":"<<x<<endl
#define d2(x, y) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl
#define d3(x, y, z) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;

const int N = (int)(1e6 + 5);
const int LOG = (int)(20);

lli n, suf[N], ans;
char s[N];

int main() {
	fast_io();
	// freopen("inp.in", "r", stdin);
	
	cin >> s + 1;
	n = strlen(s + 1);
	for(int i = n; i >= 1; i--)
		suf[i] = suf[i + 1] + (s[i] == 'W');
	for(int i = n; i >= 1; i--)
		if(s[i] == 'B')
			ans += suf[i];
	cout << ans;
}

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

#define ll long long
#define ld long double 
#define endl "\n"
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define fr(i,n) for(i=1;i<=n;i++)

typedef pair<int, int> II;
typedef vector< II > VII;
typedef vector<int> VI;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    string s;
    ll n, flag=1, tp=1;
    cin>>n;
    while(n!=0)
    {
        if(n%(tp*2)==0)
            s.PB('0');
        else
        {
            s.PB('1');
            n-=(tp*flag);
        }
        tp*=2;
        flag*=-1;
    }
    if(SZ(s)==0)
        s.PB('0');
    reverse(s.begin(), s.end());
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static class Task {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            char[] arr = in.next().toCharArray();
            int len = arr.length;
            int ans = 0;
            for (int i = 1; i < len; i++) {
                if (arr[i] != arr[i - 1]) {
                    ans++;
                }
            }
            out.println(ans);
        }
    }

    private static void sort(double[] arr) {
        Double[] objArr = Arrays.stream(arr).boxed().toArray(Double[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(int[] arr) {
        Integer[] objArr = Arrays.stream(arr).boxed().toArray(Integer[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(long[] arr) {
        Long[] objArr = Arrays.stream(arr).boxed().toArray(Long[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task task = new Task();
        task.solve(1, in, out);
        out.close();
    }

    public static void main(String[] args) {
        new Thread(null, () -> solve(), "1", 1 << 26).start();
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

    }

}

Measured memory_bytes: 30164
#include "bits/stdc++.h"
using namespace std;
typedef pair<int,int> P;

P book[1000];
bool dp[1000][1001]; //時間jをちょうど使ってi冊目までを適切に選んで感想を書けるか
int solve(int n)
{
	int ret=0;
	sort(book,book+n);
	int sum=0;
	for(int i=0;i<n-1;i++)
		sum+=book[i].first;
	if(sum<book[n-1].first)
	{
		ret=book[n-1].first*2;
		//1冊がとても重い場合スキマ時間になるべく感想を詰め込む
		int suki=book[n-1].first-sum; //スキマ時間の量
		fill(dp[0],dp[1000],false);
		dp[0][0]=true;
		for(int i=1;i<n;i++)
		{
			for(int j=0;j<1001;j++)
			{
				if(dp[i-1][j])
				{
					dp[i][j]=true;
					if(j+book[i-1].second<=suki)
						dp[i][j+book[i-1].second]=true;
				}
			}
		}
		int del=0;
		for(int i=0;i<=suki;i++)
		{
			if(dp[n-1][i])
				del=i;
		}
		sum=0;
		//感想の総時間を求める
		for(int i=0;i<n;i++)
			sum+=book[i].second;
		ret+=(sum-del);
	}else{
		//同時にすべての本が読み終わる場合感想は同時に書ける
		ret=sum+book[n-1].first;
		for(int i=0;i<n;i++)
			ret+=book[i].second;
	}
	return ret;
}

int main()
{
	while(1)
	{
		int n;
		cin>>n;
		if(n==0)
			break;
		for(int i=0;i<n;i++)
		{
			int r,w;
			cin>>r>>w;
			book[i]=P(r,w);
		}
		cout<<solve(n)<<endl;
	}
	return 0;
}


Measured memory_bytes: 4056
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

int ans;
int X;

int main(void) {
    scanf("%d", &X);

    int x = 0;
    rep(i, 1, 1000000000) {
        x += i;
        if (x >= X) {
            printf("%d\n", i);
            return 0;
        }
    }

	return 0;
}


Measured memory_bytes: 256
from functools import reduce
MOD = 10**9+7
n = int(input())
A = list(map(int, input().split()))


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    return a*(b//gcd(a, b))


x = reduce(lcm, A) % MOD
print(sum(x*pow(a, MOD-2, MOD) for a in A) % MOD)

Measured memory_bytes: 4708
n=int(input())
s=set()
wp=input()
s.add(wp)

f=True
for i in range(n-1):
  wn=input()
  if wp[-1]!=wn[0]:
    f=False
  elif wn in s:
    f=False
  wp=wn
  s.add(wn)

print('Yes' if f==True else 'No')


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

using namespace std;

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back

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

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

inline ll ds(ll n,ll b){
	ll res=0;
	while(n){
		res+=n%b;
		n/=b;
	}
	return res;
}

int main(){
	ll n,s;
	cin>>n>>s;
	for(ll b=2;b*b<=n;b++){
		if(ds(n,b)==s){
			cout<<b<<endl;
			return 0;
		}
	}
	ll g=sqrt(n)+1;
	for(ll k=min(g,s);k>=1;k--){
		ll b=(n-(s-k))/k;
		if(b>s-k&&b>k&&b*k+s-k==n&&ds(n,b)==s){
			cout<<b<<endl;
			return 0;
		}
	}
	if(n==s){
		cout<<n+1<<endl;
		return 0;
	}
	cout<<-1<<endl;
}


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

int main(){
	int n;
  	cin >> n;
  	vector<int> p(n), q(n);
  	rep(i, n) cin >> p[i];
  	rep(i, n) cin >> q[i];
  
  	vector<int> a(n);
  	rep(i, n) a[i] = i + 1;
  
  	map<vector<int>, int> mp;
  	do{
    	mp[a] = mp.size();
    }while(next_permutation(a.begin(), a.end()));
  
  	int ans = abs(mp[p] - mp [q]);
  	cout << ans << endl;
}

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

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#ifdef LOCAL
#define db(...) ({cout << "> Line " << __LINE__  \
		<< ": "; _db(#__VA_ARGS__, __VA_ARGS__);})
#else
#define db(...) true
#endif
template<class T>
void _db(const char *dbStr, T e) {
	cout << dbStr << " = " << e << endl;
}
template<class T, class... L>
void _db(const char *dbStr, T e, L... r) {
  while(*dbStr != ',') cout << *dbStr++;
  cout << " = " << e << ','; _db(dbStr + 1, r...);
}
template<class S, class T>
ostream& operator<<(ostream& o, const map<S, T>& v) {
	o << "["; int i = 0;
	for (const pair<S, T>& pr : v) o << (!i++ ? "" : ", ") << "{"
	<< pr.fs << " : " << pr.sc << "}"; return o << "]";
}
template<template <class, class...> class S, class T, class... L>
ostream& operator<<(ostream& o, const S<T, L...>& v) {
	o << "["; int i = 0;
	for (const auto& e : v) o << (!i++ ? "" : ", ") << e;
	return o << "]";
}
template<class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& pr) {
	return o << "(" << pr.fs << ", " << pr.sc << ")";
}
ostream& operator<<(ostream& o, const string& s) {
	for (const char& c : s) o << c; return o;
}
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = VV<V<T>>;
using ll = long long;
using pii = pair<int, int>;
using vi = V<int>;
using vii = V<pii>;
using vvi = VV<int>;
using mii = map<int, int>;
using umii = unordered_map<int, int>;
using si = set<int>;
using usi = unordered_set<int>;

const int MOD = 1000000007;

int main() {
	#ifdef LOCAL
	auto stTime = clock();
	#endif
//	freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin.tie(0);

	int N;
	string S;
	ll ans = 1;
	cin >> N >> S;
	int sum = 0;
	for (int i = 0; i < 2 * N; ++i) {
		if (S[i] == 'B') {
			if (sum % 2 == 0)
				++sum;
			else
				ans = (ans * sum--) % MOD;
		} else {
			if (sum % 2 == 0)
				ans = (ans * sum--) % MOD;
			else
				++sum;
		}
		if (sum < 0) {
			cout << "0\n";
			return 0;
		}
		db(sum);
	}

	if (sum) {
		cout << "0\n";
		return 0;
	}

	for (int i = 1; i <= N; ++i) {
		ans = (ans * i) % MOD;
	}

	cout << ans << '\n';
	#ifdef LOCAL
	cout << "\n\n\nExecution time: " <<
		(clock() - stTime) * 1e3 / CLOCKS_PER_SEC << " ms" << endl;
	#endif
    return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}
#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair<int,int>
#define MOD 1000000007
#define zeros(x) x&(x-1)^x
#define fi first
#define se second
#define Nmax 500005
const long double PI = acos(-1);

int n,A,B;

vector<int> solve(int A, int B, int n){
    // dbg(A,B,n);
    if (n==1){
        vector<int> ans;
        ans.push_back(A);
        ans.push_back(B);
        // dbg(ans);
        return ans;
    }
    for (int i=0;i<n;i++){
        if ((A & (1<<i)) != (B & (1<<i))){
            int msk = (1<<n) - (1<<(i+1));
            // dbg(msk,i);
            int A2 = ((A & msk)>>1) + (A & ((1<<i) - 1));
            int B2 = ((B & msk)>>1) + (B & ((1<<i) - 1));
            int C = (A2 ^ 1);
            // dbg(A2,B2,C);
            vector<int> ans1 = solve(A2, C, n-1);
            vector<int> ans2 = solve(C, B2, n-1);
            vector<int> ans;
            for (auto it : ans1){
                if (A & (1<<i)) ans.push_back(((it << 1) & msk) | (1<<i) + (it & ((1<<i) - 1)));
                else ans.push_back(((it << 1) & msk) + (it & ((1<<i) - 1)));
            }
            
            for (auto it : ans2){
                if (B & (1<<i)) ans.push_back(((it << 1) & msk) | (1<<i) + (it & ((1<<i) - 1)));
                else ans.push_back(((it << 1) & msk) + (it & ((1<<i) - 1)));
            }
            // dbg(ans);
            return ans;
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin >> n >> A >> B;
    if (__builtin_popcount(A) % 2 == __builtin_popcount(B) % 2){
        cout << "NO\n";
    }
    else{
        vector<int> ans = solve(A,B,n);
        cout << "YES\n";
        for (auto it : ans) cout << it << ' ';
        cout << '\n'; 
    }

    return 0;
}

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

// 円環の問題は切り開くと楽2周文とか
int main() {
  int k, n;
  int l_max = -1; // 家と家の距離の最大値
  std::cin >> k >> n;
  std::vector<int> a(n);
  for (int i = 0; i < n; i++) std::cin >> a[i];

  a.push_back(a[0]+k); // 円環を展開
  
  for (int i = 0; i < n; i++)
    l_max = std::max(l_max, a[i+1]-a[i]);

  std::cout << (k-l_max);
    

  return 0;
}

Measured memory_bytes: 4736
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t n,m,d;


int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> n>>m>>d;

	if (d == 0) {
		out
			<< std::fixed << std::setprecision(9)
			<< (double)(m-1) / (double)(n) << endl;
	}
	else {
		out
			<< std::fixed << std::setprecision(9)
			<< (double)(2*(m-1)) *(n - d)/(double)(n)/ (double)(n) << endl;
	}

	return 0;
}
#endif


Measured memory_bytes: 888
N, P = map(int, input().split())
A = list(map(int, input().split()))

# すべて偶数か判定
if all(a % 2 == 0 for a in A):
    if P == 0:
        print(2**N)
    else:
        print(0)
else:
    print(2**(N-1))

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

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int A = stdIn.nextInt();
		int B = stdIn.nextInt();
		int C = stdIn.nextInt();
		int D = stdIn.nextInt();
		int E = stdIn.nextInt();
		int F = stdIn.nextInt();
		
		double d = 0;
		double water = 0;
		double sugar = 0;
		double sum = 0;
		double sug = 0;
		for(int i = 0; 100*A*i <= F; i++) {
			for(int j = 0; 100*A*i+100*B*j <= F; j++) {
				for(int k = 0; 100*A*i+100*B*j+C*k <= F; k++) {
					for(int l = 0; 100*A*i+100*B*j+C*k+D*l <= F; l++) {
						water = 100*A*i+100*B*j;
						sugar = C*k+D*l;
						if((C*k+D*l) <= (A*i+B*j)*E && sugar/(water+sugar) >= d) {
							d = sugar/(water+sugar);
							sum = water+sugar;
							sug = sugar;
						}
					}
				}
			}
		}
		System.out.println((int)sum+ " " + (int)sug);
	}

}

Measured memory_bytes: 21972
use std::io::prelude::*;
fn main() {
    
    let scan = std::io::stdin();
    
    let mut line = String::new();
    let _ = scan.read_line(&mut line);
    let v: Vec<&str> = line.split_whitespace().collect();
    
    let n: usize = v[0].parse().unwrap_or(0);
    let m: usize = v[1].parse().unwrap_or(0);
    let l: usize = v[2].parse().unwrap_or(0);

    let mut a = vec![vec![0i64; m]; n];
    let mut b = vec![vec![0i64; l]; m];

    for (j,line) in scan.lock().lines().enumerate() {
        let uline = line.unwrap();
        let vec: Vec<&str> = uline.split_whitespace().collect(); 
        if j < n {
            for i in 0..m {
                a[j][i] = vec[i].parse().unwrap_or(0);
            }
        } else {
            for i in 0..l {
                b[j-n][i] = vec[i].parse().unwrap_or(0);
            }
        }
    }
    for i in 0..n {
        for j in 0..l {
            let mut sum: i64 = 0;
            for k in 0..m {
                sum += a[i][k] * b[k][j];
            }
            print!("{}",sum);
            if j != l-1 {
                print!(" ");
            }
        }
        println!("");
    }
}



Measured memory_bytes: 5060
#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 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<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef pair<double, double> pdd;

int n;
vector <int> E[100010];
int d[100010];
int ok;

void dfs(int x, int fa) {
	int cnt = 0;
	for(int e : E[x]) if(e != fa){
		dfs(e, x);
		if(d[e] == 0) ++cnt;
	}
	if(cnt == 0) d[x] = 0;
	else if(cnt == 1) d[x] = 1;
	else ok = 1;
}

void solve(){
	scanf("%d", &n);
	rep(i, n-1){
		int x, y; scanf("%d%d", &x, &y);
		E[x].pb(y);
		E[y].pb(x);
	}
	if(n == 2) {
		puts("Second");
		return;
	}
	int f = 1;
	for(int i=1;i<=n;i++) if(sz(E[i]) > 1) f = i;
	dfs(f, -1);
	puts(ok ? "First" : "Second");
}

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

Measured memory_bytes: 6272
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define enld endl

int main() {
	lint H1, M1, H2, M2, K;
	cin >> H1 >> M1 >> H2 >> M2 >> K;
	cout << (H2 * 60 + M2) - (H1 * 60 + M1) - K << endl;
}

Measured memory_bytes: 3636
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int[] b=new int[a];
        int c=0;
        int sum=0;
        for(int i=0;i<a;i++){
            b[i]=sc.nextInt();
            c=Math.max(c,b[i]);
            sum+=b[i];
        }
        System.out.println(sum-(c/2));
    }
}


Measured memory_bytes: 22740
#include<stdio.h>
int main(void)
{
	int A, B, a;

	scanf("%d", &A); scanf("%d", &B);

	a = A - B;

	int C, D;

	C = A - 1;
	D = B - 1;

	if (a > 0) {
		if (C > B)
			printf("%d", A + C);
		else
			printf("%d", A + B);
	}

	else{
		if (D > A)
			printf("%d", B + D);
		else
			printf("%d", B + A);
	}

	return 0;



}

Measured memory_bytes: 128
private fun readStrings() = readLine()!!.split(" ")
private fun readInts() = readStrings().map { it.toInt() }

private fun Long.positiveOrZero() = if (this > 0) this else 0

fun main(args: Array<String>) {
    val (N, K) = readInts().map { it.toLong() }
    if (K == 0L) return println(N * N)

    val suchPairsNum = (2..N).map { a ->
        (a - K).positiveOrZero() * (N / a) + (N % a - K + 1).positiveOrZero()
    }

    println(suchPairsNum.sum())
}

Measured memory_bytes: 40672
#include<bits/stdc++.h>
using namespace std;
int main() {
    std::ios::sync_with_stdio(false);
 
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    bool found = false;
    string res = "";
 
    for (int i = 0; i <= n - m; i++) {
        string ss = s;
        bool ok = true;
        for (int j = 0; j < m; j++) {
            if (ss[i + j] == '?') {
                ss[i + j] = t[j];
            } else if (ss[i + j] != t[j]) {
                ok = false;
                break;
            }
        }
        if (ok) {
            for (int j = 0; j < n; j++) {
                if (ss[j] == '?') ss[j] = 'a';
            }
            if (found) {
                if (ss < res) res = ss;
            } else {
                res = ss;
                found = true;
            }
        }
    }
 
    cout << (found ? res : string("UNRESTORABLE")) << "\n";
    return 0;
}

Measured memory_bytes: 256
def inpl(): return list(map(int, input().split()))

N, M, X, Y = inpl()
maxX = max(inpl())
minY = min(inpl())

for Z in range(X+1, Y+1):
    if maxX < Z and Z <= minY:
        print("No War")
        break
else:
    print("War")

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>

using namespace std;

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

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

int main(){
	int n;
	double ans=0.0;
	std::vector<double> aList;
	std::vector<std::vector<double>> dpList;

	std::cin>>n;

	aList.resize(n);
	dpList.resize(n+1);

	for(int i=0; i<n+1; i++)
		dpList[i].resize(n+1, 0.0);

	for(int i=0; i<n; i++)
		std::cin>>aList[i];

	dpList[0][0]=1.0;

	for(int i=0; i<n; i++){
		for(int j=0; j<i+1; j++){
			dpList[i+1][j]+= dpList[i][j] * aList[i];
			dpList[i+1][j+1]+= dpList[i][j] * (1.0 - aList[i]);
		}
	}

	for(int i=0; i< dpList[n].size()/2; i++)
		ans+= dpList[n][i];

	std::cout<<std::setprecision(10)<<ans<<std::endl;

	return 0;
}


Measured memory_bytes: 71808
import math
N,A,B = map(int,input().split())
H = [int(input()) for i in range(N)]
Hs = sum(H)
c = A - B
M = math.ceil(max(H) / B)

m = max(H) // A

while M - m > 1:
	n = (M + m) // 2
	H2 = [math.ceil((H[i] - n * B) / c) for i in range(N) if H[i] - n * B > 0]
	cnt = sum(H2)
	if cnt > n:
		m = n
	elif cnt == n:
		M = n
		break
	else:
		M = n
print(M)

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

int main()
{
    int n;
    cin >> n;
    int rate[9] {0};
    int a[101];
    for(int i = 0; i < n; i++){
        cin >> a[i];
        rate[min(a[i] / 400, 8)]++;
    }
    int ans = 0;
    for(int i = 0; i < 8; i++){
        if(rate[i] != 0){
            ans++;
        }
    }
    cout << max(ans, 1) << " " << ans + rate[8] << endl;
}

Measured memory_bytes: 256
N, Y = map(int, input().split())

for i in range(Y // 10000 + 1):
    money1 = Y
    money1 -= 10000 * i
    for j in range(money1 // 5000 + 1):
        money2 = money1 - 5000 * j
        k = N - i - j
        if money2 == 1000 * k:
            if i + j + k == N:
                print(i, j, k)
                exit()
else:
    print(-1, -1, -1)


Measured memory_bytes: 3060
from sys import stdin
import sys

N, K = [int(x) for x in stdin.readline().rstrip().split()]
A = list(map(int, input().split()))
B = [i for i in range(1, N+1)]
d = dict(zip(B, A))
t = [0 for i in range(N)]
d1 = dict(zip(B, t))
temp = 1
cnt = 0
ans = []
for i in range(K):
    d1[d[temp]] = d1.get(d[temp], 0)+1
    if d1.get(d[temp], 0) == 2:
        cnt += 1
        ans.append(d[temp])
        # print(i, d[temp])
    if d1.get(d[temp], 0) == 3:
        break
    temp = d[temp]
    if i == K-1:
        print(temp)
        sys.exit()
cnt1 = 0
for i, v in enumerate(d1):
    if d1[v] == 1:
        cnt1 += 1
# print(cnt, cnt1, d1, temp, ans)
k = K-1-cnt1
print(ans[k % cnt])


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

#include<algorithm>
#define str(a) to_string(a)
#define int long long
#define pb push_back
#define mp make_pair
#define SORT(c) sort(c.begin(),c.end())
#define max_heap priority_queue<int>
#define min_heap priority_queue< int,vector<int>, greater<int> >
#define mod 1000000007
#define setbits(x) __builtin_popcount(x)
#define ps(x,y) fixed<<setprecision(y)<<x
#define start(t) int x;cin>>x;while(x--)
#define inf LLONG_MAX
#define sync ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define N 1000001



int32_t main()
{
// 	ios_base::sync_with_stdio(0);
// 	cin.tie(0);
// 	cout.tie(0);
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	int n;
	cin >> n;
	vector<double> p(n + 1);
	for (int i = 1; i <= n; i++)	cin >> p[i];
	double dp[n + 1][ ((n + 1) / 2) + 1 ];
	dp[1][1] = p[1];
	double prod = 1;
	for (int i = 2; i <= n; i++) {
		dp[1][i] = 0;
	}
	for (int i = 1; i <= n; i++) {
		dp[i][0] = 1;
	}
	for (int i = 2; i <= n; i++) {
		for (int j = 1; j <= (n + 1) / 2; j++) {
			dp[i][j] = (p[i] * (dp[i - 1][j - 1])) + (1 - p[i]) * (dp[i - 1][j]);
			// cerr << "(" << i << "," << j << ") " << dp[i][j] << endl;
		}
	}
	cout << fixed << setprecision(10) << dp[n][(n + 1) / 2] << endl;

}










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

main()
{
  int n;
  int data;
  int minv = 114514, maxv = 0;
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> data;
    minv = min(data, minv);
    maxv = max(data, maxv);
  }

  cout << maxv - minv << endl;

  return (0);
}


Measured memory_bytes: 256