akhauriyash/Code-Regression huggingface dataset:
//
//  Created by Running Photon on 2015-04-09
//  Copyright (c) 2015 Running Photon. All rights reserved.
//
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>
#define ll long long
#define CLR(x) memset(x, 0, sizeof x)
using namespace std;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int maxn = 4e4 + 10;

int n, m, num, a[1005];
int dp[1005][205];
int costl[205][205];
int costs[205][205];
int main() {
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
//	freopen("out.txt","w",stdout);
#endif
	ios_base::sync_with_stdio(0);

	while(scanf("%d%d", &n, &m) != EOF && (n && m)){
		for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++){
			costs[i][j] = costl[i][j] = i == j ? 0 : inf / 3;
		}
		for(int i = 1; i <= m; i++){
			int u, v, val; char s[2];
			scanf("%d%d%d%s", &u, &v, &val, s);
			if(s[0] == 'L') costl[u][v] = costl[v][u] = min(val, costl[v][u]);
			else costs[u][v] = costs[v][u] = min(val, costs[v][u]);
		}
		scanf("%d", &num);
		for(int i = 1; i <= num; i++) scanf("%d", &a[i]);
		for(int k = 1; k <= n; k++) for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++){
			costs[i][j] = min(costs[i][j], costs[i][k] + costs[k][j]);
			costl[i][j] = min(costl[i][j], costl[i][k] + costl[k][j]);
		}
		memset(dp, 0x3f, sizeof dp);
		dp[1][a[1]] = 0;
		for(int i = 1; i <= num; i++){
			for(int j = 1; j <= n; j++){
				dp[i][j] = min(dp[i][j], dp[i-1][j] + costl[a[i-1]][a[i]]);
				for(int k = 1; k <= n; k++){
					dp[i][k] = min(dp[i][k], dp[i-1][j] + costl[a[i-1]][j] + costs[j][k] + costl[k][a[i]]);
				}
			}
		}
		int ans = inf;
		for(int i = 1; i <= n; i++) ans = min(ans, dp[num][i]);
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 2360
#include <iostream>
#include <bits/stdc++.h>
#define LEN 1000100
#define NIL -1
#define L 14
using namespace std;

char H[LEN][L];

void init () {for (int i; i < LEN; i++) H[i][0] = '\0';}
int h1 (int key) {return key % LEN;}
int h2 (int key) {return 1 + key % (LEN - 1);}
int _hash (int key, int i) {return (h1(key) + i * h2(key)) % LEN;}
int charToNumber (char a) {
    if (a == 'A') return 1;
    else if (a == 'C') return 2;
    else if (a == 'G') return 3;
    else if (a == 'T') return 4;
    return 0;
}
long long stringToNumber(char key[]) {
    long long k = 0, p = 1;
    for (int i=0; i < strlen(key); i++) {
        k += p * charToNumber(key[i]);
        p *= 5;
    }
    return k;
}

int insert (char key[]) {
    long long k = stringToNumber(key), i, h;
    for (i=0; ; i++) {
        h = _hash(k, i);
        if (strlen(H[h]) == 0) break;
        if (strcmp(H[h], key) == 0) return 1;
    }
    strcpy(H[h], key);
    return 0;
}

bool find (char key[]) {
    long long k = stringToNumber(key), i, h;
    for (i=0; ; i++) {
        h = _hash(k, i);
        if (strlen(H[h]) == 0) break;
        if (strcmp(H[h], key) == 0) return true;
    }
    return false;
}

int main(){
    int n;
    char command[10], key[L];
    init();
    cin >> n;
    for (int i=0; i < n; i++) {
        scanf("%s%s", command, key);
        if (command[0] == 'i') insert(key);
        else if (command[0] == 'f') {
            if (find(key)) printf("yes\n");
            else printf("no\n");
        }
    }
    return 0;
} 


Measured memory_bytes: 16836
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=n-1;i > m;i--)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl;
#define Vecpr vector<pair<lli,lli>>
#define mod 1000000007;
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  lli A,B,N,M,sum=0,num=0;
  string S;
  cin >> S;
  N=S.size();
  vector<int>P(0,0);
  rep(i,0,N){
    if(S[i]=='W')sum+=num;
    else num++;
  }
  Out(sum);
}

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

const int limit = 1000000;
int posr[limit+10],posc[limit+10];
int number[1010][1010];

bool prime[limit+10];

const int dr[4]={0,-1,0,1};
const int dc[4]={1,0,-1,0};

void init(){
	rep(i,limit+1) prime[i] = true;
	prime[0] = prime[1] = false;

	for(ll i = 2; i <= limit; ++i){
		if(prime[i]){
			for(ll j = i*i; j <= limit; j+=i){
				prime[j] = false;
			}
		}
	}

	
	int r = 500, c = 499, cnt = 1, step = 0;

	while(cnt < limit){
		rep(dir,4){
			if(dir % 2 ==0) step++;
			rep(loop,step){
				if(cnt > limit) break;
				number[r][c] = cnt;
				posr[cnt]=r,posc[cnt]=c;
				cnt++;
				r += dr[dir];
				c += dc[dir];
			}
		}
	}

}

using pii = pair<int,int>;
const pii ban = pii(-1,-1);
pii dp[1010][1010];

inline pii chmax(pii a,pii b){
	pii ret = a;
	if(a.first < b.first) ret = b;
	if(a.first == b.first and a.second < b.second) ret = b;
	return ret;
}


