akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007
"""
#N,K,Mが入力
    n,k,m=LI() 
    #N
    #x1 y1
    #.  .
    #xn ynが入力
    N=I()
    p=LIR(N)
    print(n,k,m,p)
"""
from itertools import accumulate

def resolve():
    n=I()
    a=LI()
    asum = list(accumulate(a))
    ans=0
    right=0
    buf=0
    for left in range(n):
        
        
        while right<n and ((asum[right]-asum[left-1] if left>0 else asum[right])==(buf^a[right] if not(left==0 and right==0) else a[right])):
            buf=buf^a[right]
            right+=1
        ans+=right-left
        if left==right:
            right+=1
        else:
            buf=buf^a[left]

    print(ans)

    return
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """4
2 5 4 6"""
        output = """5"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """9
0 0 0 0 0 0 0 0 0"""
        output = """45"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """19
885 8 1 128 83 32 256 206 639 16 4 128 689 32 8 64 885 969 1"""
        output = """37"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Measured memory_bytes: 92472
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#define ll long long
#define ln printf("\n")
#define out(a) printf("%d",a)
const int N=1e5+50;
using namespace std;
int n,s,ans;
int a[N];
int read()
{
	int s=0,t=1; char c;
	while (c<'0'||c>'9'){if (c=='-') t=-1; c=getchar();}
	while (c>='0'&&c<='9'){s=s*10+c-'0'; c=getchar();}
	return s*t;
}
ll readl()
{
	ll s=0,t=1; char c;
	while (c<'0'||c>'9'){if (c=='-') t=-1; c=getchar();}
	while (c>='0'&&c<='9'){s=s*10+c-'0'; c=getchar();}
	return s*t;
}
int gcd(int a,int b)
{
	return a==0?b:gcd(b%a,a);
}
int main()
{
	n=read(); s=read();
	for (int i=1;i<=n;i++){
	  a[i]=read();
	  if (a[i]<s) ans=gcd(ans,s-a[i]);
	  else ans=gcd(ans,a[i]-s);
	}
	out(ans);
	return 0;
}

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

const int maxn = 1010, P = 1e9 + 7;
int n, m, f[maxn][maxn]; char s[maxn][maxn];

int main() {
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf("%s", s[i] + 1);
	}
	f[1][1] = s[1][1] != '#';
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (s[i][j] != '#' && (i > 1 || j > 1)) {
				f[i][j] = (f[i - 1][j] + f[i][j - 1]) % P;
			}
		}
	}
	printf("%d", f[n][m]);
	return 0;
}

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

