akhauriyash/Code-Regression huggingface dataset:
H, W = map(int,input().split())
#A = [list(map(str,input().split())) for i in range(H)]
A = [list(input()) for i in range(H)]

#from queue import Queue
#from collections import deque

dj = [1, 0, -1, 0]
di = [0, 1, 0, -1]

sum_sharp = sum([A[i].count('#') for i in range(H)])

fin_d_max = 1

for s_i in range(H):
    for s_j in range(W):
        #print(s_i,s_j)
        d_max = 0
        q_i = []
        #q_i = Queue()
        #q_i = deque()
        q_j = []
        #q_j = Queue()
        #q_j = deque()
        D = [[-1]*W for i in range(H)]
        #flag = [[0]*W for i in range(H)]
        flag = 1

        if A[s_i][s_j] == '.':
            D[s_i][s_j] = 0
            #q_i.put(s_i)
            q_i.append(s_i)
            #q_j.put(s_j)
            q_j.append(s_j)
            #while sum(map(sum, flag)) != W*H - sum_sharp:
            #while flag < W*H - sum_sharp:
            #while q_i.empty() == False:
            while len(q_i)!=0:
            #for a in range(W*H):
                #i = q_i.get()
                i = q_i.pop(0)
                #i = q_i.popleft()
                #j = q_j.get()
                j = q_j.pop(0)
                #j = q_j.popleft()
                for x in range(4):
                    ni = i+di[x]
                    nj = j+dj[x]
                    #if ni<0 or ni>=H or nj<0 or nj>=W or A[ni][nj]== '#' or 0<=D[ni][nj]<D[i][j]+1:
                    if ni<0 or ni>=H or nj<0 or nj>=W or A[ni][nj]== '#' or D[ni][nj]!=-1:
                    #if ni<0 or ni>=H or nj<0 or nj>=W:
                        continue
                    #elif A[ni][nj]== '#' or D[ni][nj] < D[i][j]+1:
                        #flag[ni][nj] = 1
                        #continue
                    else:
                        #if D[ni][nj] == -1:
                            #print(flag)
                        flag += 1
                        D[ni][nj] = D[i][j]+1
                        d_max = max(d_max, D[ni][nj])
                        #q_i.put(ni)
                        q_i.append(ni)
                        q_j.append(nj)
                        #q_j.put(nj)
        fin_d_max = max(fin_d_max, d_max)
                
print(fin_d_max)

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

int compare_cnt = 0;

void merge(vector<int> &s, int left, int mid, int right){
    vector<int> n1(mid - left);
    vector<int> n2(right - mid);

    rep(i, mid - left){
        n1.at(i) = s.at(left + i);
    }
    rep(i, right - mid){
        n2.at(i) = s.at(mid + i);
    }
    n1.push_back(INT_MAX);
    n2.push_back(INT_MAX);

    int n1_index = 0;
    int n2_index = 0;

    // cout << "left mid right " << left << " " << mid << " " << right << endl;
    for(int i = left; i < right; i++){
        if(n1.at(n1_index) > n2.at(n2_index)){
            s.at(i) = n2.at(n2_index);
            n2_index++;
        }else{
            s.at(i) = n1.at(n1_index);
            n1_index++;
        }
        compare_cnt++;
    }
}

void mergeSort(vector<int> &s, int left, int right){
    if(left + 1 < right){
        int mid = (right + left) / 2;
        mergeSort(s, left, mid);
        mergeSort(s, mid, right);
        merge(s, left, mid, right);
    }

}

void printVec(vector<int> s){
    rep(i, s.size()-1){
        cout << s.at(i) << " ";
    }
    cout << s.at(s.size()-1) << endl;
}

int main(){
    int n; cin >> n;
    vector<int> s(n);
    rep(i, n){
        cin >> s.at(i);
    }

    int left = 0;
    int right = s.size();
    mergeSort(s, left, right);

    printVec(s);
    cout << compare_cnt << endl;
}


Measured memory_bytes: 8600
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        string[] s = Console.ReadLine().Split(' ');
        double sum = 0;

        foreach (var i in s)
            sum += 1/(double)int.Parse(i);

        Console.WriteLine(1 / sum);
    }
}

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