int main(void){
	init();

	int m,n;
	while(cin >> m >> n,m){
		rep(i,1010)rep(j,1010) dp[i][j]=ban;

		const int sr = posr[n],sc = posc[n];
		
		if(prime[n]){
			dp[sr][sc] = pii(1,n);
		}else{
			dp[sr][sc] = pii(0,0);
		}

		pii ans = ban;

		for(int r = sr; r < 1000; ++r){
			rep(c,1000){
				const int cur = number[r][c];
				if(cur > m) continue;
				if(dp[r][c] == ban) continue;

				for(auto &col:{c-1,c,c+1}){
					if(col < 0 or 1000 <= col) continue;
					const int tar = number[r+1][col];
					if(tar > m) continue;
					pii cur = dp[r][c];
					if(prime[tar]) cur.first++,cur.second = tar;
					dp[r+1][col] = chmax(dp[r+1][col],cur);
				}
			}
		}

		rep(r,1000)rep(c,1000){
			if(number[r][c] > m) continue;
			ans = chmax(ans,dp[r][c]);
		}

		cout << ans.first << " " << ans.second << endl;
	}
	return 0;
}

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

int main()
{
     int n,k;
     cin>>n;
     if(n%1000==0)
          cout<<"0\n";
     else
     {
          k=n/1000;
          k=(k+1)*1000-n;
          cout<<k<<"\n";
     }

     return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <set>
using namespace std;

int V, E;
vector<vector<int > > G;
int MAX = 100000;
int prenum[100000];
int parent[100000];
int lowest[100000];
bool visited[100000];
int timer = 0;

void dfs(int current, int prev){
    
    prenum[current] = lowest[current] = timer;
    timer++;
    visited[current] = true;
    
    int next = 0;
    for(int i = 0;  i < G[current].size(); i++){
        next = G[current][i];
        if(!visited[next]) {
            parent[next] = current;
            dfs(next, current);
            lowest[current] = min(lowest[current], lowest[next]);
        } else if(next != prev){
            lowest[current] = min(lowest[current], prenum[next]);
        }
    }
}

int main(void){
    // Your code here!
    cin >> V >> E;
    if(E==0) {
        return 0;
    } 
    G.resize(V);
    int s, t;
    for(int i = 0; i < E; i++){
        cin >> s >> t;
       
        G[s].push_back(t);
        G[t].push_back(s);
    }
    
    for(int i = 0; i < V; i++){
        visited[i] = false;
    }
    timer = 1;
    
   
    
    
    dfs(0, -1);
    set<int> ap;
    int np = 0;
    for(int i = 1; i < V; i++){
        int p = parent[i];
        if(p==0) np++;
        else if(prenum[p] <= lowest[i]) ap.insert(p);
    }
    
    if(np > 1) ap.insert(0);
    for(auto itr = ap.begin(); itr != ap.end(); ++itr) {
        cout << *itr << endl;
    }
    return 0;
}



Measured memory_bytes: 4528
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		ArrayList<Integer>[] map=new ArrayList[n];
		for(int i=0; i<n; i++){
			map[i]=new ArrayList<>();
		}
		for(int i=0; i<n-1; i++){
			int a=sc.nextInt()-1;
			int b=sc.nextInt()-1;
			map[a].add(b);
			map[b].add(a);
		}
		ArrayDeque<Integer> q=new ArrayDeque<>();
		int[] disf=new int[n];
		Arrays.fill(disf,-1);
		disf[0]=0;
		q.add(0);
		while(!q.isEmpty()){
			int s=q.poll();
			for(int i:map[s]){
				if(disf[i]==-1){
					disf[i]=disf[s]+1;
					q.add(i);
				}
			}
		}
		int[] diss=new int[n];
		Arrays.fill(diss,-1);
		diss[n-1]=0;
		q.add(n-1);
		int fe=n-1;
		while(!q.isEmpty()){
			int s=q.poll();
			for(int i:map[s]){
				if(diss[i]==-1){
					diss[i]=diss[s]+1;
					if(diss[i]<disf[i]){
						fe--;
					}else{
						continue;
					}
					q.add(i);
				}
			}
		}
		if(fe>n-fe){
			System.out.println("Fennec");
		}else{
			System.out.println("Snuke");
		}
	}
}


Measured memory_bytes: 103256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;
const int ny[4] = {-1,1,0,0}, nx[4] = {0,0,-1,1};
int sy,sx,gy,gx;

