akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  str st;
  cin >> st;
  ll n = st.length();
  ll sum = 0;
  REP(i,1<<(n-1)){
    ll temp = 0;
    ll temp_sum = 0;
    REP(j,n){
      temp += st[j]-'0';
      if(j==n-1||((i>>j)&1)){
        temp_sum += temp;
        temp = 0;
      }else{
        temp *= 10;
      }
    }
    sum += temp_sum;
  }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
use std::cmp::*;
use std::io::*;

fn main() {
    let mut s: String = String::new();
    stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let _: i64 = itr.next().unwrap().parse().unwrap();
    let b: i64 = itr.next().unwrap().parse().unwrap();
    let c: Vec<i64> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    if n == 1 {
        println!("{}", (c[0] - b).abs());
    } else {
        let kouho1 = (c[n - 2] - c[n - 1]).abs();
        let kouho2 = (c[n - 1] - b).abs();
        println!("{}", max(kouho1, kouho2));
    }
}


Measured memory_bytes: 4352
#include <iostream>
 
using namespace std;
 
int main()
{
int n, dp[1005][4],tab[100005][4];
  long double xd[100000];
 
cin>>n;
for(int i=1; i<=n; i++){
  cin>>tab[i][1]>>tab[i][2]>>tab[i][3];
}
 
dp[1][1]=tab[1][1];
dp[1][2]=tab[1][2];
dp[1][3]=tab[1][3];
 
 
for(int i=2; i<=n; i++){
dp[i][1]=max(dp[i-1][2],dp[i-1][3])+tab[i][1];
dp[i][2]=max(dp[i-1][1],dp[i-1][3])+tab[i][2];
dp[i][3]=max(dp[i-1][1],dp[i-1][2])+tab[i][3];
}
 
int wynik=max(dp[n][1],dp[n][2]);
cout<<max(wynik,dp[n][3]);
 
  return 0;
}

Measured memory_bytes: 1792
#include"bits/stdc++.h"
//#include<bits/stdc++.h>
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;
const int mod = 1000003;



int main() {
	string s;
	cin >> s;
	int g = 0;
	int p = 0;
	rep(i, 0, s.size()) {
		if (s[i] == 'g')g += 1;
		if (s[i] == 'p')p += 1;
	}
	print((g - p) / 2);
	return 0;
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ldouble = long double;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s) cout << fixed << setprecision(10) << s << endl;


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

	ll a, b;
	cin >> a >> b;

	string r;
	cin >> r;

	if (s == r)
	{
		a--;
	}
	else
	{
		b--;
	}

	println(a << " " << b);
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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 (b<a) { a=b; return 1; } return 0; }

#include <bits/stdc++.h>
using namespace std;

int main(){
  int d,ans,n;
  
  while(cin>>d){
    ans=0;
    n=600/d;
    rep(i,n) ans+=i*i*d*d*d;
    cout<<ans<<endl;
  }
    
  return 0;
}


Measured memory_bytes: 3052
#include <bits/stdc++.h>
const long long INF = LLONG_MAX / 2;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
using namespace std;
string s;
vector<ll> v;
vector<pair<ll, ll>> vp;
vector<vector<ll>> vv(110, vector<ll>(50, 0));
vector<tuple<ll, ll, ll>> vt;
set<ll> st;
map<char, ll> mp;

typedef int Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ from, to, cost });
}


int main()
{
	ll n;
	cin >> n;
	v.resize(n);
	REP(i, n) {
		cin >> v[i];
		mp[v[i] % 2]++;
	}
	mp[0] += mp[1]/2;
	ll res = mp[1] % 2;
	if(res)
	{
		cout << "NO" << endl;
		return 0;
	}
	res += mp[0] % 2;
	cout << (res<=1 ? "YES" : "NO") << endl;
}

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

using namespace std;
int main()
{
    int n,c[100],v[100];
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>c[i];
    }
    vector<int>r;
    for(int i=0;i<n;i++)
    {
        r.push_back(v[i]-c[i]);
    }
    sort(r.begin(),r.end());
    int sum=0;
    for(int i=0;i<n;i++)
    {
        if(r[i]>0)
        {
            sum+=r[i];
        }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("-ffloat-store")
 
#define int  long long
#define rep(i,begin,end) for(__typeof(end)i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define F first
#define S second
#define sz(x) ((int)x.size())
#define pb push_back
#define pf push_front
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define what_is(x) cerr << #x << " is " << x <<"\n";
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.rbegin(), v.rend())
#define PI 3.14159265358979323846
#define vout(a) for(auto x:a) cout<<x<<" ";
#define INF 2000000000000000000 //1e16
 
// #define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
 
 
// using namespace __gnu_pbds;
using namespace std;
 
using ll  = long long;
using vi  = vector<int>;
using pii = pair<int,int>;
using vii = vector<pii>;
using mi  = multiset<int>;
using mii = multiset<pii>;
 
int lcm(int a,int b) {return (a*(b/__gcd(a,b)));}



void solve()
{
    int n,m,t,i,k,r,l,u,v,w,j,s,pos,sum=0,flag=0,count=0;
    string S,T,U; 
    int mx;
    cin>>n>>mx;
    vi weight(n),value(n),dp(mx+1,0);
    rep(i,0,n) cin>>weight[i]>>value[i];
    rep(j,0,n)
    {
        rep(i,mx+1,weight[j])
        {
            if(i-weight[j]>=0)
            {
                dp[i]=max(dp[i],value[j]+dp[i-weight[j]]);
                // cout<<i<<" "<<dp[i]<<"\n";
            }
        }
    }
    cout<<dp[mx];
}

 