int main(){

    long N;
    string S;
    cin >> N;
    cin >> S;

    long R[N],G[N],B[N];
    long rtmp,gtmp,btmp;

    long ans;
    ans=0;
    
    rtmp=0; gtmp=0; btmp=0;

    for(long i=0; i<N; i++){
        if( S[i]=='R' ){
            rtmp++;
        }else if( S[i]=='G' ){
            gtmp++;
        }else if( S[i]=='B' ){
            btmp++;
        }
        R[i]=rtmp;
        G[i]=gtmp;
        B[i]=btmp;
    }

    bool rflag, gflag, bflag;
    bool ijflag;

    for(long i=0; i<N-2; i++){
        for(long j=i+1; j<N-1; j++){

            rflag=false; gflag=false; bflag=false;
            ijflag=false;
            long isj=0;

            if( S[i]=='R' || S[j]=='R' ){
                rflag = true;
            }
            if( S[i]=='G' || S[j]=='G' ){
                gflag = true;
            }
            if( S[i]=='B' || S[j]=='B' ){
                bflag = true;
            }

            if( j+(j-i) <= N-1 ){
                ijflag = true;
                isj = j+(j-i);
            }

            if( rflag && gflag ){ // case B

                if(ijflag){
                    ans += B[isj-1] - B[j] + B[N-1] - B[isj];
                }else{
                    ans += B[N-1] - B[j];
                }
               
                //cout << "B: i j isj ans " << i << " " << j << " " << isj << " " << ans << endl;

            }else if( rflag && bflag ){ // case G

                //cout << "G: ans before " << ans << endl;
                //cout << "G: ijflag " << ijflag << endl;

                if(ijflag){
                    ans += G[isj-1] - G[j] + G[N-1] - G[isj];
                }else{
                    ans += G[N-1] - G[j];
                }

                //cout << "G: i j isj ans " << i << " " << j << " " << isj << " " << ans << endl;
                //cout << "G: ans after " << ans << endl;
                //cout << "G: G[N-1] G[j]  " << G[N-1] << " " << G[j] << endl;

            }else if( gflag && bflag ){ // case R

                if(ijflag){
                    ans += R[isj-1] - R[j] + R[N-1] - R[isj];
                }else{
                    ans += R[N-1] - R[j];
                }

                //cout << "R: i j isj ans " << i << " " << j << " " << isj << " " << ans << endl;

            }else{
                continue;
            }   

        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3736
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();
		s = s.replaceAll("eraser", "-");
		s = s.replaceAll("erase", "-");
		s = s.replaceAll("dreamer", "-");
		s = s.replaceAll("dream", "-");
		s = s.replaceAll("-", "");
		if(s.length() == 0) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 30724
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i = (a); i <= (b); ++i)
#define drep(i,a,b) for (int i = (a); i >= (b); --i)
#define grep(i,u) for (int i = head[u],v = e[i].v; i; v = e[i = e[i].nxt].v)
#define il inline
#define LL long long
#define ULL unsigned LL
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<LL,LL>
#define fi first
#define se second
using namespace std;
il int read() {
	int res = 0,f = 1; char ch = getchar(); while (!isdigit(ch)) {if (ch == '-') f = -f; ch = getchar();}
	while (isdigit(ch)) {res = res*10+ch-'0'; ch = getchar();} return res*f;
}
namespace qiqi {
	const int N = 5005,P = 1e9+7; int n,ecnt,head[N],f[N][N],g[N],h[N],siz[N]; struct Edge {int v,nxt;} e[N<<1]; il void add(int u,int v) {e[++ecnt] = (Edge){v,head[u]}; head[u] = ecnt;}
	void dfs(int u,int fa) {
		f[u][siz[u] = 1] = 1; grep(k,u) if (v != fa) {
			dfs(v,u); rep(i,1,siz[u]) {h[i] = f[u][i]; f[u][i] = 0;}
			rep(i,0,siz[u]) rep(j,0,siz[v]) f[u][i+j] = (f[u][i+j]+1LL*h[i]*f[v][j]%P)%P; siz[u] += siz[v];
		}
		rep(i,1,siz[u]>>1) f[u][0] = (f[u][0]-1LL*f[u][i<<1]*g[i]%P)%P;
	}
	void main() {n = read(); g[0] = 1; rep(i,1,n>>1) g[i] = 1LL*(i*2-1)*g[i-1]%P; rep(i,1,n-1) {int u = read(),v = read(); add(u,v); add(v,u);} dfs(1,0); printf("%d\n",(-f[1][0]+P)%P);}
}
int main() {qiqi::main(); return 0;}

Measured memory_bytes: 58372
N, C, K = map(int, input().split())
T = [0 for _ in range(N)]
for i in range(N):
    T[i] = int(input())
T = sorted(T)

flag = 0
cnt = 0
ans = 0
for i in range(len(T)):
    time = T[i] - T[flag]
    cnt += 1
    if time > K or cnt > C:
        flag = i
        cnt = 1
        ans += 1
print(ans + 1)


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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	string s;
	deque<char> d;
	cin >> s;
	for(int i=0; i<s.size(); i++){
		d.push_back(s[i]);
	}
	int q, br = 0;
	cin >> q;
	while(q--){
		int x, f;
		char c;
		cin >> x;
		if(x == 2){
			cin >> f >> c;
			if(f == 2 && br%2 == 0) d.push_back(c);
			else if(f == 2 && br%2 == 1) d.push_front(c);
			if(f == 1 && br%2 == 0)	d.push_front(c);
			else if(f == 1 && br%2 == 1) d.push_back(c);
		}
		if(x == 1){
			br++;
		}
	}
	int sz = d.size();
	if(br%2 == 1){
		for(int i=0; i<sz; i++){
			cout << d.back();
			d.pop_back();
		}
	}

	else{
		for(int i=0; i<sz; i++){
			cout << d.front();
			d.pop_front();
		}
	}

    return 0;
}


Measured memory_bytes: 976
import sys
readline = sys.stdin.readline

N, W = map(int, readline().split())

dp = [0] * (W+1)

weights = {0}
add = weights.add
for i in range(N):
    item_v, item_w = map(int, readline().split())
    for w in sorted(weights, reverse=True):
        if w+item_w <= W and dp[w+item_w] < dp[w] + item_v:
            dp[w+item_w] = dp[w] + item_v
            add(w+item_w)

print(max(dp))

Measured memory_bytes: 8928
#include<stdio.h>
int main(void)
{
	int a,b,i,e,w;
	scanf("%d %d",&a,&b);
	w=0;
	if(b==100){
		a=a*1000;
	}
	if(99>=b&&b>=10){
		a=a*100;
	}
	if(9>=b&&b>=0){
		a=a*10;
	}
	e=a+b;
	for(i=1;i<=10000;i++){
		if(i*i==e){
			w++;
		}
	}
	if(w==1){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1588
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#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 <random>
#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 = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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






class UnionFind{
    std::vector<int> par;
    std::vector<int> rank;
    std::vector<int> membnum;

public:
    UnionFind(){}
    UnionFind(int n): par(n), rank(n), membnum(n){
        for(int i(0); i < n; ++i){
            par[i] = i;
            rank[i] = 0;
            membnum[i] = 1;
        }
    }

    void resize(int n){
        int m(par.size());
        par.resize(n);
        rank.resize(n, 0);
        membnum.resize(n, 1);
        for(int i(m); i < n; ++i) par[i] = i;
    }

    int find(int x){
        if(x == par[x]) return x;
        else return par[x] = find(par[x]);
    }

    bool unit(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return false;

        if(rank[x] < rank[y]){
            par[x] = y;
            membnum[y] += membnum[x];
        }else{
            par[y] = x;
            if(rank[x] == rank[y]) ++rank[x];
            membnum[x] += membnum[y];
        }
        return true;
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }

    int howmany(int x){ //同じグループに属すものの個数(自分を含む)
        return membnum[find(x)];
    }
};

int main(){
    int N, M; std::cin >> N >> M;
    UnionFind uf(N);
    {
        int A, B;
        for(int i(0); i < M; ++i){
            std::cin >> A >> B;
            uf.unit(A-1, B-1);
        }
    }
    int ans(0);
    for(int i(0); i < N; ++i){
        chmax(ans, uf.howmany(i));
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 5632
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll A,B,V,W,T;
int main(){
    cin>>A>>V>>B>>W>>T;
    if(W>=V){
        cout<<"NO";
        return 0;
    }
    if((abs(A-B)-1)/(V-W)+1 <=T){
        cout<<"YES";
    }else{
        cout<<"NO";
    }

    return 0;
}

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

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

int main()
{
    int i, a[4];
    for (i = 0; i < 4; i++)
        scanf("%d", &a[i]);
    qsort(a, 4, sizeof(int), compare_int);
    if (a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9)
        printf("YES\n");
    else
        printf("NO\n");
}

Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <numeric>
 
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
ll N,K;
ll A[200005];
ll sosuu[200005];
bool found;
ll ans;
ll si;
priority_queue<ll> so[200005];
ll m;
map<ll,ll> mm;
char a;
int main() {
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> A[i];
        ans ^= A[i];
    }
    for(int i=0;i<N;i++){
        ll a =ans ^ A[i];
        cout << a << " ";
    }
}


Measured memory_bytes: 11396
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

template<typename T>
std::vector<std::vector<T>> mk2d(size_t s1, size_t s2, T const& val) {
  std::vector<T> tmp(s2, val);
  return std::vector<std::vector<T>>(s1, tmp);
}

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int H, W; std::cin >> H >> W;
  auto wall = mk2d<bool>(H, W, false);
  for(int i = 0; i < H; ++i) {
    std::string S; std::cin >> S;
    for(int j = 0; j < W; ++j) wall[i][j] = (S[j]=='#');
  }
  auto lh = mk2d<int>(H,W,0), lv = mk2d<int>(H,W,0);
  for(int i = 0; i < H; ++i) {
    int last = 0;
    bool pre = true;
    for(int j = 0; j < W; ++j) if(wall[i][j] != pre) {
      if(wall[i][j]) {
        int v = j-last;
        for(int k = last; k < j; ++k) lh[i][k] = v;
      } else last = j;
      pre = wall[i][j];
    }
    if(!wall[i][W-1]) {
      int v = W-last;
      for(int k = last; k < W; ++k) lh[i][k] = v;
    }
  }
  for(int j = 0; j < W; ++j) {
    int last = 0;
    bool pre = true;
    for(int i = 0; i < H; pre = wall[i++][j]) if(wall[i][j] != pre) {
      if(wall[i][j]) {
        int v = i-last;
        for(int k = last; k < i; ++k) lv[k][j] = v;
      } else last = i;
    }
    if(!wall[H-1][j]) {
      int v = H-last;
      for(int k = last; k < H; ++k) lv[k][j] = v;
    }
  }
  int ans = 0;
  for(int i = 0; i < H; ++i) for(int j = 0; j < W; ++j) {
    ans = std::max(ans, lh[i][j]+lv[i][j]-1);
  }
  fin(ans);
  return 0;
}


Measured memory_bytes: 32256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 110;
const int max_v = 100100;
ll dp[N][max_v];
ll w[N];
ll v[N];
int n, max_w;

int main() {
    cin >> n >> max_w;
    for(int i = 1; i <= n; i ++) {
        cin >> w[i] >> v[i];
    }
    memset(dp, 0x3f3f3f3f, sizeof dp);
    dp[0][0] = 0;
    for(int i = 1; i <= n; i ++) {
        for(int j = 0; j <= max_v; j ++) {
            dp[i][j] = min(dp[i][j], dp[i-1][j]);
            if(j >= v[i]) dp[i][j] = min(dp[i][j], dp[i-1][j-v[i]] + w[i]);
        }
    }
    for(int i = max_v-1; i >= 0; i --) {
        if(dp[n][i] <= max_w) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 86272
#include<bits/stdc++.h>
#define ll long long
#define pii pair<ll ,int>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5+5;
const ll mod=998244353;
ll n,a[maxn],b[maxn],m;
string s;
int main(){
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=0;i<=n;i++){
        cin>>a[i];
    }
    if(!n&&a[0]!=1||n&&a[0]||a[n]==0){
        cout<<-1;
        return 0;
    }
    for(int i=n;i;i--){
        b[i]=b[i+1]+a[i];//i~n有几个叶子节点
    }
    ll x=1;//当前非叶节点数
    m=0;//答案
    for(int i=0;i<n;i++){
        x-=a[i];//最大
        x=min(x,b[i+1]);
        if(x<=0){
            cout<<-1;
            return 0;
        }
        m+=x;
        m+=a[i];
        x*=2ll;
    }
    x-=a[n];
    x=min(x,b[n+1]);
    if(x!=0){
        cout<<-1;
        return 0;
    }
    m+=a[n];
    cout<<m<<'\n';
    return 0;
}


Measured memory_bytes: 5180
#include <iostream>
#define rep(i, n) for(int i=0;i<n;i++)
#define FOR(i, j, n) for(int i=j;i<n;i++)
using namespace std;
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0096
//
int main() {
    int n;

    long long dp[4][4001] = {};
    rep(i, 1001) dp[0][i] = 1;

    for (int i = 1; i < 4; i++) {
        for (int j = 4000; j >= 0; j--) {
            for (int k = 0; k <= 1000; k++) {
                if (j - k < 0) break;
                dp[i][j] += dp[i - 1][j - k];
            }
        }
    }

    while(1) {
        cin >> n;
        if (cin.eof()) break;
        cout << dp[3][n] << endl;
    }
    return 0;
}

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

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

template<class T,class U> void chmax(T& a, U b) {if(a<b)a=b;}
template<class T,class U> void chmin(T& a ,U b) {if(b<a)a=b;}

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;
    vector<vector<pii>> v(n);
    rep(i, n) {
        int a; cin >> a;
        rep(j, a) {
            int x, y;
            cin >> x >> y;
            x--;
            v[i].emplace_back(x, y);
        }
    }

    int ans = 0;
    rep(i, 1 << n) {
        int tmp = 0;
        bool ok = true;
        rep(j, n) if (i & (1 << j)) {
            for (auto& p : v[j]) {
                if ((p.second ^ (i >> p.first)) & 1) {
                    ok = false;
                    break;
                }
            }
            if (!ok) {
                tmp = 0;
                break;
            }
            tmp++;
        }
        chmax(ans, tmp);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <set>
#include <array>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <vector>
#include <tuple>
#include <string>
#include <math.h>
#include <time.h>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <limits>
#include <climits>
#include <numeric>
#include <functional>

#define lnd '\n'
// #define reverse(i, n) for(ll i = n-1; i >= 0; --i)
#define from(i, n) for (ll i = 0; i < n; ++i)
#define loop(i, n) for(ll i = 0; i < n; i++)
#define REPN(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(s) (s).begin(), (s).end()
#define rALL(s) (s).rbegin(), (s).rend()
#define sz(s) (int)(s).size()
#define mk make_pair
#define pb push_back
#define sqr(s) ((s) * (s))

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int ui;

template <class T>
T GCD (T a, T b) {
  if(a == 0) return b;
  return GCD(b%a, a);
}

template <class T>
T modpow(T x, T p){
    T res = 1;
    while(p > 0){
        if(p&1) res *= x;
        x *= x;
        p /= 2;
    }
    return res;
}

template <class T>
void print(T a[], ll n){
    for (ll i = 0; i < n; i++) std::cout << a[i] << ' ';
    cout << endl;
}

template<class T>
void printc(T c){
    for(auto const& v: c) std::cout << v << ' ';
    cout << endl;
}

struct HASH{
  size_t operator()(const pair<long,long>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};

bool pair_sort(const pair<int, int> &p1, const pair<int,int> &p2){
    if(p1.first != p2.first) return p1.first < p2.first;
    else return p1.second < p2.second;
}

const int INF = std::numeric_limits<int>::max();
const ll M_INF = std::numeric_limits<ll>::min();

void solution();
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solution();
    return 0;
}

void solution(){
      int k;
      int s[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
      cin >> k;

      cout << s[k-1]<< endl;

}   

Measured memory_bytes: 256
#include <algorithm>
#include <deque>
#include <iostream>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  cin >> n;
  deque<int> a;
  REP(i, n) {
    int val;
    cin >> val;
    if (i % 2 == 0)
      a.push_back(val);
    else
      a.push_front(val);
  }
  if (n % 2 == 0)
    REP(i, n) cout << (i ? " " : "") << a[i];
  else
    RREP(i, n) cout << (i != n - 1 ? " " : "") << a[i];
  cout << "\n";
  return 0;
}

Measured memory_bytes: 2944
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)
 
function main()
    R, G, B, N = readline() |> split |> parseMap
 
    ans = 0
    x = div(N, R)
    for r in 0:x
        y = div(N-R*r, G)
        for g in 0:y
            z = N - R*r - G*g
            if mod(z, B) == 0
                ans += 1
            end
        end
    end
 
    println(ans)
end

main()

Measured memory_bytes: 165440
N, K = map(int,input().split())
H = list(map(int,input().split()))

#DP[i] i番目までの足場を見たときの足場iにたどり着く最小値

DP = [float('inf') for _ in range(N + 1)] 
DP[0] = 0
for i in range(N):
    for k in range(1,K + 1):
        if 0 <= i - k and i - k < N:
            cost_min = float('inf')
            cost_min = min(cost_min, DP[i - k] +  abs(H[i] - H[i - k]))
            DP[i] = min(DP[i],cost_min)
print(DP[N - 1])



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

void answer1() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<int> d(N);
  for (auto& d_i: d) {
    cin >> d_i;
  }
  int sum = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      sum += d.at(i) * d.at(j);
    }
  }
  cout << sum << endl;
}


int main() {
  answer1();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;

#define INX(x) (cin >> x)
#define OUTX(x) (cout << x << endl)

#define ADD emplace_back
#define MP make_pair
#define VVEC(type) vector<vector<type>>


int main()
{
    ll X;
    INX(X);
    OUTX((X >= 30 ? "Yes" : "No"));


 
    return 0;
}


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

int main()
{
  long long n,i,var,pairs=0,doublet;
  cin>>n;
  
  long long numbers[n];
  map<long,long long> arr;
  set<long long> nums;

  for(i=0;i<n;i++)
  {
    cin>>var;
    numbers[i]=var;
    arr[var]++;
    nums.insert(var);
  }

  for(set<long long>::iterator it=nums.begin(); it!=nums.end(); ++it)
  {
    doublet=arr[*it];
    pairs+=(doublet*(doublet-1)/2);
  }

  for(i=0;i<n;i++)
  {
    cout<<pairs-arr[numbers[i]]+1<<endl;
  }

  return 0;

}

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

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

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

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

    int q;
    cin>>q;
    rep(i, q) {
        string s, t;
        cin>>s>>t;
        vector<vector<int>> dp(s.size() + 1, vector<int>(t.size() + 1));

        rep(i, s.size()) {
            rep(j, t.size()) {
                chmax(dp[i + 1][j + 1], dp[i][j + 1]);
                chmax(dp[i + 1][j + 1], dp[i + 1][j]);
                if (s[i] == t[j]) {
                    chmax(dp[i + 1][j + 1], dp[i][j] + 1);
                }
            }
        }
        cout<<dp[s.size()][t.size()]<<endl;
    }
}


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

bool check(string s){
  int n = s.length();
  if (n%2==1){
    return false;
  }
  else {
    return (s.substr(0,n/2)==s.substr(n/2));
  }
}

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

  int n = s.length();
  for (int i=n-1;; i--){
    if (check(s.substr(0,i))){
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int n[3]; rep(i, 3) cin >> n[i];
  int K; cin >> K;

  sort(n,n+3); n[2]*=pow(2,K);
  int result=0; rep(i, 3) result+=n[i];
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 384
n=parse(Int,readline())
t,a=map(x->parse(Int,x),split(readline()))
h=map(x->parse(Int,x),split(readline()))
ans=1e9;
id=0;
for i=1:n
	now=(t-a)*1000-h[i]*6;
	now=abs(now);
	if now<ans
		ans=now;
		id=i;
	end;
end;
print(id)

Measured memory_bytes: 166972
#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 n; cin >> n;
    string s;
    cin >> s;

    REP(i,s.size()) {
        char c = s[i]+n;
        if (c > 'Z') c -= 26;
        cout << c;
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			String[] a = IntStream.range(0, sc.nextInt()/*n*/).map(x->sc.nextInt()).distinct().mapToObj(String::valueOf).toArray(String[]::new);
			System.out.println(String.join(" ", a));
		}
	}
}



Measured memory_bytes: 88452
#include <stdio.h>
int main(void){
  int i,N,ans=0;
  if(scanf("%d",&N)<1) return 1;
  int P[N];
  for(i=0;i<N;i++){
    if(scanf("%d",&P[i])<1) return 1;
  }
  int min=P[0];
  for(i=0;i<N;i++){
    if(P[i]<=min){
      min=P[i];
      ans++;
    }
  }
  printf("%d\n",ans);      
  return 0;
}

Measured memory_bytes: 896
#define Oo ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#include <bits/stdc++.h>
using namespace std;
#define PI acos(-1.0)
typedef long long ll;
int main()
{
      Oo
string s;
cin>>s;
int ans=0;
for (int i=0; i<s.size(); i++)
{
      int temp=0;
      for (int j=i; j<s.size(); j++)
      {
            if (s[j]=='R')temp++;
            else break;
      }ans=max(ans, temp);
}
cout << ans << endl;
	return 0;
}




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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl '\n';
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll POSITIVE_INFINITY = 9223372036854775807;
const ll NEGATIVE_INFINITY = -9223372036854775807;
const ll MOD = 1000000007;
const ld PI = acos(-1.0);

template <typename T> inline T bigMod(T A,T B,T M = MOD){A %= M;T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T invMod (T A,T M = MOD){return bigMod(A,M-2,M);}

const int N = 200005;

int main(){
  FASTER;
  string str;
  cin >> str;
  for (char c : str){
    if (c == '7'){
      cout << "Yes\n";
      return 0;
    } 
  }
  cout << "No\n";
  return 0;
}


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

int main() {
    int A, B, C, D, E, F; 
    cin >> A >> B >> C >> D >> E >> F;

    int sugar = 0;
    int weight = A * 100;
    double conc = 0.0;
    for (int i = 0; i <= 30 / A; i++) {
        for (int j = 0; j <= 30 / B; j++) {
            for (int k = 0; k <= 1500 / C; k++) {
                for (int l = 0; l <= 1500 / D; l++) {
                    if ((A * i + B * j) * E < k * C + l * D || i + j == 0) {
                        break;
                    } else {
                        int w = i * A * 100 + j * B * 100 + k * C + l * D;
                        int s = k * C + l * D;
                        double c = 0;
                        if (w != 0) c = 1.0 * s / w;
                        if (w > F) break;
                        if (conc < c && c < 1) {
                                conc = c;
                                sugar = s;
                                weight = w;
                        }
                    }
                }
            }
        }
    }
    cout << weight << ' ' << sugar << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,s,t;cin>>n>>m>>s>>t;
    s--;t--;
    vector<vector<pair<ll,ll>>> yen_nbs(n),sn_nbs(n);
    rep(i,m){
        ll u,v,a,b;cin>>u>>v>>a>>b;
        u--;v--;
        yen_nbs[u].push_back(make_pair(v,a)); 
        yen_nbs[v].push_back(make_pair(u,a)); 
        sn_nbs[u].push_back(make_pair(v,b)); 
        sn_nbs[v].push_back(make_pair(u,b)); 
    }
    DEBUG{
        cout <<"test" << endl;
    }
    vector<ll> d_yen(n,1LL<<60),d_sn(n,1LL<<60);
    d_yen[s]=0;d_sn[t]=0;
    priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> pq;
    pq.push(make_pair(0,s));
    while(!pq.empty()){
        ll now = pq.top().second;
        pq.pop();
        for(auto x:yen_nbs[now]){
            if(chmin(d_yen[x.first],d_yen[now]+x.second)){
                DEBUG{

                    cout <<"in: "<< x.first << endl;
                }
                pq.push(make_pair(d_yen[x.first], x.first));
            }
        }
    }
    DEBUG{
        cout <<"test" << endl;
        cout << "size: "<< pq.size() << endl;
    }
    pq.push(make_pair(0,t));
    while(!pq.empty()){
        ll now = pq.top().second;
        pq.pop();
        for(auto x:sn_nbs[now]){
            if(chmin(d_sn[x.first],d_sn[now]+x.second)){
                DEBUG{

                    cout <<"in: "<< x.first << endl;
                }
                pq.push(make_pair(d_sn[x.first], x.first));
            }
        }
    }
    rep(i,n){
        pq.push(make_pair(d_yen[i]+d_sn[i],i));
    }
    rep(i,n){
        while(pq.top().second<i){
            pq.pop();
        }
        cout << (1000000000000000LL-pq.top().first) << endl;
    }
    return 0;
}


Measured memory_bytes: 19828
n,m=map(int,input().split())

# 上端
edge_l=1
if m > 1:
    edge_l+=1
if n > 1:
    edge_l+=1
if m > 1 and n > 1:
    edge_l+=1

edge_l = 1 if edge_l%2==1 else 0

edge_c=3
if n > 1:
    edge_c+=3
edge_c = 1 if edge_c%2==1 else 0

edge_row=edge_l
if m>1:
    edge_row+=edge_l
if m>2:
    edge_row+=(m-2)*edge_c

# 中央部
inner_l = 3
if m > 1:
    inner_l+=3
inner_l = 1 if inner_l%2==1 else 0

inner_c=1 # 絶対に裏

inner_row=inner_l
if m>1:
    inner_row+=inner_l
if m>2:
    inner_row+=(m-2)*inner_c

# 合計
total=edge_row
if n>1:
    total+=edge_row
if n>2:
    total+=(n-2)*inner_row
print(total)


Measured memory_bytes: 3064
{-# LANGUAGE TypeApplications #-}

main :: IO ()
main = do
  l1 <- getLine
  let [x, y] = map (read @Int) $ words l1
  putStrLn $ f x y

f x y
  | odd y = "No"
  | 2*x > y = "No"
  | 4*x < y = "No"
  | otherwise = "Yes"


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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    string v;
    unordered_map <string, int> m;
    for (int i = 0; i < n; ++i)
    {
        cin >> v;
        ++m[v];
    }
    cout <<  "AC x " << m["AC"] << '\n' << "WA x " << m["WA"] << '\n' << "TLE x " << m["TLE"] << '\n' << "RE x " << m["RE"] << '\n';
}

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

int main()
{
    int x, y;
    cin>>x>>y;
    if(x==1 and y==1)
        cout<<1000000;
    else if(x==1 and y==2 or y==1 and x==2)
        cout<<500000;
    else if(x==1 and y==3 or y==1 and x==3)
        cout<<400000;
    else if(x==2 and y==2)
        cout<<400000;
    else if(x==2 and y==3 or y==2 and x==3)
        cout<<300000;
    else if(x==3 and y==3)
        cout<<200000;
    else if(x==1 and y>3 or y==1 and x>3)
        cout<<300000;
    else if(x==2 and y>3 or y==2 and x>3)
        cout<<200000;
    else if(x==3 and y>3 or y==3 and x>3)
        cout<<100000;
    else 
        cout<<0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define st string
#define dl double
#define ve(i) vector<i>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define each(i, n) for(auto&& i: n)
#define pr(n) cout << fixed << setprecision(n)

int main() {
  int N, a = 0;
  cin >> N;
  ve(int) A(N), B(N), C(N - 1);
  rep(i, N) {
    cin >> A.at(i);
  }
  rep(i, N) {
    cin >> B.at(i);
  }
  rep(i, N - 1) {
    cin >> C.at(i);
  }
  rep(i, N) {
    a += B.at(i);
  }
  rep(i, N - 1) {
    if(A.at(i) + 1 == A.at(i + 1)) {
      a += C.at(A.at(i) - 1);
    }
  }
  cout << a << endl;
} 

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

int main(){
  string s;
  cin >> s;
  bool ans=false;
  if(s[0]==s[1]&&s[2]==s[3]&&s[0]!=s[2]) ans=true;
  if(s[0]==s[2]&&s[1]==s[3]&&s[0]!=s[1]) ans=true;
  if(s[0]==s[3]&&s[1]==s[2]&&s[0]!=s[1]) ans=true;
  if(ans) puts("Yes");
  else puts("No");
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
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=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int n;

main(){
	while(cin >> n, n){
		vector< pair<double, string> > db;
		REP(i, n){
			string l;
			double p,a,b,c,d,e,f,s,m;
			cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m;
			db.emplace_back(-(f*m*s-p)/(a+b+c+d+e+(d+e)*(m-1)), l);
		}
		sort(ALL(db));
		REP(i, n) cout << db[i].second << endl;
		cout << "#" << endl;
	}
	return 0;
}

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

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

    //good luck kittu!
    string s; cin>>s;
    int f[26] = {0}, n  = s.size();
    for(int i = 0; i<n; i++){
        f[s[i]-'a']++;
    }

    bool ok = 1;
    for(int x : f){
        if(x&1){
            ok = 0;
            break;
        }
    }
    cout<<(ok?"Yes\n":"No\n");
    return 0;
}

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

#current height
now = 0
total = 0

for a in A:
    #print("a", a)

    if a >= now:
        now = a
        pass
    else:
        total += now - a
    #print("now", now)
    #print("total", total)

print(total)


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

int main()
{
    int n;
    cin >> n;
    vector<int> l(n);
    rep(i, n) cin >> l[i];
    int ans = 0;
    rep(i, n - 2) {
        repl(j, i + 1, n - 1) {
            repl(k, j + 1, n) {
                if(l[i] + l[j] > l[k] && l[j] + l[k] > l[i] && l[k] + l[i] > l[j]) ans++;
                else continue;
                if(l[i] == l[j] || l[j] == l[k] || l[k] == l[i]) ans--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main(void)
{
	int D, G;
	cin >> D >> G;
	vector<int> p(D);
	vector<int> c(D);
	for (int i = 0; i < D; i++){
		cin >> p[i] >> c[i];
	}
	int bin = 1;
	for (int i = 0; i < D; i++){
		bin *= 2;
	}
	
	int min = 100 * 10;
	for (int i = 0; i < bin; i++){
		int sum = 0;
		int i_max = 0;
		int cnt = 0;
		int mask = 1;
		vector<bool> flag(D, false);
		for (int k = 0; k < D; k++){
			if ((mask & i) == mask){
				//cout << i << " " << mask << endl;
				sum += p[k] * (k + 1) * 100 + c[k];
				cnt += p[k];
			}
			else
				i_max = k;
			mask = mask << 1;
		}
		//cout << sum << " " << cnt << endl;
		
		if (sum < G){
			for (int k = 0; k < p[i_max]; k++){
				sum += (i_max + 1) * 100;
				cnt++;
				if (sum >= G)
					break;
			}
		}
		if (sum >= G){
			if (min > cnt){
				min = cnt;
			}
		}
	}
	cout << min << endl;
	return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(deprecated)]

use std::cell::{Cell, Ref, RefCell, RefMut};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;
use std::usize;

const MOD_10_9_7: u64 = 1_000_000_007;
const INF: i64 = 1_000_000_000_000;
const MIN_INF: i64 = -1_000_000_000_000;

/// FYI: https://github.com/vain0x/scan-bench
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let n = read!(usize);
    let strings: Vec<String> = read!(String; n);

    let mut cs: Vec<String> = strings
        .into_iter()
        .map(|s| {
            let mut tmp: Vec<_> = s.chars().collect();
            tmp.sort();
            tmp.into_iter().collect()
        })
        .collect();
    cs.sort();

    let mut ans = 0u64;
    let mut con_len = 1u64;
    let mut prev = "";
    for c in &cs {
        if &prev == c {
            con_len += 1;
        } else {
            prev = c;
            ans += (con_len * (con_len - 1)) / 2;
            con_len = 1;
        }
    }
    ans += (con_len * (con_len - 1)) / 2;

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


Measured memory_bytes: 12540
use std::io::*;
use std::mem;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let (n, k) = i.read2::<usize, usize>();
    let a = i.read_vec::<usize>(n);

    writeln!(o, "{}", solve(&a, k)).unwrap();
}
fn solve(a: &[usize], k: usize) -> usize {
    let mut s = Vec::new();
    let mut sum = 0;
    s.push(0);
    for &a in a {
        sum += a;
        s.push(sum);
    }

    let mut vs = (Vec::new(), Vec::new());
    for begin in 0..a.len() {
        for end in begin + 1..s.len() {
            vs.0.push(s[end] - s[begin]);
        }
    }

    let mut result = 0;
    for b in (0..64).rev() {
        vs.1.clear();
        for &v in &vs.0 {
            if (v >> b) & 1 == 1 {
                vs.1.push(v);
            }
        }
        if vs.1.len() >= k {
            result |= 1 << b;
            mem::swap(&mut vs.0, &mut vs.1);
        }
    }
    result
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        { $f:ident($($t:ident),*) } => {
            #[allow(dead_code)]
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                ($(read_next::<$t,_>(i)),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        fn_read! { read2(T1, T2) }
        fn_read! { read3(T1, T2, T3) }
        fn_read! { read4(T1, T2, T3, T4) }
        fn_read! { read5(T1, T2, T3, T4, T5) }

        pub fn read_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            self.read_line()
                .split(' ')
                .take(n)
                .map(|x| x.parse().ok().unwrap())
                .collect()
        }
    }
    fn read_next<'a, T: FromStr, I: Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }

}


Measured memory_bytes: 10360
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>

#define MAX_SIZE 100000000
typedef unsigned long long ull;
using namespace std;

bool solve() {
  int N,M,X,Y; cin >> N >> M >> X >> Y;

  vector<int> z_vec;
  for(int i = X + 1; i <= Y; i++) {
    z_vec.push_back(i);
  }

  vector<int> x_vec(N);
  for(auto& x : x_vec) {
    cin >> x;
  }
  vector<int> y_vec(M);
  for(auto& y : y_vec) {
    cin >> y;
  }

  for(auto z : z_vec) {
    bool ans = true;
    for(auto x : x_vec) {
      if(x >= z) {
        ans = false;
      }
    }

    for(auto y : y_vec) {
      if(y < z) {
        ans = false;
      }
    }

    if(ans) return true;
  }
  return false;
}

int main() {
  if(!solve()) {
    cout << "War" << endl;
  } else {
    cout << "No War" << endl;
  }
}


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

const int MOD = 1e9+7;
const int MAX_N = 1e5+10;
int N;
int a[MAX_N];
int cnt[MAX_N];

void solve()
{
	cnt[0]=3;
	ll ans = 1;
	for(int i=1;i<=N;++i){
		ans = (ans * cnt[a[i]]) % MOD;
		cnt[a[i]]--;
		cnt[a[i]+1]++;
	}
	cout << ans << "\n";
}

int main()
{
	cin >> N;
	for(int i=1;i<=N;++i) cin >> a[i];
	solve();
	return 0;
}

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

int ham[1000010]={0};
lld sum[1000010]={0};
int num[] = {2,3,5};

void solve(int now){
  if(now > 1000000) return;
  if(ham[now] != 0) return;
  for(int i=0;i<3;i++){
    solve(now*num[i]);
  }
  ham[now] = 1;
  return;
}

int main(){
  solve(1);
  for(int i=1;i<1000001;i++){
    sum[i] = ham[i] + sum[i-1];
  }
  int m,n;
  while(cin >> m , m){
    cin >> n;
    cout << sum[n] - sum[m-1] << endl;
  }
}

Measured memory_bytes: 11576