int main()
{
    int n, r;
    cin >> n >> r;
    if (n < 10)
    {
        cout << (10 - n) * 100 + r << endl;
        return 0;
    }
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstring>
#include<iostream>
#include<string>
#include<vector>
#include<fstream>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;
ll mmin=10000000000; 
ll mmax=-1;
int main()
{	
 int n;
 scanf("%d",&n);
 ll in;
 for(int i=1;i<=n;i++)
 {
 	scanf("%lld",&in);
 	mmin=min(in,mmin);
 	mmax=max(in,mmax);
 }
 cout<<mmax-mmin<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000           // 2000000000
#define LINF 1000000000000000000 // 9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979

//.size()はunsigned int　0-1をするとオーバーフローする

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

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

int main(void) {
    long long int n,k;
    long long int total=0;

    cin>>n>>k;
    vector<long long int > h(n);

    FOR(i,0,n-1){
        cin>>h[i];
    }
    sort(h.begin(),h.end());

    if(n>k){
        FOR(i,0,n-k-1){
            total+=h[i];
        }
    }
    cout<<total<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <math.h>
#include <iomanip>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;

int main(){
    int n;
    cin >> n;
    int x[n],y[n];
    rep(i,n) cin >> x[i] >> y[i];

    int root[n];
    rep(i,n) root[i]=i;

    double sum=0.0;
    int count=0;
    do{
        count++;
        for(int i=1; i<n; i++){
            double dx = abs(x[root[i]]-x[root[i-1]]);
            double dy = abs(y[root[i]]-y[root[i-1]]);
            sum += sqrt(dx*dx + dy*dy);
        }
    
    }while(next_permutation(root, root+n));
    
    double result = sum / count;
    cout << setprecision(15)<<result << endl; 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (int)(a.size())
const int M=2e5+5;
const ll mod=1e9+7;
int ind[M],tot[M];
ll pw[M];
std::vector<int> vtr[M];
unordered_map<int,ll> cnt[M][2];
void dfs(int x,int p,int l)
{
	tot[l]++;
	if(sz(vtr[x])==0)
	{
		ind[x]=x;
		cnt[x][0][l]=1;
		cnt[x][1][l]=1;
		return;
	}
	int id=ind[vtr[x][0]];
	for(auto u:vtr[x])
	{
		dfs(u,x,l+1);
		if(sz(cnt[ind[u]][0])>sz(cnt[id][0]))
			id=ind[u];
	}
	unordered_map<int,ll> res[3];
	int mx=-1;
	for(auto u:vtr[x])
		if(ind[u]!=id)
			mx=max(mx,sz(cnt[ind[u]][0]));
	cnt[id][0][l]=1;
	cnt[id][1][l]=1;
	ind[x]=id;
	if(mx==-1)
		return;
	for(int i=1;i<=mx;i++)
	{
		res[0][l+i]=1; // all 0s
		res[1][l+i]=0; // exactly 1 1
		res[2][l+i]=1; // all possible
	}
	for(auto u:vtr[x])
	{
		if(ind[u]==id)
			continue;
		for(auto vv:cnt[ind[u]][0])
		{
			int v=vv.ff;
			ll a = cnt[ind[u]][0][v];
			ll b = cnt[ind[u]][1][v];
			ll c = (a+b)%mod;
			res[2][v]=(res[2][v]*c)%mod;
			res[1][v]=(res[0][v]*b+res[1][v]*a)%mod;
			res[0][v]=(res[0][v]*a)%mod;
		}
	}
	for(auto u:res[0])
	{
		int v=u.ff;
		ll a = res[0][v];
		ll b = res[1][v];
		ll c = (res[2][v]-(a+b)%mod+mod)%mod;
		ll x = ((cnt[id][0][v]+cnt[id][1][v])*c)%mod;
		x=(x+(cnt[id][0][v]*a))%mod;
		x=(x+(cnt[id][1][v]*b))%mod;
		ll y=((cnt[id][0][v]*b)%mod+(cnt[id][1][v]*a)%mod)%mod;
		cnt[id][0][v]=x;
		cnt[id][1][v]=y;
		// cout<<x<<" "<<y<<endl;
	}
}
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	pw[0]=1;
	for(int i=1;i<=n;i++)
	{
		pw[i]=(2*pw[i-1])%mod;
		int p;cin>>p;
		vtr[p].pb(i);
	}
	dfs(0,0,0);
	ll ans=0;
	for(auto u:cnt[ind[0]][1])
		ans=(ans+u.ss*pw[n+1-tot[u.ff]])%mod;
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 115216
import java.util.*;
import static java.util.Arrays.*;

class Main {

	int[] ns;
	int n, m;

	void run(){
		Scanner in = new Scanner(System.in);
		for(;;){
			n = in.nextInt();
			m = in.nextInt();
			if(n == 0) return;
			ns = new int[n];
			for(int i=0; i<n; i++)
				ns[i] = in.nextInt();
			System.out.println(solve());
		}
	}
	

	int solve(){
		int ans = 0;
		sort(ns);
		for(int i=0; i<n; i++)if(i%m != m-1)
			ans += ns[n-i-1];
		return ans;
	}
	
	public static void main(String args[]){
		new Main().run();
	}
}

Measured memory_bytes: 12000
from collections import deque

n = int(input())
a = ["dummy!"] + [list(map(int, input().split())) for _ in range(n)]
t = 0
f = 1
cur = [0]*(n+1)
date = [0]*(n+1)
seed = deque()
for i in range(1,n+1):
    op = a[i][cur[i]]
    if a[op][cur[op]] == i:
        seed.append((i,op))
        cur[i] += 1
        cur[op] += 1
        date[i] = date[op] = max(date[i],date[op]) + 1
while seed:
    p,q = seed.popleft()   
    for i in p,q:
        if cur[i] >= n-1:
            continue
        op = a[i][cur[i]]
        if a[op][cur[op]] == i:
            seed.append((i,op))
            cur[i] += 1
            cur[op] += 1
            date[i] = date[op] = max(date[i],date[op]) + 1
if any(x < n-1 for x in cur[1:]):
    print(-1)
else:
    print(max(date))


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

using namespace std;

const int MAXW = 1e5 + 5;
const int MAXN = 105;
long long dp[MAXN][MAXW];
long long a[MAXN];
int w[MAXN];

int main()
{
    int n, x;
    cin >> n >> x;
    for(int i = 1; i <= n; i++){
        cin >> w[i] >> a[i];
    }
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= x; j++){
            dp[i][j] = dp[i - 1][j];
            if(j >= w[i]){
                dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + a[i]);
            }
        }
    }
    cout << dp[n][x];
}


Measured memory_bytes: 79360
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
2 20
5 9
4 10

output:
9

1 ??? N ??? 100
1 ??? vi ??? 100
1 ??? wi ??? 10,000,000
1 ??? W ??? 1,000,000,000
"""

import sys
from collections import namedtuple

MAX_V = 100


def solve():
    dp = [[float('inf')] * (c_items * MAX_V + 1) for _ in range(c_items + 1)]
    dp[0][0] = 0
    for i, item in enumerate(item_list):
        v, w = item.value, item.weight
        for j in range(c_items * MAX_V + 1):
            if j < v:
                dp[i + 1][j] = dp[i][j]
            else:
                dp[i + 1][j] = min(dp[i][j], dp[i][j - v] + w)

    ans = 0
    res_list = dp[-1]
    for i in range(c_items * MAX_V + 1):
        if res_list[i] <= knapsack_cp:
            ans = i

    return ans


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    c_items, knapsack_cp = map(int, _input[0].split())
    items = map(lambda x: x.split(), _input[1:])

    Item = namedtuple('Item', ('value', 'weight'))
    item_list = [Item(int(v), int(w)) for v, w in items]

    print(solve())

Measured memory_bytes: 19396
#include <stdio.h>
#define INF 100000000
#define N 100

int n;
int size[N];
int to[N][N];
int cost[N][N];
int dist[N];

void DFS(int,int);

int main(int argc,char *argv[]) {
    int i,j;
    scanf("%d",&n);
    
    for(i=0; i<n; i++) {
        int u;
        
        scanf("%d",&u);
        scanf("%d",&size[u]);
        
        for(j=0; j<size[u]; j++) {
            scanf("%d",&to[u][j]);
            scanf("%d",&cost[u][j]);
        }
    }
    
    for(i=0; i<n; i++) dist[i] = INF;
    
    DFS(0,0);
    
    for(i=0; i<n; i++) printf("%d %d\n",i,dist[i]);
    
    return 0;
}


void DFS(int p,int c) {
    int i;
    
    dist[p] = c;
    
    for(i=0; i<size[p]; i++) {
        if(dist[to[p][i]]>c+cost[p][i]) DFS(to[p][i],c+cost[p][i]);
    }
}

Measured memory_bytes: 680
#include<bits/stdc++.h>
using namespace std;
int main(){
  int K,U,P,C;
  string s;
  cin>>s;
  K=U=P=C=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='K'){
      K++;
    }else if(s[i]=='U'){
      U++;
    }else if(s[i]=='P'){
      P++;
    }else if(s[i]=='C'){
      C++;
    }
  }
  cout<<min(K,min(U,min(P,C)))<<endl;
  return 0;
}
      
  

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#define SIZE 402
using namespace std;

typedef pair<int, int> P;
const int di[] = {0, 0, -1, 1};
const int dj[] = {-1, 1, 0, 0};
char s[SIZE][SIZE];
int t[SIZE][SIZE];

int main(){
  int h, w;
  cin >> h >> w;
  long long result = 0;
  queue<P> q;
  
  int im = h+1, jm = w+1;
  for(int i=0; i<=im; i++) t[i][0] = t[i][jm] = 1;
  for(int j=0; j<=jm; j++) t[0][j] = t[im][j] = 1;
  
  for(int i=1; i<=h; i++)
      scanf("%s", s[i] + 1);
  
  for(int i=1; i<=h; i++)
    for(int j=1; j<=w; j++){
      int bl = 0, wh = 0;
      if (t[i][j]==0){
        t[i][j] = 1;
        q.push(P(i, j));
      }
      while( !q.empty() ){
        P p = q.front();
        q.pop();
        if(s[p.first][p.second] == '#')bl++; else wh++;
        for(int a=0; a<4; a++){
          int k = p.first + di[a];
          int l = p.second+ dj[a];
          if(
            t[k][l] == 0
            && s[p.first][p.second] != s[k][l]
          ){
            t[k][l] = 1;
            q.push(P(k,l));
          }
        }
      }
      result += (long long)bl * (long long)wh;
    }
  cout << result << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std; 
int main()
{
	int n;
	cin>>n;
	std::vector<int> v(n);
	std::vector<int> c(n);
	for (int i = 0; i < n; ++i)
	{
		cin>>v[i];
	}
	for (int i = 0; i < n; ++i)
	{
		cin>>c[i];
	}
	int ans =0;
	for (int i = 0; i < n; ++i)
	{
		if(v[i]>c[i])
		{
			ans+= v[i]-c[i];
		}
	}
	cout<<ans<<endl;
}	


Measured memory_bytes: 256
#include<stdio.h>

int dp[50];

int fib(int n) {
  if(n==0 || n==1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
return dp[n] = fib(n-1) + fib(n-2);
}

int main(){
  int n,i;
  for(i=0; i<50; i++) dp[i] = -1;

  scanf("%d",&n);
  printf("%d\n",fib(n));

  return 0;
}

Measured memory_bytes: 596
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });

            int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = vs[0];
            int K = vs[1];
            int[] h = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int ans = 0;
            for (int i = 0; i < N; i++) {
                if (h[i] >= K) {
                    ans++;
                }
            }
            Console.WriteLine(ans);

            Console.Out.Flush();
		}
	}
}


Measured memory_bytes: 19168
def li():
    return list(map(int, input().split()))


if __name__ == "__main__":
    [a, b] = li()

    tap_count = 1
    use_count = 0
    while tap_count < b:
        use_count = use_count + 1
        tap_count = tap_count + a - 1
    print(use_count)


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;
 
template<typename T>
T Pow(T a,T b) {
    T ret = 1;
    for(int i = 0;i < b;i++) {
        ret *= a;
    }
    return ret;
}
 
ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}
 
ll RS(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P%2==0){
        ll t = RS(N, P/2, M);
        return t*t % M;
    }
    return N * RS(N, P-1, M) % M;
}

ll dp[55][55][2550] = {0}; //dp[i][j][k] = i番目までのカードからj枚選んだ時に和がkになる組み合わせ

int main() {
    int N,A;
    cin >> N >> A;
    vector<int> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(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 < 2510;k++) {
                if(vec.at(i) + k <= 2500) {
                    dp[i + 1][j + 1][vec.at(i) + k] += dp[i][j][k];
                }
            }
            for(int k = 0;k < 2510;k++) {
                dp[i + 1][j][k] += dp[i][j][k];
            }
        }
    }
    ll ret = 0;
    for(int i = 1;i <= N;i++) {
        ret += dp[N][i][i * A];
    }
    cout << ret << endl;
}

Measured memory_bytes: 56448
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimization_level 3
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    int n;
    cin >> n;
    // vector<int> b(n - 1);

    vector<int> a(n);
    int total = 0;

    rep(i, n - 1) {
        // cin >> b[i];
        cin >> a[i + 1];
    }

    a[0] = a[1];

    for(size_t i = 1; i < a.size(); i++) {
        if(!(a[i - 1] <= a[i])) {
            a[i - 1] = a[i];
        }
    }

    rep(i, a.size()) { total += a[i]; }

    cout << total;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1
#define INFTY 1000000000000000000

LL labs(LL x){
    if(x>0){
        return x;
    }else{
        return -1*x;
    }
}

int main(){
    LL n;
    LL k;
    cin >> n >> k;
    vector<LL> h(n);
    vector<LL> dp(n, INFTY);

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

    dp[0]=0;
    for(LL i=0; i<n; i++){
        for(LL j=1; j<=k; j++){
            if(i+j>=n){
                continue;
            }
            dp[i+j]=min(dp[i+j], dp[i]+labs(h[i+j]-h[i]));
        }
    }

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

    return 0;
}


Measured memory_bytes: 4828
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> h(N);
	vector<int> x(N);
	vector<int> y(N);
	int res = 0;

	int t = 0;
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i] >> h[i];
		if (h[i] != 0) {
			t = i;
		}
	}
	int resx, resy;
	for (int X = 0; X <= 100; X++) {
		for (int Y = 0; Y <= 100; Y++) {
			int H = h[t] + abs(x[t] - X) + abs(y[t] - Y);

			bool ok = true;
			for (int i = 0; i < N; i++) {
				if (max((int)0, H - abs(x[i] - X) - abs(y[i] - Y)) != h[i]) {
					ok = false;
					break;
				}
			}
			if (ok) {
				resx = X;
				resy = Y;
				res = H;
			}
		}
	}
	cout << resx << " " << resy << " " << res << endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(n)]
C=[list(map(int,input().split())) for _ in range(m)]
for i in A:
  D=[abs(i[0]-j[0])+abs(i[1]-j[1]) for j in C]
  print(D.index(min(D))+1)

Measured memory_bytes: 3064
import fractions

N, X = map(int, input().split())

x = list(map(int, input().split()))

diff = [-1 for i in range(N)]
for i in range(N):
    diff[i] = abs(x[i] - X)

if x == 1:
    print(diff[0])
else:
    ans = diff[0]
    for i in range(1, N):
        ans = fractions.gcd(ans, diff[i])
    print(ans)


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

using namespace std;

int main(){
  int i,j,n,d,x,a;
  vector <int> v;
  
  cin>>n>>d>>x;
  for(i=0;i<n;i++){
    cin>>a;
    for(j=1;j<=d;j+=a){
      v.push_back(j);
    }
  }
  cout<<v.size()+x<<endl;
  
  return 0;
}

Measured memory_bytes: 256
n = gets.to_i
s = gets.to_i
rn = Math.sqrt(n).to_i

if n == s
  p n + 1
  exit
end

def f(b, n)
  return n if n < b
  f(b, n / b) + n.modulo(b)
end

(2..rn).each do |i|
  if f(i, n) == s
    p i
    exit
  end
end

rn.downto(1) do |i|
  b = (n - s) / i + 1
  if b > rn && f(b, n) == s
    p b
    exit
  end
end

p -1


Measured memory_bytes: 1916
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		n = scanner.nextInt();
		char[] c = scanner.next().toCharArray();
		num = new int[n];
		for (int i = 0; i < n; i++)
			if (c[i] == 'J')
				num[i] = 1;
			else if (c[i] == 'O')
				num[i] = 2;
			else
				num[i] = 4;
		dp = new int[8][n];
		for (int[] dp1 : dp)
			Arrays.fill(dp1, -1);
		System.out.println(slove(1, 0));
	}

	private int slove(int x, int day) {
		if (day == n)
			return 1;
		if (dp[x][day] != -1)
			return dp[x][day];
		int ans = 0;
		for (int i = 1; i < 8; i++) {
			if (((x & i) >= 1) && (i & num[day]) >= 1) {
				ans += slove(i, day + 1);
				ans %= mod;
			}
		}
		return dp[x][day] = ans % mod;
	}

	int n;
	int[] num;
	int[][] dp;
	int mod = 10007;
}

Measured memory_bytes: 19340
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
#define int long long
bool Prime[55556] = {};

bool isPrime(long a) {
	if (a < 2) return false;
	long i;
	for (i = 2; i * i <= a; i++) {
		if (a % i == 0) return false;
	}
	if ((a + 5) % 5 == 3) {
		return true;
	}
	return false;
}

signed main() {
	int n;
	cin >> n;
	for (int i = 0; i < 55556; i++) {
		if (isPrime(i)) {
			Prime[i] = true;
		}
	}
	vector<int> vec;
	int cnt = 0;
	if (n % 2 == 0) {
		for (int i = 3; i < 55556; i++) {
			if (Prime[i] && cnt < n) {
				vec.push_back(i);
				cnt++;
			} else if (cnt >= n) {
				break;
			}
		}
	} else {
		vec.push_back(2);
		cnt++;
		for (int i = 3; i < 55556; i++) {
			if (Prime[i] && cnt < n) {
				vec.push_back(i);
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (i == n - 1) {
			cout << vec[i] << endl;
		} else {
			cout << vec[i] << " ";
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include <string>
#include <math.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;
int main(){
  ll w,h,x,y; cin >>w>>h>>x>>y;
  if(w/2==x&&h/2==y&&w%2==0&&h%2==0){
    ll ans=h*w/2;
    cout << ans << " " << 1 << endl;
    return 0;
  }
  else if(w/2==x&&w%2==0){
    ll ans=w*h/2;
    cout << ans << " " << 0 << endl;
    return 0;
  }
  else if(h/2==y&&h%2==0){
    ll ans=w*h/2;
    cout << ans << " " << 0 << endl;
    return 0;
  }
  else{
    double ans=1.0*h*w/2.0;
    printf("%.9f",ans);
    cout << " " << 0 << endl;
  }
}

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

#define F first
#define S second
#define mp make_pair
#define pb push_back        
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()

using namespace std;

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

const int N = 2e5 + 123;
const int inf = 1e9 + 1;
const int mod = 1e9 + 7;
const ll infl = 3e18 + 1;
const double pi = acos(-1.0);

inline void boost () {
    ios_base::sync_with_stdio (0);
    cin.tie (0); cout.tie (0);
}
inline void SmartRandom228 () {
	unsigned int key;
	asm ("rdtsc" : "=A"(key));
	srand (key);
}
ll a, b, c;

int main () {
	boost ();
	cin >> a >> b >> c;
	if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) cout << 0;
	else {
		if (a > b) swap (a, b);
		if (a > c) swap (a, c);
		if (b > c) swap (b, c);
		cout << a * b; 
	} 	

return 0;       
}
                                                          

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t N;
  cin>>N;
  int a=1;
  for(int64_t i=1;i*i<=N;i++){
  if(N%i==0)
    a=i;
 }
  int64_t ans=a+(N/a)-2;
  
  cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=1000000007;
const int MAXN=100010, LOG=20;

int n, m, k, u, v, x, y, t, a, b;
int col[MAXN], mark[MAXN];
pii E[MAXN];
vector<int> G[MAXN];

int dfs1(int node){
	int res=node*(G[node].size()%2==0);
	for (int v:G[node]){
		int tmp=dfs1(v);
		if (res && tmp){
			E[m++]={res, tmp};
			res=0;
		}
		else res^=tmp;
	}
	return res;
}

void dfs2(int node, int c){
	col[node]=c;
	mark[node]=0;
	for (int v:G[node]) if (mark[v]) dfs2(v, -c);
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n;
	for (int T:{0, 1}){
		for (int i=1; i<=n; i++){
			cin>>x;
			if (x==-1) y=i;
			else G[x].pb(i);
		}
		dfs1(y);
		for (int i=1; i<=n; i++){
			if (G[i].size()%2==0) col[i]^=1, mark[i]=1;
			G[i].clear();
		}
	}
	for (int i=1; i<=n; i++) if (col[i]) kill("IMPOSSIBLE")
	for (int i=0; i<m; i++){
		int u=E[i].first, v=E[i].second;
		G[u].pb(v);
		G[v].pb(u);
	}
	for (int i=1; i<=n; i++) if (mark[i]) dfs2(i, 1);
	cout<<"POSSIBLE\n";
	for (int i=1; i<=n; i++) cout<<col[i]<<" \n"[i==n];
	
	return 0;
}


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

int main(){
	int n,m,h,i,j,k;
	int *card,*card2,*tmp;

	scanf("%d",&n);

	card = (int *)malloc(sizeof(int)*2*n);
	card2 = (int *)malloc(sizeof(int)*2*n);
	tmp = (int *)malloc(sizeof(int)*2*n);

	for(i = 0;i < 2*n;i++){
		card[i] = i+1;
	}

	scanf("%d",&m);

	for(i = 0;i < m;i++){
		scanf("%d",&k);
		if(!k){
			for(j = 0;j < n;j++){
				card2[2*j] = card[j];
				card2[2*j+1] = card[n+j];
			}
		}else{
			for(j = 0;j < 2*n;j++){
				if(j < k){
					card2[2*n-k+j] = card[j];
				}else{
					card2[j-k] = card[j];
				}
			}
		}

		tmp = card;
		card = card2;
		card2 = tmp;
	}

	for(i = 0;i < 2*n;i++){
		printf("%d\n",card[i]);
	}

	return 0;
}

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

const int N = 1e6 + 5;

int main(){
    ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0);
    int n , k; cin >> n >> k;
    int arr[N] , dd[N] = {};
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }
    for (int i = 0; i < N   ; ++i) {
        dd[i] = INT_MAX;
    }
    dd[0] = 0;
    dd[1] = abs(arr[0] - arr[1]);

    for (int i = 2; i < n; ++i) {
        for(int j = i - 1 ; j >= i - k && j >= 0; j --) {
            dd[i] = min(dd[i] , dd[j] + abs(arr[i] - arr[j]));
        }
    }
    

    cout << dd[n - 1];
}

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

int main() {
  int N;
  cin >> N;
  int ans = 0;
  int c = 0;
  int b = 0;
 
 vector<int> a(N);
  for(int i=0;i<N;i++) cin >> a.at(i);
  
  for(int i=0;i<N;i++){
    sort(a.begin(),a.end());
    if(i%2 == 1){
      c += a.at(i);
    }
    else{
      b += a.at(i);
    }
  }
  cout << abs(c - b) << endl;
}

Measured memory_bytes: 3608
// AtCoder Beginner Contest 147.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include<vector>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
#define foradd(i,a,b) for(int i = (a);i<(b);++i)
using ull = unsigned long long;
const int N = 10000;
int arr[N];

int main()
{
	string str1,str2;
	int rec{ 0};
	cin >> str1;
	str2 = str1;
	int len = str1.length();
	for (int i = 0;i < len;i++) {
		if (str1[i] != str1[len - 1 - i])
			++rec;
	}
	cout << rec / 2;
	return 0;
}





Measured memory_bytes: 256
import collections

n = int(input())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

if n == 1: # 1
    print(0)
    exit()

c = collections.Counter(prime_factorize(n))
_, counts = zip(*c.most_common())

l = list(counts)
ans = 0

for i in l:
    x = 0
    for j in range(i):
        x += j + 1
        if i >= x:
            ans += 1
        else:
            break

print(ans)

Measured memory_bytes: 9376
#include <iostream>
 #include <cmath>

 using namespace std;
 typedef long long ll;

int main(void){
 ll a,b,c;

 cin >> a >> b >> c;
 ll d = c - a - b;
 if(d > 0 && d * d > 4 * a * b){
 cout << "Yes" << endl;
 } else {
 cout << "No" << endl;
  }

return 0;
}


Measured memory_bytes: 256
# Input the amount of money Takahashi paid
N = int(input())
 
# Check if the price before tax is X, for X = 1, 2, 3, ..., N
ans = -1
for i in range(1, N + 1):
	if int(i * 1.08) == N:
		ans = i
 
# Print answer
if ans != -1:
	print(ans)
else:
	print(":(")

Measured memory_bytes: 2940
n = gets.to_i
w = []
flg=1
for i in 0...n
	w[i] = gets
end
for i in 0...n
	if(i < n-1)then
		if(w[i][-2] != w[i + 1][0])then
			flg = 0
		end
	end
	for j in 0...i
		if(w[i] == w[j])then
			flg = 0
		end
	end
end

if(flg == 0)then
	puts "No"
else
	puts "Yes"
end 


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

#define reps(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) reps(v, 0, n)
#define lep(v, n) reps(v, 1, n + 1)
#define rreps(v, f, l) for (int v = (l), v##_ = (f); v >= v##_; --v)
#define rrep(v, n) rreps(v, 0, n - 1)
#define rlep(v, n) rreps(v, 1, n)
#define show_a(a, size) rep(a##_it, size) std::cout << a[a##_it] << " \n"[a##_it == a##_it_ - 1];
#define show_v(v) show_a(v, v.size())
#define debug(x) std::cerr << #x << " = " << (x) << "\n";

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }

int main()
{
  int a, b, n;
  while (~scanf("%d %d %d", &a, &b, &n)){
    int sum = 0;
    a %= b;
    rep(i, n){
      a %= b;
      a *= 10;
      if (a == 0) break;
      sum += a / b;
    }
    printf("%d\n", sum);
  }

  return 0;
}

Measured memory_bytes: 1188
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;

int main() {
    int n;
    cin>>n;
    long long sums=0;
    vector<long long> sum(n);
    vector<int> a(n);
    cin>>a[0];
    sums += abs(a[0]);
    for(int i=1; i<n; i++) {
        cin>>a[i];
        sums += abs(a[i]-a[i-1]);
    }
    sums += abs(a[n-1]);

    cout<<sums-abs(a[0])-abs(a[0]-a[1])+abs(a[1])<<endl;
    for(int i=1; i<n-1; i++) {
        cout<<sums+abs(a[i-1]-a[i+1])-abs(a[i-1]-a[i])-abs(a[i]-a[i+1])<<endl;
    }
    cout<<sums-abs(a[n-1])-abs(a[n-1]-a[n-2])+abs(a[n-2])<<endl;
}

Measured memory_bytes: 2432
n=int(input())
a,b,c=list(input() for i in range(3))
ans=0
for i in range(n):
    if a[i]==b[i]:
        if b[i]!=c[i]:
            ans+=1
    elif b[i]!=c[i] and a[i]!=c[i]:
        ans+=2
    else:
        ans+=1
print(ans)

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

int N;

int sum_n(int n){
    int sum=0;
    while(n != 0){
      sum += n%10;
      n = n/10;
    }
    return sum;    
}

int main() {
    cin >> N;
    int ans = 99999;
    int temp;
    for(int i=1;i<N;i++){
      temp = sum_n(i)+sum_n(N-i);
      if(ans > temp ) ans = temp;
    }
    cout << ans << endl;
}

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

int main() {
	int n,sum=0;
	cin >> n;
	vector<int>s(n);
	for (int i = 0; i < n; ++i) {
		cin >> s[i];
		sum += s[i];
	}
	sort(s.begin(), s.end());
	for (int i = 0; i < n;++i) {
		if (sum % 10 != 0)break;
		if(s[i]%10!=0)sum -= s[i];
	}if (sum % 10 == 0)sum = 0;
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b;
  cin >> a >> b;
  int s,t,u,v,w;
  int ans = 0;
  for(int i = a; i <= b; i++){
    s = i % 10;
    t = i/10 % 10;
    u = i/100 % 10;
    v = i/1000 % 10;
    w = i/10000 % 10;
    
    if(s == w && t == v){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
struct TArea{
    int Point;
    int Area;
};

int GetArea(string str, vector<TArea>& AreaList);

int GetArea(string str, vector<TArea>& AreaList)
{
    int TotalArea = 0;
    TArea Temp;
    vector<int> List;
    List.clear();
    AreaList.clear();
    
    for(int i = 0; i < str.size(); i++){
        if(str[i] == '\\')  List.push_back(i);
        if(str[i] == '/' && !List.empty()){
            Temp.Area = i - List[List.size() - 1];
            Temp.Point = List[List.size() - 1];
            TotalArea += Temp.Area;
            for(int j = AreaList.size() - 1; j >= 0; j--){
                if(Temp.Point < AreaList[j].Point){
                    Temp.Area += AreaList[j].Area;
                    AreaList.pop_back();
                }
            }
            AreaList.push_back(Temp);
            List.pop_back();
        }
    }
    return TotalArea;
}

int main(void){
    string str;
    std::cin >> str;
    
    std::vector<TArea> AreaList;
    cout << GetArea(str, AreaList) << endl;
    
    cout << AreaList.size();
    for(int i = 0; i < AreaList.size(); i++){
        cout << " " << AreaList[i].Area;
    }
    cout << endl;
}

Measured memory_bytes: 1340
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define MAX 1e9

ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
const ld pi=acos(-1);

int main(){
    IOS;
    ll a;string s;cin>>a>>s;
    if(a<3200)cout<<"red";
    else cout<<s;
    return 0;
}   


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int OO = (int) 2e9;
const double eps = 1e-9;

const int N = 81;

int n;
ll a[N];

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	ll res = 1000;
	for (int i = 0; i < n; i++) {
		int j = i + 1;
		for (; j < n; j++) {
			if (a[j] > a[j - 1]) {
				break;
			}
		}
		if (j == n)
			break;
		res = res % a[j - 1] + res / a[j - 1] * a[j];
		i = j - 1;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 3612
import math

def factor(n):
    r = []
    tmp = n
    for i in range(2, int(math.sqrt(n)) + 1):
        if tmp % i == 0:
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            r.append((i, cnt))
    if tmp != 1:
        r.append((tmp, 1))
    if not r:
        r.append((n, 1))
    return r

def all_pat(l):
    k = [0] * len(l) 
    t = [tuple(k)]
    while True:
        k[0] += 1
        for i in range(len(l)):
            if k[i] <= l[i][1]:
                break
            k[i] = 0
            if i == len(l) - 1:
                return t
            k[i + 1] += 1
        t.append(tuple(k))
    

def main():
    a = int(input())
    l = factor(a)
    p = all_pat(l)
    t = []
    for i in p:
        m = 1
        for j in range(len(l)):
            m *= l[j][0] ** i[j]
        t.append(m + (a // m))
    print(min(t) - 2)
            


if __name__ == '__main__':
    main()


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

int solve(vector<int> &a) {
    int n = a.size();
    for (int i = 0; i < n; i++) {
        int cur = i;
        bool ok = true;
        for (int tgt: {5, 7, 5, 7, 7}) {
            int cnt = 0;
            while (cur < n && cnt + a[cur] <= tgt) cnt += a[cur++];
            if (cnt != tgt) { ok = false; break; }
        }
        if (ok) return i;
    }
    return -1;
}

int main() {
    int n;
    while (cin >> n, n) {
        vector<int> len(n);
        for (int i = 0; i < n; i++) {
            string s; cin >> s;
            len[i] = s.size();
        }
        cout << solve(len) + 1 << endl;
    }
    return 0;
}



Measured memory_bytes: 3112
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;class Program
{
	static void Main(string[] args)
	{
        //var exStdIn = new System.IO.StreamReader( "stdin.txt" );System.Console.SetIn( exStdIn );
		

		int n = int.Parse(Console.ReadLine());
		var l = Console.ReadLine().Split().Select(long.Parse).ToArray();
		int ans = 0;
		for (int i = 0; i < n; i++)
		{
			for (int j = i+1; j < n; j++)
			{
				for (int k = j+1; k < n; k++)
				{
					if(l[i]==l[j]||l[j]==l[k]||l[k]==l[i])continue;
					long m = Max(l[i], l[j]);
					m = Max(m, l[k]);
					if(l[i]+l[j]+l[k]-m>m)ans++;
				}
			}
		}
		
		Console.WriteLine(ans);
	}
}


Measured memory_bytes: 28208
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
int main(int argc, const char * argv[]) {



    cin.tie(0);
    ios::sync_with_stdio(false);

    int n,m;
    cin>>n>>m;
    cout<<(n-1)*(m-1)<<endl;

    return 0;
}



Measured memory_bytes: 3620
#include <iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<string>
#include<math.h>
#define REP(i,n) for(int i=0;i<n;i++)

using namespace std;

int main() {
    int n,a,b,c,d;
    string s;
    cin >>n>>a>>b>>c>>d;
    cin >> s;
    int cnt =0;
    int min_cnt = pow(10, 7);
    int max_cnt = 0;

    for(int i =a-1; i< b;i++){
        if(s[i] == '.') cnt++;
        else {
            min_cnt = min(cnt, min_cnt);
            cnt = 0;
        }
    }

    for(int i = b; i< min(c,d);i++){
        if(s[i] == '.') cnt++;
        else {
            min_cnt = min(cnt, min_cnt);
            if(i != b) max_cnt = max(cnt, max_cnt);
            cnt = 0;
        }
    }

    int flag = 0;
    if(cnt != 1) flag = 1;
    for(int i =min(c,d); i< max(c,d);i++){
        if(s[i] == '.') cnt++;
        else {
            if (flag == 1) {
                max_cnt = max(cnt, max_cnt);
                flag = 0;
            }
            min_cnt = min(cnt, min_cnt);
            cnt = 0;
        }
    }

    if (flag == 1) max_cnt = max(cnt, max_cnt);
    min_cnt = min(cnt, min_cnt);

    if (d < c && max_cnt < 3) cout << "No" << endl;
    else if ( min_cnt == 0 ) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 640
from bisect import bisect_left#(sorted_list,x)で昇順ソート位置

n = int(input())
l = list(map(int, input().split()))

l.sort()
ans = 0
for i in range(n-2):
  for j in range(i+1,n-1):
    s = l[i]+l[j]
    ans += bisect_left(l,s,j+1)-j-1
print(ans)

Measured memory_bytes: 3188
package main

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

func main() {
	sc := NewScanner()

	s := sc.NextLine()

	l := 0
	r := len(s) - 1
	ans := 0
	for {
		if l >= r {
			break
		}
		if s[l] != s[r] {
			ans++
		}
		l++
		r--
	}

	fmt.Printf("%v\n", ans)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#define ll long long
#define ull unsigned long long
#define loop(x,n) for(ll x = 0; x < n; x++)
#define f(n) for(ll i = 0; i < n; i++)

#include <bits/stdc++.h>


using namespace std;

int NMAX = 20;
int MMAX = 50000;
int INFTY = 10000000;



int main()
{
   int n, m; cin >> n >> m;
   int c[NMAX+1];
   int t[MMAX+1];

   for(int i = 0; i < m; i++){
        cin >> c[i];
   }

   for(int i = 0; i <= n; i++){
        t[i] = INFTY;
   }
   t[0] = 0;
   for(int i = 0; i < m; i++){
        t[c[i]] = 1;
   }

   for(int i = 0; i < m; i++){
        for(int j = c[i]; j <= n; j++){
            t[j] = min(t[j], t[j-c[i]]+1);
        }
   }

   cout << t[n]<< endl;


    return 0;
}



Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
lint N, A, B, C;
vector<lint> l;
const lint INF = 1e18;

lint dfs(lint a, lint b, lint c, lint num){
  if(num == N){
    if(min({a, b, c}) > 0) return abs(A- a) + abs(B - b) + abs(C - c) - 30;
    else return INF;
  }
  lint x = dfs(a + l[num], b, c, num + 1) + 10;
  lint y = dfs(a, b + l[num], c, num + 1) + 10;
  lint z = dfs(a, b, c + l[num], num + 1) + 10;
  lint w = dfs(a, b, c, num + 1);
  return min({x, y, z, w});
}

signed main(){
  cin >> N >> A >> B >> C;
  l.resize(N);
  for(lint i = 0; i < N; i++) cin >> l[i];
  cout << dfs(0, 0, 0, 0) << endl;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
R,S,P=map(int,input().split())
T=input()
t=""
count=0
for i in range(n):
    if i>k-1:
        if T[i]=="r":
            if t[i-k]!="p":
                t=t+"p"
                count+=P
            else:
                t=t+" "
        if T[i]=="s":
            if t[i-k]!="r":
                t=t+"r"
                count+=R
            else:
                t=t+" "
        if T[i]=="p":
            if t[i-k]!="s":
                t=t+"s"
                count+=S
            else:
                t=t+" "
    else:
        if T[i]=="r":
            t=t+"p"
            count+=P
        if T[i]=="p":
            t=t+"s"
            count+=S
        if T[i]=="s":
            t=t+"r"
            count+=R
print(count)

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,k;
char c[1000005];
int main(){
	cin>>k;
	if(k%2==0||k%5==0){
		cout<<-1;
		return 0;
	}
	int cur=7%k;
	int ans=1;
	while(cur!=0){
		cur=cur*10+7;
		cur%=k;
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3640
def main():
    n = int(input())
    data = [ list(map(int, input().split())) for _ in range(n)]

    data.sort(key=lambda x: x[1])

    sum_all = 0
    count = 0

    for i in range(n):
        sum_all += data[i][0]

    if sum_all > int(data[-1:][0][1]):
        return "No"

    for i in range(n):
        count += data[i][0]
        if count > data[i][1]:
            return "No"

    return "Yes"

if __name__ == '__main__':
    print( main() )


Measured memory_bytes: 53712
#include<bits/stdc++.h>
#include<string>
#include<cctype>
#include<cmath> 
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
 
int main(){
 
  long long N,X,Y,i;
  
  cin >> N;
  long long a[N];
  long long ans[N];
  long long ans1,min;
  rep(i,N){
    cin >> a[i];
  }
  rep(i,N-1){
    ans[0]=a[0];
    ans[i+1]=ans[i]+a[i+1];
  }
  min=200000000000000;
  for(i=0;i<N-1;i++){
    X = ans[i];
    Y = ans[N-1]-X;
    ans1 = abs(X-Y);
 
    if(min>ans1){
      min = ans1;
    }
  }
  
  cout << min << endl;
  return 0;
}



Measured memory_bytes: 3328
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;



int main() {
	string S;
	string SS[3] = { "Sunny", "Cloudy", "Rainy" };

	cin >> S;

	for (int n = 0; n < 3; n++) {
		if (S == SS[n]) {
			cout << SS[(n + 1) % 3];
		}
	}
	

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
using namespace std;
bool a[1500000];
int main() {
	fill(a, a + 1500000, true);
	a[0] = false; 1[a] = false;
	for (int i = 2; i < 1500000; i++) {
		if (a[i]) {
			int j = 2;
			while (i*j < 1500000) {
				a[i*j] = false;
				j++;
			}
		}
	}
	int n;
	while (cin >> n&&n != 0) {
		int s = n, e = n;
		while (!a[s]) s--;
		while (!a[e]) e++;
		cout << e - s << endl;
	}
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

using namespace std;

int main() {
    int N;
    cin >> N;
    int W[N];
    rep(i,N) {
        if(i==0) cin >> W[i];
        else {
            cin >> W[i];
            W[i]+=W[i-1];
        }
    }
    int diff = 100000;
    rep(i,N) {
        diff = min(abs((W[N-1]-W[i])-W[i]),diff);
    }

    cout << diff << endl;
}


Measured memory_bytes: 256