signed main()
{

    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve();
        if(t)cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3984
//#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e7+5;
const int mod=1e9+7;
ll n,k,m;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    m=n%k;
    cout<<max((ll)0,min(abs(m-k),m))<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;



int main() {
	int N,A,B;
	int ans = 0;
	cin >> N >> A >> B;

	for (int i = 1; i <= N; i++)
	{
		int temp = i;
		int total = 0;
		
		while (temp > 0)
		{
			total += temp % 10;
			temp = temp / 10;
		}
		if(total >= A && total <= B){
			ans += i;
		}

	}
	cout << ans << endl;

}

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

using namespace std;
typedef long long int lld;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define trav(a,v) for(auto a:v)

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  string s;
  cin>>s;
  int arr[n-1];
  int sum=0;
  rep(i,0,n-1){
    arr[i]=s[i+1]-s[i];
    if(arr[i]<0)arr[i]=-arr[i];
    bool b=true;
    rep(j,0,21){
      //cout<<((i>>j)%2)<<" "<<(((n-2)>>j)%2)<<endl;
      if((i>>j)%2==1 && ((n-2)>>j)%2==0){
	b=false;
      }
    }
    //cout<<b<<" "<<arr[i]<<endl;
    if(b)sum+=arr[i];
  }
  if(sum%2==1){
    cout<<1<<endl;
    return 0;
  }
  rep(i,0,n-1){
    if(arr[i]==1){
      cout<<0<<endl;
      return 0;
    }
  }
  sum=0;
  rep(i,0,n-1){
    arr[i]/=2;
    bool b=true;
    rep(j,0,21){
      //cout<<((i>>j)%2)<<" "<<(((n-2)>>j)%2)<<endl;
      if((i>>j)%2==1 && ((n-2)>>j)%2==0){
	b=false;
      }
    }
    //cout<<b<<" "<<arr[i]<<endl;
    if(b)sum+=arr[i];
  }
  sum%=2;
  sum*=2;
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 5276
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

int ans[51][1 << 18];
const int inf = 1e5;

int Solve(int last, int mask, const vector<int>& a, const vector<int>& b) {
  if (mask == 0) return 0;
  int& result = ans[last][mask];
  if (result != -1) return result;
  result = inf;
  vector<int> A, B, ind;
  int parity = 0;
  for (int i = a.size() - 1; i >= 0; --i) if (mask & (1 << i)) {
    A.push_back(parity == 0 ? a[i] : b[i]);
    B.push_back(parity == 1 ? a[i] : b[i]);
    ind.push_back(i);
  } else {
    parity ^= 1;
  }
  reverse(A.begin(), A.end());
  reverse(B.begin(), B.end());
  reverse(ind.begin(), ind.end());
  for (int i = 0; i < A.size(); ++i) {
    int cur = A[i];
    if (i % 2) cur = B[i];
    if (last > cur) continue;
    result = min(result, i + Solve(cur, mask ^ (1 << ind[i]), a, b));
  }
  return result;
}

int main()
{
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) cin >> b[i];
  memset(ans, -1, sizeof(ans));
  int result = Solve(0, (1 << n) - 1, a, b);
  if (result >= inf) result = -1;
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 52480
def solve(h,w):
    ans1 = float("inf")
    ans2 = float("inf")
    for i in range(1,h):
        w_mid = w//2
        s1_max = max(i*w,(h-i)*w_mid,(h-i)*(w-w_mid))
        s1_min = min(i*w,(h-i)*w_mid,(h-i)*(w-w_mid))
        ans1 = min(ans1,s1_max - s1_min)
    for i in range(1,h):
        h_mid = (h-i)//2
        s2_max = max(i*w,h_mid*w,(h-i-h_mid)*w)
        s2_min = min(i*w,h_mid*w,(h-i-h_mid)*w)
        ans2 = min(ans2,s2_max-s2_min)
    return min(ans1,ans2)
def main():
    h,w = map(int,input().split())
    print(min(solve(h,w),solve(w,h)))
if __name__=='__main__':
    main()

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

int main(){
    
    int cA,cB,cC;
    int mResult=0;
    
    cin>>cA>>cB>>cC;
    
    while(cC>0){
        mResult++;
        cC-=cA;
        if(!(mResult%7)){
            cC-=cB;
        }
    }
    
    cout<<mResult<<endl;
    
    return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#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 ALL(a) (a).begin(), (a).end()

int main() {
    ll N;
    cin >> N;
    map<ll, ll> mii;

    FOR(i, 2, 1000000) {
        while (N % i == 0) {
            mii[i]++;
            N /= i;
        }
    }
    if (N != 1) mii[N]++;

    ll ans = 0;
    for (auto p : mii) {
        ll i = 1;
        while (true) {
            p.second -= i;
            if (p.second < 0) break;
            i++;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3604
#include<map>
#include<set>
#include<list>
#include<ctime>
#include<cmath>
#include<deque>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<iostream>
#include<algorithm>
#define rep(i,s,t) for(register int i=s;i<=t;++i)
#define _rep(i,s,t) for(register int i=s;i>=t;--i)
#define Rep(i,s,t) for(register int i=s;i<t;++i)
#define go(x) for(register int e=las[x];e;e=nxt[e])
#define re register
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define is insert
#define es erase
#define pii pair<int,int>
#define ms(f,x) memset(f,x,sizeof f)
#define mc(f,x) memcpy(f,x,sizeof f)
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
#define gi(x) read(x)
#define gii(x,y) read(x),read(y)
#define giii(x,y,z) read(x),read(y),read(z)
namespace IO{
    #define gc getchar()
    #define pc(x) putchar(x)
    template<typename T>inline void read(T &x){
        x=0;int f=1;char ch=gc;while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=gc;}
        while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=gc;x*=f;return;
    }
    template<typename T>inline void write(T x=0){
        T wr[51];wr[0]=0;if(x<0)pc('-'),x=-x;if(!x)pc(48);
        while(x)wr[++wr[0]]=x%10,x/=10;while(wr[0])pc(48+wr[wr[0]--]);return;
    }
}
using IO::read;
using IO::write;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
int a,b,c;
int main(){
	scanf("%d%d%d",&a,&b,&c);
	if(a==b&&b==c)puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
while 1:
    n,v=int(input()),0
    if n==0:break
    for _ in range(n):
        x,y,h,w=map(int,input().split())
        x=x+y+h
        if x<61 and w<3:v+=6
        elif x<81 and w<6:v+=8
        elif x<101 and w<11:v+=10
        elif x<121 and w<16:v+=12
        elif x<141 and w<21:v+=14
        elif x<161 and w<26:v+=16
    print(v*100)

Measured memory_bytes: 7564
from collections import deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
    N, M, P = map(int, readline().split())
    G = [[] for i in range(N)]
    for i in range(M):
        u, v = map(int, readline().split())
        G[u-1].append(v-1)
        G[v-1].append(u-1)
    N1 = 1 << N
    bc = [0]*N1
    for i in range(1, N1):
        bc[i] = bc[i ^ (i & -i)] + 1
    ec = [0]*N1
    for state in range(1, N1):
        c = 0
        for v in range(N):
            if (state & (1 << v)) == 0:
                continue
            for w in G[v]:
                if (state & (1 << w)) == 0:
                    continue
                c += 1
        ec[state] = c >> 1
    N0 = 1 << (N-1)
    dp = [0]*N1
    dp[1] = 1
    for s0 in range(1, N0):
        state0 = (s0 << 1) | 1
        state1 = (state0-1) & state0
        v = 0
        while state1:
            if state1 & 1:
                k = ec[state0] - ec[state1] - ec[state0 ^ state1]
                v += dp[state1] * (P/100)**k
            state1 = (state1 - 1) & state0
        dp[state0] = 1 - v
    write("%.16f\n" % dp[N1-1])
solve()


Measured memory_bytes: 6580
import math
n,m=map(int, input().split())
c=[]
if n==1:
    print(m)
else:
    for i in range(1,math.floor(m**(1/2))+1):
        if m%i==0:
            c.append(i)
            c.append(m//i)
    c=sorted(c, reverse=True)
    for ci in c:
        if ci*n<=m:
            print(ci)
            break

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

int solve(int n)
{
    if(n % 2 != 0){
        return 0;
    }
    return solve(n / 2) + 1;
}

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

    int max_div = 0;
    int max_num = 1;
    for(int i=N; i>0; i--){
        int r = solve(i);
        if(r > max_div){
            max_div = r;
            max_num = i;
        }
    }
    cout << max_num << endl;
    return 0;
}


Measured memory_bytes: 888
n = int(input())
points = []
tmp = (list(map(int, input().split())))
tmp.sort()
points.append(tmp)

for i in range(n-1):
	new = list(map(int, input().split()))
	new.sort()
	flag = True
	for arr in points:
		if(arr[0] == new[0] and arr[1] == new[1] and arr[2] == new[2]):
			flag = False
	if(flag):
		points.append(new)
		
print(n - len(points))


Measured memory_bytes: 5780
#include <stdio.h>

int main(){
  int a, b, c;
  scanf("%d",&a);
  switch(a%7){
    case 2: printf("sat\n");break;
    case 3: printf("sun\n");break;
    case 4: printf("mon\n");break;
    case 5: printf("tue\n");break;
    case 6: printf("wed\n");break;
    case 0: printf("thu\n");break;
    case 1: printf("fri\n");break;
  }
  return 0;
}


Measured memory_bytes: 2696
#include <iostream>
#include <string>

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

using namespace std;
using ll = long long;

int n;
int a[102];
ll dp[102][21];
ll dfs(int idx, int sum) {
    if (!(0 <= sum && sum <= 20)) return 0;
    if (idx == n - 1) return sum == a[idx];
    if (dp[idx][sum] != -1) return dp[idx][sum];
    ll ret = 0;
    ret += dfs(idx + 1, sum + a[idx]);
    ret += dfs(idx + 1, sum - a[idx]);
    return dp[idx][sum] = ret;
}
int main() {
    cin >> n;
    rep(i, n) cin >> a[i];
    rep(i, 102) rep(j, 21) dp[i][j] = -1;
    cout << dfs(1, a[0]) << endl;
}

Measured memory_bytes: 3116
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

int main(void){
    std::string s, t;
    std::cin >> s;
    std::cin >> t;

    long long cnt = 0;
    for(int i=0; i<s.size(); i++){
        if(s[i]!=t[i]) cnt++;
    }

    std::cout << cnt << std::endl;
}

Measured memory_bytes: 3916
#include <iostream>
#include <set>
#include <iterator>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;


int count(string S, int index){
  set<char> a;
  set<char> b;
  // a
  for(int i=0;i<index+1;i++){
    a.insert(S.at(i));
  }
  for(int i=index+1;i<S.size();i++){
    b.insert(S.at(i));
  }
  set<char> c;
  set_intersection(a.begin(), a.end(),
		   b.begin(), b.end(),
		   inserter(c, c.end()));
  return c.size();
}

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

  int N;
  string S;
  cin >> N;
  cin >> S;

  int ans = -1;
  for(int i=0;i<N-1;i++){
    int s = count(S, i);
    ans = max(s, ans);
  }

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


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){

  int N, K;
  int d[100];
  int Ai[100][100];
  int A[100];
  int sum = 0;

  cin >> N >> K;

  for(int i=0; i<N; i++){
    A[i] = 0;
  }

  for(int i=0; i<K; i++){
    cin >> d[i];
    for(int j=0; j<d[i]; j++){
      cin >> Ai[j][i];
      A[Ai[j][i]-1]++;
    }
  }

  for(int i=0; i<N; i++){
    if(A[i] == 0) sum++;
  }

  cout << sum << endl;

}


Measured memory_bytes: 3644
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long

using namespace std;
using P = pair<int,int>;

int main(){

  ll A, B, C, x1, x2, x3;
  cin >> A >> B >> C;

  if(A%2 != 0 && B%2 != 0 && C%2 != 0){
    ll mx = max(A, max(B, C)); // 最大値
    x1 = mx /2;
    x2 = mx /2 + 1;
    ll y;

    if(mx == A){
      y = B*C;
    }else if(mx == B){
      y = A*C;
    }else if(mx == C){
      y = A*B;
    } 

    cout << (x2 * y) - (x1 * y) << endl;
  } else {
    cout << 0 << endl;
  }

  return 0;
}

Measured memory_bytes: 3612
//agc016_a.cpp
//Sun Sep 30 11:11:04 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	unordered_map<char,int> letters;
	for (int i=0;i<s.size();i++){
		auto itr = letters.find(s[i]);
		if (itr != letters.end()){
			letters[s[i]]++;
		}else {
			letters[s[i]] = 1;
		}
	}
	int ans = INTINF;
	for (auto itr=letters.begin();itr!=letters.end();++itr){
		int maxdis = 0;
		int dis = 0;
		int tempchar = itr->first;
		for (int i=0;i<s.size();i++){
			if (s[i] == tempchar){
				if (maxdis < dis){
					maxdis = dis;
				}
				dis = 0;
			}else {
				dis++;
			}
		}
		if (maxdis < dis){
			maxdis = dis;
		}

		if (maxdis < ans){
			ans = maxdis;
		}
	}

	cout << ans << endl;
}

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

using namespace std;

#define fr(i,s,e) for(i=s;i<e;i++)

int main() {
    int res=0,mx,mn=INT_MAX;
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;

    res=(a*x)+(b*y);
    mn=min(mn,res);
    mx=max(x,y);
    res=2*mx*c;
    mn=min(mn,res);
    if(x<y){
        res=(c*2*x)+(b*(y-x));
        mn=min(mn,res);}
    if(y<x){
        res=(c*2*y)+(a*(x-y));
        mn=min(mn,res);}
    cout<<mn;
return 0;
}


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

using ll = long long;

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

template<typename T>
T lcm(T a, T b)
{
	return a * b / gcd(a, b);
}

template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
	x = 1;
	y = 0;
	T x0 = 0, y0 = 1;
	while (b != 0)
	{
		T q = a / b;
		a -= q * b;
		swap(a, b);
		x -= q * x0;
		swap(x, x0);
		y -= q * y0;
		swap(y, y0);
	}
	return a;
}

template<typename T>
T inv_mod(T a, T mod)
{
	T t1, t2;
	ext_gcd(a, mod, t1, t2);
	t1 %= mod;
	if (t1 < 0)		t1 += mod;
	return t1;
}

template<typename T>
T combination_large(T n, T k, T mod)
{
	if (n < k || n < 0 || k < 0)	return 0;
	vector<T> inv(n + 1, 1), fact(n + 1, 1), fact_inv(n + 1, 1);
	for (T i = 2; i <= n; ++i)
	{
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		fact[i] = (fact[i - 1] * i) % mod;
		fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
	}
	return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
}

template<typename T>
T combination(T n, T k, T mod = 1)
{
	vector<vector<T>> table(n + 1, vector<T>(k + 1, 1));
	for (T i = 1; i <= n; ++i)
	{
		table[i][0] = 1;
		for (T j = 1; j <= n; ++j)
		{
			table[i][j] = (table[i - 1][j - 1] + table[i - 1][j]) % mod;
		}
	}
}


int main(int, char**)
{
	std::string S;
	std::cin >> S;

	cout << (S[2] == S[3] && S[4] == S[5] ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
//#include <list>
#include <iomanip>
//#include <stdlib.h>
//#include <cctype>

using namespace std;

const int MAX_N = 1000000;
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)
template <typename T>
void printV(const std::vector<T>& v, const char * const separator = " ")
{
    if(!v.empty())
    {
        std::copy(v.begin(),
                  --v.end(),
                  std::ostream_iterator<T>(std::cout, separator));
        std::cout << v.back() << "\n";
    }
}


Int gcd(Int a, Int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

Int lcm(Int a, Int b) {
    return a / gcd(a, b) * b;
    //a*bは64bit integer overflow
}

int Max(int a, int b, int c) {
    int temp = max(a, b);
    return max(temp, c);
}

int Min(int a, int b, int c) {
    int temp = min(a, b);
    return min(temp, c);
}

bool integer(double num) {
    return floor(num) == num;
}

Int fact(int num) {
    if (num == 0)
        return 1;
    else
        return num * fact(num - 1);
}

void y() {
    cout << "Yes" << endl;
    exit(0);
}

void n() {
    cout << "No" << endl;
    exit(0);
}

void Y() {
    cout << "YES" << endl;
    exit(0);
}

void N() {
    cout << "NO" << endl;
    exit(0);
}

Int yakusu(int n) {
    int cnt = 0;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            cnt++;
            if (i * i != n) cnt++;
        }
    }
    return cnt;
}

/*   kokomade  */

int cnt = 0;
bool is_prime[ 50000 + 1 ];
vector<int> P;
void Eratosthenes( const int N )
{
    for( int i = 0; i <= N; i++ )
    {
        is_prime[ i ] = true;//初期化
    }
    for( int i = 2; i <= N; i++ )
    {
        if( is_prime[ i ] )
        {
            for( int j = 2 * i; j <= N; j += i )
            {
                is_prime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
}

int main() {
    IOS;
   int n;
   cin>>n;
   Int ans=0;
    vector<int> a(n);
    vector<int> b(n);
   vector<int> c(n-1);
   //int s,t;
    for (int i = 0; i < n; ++i) {
        cin>>a[i];
        a[i]=a[i]-1;
    }
    for (int i = 0; i <n ; ++i) {
        cin>>b[i];
        ans+=b[i];
    }
    for (int i = 0; i < n-1; ++i) {
        cin>>c[i];
    }
    int mem=a[0];
    for (int j = 0; j < n-1; ++j) {
        if(a[j]+1==a[j+1])ans+=c[a[j]];
        mem=a[j+1];
    }
    cout<<ans;




    cout<<endl;
    return 0;
}

/*
テレビも無ェ ラジオも無ェ
自動車もそれほど走って無ェ
ピアノも無ェ バーも無ェ
巡査 毎日ぐーるぐる
朝起ぎで 牛連れで
二時間ちょっとの散歩道
電話も無ェ 瓦斯も無ェ
バスは一日一度来る
俺らこんな村いやだ 俺らこんな村いやだ
東京へ出るだ 東京へ出だなら
銭コァ貯めで 東京でベコ(牛)飼うだ
*/


Measured memory_bytes: 256
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};


struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}


bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

ll dx8[8]={1,0,-1,0,1,-1,1,-1};
ll dy8[8]={0,1,0,-1,1,-1,-1,1};
ll dx4[4]={0,0,1,-1};
ll dy4[4]={1,-1,0,0};



int main(){
    IOS;
    make(ll,n);
    make(string,s);
    ll c=0; ll ans=0;
    fr(i,n) if(s[i]=='W') c++;
    for(ll i=n-1;i>n-1-c;i--){
        if(s[i]=='R') ans++;
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3776
#include<bits/stdc++.h>
#define reg register int
#define il inline
#define fi first
#define se second
#define mk(a,b) make_pair(a,b)
#define numb (ch^'0')
#define pb push_back
#define solid const auto &
#define enter cout<<endl
#define pii pair<int,int>
using namespace std;
typedef long long ll;
template<class T>il void rd(T &x){
    char ch;x=0;bool fl=false;while(!isdigit(ch=getchar()))(ch=='-')&&(fl=true);
    for(x=numb;isdigit(ch=getchar());x=x*10+numb);(fl==true)&&(x=-x);}
template<class T>il void output(T x){if(x/10)output(x/10);putchar(x%10+'0');}
template<class T>il void ot(T x){if(x<0) putchar('-'),x=-x;output(x);putchar(' ');}
template<class T>il void prt(T a[],int st,int nd){for(reg i=st;i<=nd;++i) ot(a[i]);putchar('\n');}
namespace Modulo{
const int mod=1e9+7;
int ad(int x,int y){return (x+y)>=mod?x+y-mod:x+y;}
void inc(int &x,int y){x=ad(x,y);}
int mul(int x,int y){return (ll)x*y%mod;}
void inc2(int &x,int y){x=mul(x,y);}
int qm(int x,int y=mod-2){int ret=1;while(y){if(y&1) ret=mul(x,ret);x=mul(x,x);y>>=1;}return ret;}
template<class ...Args>il int ad(const int a,const int b,const Args &...args) {return ad(ad(a,b),args...);}
template<class ...Args>il int mul(const int a,const int b,const Args &...args) {return mul(mul(a,b),args...);}
}
using namespace Modulo;
namespace Miracle{
const int N=603;
int f[2][303][303];
int n;
int a[N];
int J,K;
int gu[N],hk[N];
int exi[N];
int die[N];
int main(){
    rd(n);
    for(reg i=1;i<=2*n;++i){
        rd(a[i]);
        if(a[i]!=-1) exi[a[i]]=1;
        if(i%2==0){
            if(a[i]==-1&&a[i-1]==-1) ++K;
            else if(a[i]==-1&&a[i-1]!=-1){
                ++J;++hk[a[i-1]];
            }else if(a[i]!=-1&&a[i-1]==-1){
                ++J;++hk[a[i]];
            }else{
                die[a[i]]=1;die[a[i-1]]=1;
            }
        }
    }
    for(reg i=2*n;i>=1;--i){
        gu[i]=gu[i+1]+exi[i];
        hk[i]+=hk[i+1];
    }
    int tmp=0;
    f[0][0][0]=1;
    for(reg i=2*n;i>=1;--i){
        if(die[i]) continue;
        tmp^=1;
        memset(f[tmp],0,sizeof f[tmp]);
        for(reg j=0;j<=hk[i];++j){
            for(reg k=0;k<=min(K,(2*n-i)+1);++k){
                if(exi[i]){
                    if(j&&2*n-i-(j-1)-2*k-gu[i+1]>=1){
                        inc(f[tmp][j][k],f[tmp^1][j-1][k]);
                    }
                    inc(f[tmp][j][k],f[tmp^1][j][k]);
                }else{
                    if(j) inc(f[tmp][j][k],mul(f[tmp^1][j-1][k],(hk[i]-(j-1))));
                    if(k&&(2*n-i-j-2*(k-1)-gu[i+1])>=1) inc(f[tmp][j][k],mul(f[tmp^1][j][k-1],K-(k-1)));
                    inc(f[tmp][j][k],f[tmp^1][j][k]);
                }
            }
        }
    }
    ll ans=f[tmp][J][K];
    ot(ans);
    return 0;
}

}
signed main(){
    Miracle::main();
    return 0;
}

/*
   Author: *Miracle*
*/

Measured memory_bytes: 1024
N = int(input())
conditions = [[] for _ in range(N) ]
for i in range(N):
  a = int(input())
  for _ in range(a):
    x,y = map(int,input().split())
    x -= 1
    conditions[i].append([x,y])

res = 0
for i in range(1<<N):
  mapper = {1: [], 0: []}
  flg = True
  cnt = 0
  for j in range(N):
    if (i>>j)&1:
      cnt += 1
      for x,y in conditions[j]:
        if y==1 and not (i>>x)&1:
          flg = False
          break
        elif y==0 and (i>>x)&1:
          flg = False
          break
    if not flg: 
      break

  if flg:
    res = max(res, cnt)

print(res)


Measured memory_bytes: 45292
#define FORI(x) for(int i=0;i<x;++i)
#define FORJ(x) for(int j=0;j<x;++j)

#include <iostream>
#include <string>
#include <math.h>

using namespace std;

int main() {
	char n[4];
	bool f = false;
	FORI(4) {
		cin >> n[i];
	}
	for (int i = 0; i < 3; ++i) {
		if (n[i] == n[i + 1]) {
			f = true;
			break;
		}
	}
	cout << ((f) ? "Bad" : "Good");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>//pow(x,y)=x^y
#include <algorithm>//sort(a.begin(), a.end());reverse(a.begin(), a.end());
#define rep(i,n) for (int i=0; i <(n);i++)
#define ll long long
using namespace std;


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

   if (isupper(s))
   {
       cout << "A" << endl;
   }
   else
   {
       cout << "a" << endl;
   }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<tuple<string, int, int>> vt(n);
  rep(i, n){
    string s;
    int p;
    cin >> s >> p;
    vt.at(i) = (make_tuple(s, p, i+1));
  }
  sort(vt.begin(), vt.end(), [](const auto &l, const auto &r) -> bool{
    if(get<0>(l) == get<0>(r)){
      return get<1>(l) > get<1>(r);
    }else{
      return get<0>(l) < get<0>(r);
    }
  });
  rep(i, n){
    cout << get<2>(vt.at(i)) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
N=int(input())
def make_divisors(n):
  divisors=[]
  for i in range(1, int(n**0.5)+1):
    if n%i==0:
      divisors.append(i)
      if i!=n//i:
        divisors.append(n//i)
  A=sorted(divisors)
  p=len(A)//2
  return len(str(A[p]))
print(make_divisors(N))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

const int MOD = 1000000007;

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

  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, 0, n) cin >> a[i];

  ll ans = 0;
  rep(i, 0, 61) {
    ll x = 0;
    rep(j, 0, n) if (a[j] >> i & 1) x++;
    ll v = pow(2, i);
    v %= MOD;
    ll y = x * (n - x);
    y %= MOD;
    v *= y;
    v %= MOD;
    ans += v;
    ans %= MOD;
  }

  cout << ans << endl;
}


Measured memory_bytes: 5584
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

ll dp[101][101];

void print_dp(int h, int w) {
  rep(i,h) {
    rep(j,w) {
      cout << dp[i][j];
    }
    cout << endl;
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  memset(dp,0,sizeof(dp));
  int h,w;
  cin>>h>>w;
  vector<string> ss(h);
  rep(i,h) {
    cin>>ss[i];
  }
  if(ss[0][0]=='#')
    dp[0][0]=1;
  repeat(i,1,h) {
    dp[i][0]=dp[i-1][0];
    if(ss[i][0]=='#'&&ss[i-1][0]=='.') {
      dp[i][0]++;
    }
  }
  repeat(i,1,w) {
    dp[0][i]=dp[0][i-1];
    if(ss[0][i]=='#'&&ss[0][i-1]=='.')
      dp[0][i]++;
  }
  //  print_dp(h,w);
  repeat(i,1,h) {
    repeat(j,1,w) {
      if(ss[i][j]=='#'&&ss[i-1][j]=='.') {
	dp[i][j]=dp[i-1][j]+1;
      } else {
	dp[i][j]=dp[i-1][j];
      }
      if(ss[i][j]=='#'&&ss[i][j-1]=='.') {
	dp[i][j]=min(dp[i][j],dp[i][j-1]+1);
      } else {
	dp[i][j]=min(dp[i][j],dp[i][j-1]);
      }
    }
  }
  cout << dp[h-1][w-1] << endl;
  return 0;
}


Measured memory_bytes: 384
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 100001), 100001*100)
}

func main() {
	s := scanString()

	fmt.Println(strings.LastIndex(s, "Z") - strings.Index(s, "A") + 1)
}


Measured memory_bytes: 1152
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    let n: i64 = read();
    let k: i64 = read();
    println!("{}", k + 100 * std::cmp::max(10 - n, 0));
}



Measured memory_bytes: 4352
import java.util.*;

public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);

    long a = sc.nextLong();
    long b = sc.nextLong();
    long x = sc.nextLong();

    long cnt = b / x - a / x;
    if (a % x == 0) cnt++;

    System.out.println(cnt);
  }
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){

    int a,b,c,k;
    cin>>a>>b>>c>>k;

    int ans=0;

    if(k<=a){
        cout<<k<<"\n";
        return 0;
    }
    ans+=a;
    k-=a;

    if(k<=b){
        cout<<ans<<"\n";
        return 0;
    }
    k-=b;

    cout<<ans-k<<"\n";

    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll cnt[66];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  vi A(n);
  for(auto &a:A)cin>>a;
  ll ans=0;
  for(int i=0;i<n;i++){
    for(ll j=0;j<=60;j++){
      if(BITLE(j)&A[i]){
	cnt[j]++;
      }
    }
  }
  for(ll i=0;i<=60;i++){
    ans+=(((BITLE(i)%MOD)*(n-cnt[i])%MOD)*cnt[i])%MOD;
    ans%=MOD;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 2560
N = int(input())

p = [int(x) for x in input().split()]

q = [int(y) for y in range(1, N+1)]

count = 0

for i in range(N):
  if p[i] != q[i]:
    count += 1
    
if count == 0 or count == 2:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3060
import math as m
n, d=map(int, input().split())
a=[]
p=[]
q=[]
for _ in range(n):
	a.append(list(map(int, input().split())))
for i in range(n):
	k=i+1
	while k<n:
		x=0
		for j in range(d):
			x+=(a[i][j]-a[k][j])**2
		x=m.sqrt(x)
		p.append(x)
		q.append(int(x))
		k+=1
x=0
for i in range(len(p)):
	if p[i]==q[i]:
		x+=1
print(x)

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("sample.txt")
    N, K = Scanner.map_int()
    H = Scanner.map_int()
    dp = [INF] * (N)
    dp[0] = 0
    for i in range(1, N):
        for k in range(1, K+1):
            if 0 <= i - k:
                dp[i] = min(dp[i], dp[i-k] +
                            abs(H[i] - H[i-k]))
    print(dp[N-1])


if __name__ == "__main__":
    main()


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

template<int um> class UF {
	public:
	vector<int> par,rank,cnt;
	UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;}
	void reinit() {int i; FOR(i,um) rank[i]=0,cnt[i]=1,par[i]=i;}
	int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
	int count(int x) { return cnt[operator[](x)];}
	int operator()(int x,int y) {
		if((x=operator[](x))==(y=operator[](y))) return x;
		cnt[y]=cnt[x]=cnt[x]+cnt[y];
		if(rank[x]>rank[y]) return par[x]=y;
		rank[x]+=rank[x]==rank[y]; return par[y]=x;
	}
};
UF<101010> uf;
int N,M;


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,M) {
		cin>>x>>y>>r;
		uf(x,y);
	}
	int ret=0;
	for(i=1;i<=N;i++) if(i==uf[i]) ret++;
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
const int INF_INT = 2147483647;
const long long INF_LONG = 9223372036854775807;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
     