int main(){
  int s; cin >> s;
  vector<int> a;
  a.push_back(s);
  while(1){
    int temp = a.back();
    if(temp % 2 == 0){
      a.push_back(temp/2);
    }else{
      a.push_back(temp * 3 + 1);
    }
    for(int i = 0; i < a.size(); i++){
      for(int j = i+1; j < a.size(); j++){
        if(a[i] == a[j]){
          cout << j+1 << endl;
          return 0;
        }
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>	
#include <cmath>
#include <string>
#include<math.h>
#include<sstream>//���炵���̂Œ���
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define Cout(s) cout<<s<<endl
using namespace std;
typedef long long ll;
string Yes(bool b) { if (b) { return "Yes"; } else { return "No"; } }
string YES(bool b) { if (b) { return "YES"; } else { return "NO"; } }
//================================================

int a = 1, b = 0, c, d, n, k = 0, ans = 0;
string s, t;
int mod = 1000000007;

int main()
{
	int k, a, b; cin >> k >> a >> b;
	for (int i = a; i <= b; i++) {
		if (i % k == 0) { cout << "OK" << endl; return 0; }
	}
	cout << "NG" << endl;

	return 0;
}


Measured memory_bytes: 3616
import math
n, m = map(int, input().split())
if abs(n - m) >= 2:
    print(0)
elif n == m:
    print((2 * math.factorial(n) * math.factorial(m)) % (10**9 + 7))
else:
    print(math.factorial(n) * math.factorial(m) % (10**9 + 7))


Measured memory_bytes: 10992
import sys
input = sys.stdin.readline

def dijkstra(edges, size, src):
    from heapq import heappush, heappop

    INF = 10**18
    dist = [INF] * size
    dist[src] = 0
    pq = [(0, src)]
    while pq:
        d, v = heappop(pq)
        if d > dist[v]:
            continue
        for u, weight in edges[v]:
            nd = d + weight
            if dist[u] > nd:
                dist[u] = nd
                heappush(pq, (nd, u))
    return dist

xs, ys, xt, yt = map(int, input().split())
N = int(input())
xyr = [tuple(map(int, input().split())) for _ in range(N)]
xyr.append((xs, ys, 0))
xyr.append((xt, yt, 0))
edges = [[] for _ in range(N+2)]
for i in range(N+1):
    for j in range(i, N+2):
        xi, yi, ri = xyr[i]
        xj, yj, rj = xyr[j]
        d = max(0, ((xj-xi)**2 + (yj-yi)**2)**0.5 - (ri + rj))
        edges[i].append((j, d))
        edges[j].append((i, d))
d = dijkstra(edges, N+2, N)
print(d[N+1])

Measured memory_bytes: 126600
use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let b: Vec<u32> = (0..(n - 1)).map(|_| it.next().unwrap().parse().unwrap()).collect();
    let mut ans = b[0] + b[n - 2];
    for i in 1..(n - 1) {
        ans += std::cmp::min(b[i - 1], b[i]);
    }
    println!("{}", ans);
}

fn main() {
    run();
}

Measured memory_bytes: 4352
#pragma warning(disable:4996)
#include<stdio.h>
int main(void) {
	char s[101];
	bool j = true;
	fgets(s, sizeof(s), stdin);
	for (int i = 0; s[i] != NULL; ++i) {
		if ((i + 1) % 2 == 0) {
			if (s[i] == 'R') {
				j = false;
				break;
			}
		}
		else {
			if (s[i] == 'L') {
				j = false;
				break;
			}
		}
	}
	j ? printf("Yes") : printf("No");
	return 0;
}


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

int main() {
    long long a, b, c, k;  cin >> a >> b >> c >> k;
    long long ans = 0;

    ans += min(a, k);
    k -= min(a, k);

    k -= min(b, k);

    ans -= min(c, k);

    cout << ans << endl;
}


Measured memory_bytes: 3596
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

#ifdef DEBUG
mt19937 mrand(300); 
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); 
#endif

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int mod = (int) 1e9 + 7;

int mul (int a, int b) {
  return (long long) a * b % mod;
}

void add(int &a, int b) {
  a += b;
  if (a >= mod) {
    a -= mod;
  }
}

const int maxn = 4005;
int n, m, k;

bool read() {
  if (scanf("%d%d%d", &n, &m, &k) < 3) {
    return false;
  }
  return true;
}

int dp[maxn][maxn];

void solve() {
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;
  for (int i = 0; i + 1 < maxn; i++) {
    for (int j = 0; j < maxn; j++) {
      auto cur = dp[i][j];
      if (!cur) {
        continue;
      }
      add(dp[i + 1][j], cur);
      if (j + k < maxn) {
        add(dp[i + 1][j + k], mod - cur);
      }
    }
    for (int j = 0; j + 1 < maxn; j++) {
      add(dp[i + 1][j + 1], dp[i + 1][j]);
    }
  }
  int res = 0;
  for (int del1 = 0; del1 < m; del1 += k - 1) {
    int len = (n + m - del1 - 1) / (k - 1);
    add(res, dp[len][m - del1]);
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


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

char s[2000010];
set <int> S;
int nextt[2000010][30],i,j;
int now[30];
int now_tot[2000010];

int main()
{
    scanf("%s",s);
    int len=strlen(s);
    int tot=0;
    for (i=len; i>=1; i--)
    {
        S.insert(s[i-1]-'a' );
        now_tot[i]=tot;
        if (S.size()==26)
        {
            tot++;
            S.clear();
        }
    }
    if (tot==0)
    {
        for(i=0; i<26; i++)
            if(S.count (i )==0)
            {
                printf("%c",i+'a');
                return 0;
            }
    }
    memset(now,0,sizeof(now));
    for (i=len; i>=1; i--)
    {
        for (j=0; j<26; j++)
            nextt[i][j]=now[j];
        now[s[i-1]-'a']=i;
    }
    int tmp=0;
    for (i=0; i<26; i++)
        if (S.count(i)==0)
        {
            tmp=now[i];
            break;
        }
    printf("%c",s[tmp-1]);
    for (i=1; i<tot; i++)
    {
        for (j=0; j<26; j++)
            if(now_tot[nextt[tmp][j]]==now_tot[tmp] -1 )
            {
                tmp=nextt[ tmp ][ j ];
                printf("%c",s[tmp-1]);
                break;
            }
    }
    for(i=0; i<26; i++)
        if(nextt[ tmp ][ i ]==0)
        {
            printf("%c",i+'a');
            break;
        }
    return 0;
}


Measured memory_bytes: 29696
n = int(input())
h = list(map(int,input().split()))

dp = [999999]*(n+1)
dp[0] = 0
dp[1] = 0
dp[2] = abs(h[1]-h[0])

for i in range(3,n+1):
	dp[i] = min(dp[i-1] + abs(h[i-1]-h[i-2]),
	 		dp[i-2] +abs(h[i-1] - h[i-3]))

print(dp[n])

Measured memory_bytes: 20492
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

typedef pair<int,int> P;

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

	bool ok = true;
	if(S[0]!='A'){
		ok = false;
	}else if('A'<=S[1]&&S[1]<='Z'){
		ok = false;
	}else{
		int n = 0;
		for(int i=2;i<strlen(S)-1;i++){
			if(S[i]=='C') n++;
		}
		bool small = true;
		for(int i=1;i<strlen(S);i++){
			if(S[i]!='C'&&'A'<=S[i]&&S[i]<='Z') small = false;
		}
		if(n!=1||!small) ok = false;
	}
	if(ok){
		printf("AC\n");
	}else{
		printf("WA\n");
	}

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
int main(){
    
    int n;
    std::cin>> n;
    
    constexpr int N_MAX=100;
    double a_inverse[N_MAX]={};
    
    double a_inverse_sum = 0.0;
    for(int i=0;i<n;i++){
        int a;
        std::cin>> a;
        a_inverse[i] = 1.0 / a;
        a_inverse_sum += a_inverse[i];
    }
    
    printf("%lf\n", 1.0 / a_inverse_sum);
    
    
    return 0;
}

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

int main() {
    std::cout<<std::fixed<<std::setprecision(10);

    int a, b, x; cin >> a >> b >> x;
    double y = double(2*x)/pow(a,2)-b;
    // cout << "y: " << y << endl;

    double theta = 0;

    if (y >= 0) {
        // yが0より大きい時は台形
        // thetaはradian
        theta = atan((b-y)/a);
    } else {
        // yが0より小さい時は三角形
        double z = float(x)*2/a/b;
        theta = atan(b/z);
    }
    double deg = theta/M_PI*180;
    cout << deg << endl;
    return 0;
}

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

void change(int *a,int *b)
{
    int temp = *a;
    *a = *b;
    *b = temp;
}
 
int main(void)
{
    int a,b;

    cin >> a;

    a = a + a*a + a*a*a;

    cout << a << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N,M,K;
    cin >> N >> M >> K;
    vector<int>A1(N);
    vector<int>B1(M);
    vector<int>A;
    vector<int>B;
    int cnt1 = N;
    for(int i = 0; i < N; i++) {
        cin >> A1[i];
    }
    for(int i = 0; i < M; i++) {
        cin >> B1[i];
    }
    A.push_back(0);
    B.push_back(0);
    int cnt = 0;
    for(int i = 0; i < N; i++) {
        cnt = cnt+A1[i];
        if(cnt > K) {
            cnt1 = i;
        }
        A.push_back(cnt);
    }
    cnt = 0;
    for(int i = 0; i < M; i++) {
        cnt = cnt+B1[i];
        B.push_back(cnt);
    }
    int ans = 0;
    for(int i = 0; i <= cnt1; i++) {
        auto it = upper_bound(B.begin(),B.end(),K-A[i]);
        if(it == B.end()) {
            ans = max(ans,i+M);
        }
        int X = it-B.begin()-1;
        if(X >= 0) {
            ans = max(ans,i+X);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 11048
N=int(input())
s=[0]*N
for i in range(0,N):
    s[i]=int(input())
if sum(s)%10!=0:
    print(sum(s))
else:
    NN=sum(s)
    for i in range(0,N):
        if s[i]%10!=0 and s[i]<NN:
            NN=s[i]
    print(sum(s)-NN)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp fixed << setprecision
#define pb(x) push_back(x)
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    cout << C << ' ' << A << ' ' << B << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
vector<int> graph[51];
bool visited[51];
vector<pair<int, int>> edge;

bool dfs(int s, int v, bool f){
    for(int i = 0;i < graph[s].size();i++){
        int c = graph[s][i];
        if(!visited[c]){
            if(c == v){
                if(f)   return false;
                else    continue;
            }
            visited[c] = true;
            if(!dfs(c, v, true)){
                return false;
            }
        }
    }
    return true;
}
int main(){
    int N, M;
    cin >> N >> M;
    for(int i = 0;i < M;i++){
        int ai, bi;
        cin >> ai >> bi;
        graph[ai].emplace_back(bi);
        graph[bi].emplace_back(ai);
        edge.emplace_back(ai, bi);
    }
    int ans = 0;
    for(int i = 0;i < edge.size();i++){
        int ss = edge[i].first;
        int vv = edge[i].second;
        for(int j = 1;j <= N;j++)   visited[j] = false;
        visited[vv] = true;
        if(dfs(vv, ss, false)) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        char[] s = sc.next().toCharArray();
        boolean[] ok = new boolean[n+1];
        for (int i = 0; i < n+1; i++) {
            if(s[i] == '0') ok[i] = true;
        }
        int[] dp = new int[n+1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        ArrayDeque<Integer> q = new ArrayDeque<>();
        q.add(0);
        for (int i = 1; i <= n; i++) {
            if(m < i - q.peek()) q.poll();
            if(q.isEmpty()) break;
            if(!ok[i]) continue;
            dp[i] = dp[q.peek()] + 1;
            q.add(i);
        }
        if(n < dp[n]){
            System.out.println(-1);
        }else{
            int pre = n;
            int tpre = n;
            int idx = dp[n]-1;
            int[] ans = new int[dp[n]+1];
            for (int i = n-1; i >= 0; i--) {
                if(m < pre - i){
                    ans[idx+1] = pre - tpre;
                    pre = tpre;
                    idx--;
                }
                if(dp[i] == idx){
                    tpre = i;
                }
            }
            ans[1] = pre;
            StringBuilder sb = new StringBuilder();
            for (int i = 1; i <= dp[n]; i++) {
                sb.append(ans[i] + " ");
            }
            System.out.println(sb.toString().trim());
        }
        sc.close();

    }

}


Measured memory_bytes: 44212
#include <iostream>
using namespace std;
int main(){
    int x, y, i, j;
    while(true){
        cin >> x >> y;
        if(x==0 && y==0)
            break;
        for(i=0; i<x; i++){
            for(j=0; j<y; j++){
                if(i==0 || j==0 || j==y-1 || i==x-1){
                    cout << '#';
                }else{
                    cout << '.';
                }
            }
        cout << endl;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3024
#include <iostream>
#include <algorithm>
#include <climits>
#define SIZE 100001
#define INF INT_MAX >> 1

using namespace std;

int dp[SIZE];

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

	fill(dp, dp+n, INF);
	dp[0] = 0;
	for(int i=1; i<n; i++){
		for(int j=1; j<=k; j++){
			if(i-j >= 0) dp[i] = min(dp[i], dp[i-j] + abs(h[i-j]-h[i]));
		}
	}

	cout << dp[n-1] << endl;
}

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

void solve(long long N, long long K) {
    long long int n, m;
    double ans = 0;
    for (n = 1; n <= N; n++) {
        if (n < K) {
            m = ceil(log2((double)K/n));
            ans += 1.0 / N * pow(0.5, m);
        } else {
            ans += 1.0 / N;
        }
    }

    printf("%.12lf\n", ans);
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  solve(N, K);
  return 0;
}


Measured memory_bytes: 4164
# エラトステネスの篩, 累積和
def make_prime_table(N):
    sieve = [0] * (N + 1)
    sieve[0] = -1
    sieve[1] = -1
    for i in range(2, N + 1):
        if sieve[i] != 0:
            continue
        sieve[i] = i
        for j in range(i * i, N + 1, i):
            if sieve[j] == 0:
                sieve[j] = i
    return sieve

max_lr = 10 ** 5

prime_table = make_prime_table(max_lr)

cs = [0] * (max_lr + 1)
for i in range(3, max_lr + 1, 2):
    if prime_table[i] == i and prime_table[(i + 1) // 2] == (i + 1) // 2:
        cs[i] = 1
for i in range(1, max_lr + 1):
    cs[i] += cs[i - 1]

Q = int(input())
for _ in range(Q):
    l, r = map(int, input().split())
    print(cs[r] - cs[l - 1])


Measured memory_bytes: 12540
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
/*template <typename T>
T pow(T a, ll n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}
 
template <int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) {
        if ((x = x_ % mod + mod) >= mod) x -= mod;
    }
    ModInt& operator+=(ModInt rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator-=(ModInt rhs) {
        if ((x -= rhs.x) < 0) x += mod;
        return *this;
    }
    ModInt& operator*=(ModInt rhs) {
        x = (unsigned long long)x * rhs.x % mod;
        return *this;
    }
    ModInt& operator/=(ModInt rhs) {
        x = (unsigned long long)x * rhs.inv().x % mod;
        return *this;
    }
 
    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }
 
    friend ostream& operator<<(ostream& s, ModInt<mod> a) {
        s << a.x;
        return s;
    }
    friend istream& operator>>(istream& s, ModInt<mod>& a) {
        s >> a.x;
        return s;
    }
};
 
using mint = ModInt<1000000007>;
*/
using Graph = vector<vector<int>>;
Graph G;
/*------------------------------------------------------------------*/
int main(){
  int n; cin >> n;
  vector<ll> x(n), y(n);
  rep(i, n) cin >> x[i] >> y[i];
  
  int sum_min = n;
  rep(i, n)rep(j, n){
    int sum = n;
    if(i == j) continue;
    int p = x[i] - x[j];
    int q = y[i] - y[j];
    rep(k, n)rep(l, n){
      if(k == l) continue;
      if(x[k] - x[l] == p and y[k] - y[l] == q) sum--;
    }
    sum_min = min(sum, sum_min);
  }
  cout << sum_min << endl;
}

Measured memory_bytes: 3552
type
    datatype=Integer;
    obj=array[1..100] of datatype;

var
    n,i,x,y: Integer;
    a: obj;

procedure qsort(l,r:Longint;var data:obj);
var
    i,j,mid,t: datatype;
begin
    if l>=r then
    begin
        exit;
    end;
    i:=l;
    j:=r;
    mid:=data[(l+r) div 2];
    // mid:=(data + (l+r) div 2)^;
    repeat
        while data[i]<mid do
        begin
            inc(i);
        end;
        while data[j]>mid do
        begin
            dec(j);
        end;
        if i<=j then
        begin
            t:=data[i];
            data[i]:=data[j];
            data[j]:=t;
            inc(i);
            dec(j);
        end;
    until i>j;
    qsort(l,j,data);
    qsort(i,r,data);
end;
begin
    readln(n);
    for i := 1 to n do
    begin
        read(a[i]);
    end;
    qsort(1,n,a);
    x:=0;
    y:=0;
    i:=n;
    while i>0 do
    begin
        inc(x,a[i]);
        dec(i,2);
    end;
    i:=n-1;
    while i>0 do
    begin
        inc(y,a[i]);
        dec(i,2);
    end;
    writeln(x-y);
    readln;
    readln;
end.

Measured memory_bytes: 128
N=int(input())
p=100
for i in range(1,N,1):
    s=i
    t=0
    while s>0:
        t+=s%10
        s=(s-s%10)//10
    u=N-i
    v=0
    while u>0:
        v+=u%10
        u=(u-u%10)//10
    n=t+v
    if p>n:
        p=n
print(p)

Measured memory_bytes: 3064
#coding:utf-8

n, a, b = map(int, input().split(' '))

total = 0
for i in range(1, n + 1):
  str_i = str(i)
  sum = 0
  for char in str_i:
    sum += int(char)
  if sum >= a and sum <= b:
    total += i
    
print(total)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define double long double

const int N = 1e5 + 5;

int n;
int x[N], y[N];
char d[N];

double calc(double t)
{
	double xmin = 1e12, xmax = -1e12, ymin = 1e12, ymax = -1e12;
	for(int i = 1; i <= n; i++)
	{	
		double cx = x[i], cy = y[i];
		if(d[i] == 'R')
			cx += t;
		else if(d[i] == 'L')
			cx -= t;
		else if(d[i] == 'U')
			cy += t;
		else
			cy -= t;
		xmin = min(xmin, cx);
		xmax = max(xmax, cx);
		ymin = min(ymin, cy);
		ymax = max(ymax, cy);
	}
	double ans = (xmax - xmin) * (ymax - ymin);
	return ans;
}

double ternary_search(double lo, double hi)
{
	for(int i = 1; i <= 500; i++)
	{
		double m1 = (lo * 2 + hi) / 3;
		double m2 = (lo + hi * 2) / 3;
		if(calc(m1) < calc(m2))
			hi = m2;
		else
			lo = m1;
	}
	return calc(lo);
}

int32_t main()
{
	IOS;
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> x[i] >> y[i] >> d[i];
	double ans = ternary_search(0, 2e8);
	cout << fixed << setprecision(12) << ans;
	return 0;
}

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


int main()
{
	string inputString;
	getline(cin, inputString);
	for (auto& c : inputString)
	{
		if (c != '.' && c != ' ') c += 'A' - 'a';
	}

	cout << inputString << endl;

	return 0;
}

Measured memory_bytes: 2988
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	var n int
	fmt.Scan(&n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	var (
		sum       int64
		min       = 10000000001
		isNegaOdd bool
	)
	for i := 0; i < n; i++ {
		sc.Scan()
		a, _ := strconv.Atoi(sc.Text())
		if a < 0 {
			isNegaOdd = !isNegaOdd
			a = -a
		}
		sum += int64(a)
		if a < min {
			min = a
		}
	}
	if isNegaOdd {
		sum -= int64(min * 2)
	}
	fmt.Println(sum)
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;

const ll INF = 1e18L+5;

void max_self(ll& a, ll b){
	a=max(a,b);
}

void min_self(ll& a ,ll b){
		a=min(a,b);
}

void test_case() {
	int n , w; 
	cin >> n >> w;
	vector<int> weight(n),value(n);
	for(int i=0 ; i < n ; i++)
		cin >> weight[i] >> value[i];
	int sum_value = 0;
	for(int x:value)
		sum_value+=x;
	vector<ll> dp(sum_value + 1,INF);
	dp[0]=0;
	for(int item = 0 ; item < n ; item++){
		for(int value_already = sum_value-value[item] ; value_already >= 0 ; value_already--){
			min_self(dp[value_already+value[item]],dp[value_already]+weight[item]);
		}
	}
	ll answer = 0;
	for(int i = 0 ; i <= sum_value ; i++){
		if(dp[i] <= w){
			answer = max(answer,(ll)i);
		}
	}
	cout<<answer;
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int T=1;
	while(T--) {
		test_case(); 
		
	}
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
long long gcd(long long a, long long b) {
  return b != 0 ? gcd(b, a % b) : a;
}

int main(){
  int n,i;
  scanf("%d",&n);
  long long t,s,ans=1;
  for(i=0;i<n;++i){
    scanf("%lld",&t);
    s=gcd(t,ans);
    ans=ans/s*t;
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 256
s=input()

s2list=list(s.replace("BC","D"))
#print(s2list)

block_list=[]
bl=[]
for s2 in s2list:
  if s2=="A" or s2=="D":
    bl.append(s2)
  else:
    if len(bl)>0:
      block_list.append("".join(bl))
      bl=[]
else:
  if len(bl)>0:
    block_list.append("".join(bl))
#print(block_list)

answer=0
for bl in block_list:
  #print(bl)
  cnt_a=0
  for c in bl:
    if c=="A":
      cnt_a+=1
    else:
      answer+=cnt_a
    
print(answer)

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

int main() {
    int n;
    cin>>n;
    if(n>=30){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
        

    
    
        
        
    return 0;
    
    
}

Measured memory_bytes: 3596
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
using namespace std;
using ll = long long;

ll dp[51][51][3000];

int main(){
  int n, a;
  cin >> n >> a;
  vector<int> x(n);
  
  for(int i = 0; i < n; i++){
    cin >> x[i];
  }
  
  dp[0][0][0] = 1;
  
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      for(int k = 0; k < 50*50; k++){
        if(dp[i][j][k]){
          dp[i+1][j][k] += dp[i][j][k];
          dp[i+1][j+1][k+x[i]] += dp[i][j][k];
        }
      }
    }
  }
  ll ans = 0;
  for(int i = 1; i < n+1; i++){
    ans += dp[n][i][i*a];
  }
  cout << ans << endl;
  
  
  return 0;
} 


Measured memory_bytes: 58112
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=int(a);i<=int(b);i++)
#define ROF(i,a,b) for(int i=int(b);i>=int(a);i--)
#define pb push_back
#define pq priority_queue
#define ps push
#define x first
#define y second
using namespace std;
int n,m,anw,now;
int main(){
    cin>>n>>m;
    anw=1;
    now=n;
    while(now<m){
        now+=(n-1);
        anw++;
    }
    if(m==1) cout<<"0";
    else cout<<anw;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    string S;
    cin >> S;
    
    int no_of_1s = 0;
    for(int i = 0; i < S.size(); i++)
        no_of_1s += (S[i] == '1');
    
    cout << no_of_1s;
    return 0;
}


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

int main(){
    int n; ll k;
    cin>>n>>k;
    vector<int>a(n);
    rep(i,n){
        cin>>a[i];
        a[i]--;
    }
    int now=a[0];
    vector<int>ans;
    set<int>se;
    ans.push_back(0);
    se.insert(0);
    ans.push_back(now);
    se.insert(now);
    while(1){
        now=a[now];
        ans.push_back(now);
        if(se.find(now)!=se.end())break;
        se.insert(now);
    }
    int start,loop,as=ans.size();
    rep(i,as-1){
        if(ans[i]==ans[as-1]){
            start=i;
            loop=as-1-i;
        }
    }
    if(k<=start)cout<<ans[k]+1<<endl;
    else{
        k-=start;
        cout<<ans[start+k%loop]+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 13912
a = gets.to_i
b = gets.to_i
c = gets.to_i
x = gets.to_i

count = 0

(a + 1).times do |i|
  (b + 1).times do |j|
    (c + 1).times do |k|
      if i * 500 + j * 100 + k * 50 == x
        count += 1
      end
    end
  end
end

puts count

Measured memory_bytes: 1788
n,a,b,c = map(int,input().split())

si = [input() for i in range(n)]

if a == 0 and b == 0 and c== 0:
    print("No")
    exit()

s1 = 0
s2 = 0

abc = [a,b,c]
moji = ['A','B','C']

def checkmoji(s):
    if s == "AB":
        s1 = 0
        s2 = 1
    elif s == 'AC':
        s1 = 0
        s2 = 2
    elif s == 'BC':
        s1 = 1
        s2 = 2
    return s1,s2

ans = []

for i in range(n):
    s1,s2 = checkmoji(si[i])
    if abc[s1] == 0 and abc[s2] == 0:
        print('No')
        exit()
    if abc[s2] == 0:
        abc[s1] -= 1
        abc[s2] += 1
        ans.append(moji[s2])
    elif abc[s1] == 0:
        abc[s1] += 1
        abc[s2] -= 1
        ans.append(moji[s1])
    else:
        
        if i == n-1:
            ans.append(moji[s1])
            break
        
        s1_a,s2_a = checkmoji(si[i+1])
        if s1 == s1_a or s1 == s2_a:
            abc[s1] += 1
            abc[s2] -= 1
            ans.append(moji[s1])
        else:
            abc[s1] -= 1
            abc[s2] += 1
            ans.append(moji[s2])
print('Yes')
for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 86292
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;

public class Main {
	
	public static final int SIZE = 5;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int count = 0;
		while(true){
			final int N = sc.nextInt();
			
			if(N == 0){
				break;
			}
			
			if(count != 0){
				System.out.println();
			}
			
			boolean[][][] box = new boolean[SIZE + 2][SIZE + 2][SIZE + 2];
			boolean[][][] tmp_box = new boolean[SIZE + 2][SIZE + 2][SIZE + 2];
			
			for(int z = 0; z < SIZE; z++){
				for(int y = 0; y < SIZE; y++){
					char[] input = sc.next().toCharArray();
					
					for(int x = 0; x < SIZE; x++){
						box[z + 1][y + 1][x + 1] = input[x] == '1';
					}
				}
			}
			
			final int M1 = sc.nextInt();
			Set<Integer> a_set = new HashSet<Integer>(M1);
			for(int i = 0; i < M1; i++){
				a_set.add(sc.nextInt());
			}
			
			final int M2 = sc.nextInt();
			Set<Integer> b_set = new HashSet<Integer>(M2);
			for(int i = 0; i < M2; i++){
				b_set.add(sc.nextInt());
			}
			
			
			for(int day = 0; day < N; day++){
				for(int z = 0; z < SIZE; z++){
					for(int y = 0; y < SIZE; y++){
						for(int x = 0; x < SIZE; x++){
							int around = 0;
							
							for(int z_t = -1; z_t <= 1; z_t++){
								for(int y_t = -1; y_t <= 1; y_t++){
									for(int x_t = -1; x_t <= 1; x_t++){
										if(z_t == 0 && y_t == 0 && x_t == 0){
											continue;
										}
										
										if(box[z + 1 + z_t][y + 1 + y_t][x + 1 + x_t]){
											around++;
										}
									}
								}
							}
							
							if(box[z + 1][y + 1][x + 1]){
								if(!b_set.contains(around)){
									tmp_box[z + 1][y + 1][x + 1] = false;
								}else{
									tmp_box[z + 1][y + 1][x + 1] = box[z + 1][y + 1][x + 1];
								}
							}else{
								if(a_set.contains(around)){
									tmp_box[z + 1][y + 1][x + 1] = true;
								}else{
									tmp_box[z + 1][y + 1][x + 1] = box[z + 1][y + 1][x + 1];
								}
							}
						}
					}
				}
				
				boolean[][][] swap = box;
				box = tmp_box;
				tmp_box = swap;
			}
			
			System.out.println("Case " + (count + 1) + ":");
			for(int z = 0; z < SIZE; z++){
				for(int y = 0; y < SIZE; y++){
					for(int x = 0; x < SIZE; x++){
						System.out.print(box[z+1][y+1][x+1] ? "1" : "0");
					}
					System.out.println();
				}
				
				if(z != SIZE - 1){
					System.out.println();
				}
			}
			
			count++;
		}
	}

}

Measured memory_bytes: 34932
using System;
using System.Collections.Generic;
 
public class Program{
    public static void Main(){
        int N=int.Parse(Console.ReadLine());
        long ans=0;
        var dict = new Dictionary<string, int>();
        for(int i=0;i<N;i++){
            char[] a=Console.ReadLine().ToCharArray();
            Array.Sort(a);
            string s=new String(a);
            if(dict.ContainsKey(s)){
                ans+=dict[s];
                dict[s]++;
            }else{
                dict.Add(s,1);
            }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 29144
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

const ll mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};


struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
    ll N;
    cin >> N;
    vector<ll> C(N);
    REP(i, N) cin >> C[i];
    sort(ALL(C));
    // reverse(ALL(C));
    
    combination comb = combination(N);
    mint ans = mint(0);
    // FOR(i, 1, N) {
    //     FOR(k, 0, N-i) {
    //         FOR(l, 0, i-1) {
    //             // iを変える時点で残ってるものの数
    //             ans += mint(2).pow(N) * mint(k + 1) * comb.operator()(N - i, k) * comb.operator()(i-1, l) * mint(C[i-1]);
    //         }
    //     }
    // }

    FOR(i, 1, N) {
        if(i < N)
            ans += mint(C[i-1]) * mint(2).pow(i-1) * mint(2).pow(N-i-1) * mint(N - i + 2);
        else
            ans += mint(C[i-1]) * mint(2).pow(i-1);
    }
    ans *= mint(2).pow(N);
    cout << ans.x << endl; 
    return 0;
}

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

using namespace std;

const int N = 1e2+7;

int a[3];

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int sum = 0;
    for (int i = 0; i < 3; ++i) cin >> a[i], sum += a[i];
    cout << (sum >= 22 ? "bust" : "win") << endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define M_PI 3.14159265358979
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include<iomanip>
#include<vector>
#include<cmath>
#include <algorithm>

using namespace std;


int main()
{
	int n, counter = 0;
	while (scanf("%d", &n) != -1){
		counter = 0;
		for (int a = 0; a < 10; a++){
			for (int b = 0; b < 10; b++){
				for (int c = 0; c < 10; c++){
					for (int d = 0; d < 10; d++){
						if (a + b + c + d == n) counter++;
					}
				}
			}
		}
		cout << counter<<endl;
	}
	return 0;
}

Measured memory_bytes: 1208
h, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
max_a = max(a for a, _ in ab)
dp = [10 ** 18 for _ in range(h + max_a)]
dp[0] = 0
for i in range(1, h + max_a):
    dp[i] = min(dp[i-a] + b for a, b in ab)
print(min(dp[h:]))


Measured memory_bytes: 3960
#include<bits/stdc++.h>
using namespace std;
int sum[200100],n,ans;
char s[200100];
int main()
{
	scanf("%d%s",&n,s+1);ans=n;
	for(int i=1;i<=n;i++) sum[i]=sum[i-1]+(s[i]=='#');
	for(int i=0;i<=n;i++)
		ans=min(ans,sum[i]+n-i-sum[n]+sum[i]);
	cout<<ans<<endl;
}

Measured memory_bytes: 4748
#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main() 
{ 
int a,b;
cin>>a>>b;
int a1=a+b;
if(a1%3==0||a%3==0||b%3==0)
cout<<"Possible";
else
cout<<"Impossible";
return 0;  
}

Measured memory_bytes: 3624
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <stack>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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;}

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

  int h, w;
  char a[110][110], ans[110][110];
  cin >> h >> w;
  REP(i, h) REP(j, w) cin >> a[i][j];

  int idx = 0, jdx = 0;
  REP(i, h) {
    bool ok = true;
    REP(j, w) if(a[i][j] == '#') ok = false;
    if(!ok){
      REP(j, w) ans[idx][j] = a[i][j];
      idx++;
    }    
  }

  REP(j, w) {
    bool ok = true;
    REP(i, h) if(a[i][j] == '#') ok = false;
    if(!ok){
      REP(i, h) ans[i][jdx] = ans[i][j];
      jdx++;
    }    
  }  
  
  REP(i, idx) {
    REP(j, jdx) cout << ans[i][j];
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
// Frog 1

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>
#include <numeric>

using namespace std;

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

    //vector< vector<int> > dp = vector< vector<int> >(n, vector<int>(n, 0));

    // dp[i]: 足場iに着くまでにかかる最小コスト
    int *dp;
    dp = (int*)malloc(sizeof(int) * n);

    dp[1] = abs(h[0] - h[1]);

    for (int i = 2; i < n; i++) {
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
    }

    cout << dp[n-1] << endl;

    return 0;
}


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

int main()
{
	int a, b, h, m;
	cin >> a >> b >> h >> m;

	int s = 3600 * h + 60 * m;

	long double d = min(11.0 * s / 120, 360 - 11.0 * s / 120);

	cout << fixed << setprecision(20) << sqrt(a * a + b * b - 2 * a * b * cos(d * acos(-1) / 180)) << endl;

	return 0;
}

Measured memory_bytes: 4164