int main() {
  int a;  cin >> a;
  cout << a + pow(a, 2) + pow(a, 3) << endl;
}

Measured memory_bytes: 4132
'use strict';
const inputs = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
const CODE_A = 97;
let s = inputs[0];
let K = parseInt(inputs[1]);
let cur = 0;
let result = '';
let lastFailedCur = -1;
let lastFailedCode = -1;

while (cur < s.length) {
	let distance = 26 - (s.charCodeAt(cur) - CODE_A);
	
	if (distance === 26) {
		result += 'a';

	} else if (distance <= K) {
		K -= distance;
		result += 'a';
	} else {
		lastFailedCur = cur;
		lastFailedCode = s.charCodeAt(cur);
		result += s[cur];
	}
	
	cur++;
	
}

if (K > 0) {
	K = K % 26;

	if (lastFailedCode === -1) {
		lastFailedCur = s.length - 1;
		lastFailedCode = result.charCodeAt(result.length - 1);
	}
	
	result = result.substr(0, lastFailedCur) +
		String.fromCharCode(CODE_A + (lastFailedCode + K - CODE_A) % 26) +
		result.substr(lastFailedCur + 1);
}

console.log(result);

Measured memory_bytes: 12664
class Combination:
    def __init__(self, mod, max_num):
        self.mod = mod
        self.fac = [0] * max_num
        self.finv = [0] * max_num
        self.inv = [0] * max_num

        self.fac[0], self.fac[1] = 1, 1
        self.finv[0], self.finv[1] = 1, 1
        self.inv[1] = 1

        for i in range(2, max_num):
            self.fac[i] = self.fac[i-1] * i % mod
            self.inv[i] = mod - self.inv[mod % i] * (mod // i) % mod
            self.finv[i] = self.finv[i - 1] * self.inv[i] % mod

    def calc(self, n, k):
        if n < k:
            return 0
        if n < 0 or k < 0:
            return 0
        return self.fac[n] * (
            self.finv[k] * self.finv[n - k] % self.mod) % self.mod


def modpow(val, n, mod):
    ret = 1
    while n:
        if n & 1:
            ret = (ret * val) % mod
        val = (val * val) % mod
        n = n >> 1
    return ret


n, m, k = map(int, input().split())
com = Combination(998244353, 510000)
all_ptn = modpow(m, n, 998244353)
exct_ptn = 0

for i in range(k+1, n):
    cnt = com.calc(n-1, i) * m * modpow(m - 1, n - 1 - i, 998244353)
    exct_ptn += cnt
    exct_ptn %= 998244353

ret = all_ptn - exct_ptn
if ret < 0:
    ret += 998244353

print(ret)


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

long long f(long long x)
{
	long long ans, i = 1;

	while (i * i <= x)
	{
		if (x % i == 0)
			ans = i;
		i++;
	}
	return ans;
}

signed main(void)
{
	long long n, x, y, ans1, ans2;
	cin >> n;
	x = f(n);
	y = n / x;
	ans1 = ans2 = 0;
	while(x)
	{
		ans1++;
		x /= 10;
	}
	while (y)
	{
		ans2++;
		y /= 10;
	}
	cout << max(ans1, ans2) << endl;
	return 0; 
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
cnt = 0
for i in range(n):
    if a[i]<0:
        cnt+=1
an = list(map(abs,a))
if cnt%2==0:
    print(sum(an))
else:
    c = min(an)*-1
    print(sum(an)+2*c)

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

#define all(x) (x).begin(),(x).end()
#define init() \
  ios::sync_with_stdio(false); \
  cin.tie(0)

using namespace std;

using ll = long long;
using ull = unsigned long long;

template<typename M, typename N>
constexpr common_type_t<M, N> gcd(M a, N b) {
  return a == 0 ? b
    : b == 0 ? a
    : gcd(b, a % b);
}

template <typename M, typename N>
constexpr common_type_t<M, N> lcm(M a, N b) {
  return a * b / gcd(a, b);
}

int main() {
  init();

  int n;
  cin >> n;
  vector<int> a(n);
  for(int i =0; i<n; i++){
    cin >> a[i];
  }
  sort(all(a), greater<int>());
  int ali = 0;
  for(int i =0; i<n; i+=2){
    ali+=a[i];
  }
  int bob = 0;
  for(int i =1; i<n; i+=2){
    bob+=a[i];
  }
  cout << ali-bob << '\n';

  return 0;
}


Measured memory_bytes: 256
from sys import stdin, setrecursionlimit
input = stdin.buffer.readline

MOD = 10 ** 9 + 7
N = int(input())

dp = [[0 for _ in range(N + 3)] for _ in range(4)]
dp[0][0] = 1

for i in range(1, N +  1):
    dp[0][i] = (dp[0][i - 1] * 8) % MOD
    dp[1][i] = (dp[0][i - 1] * 1 + dp[1][i - 1] * 9) % MOD
    dp[2][i] = (dp[0][i - 1] * 1 + dp[2][i - 1] * 9) % MOD
    dp[3][i] = (dp[1][i - 1] * 1 + dp[2][i - 1] * 1 + dp[3][i - 1] * 10) % MOD
    
print(dp[3][N])

Measured memory_bytes: 213512
def prime(x):
  p = {}
  cnt = 2
  Flag = True
  while Flag:
    last = math.ceil(x ** 0.5) 
    if cnt > last:
      break
    for i in range(cnt, last + 1):
      if x % i == 0:
        x //= i
        p[i] = 1
        cnt = i + 2
        while x % i == 0:
          x //= i
          p[i] += 1
        cnt = i + 1
        break
      if i == last:
        Flag = False
  if x != 1:
    p[x] = 1
  if len(p) == 1:
    for i in p:
      if p[i] == 1:
        return True
      else:
        return False
  else:
    return False

X = int(input())
import math

ans = X
while True:
  if prime(ans):
    print(ans)
    break
  ans += 1

Measured memory_bytes: 3188