akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(c) (c).begin(), (c).end()
#define pb push_back
#define eb emplace_back
using namespace std;
const long long INF = 1LL<<60; // 仮想的な無限大の値;
using ll = long long;
using P  = pair<int, int>;
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
    ll A, B, N;
    cin >> A >> B >> N;

    if(N < B)
    {
        ll i = N;
        cout << (A*i)/B - A*(i/B) << endl;
    }
    else{
        ll i = B-1;
        cout << (A*i)/B - A*(i/B) << endl;
    }
    // ll i = N/B;
    // if(i == 0)
    // {
    //     int p = A*N/B;
    //     int q = N/B;
    //     cout << p - A*q << endl;
    // }
    
    // rep2(i,1 ,N+1){
    //     cout << (A*i)/B - A*(i/B) << " ";
    // }

    return 0;
}

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

int H, W;
vector<string> fi;

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

int main() {
    cin >> H >> W;
    fi.resize(H);
    for (int i = 0; i < H; ++i) cin >> fi[i];

    // 多点をスタートとして扱う
    vector<vector<int> > dist(H, vector<int>(W, -1));
    using pint = pair<int, int>;
    queue<pint> que;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (fi[i][j] == '#') {
                dist[i][j] = 0;
                que.push(pint(i, j));
            }
        }
    }

    // BFS
    while (!que.empty()) {
        auto cur = que.front();
        que.pop();
        for (int dir = 0; dir < 4; ++dir) {
            int nx = cur.first + dx[dir];
            int ny = cur.second + dy[dir];
            if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
            if (dist[nx][ny] == -1) {
                dist[nx][ny] = dist[cur.first][cur.second] + 1;
                que.push(pint(nx, ny));
            }
        }
    }
    int res = 0;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            res = max(res, dist[i][j]);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 13456
{-# LANGUAGE OverloadedStrings #-}
import Data.List
import Data.Ord
import Data.Char
import Data.Ratio
import Data.Maybe
import Data.String
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as BS
---------------------------------------------------------------------------------
main = do
  n <- getInt
  let list = [x|x<-[1..n], floor(fromIntegral x * 1.08)==n]
  tax $ list
  
tax [] = putStrLn ":("
tax list = putStrLn . show . head $ list
---------------------------------------------------------------------------------

{-ByteString関連-}
--IO
getLine' = BS.getLine
getContents' = BS.getContents
getInt = fst . fromJust . BS.readInt <$> getLine'
getIntListl = map (fst . fromJust. BS.readInt) .BS.words <$> getLine'
getIntListc = map (fst . fromJust. BS.readInt) .BS.words <$> getContents'
getInteger = fst . fromJust. BS.readInteger <$> getLine'
putStr' = BS.putStr
putStrLn' = BS.putStrLn
--演算子
bs1 |++| bs2 = BS.append bs1 bs2
chr |:+| bs2 = BS.cons chr bs2
bs1 |+:| chr = BS.snoc bs1 chr

{-elem関連-}
--elemの第一引数をリストにしたもの。
--elemList "abc" "atcoder" -> [True,False,True]
elemList [] _ = []
elemList (x:xs) list  = elem x list : elemList xs list

--elemIndexの第一引数をリストにしたもの。
elemIndexList [] list = []
elemIndexList (x:xs) list  = elemIndex x list : elemIndexList xs list

--elemIndicesの第一引数をリストにしたもの。
elemIndicesList [] list = []
elemIndicesList (x:xs) list  = elemIndices x list : elemIndicesList xs list

Measured memory_bytes: 3688
n,m=map(int,input().split())
x_l=[]
for i in range(m):
    x_l+= list(map(int,input().split()))
dic={}
for i in x_l:
    if i not in dic:
        dic[i]=1
    else:dic[i]+=1

for i in range(1,n+1):
    if i not in dic:
        print(0)
    else: print(dic[i])

Measured memory_bytes: 3060
// AOJ 2169 Colored Octahedra
// 2018.3.20 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int  hash[16777218];

int tbl[24][8] = {
{0,1,2,3,4,5,6,7},{0,3,7,4,1,2,6,5},{0,4,5,1,3,7,6,2},
{1,0,4,5,2,3,7,6},{1,2,3,0,5,6,7,4},{1,5,6,2,0,4,7,3},
{2,1,5,6,3,0,4,7},{2,3,0,1,6,7,4,5},{2,6,7,3,1,5,4,0},
{3,0,1,2,7,4,5,6},{3,2,6,7,0,1,5,4},{3,7,4,0,2,6,5,1},
{4,0,3,7,5,1,2,6},{4,5,1,0,7,6,2,3},{4,7,6,5,0,3,2,1},
{5,1,0,4,6,2,3,7},{5,4,7,6,1,0,3,2},{5,6,2,1,4,7,3,0},
{6,2,1,5,7,3,0,4},{6,5,4,7,2,1,0,3},{6,7,3,2,5,4,0,1},
{7,3,2,6,4,0,1,5},{7,4,0,3,6,5,1,2},{7,6,5,4,3,2,1,0}};

char name[8][22];
int id[8]; int n;
char used[8];
int color[8];
int ans;

int check()
{
	int i, j, id;
	int t[8];

	id = 0; for (i = 0; i < 8; i++) id = (id << 3) | color[i];
	if (hash[id]) return 0;
	hash[id] = 1;
	for (j = 0; j < 24; j++) {
		for (i = 0; i < 8; i++) t[i] = color[tbl[j][i]];
		id = 0; for (i = 0; i < 8; i++) id = (id << 3) | t[i];
		hash[id] = 1;
	}
	return 1;
}

void rec(int k)
{
	int i, p;

	if (k == 8) {
		if (check()) ans++;
		return;
	}
	p = -1;
	for (i = 0; i < 8; i++) {
		if (used[i] || id[i] == p) continue;
		color[k] = p = id[i];
		used[i] = 1, rec(k+1), used[i] = 0;
	}
}

int cmp(char *a, char *b) { return *a - *b; }

int main()
{
	int i, j, p;

    while (1) {
		memset(hash, 0, sizeof(hash));
		n = 0;
		for (i = 0; i < 8; i++) {
			if (scanf("%s", name[i]) != 1) return 0;
			for (j = 0; ; j++) {
				if (j == i) { id[i] = n++; break; }
				if (!strcmp(name[j], name[i])) { id[i] = id[j]; break; }
			}
		}
		if (n == 1) { puts("1"); continue; }
		if (n == 8) { puts("1680"); continue; }
		qsort(id, 8, sizeof(int), cmp);

		ans = 0; p = -1;
//		memset(used, 0, sizeof(used));
		used[0] = 1;
		color[0] = id[0];
		rec(1);
		used[0] = 0;
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 67200
#include<bits/stdc++.h>
#define ll long long
#define N 100010
#define M 100010
using namespace std;
struct EDGE{
	ll u, v;
	ll Next;
}G[M << 1];
ll Head[N];
ll tot = 0;
inline void Add(ll u, ll v)
{
	++ tot;
	G[tot].u = u;
	G[tot].v = v;
	G[tot].Next = Head[u];
	Head[u] = tot;
}
struct Node{
	ll a, b, num;
}E[N];
inline bool cmp(Node x, Node y)
{
	return x.a - x.b < y.a - y.b;
}
ll f[N];
ll b[N];
ll w[N];
inline ll Get(ll u)
{
	return f[u] == u ? u : f[u] = Get(f[u]);
}
bool vis[N];
ll d[N], top;
int main()
{
	ll n, m;
	scanf("%lld%lld", &n, &m);
	for(ll i = 1; i <= n; ++ i)
		scanf("%lld%lld", &E[i].a, &E[i].b);
	for(ll i = 1; i <= m; ++ i)
	{
		ll u, v;
		scanf("%lld%lld", &u, &v);
		Add(u, v);
		Add(v, u);
	}
	for(ll i = 1; i <= n; ++ i)
	{
		E[i].num = i;
		b[i] = E[i].b;
		f[i] = i;
	}
	sort(E + 1, E + n + 1, cmp);
	for(ll i = 1; i <= n; ++ i)
	{
		vis[E[i].num] = true;
		ll sumb = 0;
		top = 0;
		for(ll j = Head[E[i].num]; j; j = G[j].Next)
		{
			ll v = G[j].v;
			if(! vis[v])
				continue;
			ll fv = Get(v);
			if(fv != E[i].num)
			{
				sumb += b[fv];
				d[++ top] = fv;
				f[fv] = E[i].num;
			}
		}
		b[E[i].num] = sumb + E[i].b;
		w[E[i].num] = 1000000000000000;
		for(ll j = 1; j <= top; ++ j)
			w[E[i].num] = min(w[E[i].num], sumb - b[d[j]] + max(w[d[j]] + E[i].b, E[i].a));
		w[E[i].num] = min(w[E[i].num], sumb + max(E[i].a, E[i].b));
	}
	printf("%lld", w[E[n].num]);
	return 0;
}

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

using namespace std;

int H, W;
char MapData[3000][3000];
int DpCountO[3001][3001];
int DpCountI[3001][3001];

void solve() {
	unsigned long long int total;
	
	memset(DpCountO, 0, sizeof(DpCountO));
	for (int i = 0; i < H; ++i) {
		for (int j = W - 1; j >= 0; --j) {
			DpCountO[i][j] += DpCountO[i][j + 1];
			if (MapData[i][j] == 'O') {
				++DpCountO[i][j];
			}
		}
	}

	memset(DpCountI, 0, sizeof(DpCountI));
	for (int j = 0; j < W; ++j) {
		for (int i = H - 1; i >= 0; --i) {
			DpCountI[i][j] += DpCountI[i + 1][j];
			if (MapData[i][j] == 'I') {
				++DpCountI[i][j];
			}
		}
	}

	total = 0;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (MapData[i][j] == 'J') {
				total += DpCountO[i][j + 1] * DpCountI[i + 1][j];
			}
		}
	}
	cout << total << endl;
}

int main() {

	cin >> H >> W;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			cin >> MapData[i][j];
		}
	}
	solve();

	return 0;
}


Measured memory_bytes: 82280
#include<bits/stdc++.h>
using namespace std;
 string S[200001];
int main()
{
    map <string,int> mp;

    int i, cnt = 0, n;
    cin >> n;
    for(i = 0; i < n; i++)
    {
        cin >> S[i];
        mp[S[i]]++;
    }
    for(i = 0; i < n; i++)
    {
        if(mp[S[i]] != 0)
        {
            cnt++;
            mp[S[i]] = 0;
        }
    }
    cout << cnt << endl;

}


Measured memory_bytes: 25400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll h,w,d;
  cin >> h >> w >> d;
  vector<pll> n(h*w+10);
  for(ll y=1;y<=h;y++) {
    for(ll x=1;x<=w;x++) {
      ll tmp;
      cin >> tmp;
      n[tmp]=pll(y,x);
    }
  }
  vec p(h*w+10);
  for(ll i=1;i<=h*w-d;i++) {
    p[i+d]=p[i]+abs(n[i+d].first-n[i].first)+abs(n[i+d].second-n[i].second);
  }
  ll q;
  cin >> q;
  while(q--) {
    ll l,r;
    cin >> l >> r;
    ll ans=p[r]-p[l];
    cout << ans << endl;
  }
}

Measured memory_bytes: 3200
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int n, a, b, c, d; pair<int, string> p[10];
int main() {
	while(scanf("%d", &n), n) {
		for(int i = 0; i < n; i++) {
			cin >> p[i].second >> a >> b >> c;
			p[i].first = i - a * 30 - c * 10;
		}
		sort(p, p + n);
		if(d++) printf("\n");
		for(int i = 0; i < n; i++) {
			cout << p[i].second << ',' << (-p[i].first + 9) / 10 << endl;
		}
	}
	return 0;
}

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

using ll = long long;

int main() {
    int n, k; cin >> n >> k;
    map<int, int> memo;

    ll s = 0;
    ll ans = 0;
    vector<ll> ls;
    for (int i = 0; i < n; ++i) {
        int a; cin >> a;
        --a;
        s += a;
        ls.push_back(s);
        if (s%k == 0 && i < k-1) ans += 1;
        if (i >= k) {
            --memo[ls[i-k]%k];
        }
        ans += memo[s%k];
        ++memo[s%k];
        // cerr << a << " " << s << " " << s%k << " " << memo[s%k] << endl;
    }
    cout << ans << endl;
}


Measured memory_bytes: 11248
using System;
using System.Linq;
using System.Security.Cryptography.X509Certificates;

namespace _0815
{
    class Program
    {
        static long[] a;
        static long n, k;
        static void Main(string[] args)
        {
            var nk = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            n = nk[0];
            k = nk[1];
            a = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            long result = Solution();
            Console.WriteLine(result);
        }

        static long Solution()
        {
            long lb = 0, ub = a.Max();
            while (ub - lb > 1)
            {
                long mid = (lb + ub) / 2;
                if (p(mid))
                {
                    ub = mid;
                }
                else
                {
                    lb = mid;
                }
            }
            return ub;
        }
        static bool p(long x)
        {
            long res = 0;
            foreach(long num in a)
            {
                res += ((num + x - 1) / x) - 1;
            }
            return res <= k;
        }
    }
}


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

int suit_str_to_int (char s[1]) {
  int suit;
  if (s[0]=='S') {
    suit = 0;
  } else if (s[0]=='H') {
    suit = 1;
  } else if (s[0]=='C') {
    suit = 2;
  } else if (s[0]=='D') {
    suit = 3;
  } else {
  cout << "You got an unexpected character.";
  }
  return suit;
}

char suit_int_to_str (int i) {
  char s[1];
  if (i == 0) {
    s[0] = { 'S' };
  } else if (i == 1) {
    s[0] = { 'H' };
  } else if (i == 2) {
    s[0] = { 'C' };
  } else if (i == 3) {
    s[0] = { 'D' };
  } else {
    cout << "You got an unexpected number";
  }
  return s[0];
}

int main () {
  int input_cards[5][14]={ 0 } ,l,n,suit;
  char str[0];

  cin >> l;
  for  (int i=0; i<l; ++i) {
    cin >> str[0] >> n;
    suit = suit_str_to_int (str);
	input_cards[suit][n] = 1;
  }
	for (int j=0; j<4; ++j) {
	   for (int k=1; k<14; ++k) {
	     if (input_cards[j][k]==1) {
		   continue;
		 } else {
		   cout << suit_int_to_str(j) << " " << k << endl;
		 }
  	   }
    }
  return 0;
}

Measured memory_bytes: 3108
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner s = new Scanner(System.in)) {
			int a = s.nextInt();
			int b = s.nextInt();

			if (a <= 5) {
				System.out.println(0);
			} else if (a <= 12) {
				System.out.println(b / 2);
			} else {
				System.out.println(b);
			}
		}
	}
}


Measured memory_bytes: 22228
/*Made by Shivam Solanki*/
#include<bits/stdc++.h>
#pragma GCC optimize ("Ofast")
using namespace std;
#define DEBUG(x) cerr << '>' << #x << ':' << x << endl;
#define ll long long int
#define endl '\n'
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<pii> vp;
typedef vector<pll> vpll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef set<int> sii;
typedef set<ll> sll;
typedef queue<int> qii;
typedef priority_queue<int> pq;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;
#define all(x) x.begin(),x.end()
#define rep(i,k,n) for (int i = k; i < n; ++i) 
#define repr(i,k,n) for (int i = n; i>=k; --i)
#define repll(i,k,n) for (ll i = k; i < n; ++i) 
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int INF = 1e9+5;
const int MOD = 1e9+7;
const ll inf = 2e18+11;
double pi = 2 * acos(0.0); 
 
void solve(){
    char c;
    cin>>c;
    cout<<(c-'A'<=26?"A":"a");
}
 
int main(){ 
    // #ifndef ONLINE_JUDGE  
        // freopen("input.txt", "r", stdin); 
        // freopen("output.txt", "w", stdout); 
    // #endif 
    fastio;
    int t=1;
    // cin>>t;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 3520
/**************************************
*Coded By: BadduCoder (Sumit Badsara) *
***************************************/
#include<bits/stdc++.h>
using namespace std;

//All the Loops and defines required
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define ff first
#define ss second
#define _cin ios_base::sync_with_stdio(0);  cin.tie(0); cout.tie(0);
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

//All the declarations using typedef

typedef long long int ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef map<int,int> MII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int l;

int main()
{
    _cin;
    ll n,k;
    cin>>n>>k;
    ll h[n],ans[n];
    REP(i,n)
        cin>>h[i];
    
    ans[0] = 0;

    FOR(i,1,n,1)
    {
        ans[i] = INF;
        FOR(j,1,k+1,1)
        {
            if(j<=i)
                ans[i] = min(ans[i], ans[i-j]+abs(h[i]-h[i-j]));
        }
    }

    cout<<ans[n-1];

    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int main(void){
    int height,width;
    char **cell,**expand;

    scanf("%d %d",&height,&width);
    cell=(char **)malloc(sizeof(char *)*height);
    int i;

    for(i=0;i<height;i++){
        cell[i]=(char *)malloc(sizeof(char)*(width+1));
    }

    expand=(char **)malloc(sizeof(char *)*2*height);
    for(i=0;i<2*height;i++){
        expand[i]=(char *)malloc(sizeof(char)*(1+width));
    }

    int j;
    for(i=0;i<height;i++){
        for(j=0;j<width+1;j++){
            scanf("%c",&cell[i][j]);
        }
    }
    /*for(i=0;i<height;i++){
        for(j=0;j<width;j++){
            printf("%c",cell[i][j]);
        }
        printf("\n");
    }*/
    for(i=0;i<height;i++){
        for(j=0;j<width+1;j++){
            expand[2*i][j]=cell[i][j];
            expand[2*i+1][j]=cell[i][j];
        }
    }    
    for(i=0;i<2*height;i++){
        for(j=0;j<width+1;j++){
            printf("%c",expand[i][j]);
        }
        printf("\n");
    }
    return 0;

}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int a[3];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a[0]>>a[1]>>a[2];
    sort(a,a+3);
    cout << a[2]*10+a[1]+a[0]<< "\n";
}

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

using namespace std;
vector<long long> factors;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define _ <<'\n'
#define __ << ' '
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
int IT_MAX = 1 << 17;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
#define szz(x) (int)(x).size()
#define IOS ios_base::sync_with_stdio(false); cout.tie(0);cin.tie(0);


int main()
{
	IOS

	vector<int> n(4);
	for(int i = 0;i < 4;++i){
		cin >> n[i];
	}
	sort(all(n));
	if(n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9)
		cout << "YES";
	else
		cout << "NO";

	return 0;
}

Measured memory_bytes: 256
import collections
import functools
import operator



n=int(input())
s=input()
c=collections.Counter(s)
if len(c)<=2:
    print(0)
    exit()
# l=r*g*b
l = functools.reduce(operator.mul, c.values())
for i in range(0,n-1):
    for j in range(i+1,n):
        k=j-i+j
        if k>=n:
            continue
        if s[i]!=s[j] and s[k]!=s[j] and s[i]!=s[k]:
            l-=1
print(l)


Measured memory_bytes: 68848
#include<cstdio>
#include<queue>
#include<utility>
#include<algorithm>

using namespace std;

typedef pair<long long,int> P;

long long G[100][100];
priority_queue<P,vector<P>,greater<P> > que;

long long dis[100];

const long long inf=1ll<<55;

int main()
{
	while(true)
	{
		int N,K;
		scanf("%d%d",&N,&K);
		if(N==0&&K==0) break;
		for(int i=0;i<N;i++) for(int j=0;j<N;j++) G[i][j]=inf;
		for(int i=0;i<N;i++) G[i][i]=0;
		for(int q=0;q<K;q++)
		{
			int type;
			scanf("%d",&type);
			if(type==0)
			{
				int a,b;
				scanf("%d%d",&a,&b);
				a--;b--;
				que.push(P(0,a));
				for(int i=0;i<N;i++) dis[i]=inf;
				dis[a]=0;
				while(!que.empty())
				{
					P p=que.top();
					que.pop();
					if(dis[p.second]<p.first) continue;
					for(int i=0;i<N;i++)
					{
						if(G[p.second][i]==inf) continue;
						if(i==p.second) continue;
						if(dis[i]>dis[p.second]+G[i][p.second])
						{
							que.push(P(dis[p.second]+G[i][p.second],i));
							dis[i]=dis[p.second]+G[i][p.second];
						}
					}
				}
				if(dis[b]==inf) printf("-1\n");
				else printf("%lld\n",dis[b]);
			}
			else
			{
				int u,v;
				long long c;
				scanf("%d%d%lld",&u,&v,&c);
				u--;v--;
				G[u][v]=min(G[u][v],c);
				G[v][u]=min(G[v][u],c);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1132
N, K = map(int, input().split(" "))
logs = list(map(int, input().split(" ")))

def cal( max_length ):
    cut_count = 0 
    for l in logs :
        cut_count += (l//max_length -1)
        if l % max_length != 0 :
            cut_count += 1
    return cut_count <= K 

i = 1 
j = max(logs)
while i < j :
    m = (i+j)//2
    if cal(m) :
        j = m
    else :
        i = m+1

print(i)


Measured memory_bytes: 30720
#include<bits/stdc++.h>
#define forn(i, n) for(int i=0;i<(int)(n);i++)
#define for1(i, n) for(int i=1;i<=(int)(n);i++)
#define fore(i, l, r) for(int i=(int)(l);i<=(int)(r);i++)
#define ford(i, n) for(int i=(int)(n)-1;i>=0;i--)
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl "\n"
#define MAX 1000000007
using namespace std;
typedef int64_t ll;
typedef vector<int> vi;
typedef vector<int64_t> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
ll gcd(ll, ll);
int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.precision(10);
	cout << fixed;
	ll a,b;
	cin >> a >> b;
	ll g = gcd(a,b);
	cout << (a/g)*b;
	return 0;
}
ll gcd(ll a, ll b){
	if(b==0)
		return a;
	else
		return gcd(b,a%b);
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<cmath>
#include<queue>	
#include<functional>
#include<climits>
#include<tuple>
#include<utility>
#include<cassert>
using namespace std;

//define
#define ALL(a) a.begin(),a.end()
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) if(1)cout<<#x<<":"<<x<<endl;
#define DEBUG(x) if(1)cout<<#x<<":"<<x<<endl;
#define ll long long
#define PB push_back
#define LB lower_bound
#define UB upper_bound


//constant
const int MOD = 1000000007;
const int INF = INT_MAX / 3 - 1;
const double EPS = 1e-9;
const int dx4[4] = { 1,0,-1,0 };
const int dy4[4] = { 0,1,0,-1 };
const int dx8[8] = { -1,0,1,-1,1,-1,0,1 };
const int dy8[8] = { -1,-1,-1,0,0,1,1,1 };

//typedef
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

int main() {
	string s;
	cin >> s;
	long long int sum = 0;
	for (int i = 0; i < (1 << ((int)(s.size())-1)); i++) {
		long long int x = stoi(s.substr(0,1));
		for (int j = 0; j < s.size() - 1; j++) {
			if ((i >> j) & 1) {
				x *= 10;
				x += stoi(s.substr(j + 1, 1));
			}
			else {
				sum+= x;
				x = stoi(s.substr(j + 1, 1));
			}

			
		}

		sum += x;
	}

	cout << sum << endl;
	return 0;
}

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

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

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

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

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

bool check(LL x, LL a, LL b) {
    int res = 0;
    while(x != 0) {
        res += x % 10;
        x /= 10;
    }

    return a <= res && res <= b;
}

void solve(long long N, long long A, long long B){
    int ans = 0;
    REP1(i, N+1) {
        if(check(i, A, B)) {
            ans += i;
        }
    }

    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(N, A, B);
    return 0;
}



Measured memory_bytes: 256
import java.io.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(br.readLine());
		while(n!=0){
			double[] s=new double[n];
			String[] a=br.readLine().split(" ");
			double sum=0;
			for(int i=0;i<n;i++){
				s[i]=Double.parseDouble(a[i]);
				sum+=s[i];
			}
			double m=sum/n;
			double v=0;
			for(int i=0;i<n;i++){
				v+=Math.pow(s[i]-m, 2);
			}
	        System.out.printf("%.8f%n", Math.sqrt(v/n));
	        n=Integer.parseInt(br.readLine());
		}
	}
}

Measured memory_bytes: 19472
from collections import defaultdict

n,u,v,m = map(int, raw_input().split())
U=defaultdict(tuple)
N=defaultdict(tuple)
for i in range(n):
    l=map(int, raw_input().split())
    for j in range(n):
        U[ l[j] ] = (i,j)
for i in range(n):
    l=map(int, raw_input().split())
    for j in range(n):
        N[ l[j] ] = (i,j)
Uw = [[0 for i in range(n)],[0 for i in range(n)],[0,0],0]
Nw = [[0 for i in range(n)],[0 for i in range(n)],[0,0],0]
if n==1:
    Uw[3]-=3
    Nw[3]-=3
for x in range(m):
    q=int(raw_input())
    for A in  [[U,Uw],[N,Nw]]:
        if A[0][q]!=():
            qi,qj = A[0][q]
            A[1][0][qi] += 1
            A[1][1][qj] += 1
            A[1][3] += A[1][0][qi]==n
            A[1][3] += A[1][1][qj]==n
            if qi==qj:
                A[1][2][0]+=1
                A[1][3] += A[1][2][0] ==n
            if qi==n-qj-1:
                A[1][2][1]+=1
                A[1][3] += A[1][2][1] ==n
    if Uw[3]>=u and Nw[3]<v:
        ans="USAGI"
        break
    if Nw[3]>=v and Uw[3]<u:
        ans="NEKO"
        break
    if Nw[3]>=v and Uw[3]>=u:
        ans="DRAW"
        break
else:
    ans="DRAW"
print ans
#print Uw,U
#print Nw,N



Measured memory_bytes: 48372
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;
//vector<vector<int>> vec(縦,vector<int>(横));

int main(){
  int A,B,M;
  cin>>A>>B>>M;
  vector<int> a(A),b(B);
  vector<vector<int>> m(M,vector<int>(3));
  for(int i=0;i<A;i++) cin>>a[i];
  for(int i=0;i<B;i++) cin>>b[i];
  for(int i=0;i<M;i++) {
    for(int j=0;j<3;j++) cin>>m[i][j];
  }
  
  int minA= *min_element(a.begin(),a.end());
  int minB= *min_element(b.begin(),b.end());
  int ans= minA+minB;
  for(int i=0;i<M;i++) ans=min(ans,a.at(m[i][0]-1)+b.at(m[i][1]-1)-m[i][2]);
  cout<<ans<<endl;
}

    
  


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin >> s;
    int n;
    cin >> n;
    for(int i=0;i<n;i++) {
        string p;
        cin >> p;
        if(p=="print"){
            int m,l;
            cin >> m >> l;
            cout << s.substr(m,l-m+1) << endl;
        }
        else if(p=="reverse") {
            int m,l;
            cin >> m >> l;
            string q = s;
            for(int i=m;i<=l;i++) {
                q[i] = s[l-i+m];
            }
            s = q;
        }
        else {
            int m,l;
            string q;
            cin >> m >> l >> q;
            for(int i=m;i <= l;i++) {
                s[i] = q[i-m];
            }
        }
    }
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
 
int main(void) 
{
 
    long long N;
    cin >> N;

    vector<long long> a(N);

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

    if (N%2==0)
    {
        for(int i=N/2;i>0;--i)
        {
            cout << a[i*2-1] << " ";
        }
        for(int i=0;i<N/2;++i)
        {
            cout << a[i*2] << " ";
        }
        cout << endl;
    }
    else
    {
        for(int i=N/2;i>=0;--i)
        {
            cout << a[i*2] << " ";
        }
        for(int i=0;i<N/2;++i)
        {
            cout << a[i*2+1] << " ";
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3712
from collections import deque
N,M = list(map(int, input().split()))

# node 3bai
# 0 N-1, N 2N-1, 2N 3N-1.
G = {}
for i in range(3*N):
  G[i] = []

for i in range(M):
  u,v = list(map(int, input().split()))
  u,v = u-1, v-1 # 0-indexed
  G[u].append(v+N)
  G[u+N].append(v+2*N)
  G[u+2*N].append(v)
  
S,T = list(map(int, input().split()))
S,T = S-1, T-1 # 0-indexed

q = deque()
visited = [False for i in range(3*N)]
willsearch = [False for i in range(3*N)]
dists = [-1 for i in range(3*N)]
q.append(S)
dists[S] = 0

while len(q) > 0:
  now = q.popleft()
  visited[now] = True
  for nextp in G[now]:
    if visited[nextp] or willsearch[nextp]:
      continue
    willsearch[nextp] = True
    q.append(nextp)
    dists[nextp] = dists[now] + 1
    
if dists[T] > 0:
  print(dists[T] // 3)
else:
  print(-1)

Measured memory_bytes: 117344
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long N, vector<long long> a){
	ll now = 1, c = 0;
	rep(i, N) {
		if (a[i] == now) {
			now++;
		} else {
			c++;
		}
	}
	if (now != 1) cout << c << endl; else cout << "-1" << endl;
}

int main(){	
	long long N;
	scanf("%lld",&N);
	vector<long long> a(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&a[i]);
	}
	solve(N, a);
	return 0;
}



Measured memory_bytes: 3456
#include <stdio.h>
#include<math.h>

int gcd(int x, int y){
    if(x < y){
        int temp = x;
        x = y;
        y = temp;
    }

    while(y > 0){
        int r = x % y;
        x = y;
        y = r;
    }
    return x;
}


int main(){
    int x, y;
    scanf("%d%d", &x, &y);
    int ans = gcd(x, y);
    printf("%d\n", ans);

    return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);


using ll = long long;
using pint = pair<int, int>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

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; }
template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    };
}fastio;

class UnionFind {
public:
	vector<ll> parent;

	UnionFind(int n) {
		parent = vector<ll>(n, -1);
	}

	int root(int a) {
		if (parent[a] < 0) return a;
		return parent[a] = root(parent[a]);
	}

	int size(int a) {
		return -parent[root(a)];
	}

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

	bool unite(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b) {
			return false;
		}

		if (size(a) < size(b)) swap(a, b);

		parent[a] += parent[b];
		parent[b] = a;

		return true;
	}
};

int main(){

    int n, m;
    cin >> n >> m;

    UnionFind uf(3*n);
    vector<int> p(n), pos(n+1);
    int cnt = 0;
    rep(i, n) {
        cin >> p[i];
        pos[p[i]] = i+1;
        uf.unite(p[i], n+pos[p[i]]);
    }

    rep(i, m){
        int x, y;
        cin >> x >> y;
        uf.unite(x, y);
        uf.unite(x, n+pos[x]);
        uf.unite(y, n+pos[y]);
    }
    rep(i, n){
        if(uf.same(p[i], n+p[i]))  ++cnt;
    }

    ppp(cnt);

    return 0;
}


Measured memory_bytes: 3456
use std::io::*;
use std::str::FromStr;
use std::cmp::{min, max};

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

fn main() {
    let N:usize = read();
    let K:usize = read();
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s = s.trim_right().to_owned();
    let b :Vec<i32> = s.into_bytes().iter().map(|&x| x as i32 - '0' as i32).collect();
    let mut c:Vec<i32> = Vec::new();
    let mut temp = 1;
    for i in 0..N-1 {
        let i = i as usize;
        if b[i]!=b[i+1]{
            c.push(temp);
            temp = 0;
        }
        temp = temp+1;
    }
    c.push(temp);
//    println!("{:?}",c);

    let clen = c.len();
    let mut sumvec:Vec<i32> = vec![0];
    for i in 0..clen{
        let temp = sumvec[i];
        sumvec.push(temp+c[i]);
    }

    sumvec.push(N as i32);
    sumvec.push(N as i32);
    sumvec.push(N as i32);
    sumvec.push(N as i32);

//    println!("{:?}",sumvec);

    let flag:bool = b[0]==1;

    //0スタート : 2K個

    let mut ans = 0;

    if !flag {
        let left:usize = 0;
        let right:usize = min(left+2*K,clen);
        ans = sumvec[right]-sumvec[left];
    }

    //1スタート : 2K+1個
    let mut left = if flag{0}else{1};
    let mut right = min(left+2*K+1,clen);
    left = min(clen,left);
    while right <= clen+1 {
//        println!("[1]left:{}, right:{}, sum:{}",left,right,ans);
        ans = max(sumvec[right]-sumvec[left],ans);
        left = left+2;
        right = right+2;
    }
//    println!("[1]left:{}, right:{}, sum:{}",left,right,ans);

    println!("{}",ans);

}


Measured memory_bytes: 4352
// FindingAWord.c
// １つの単語 W と文章 T が与えられます。
// T の中にある W の数を出力するプログラムを作成して下さい。
//
// 文章 T に含まれるスペースまたは改行で区切られた文字列を単語 Ti とします。
// すべての Ti において単語 W と同じになるものを数えて下さい。
//
// なお、大文字と小文字は区別しません。
// 【制約】
// Wの文字列の長さは10を超えない
// Wに含まれる文字はすべてアルファベット小文字である
// Tの１行あたりの文字列の長さは1000を超えない
// 【入力】
// １行目に単語 W が与えられます。
// 続いて、複数の行にまたがった文章与えられます。END_OF_TEXT という文字列が文章の終わりを示します。
// 【出力】
// 単語 W の数を出力して下さい。
// 【例】
// 入力：
// computer
// Nurtures computer scientists and highly-skilled computer engineers
// who will create and exploit "knowledge" for the new era.
// Provides an outstanding computer environment.
// END_OF_TEXT
// 出力：
// 3
#include<stdio.h>
#include<ctype.h>
#include<string.h>

int main( void) {
  int counter = 0;
  char word[10+1], sentence[1000+1];
  int word_size;

  scanf( "%s", word);
  // 大文字と小文字は区別しないので、小文字に変換する。
  for ( int i = 0; i < strlen( word); i++) {
    word[i] = tolower( word[i]);
  }

  while ( 1) {
    scanf( "%s", sentence);
    if ( strcmp( sentence, "END_OF_TEXT") == 0) break;
    for ( int i = 0; i < strlen( sentence); i++) {
      sentence[i] = tolower( sentence[i]);
    }
    if ( strcmp( sentence, word) == 0) counter++;
  }

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

  return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll ans = 0;
    ll k, s; cin >> k >> s;
    for(ll i=0; i<=k; i++){
        for(ll j=0; j<=k; j++){
            ll m = s-i-j;
            if(m >= 0 && m <= k) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
"""
AtCoder Beginner Contest 064
B - Traveling AtCoDeer Problem
@author haru
"""

arg1 = input()
arg2 = input()
if not arg2.replace(" ","").isdigit(): exit("Error: Invalid Input")
DIMENTION = int(arg1) if arg1.isdigit() else exit("Error: Invalid Input")
POSITIONS = [int(a) for a in arg2.split(" ")]
if not DIMENTION == len(POSITIONS): exit("Error: Invalid Input")
print(max(POSITIONS) - min(POSITIONS))

Measured memory_bytes: 3060
import sys
from collections import deque


def input():
    return sys.stdin.readline().strip()


S = input()
Q = int(input())
q = deque(S)
flipped = False
for _ in range(Q):
    q_t, *q_d = input().split()
    if q_t == "1":
        flipped = not flipped
    else:
        F, C = q_d
        if (not flipped and F == "2") or (flipped and F == "1"):
            q.append(C)
        else:
            q.appendleft(C)

ans = list(q)
if flipped:
    print("".join(ans[::-1]))
else:
    print("".join(ans))


Measured memory_bytes: 16436
from collections import Counter
def facrorize(n):
    c = Counter()
    t = 2
    while t**2 <= n:
        if n%t:
            t += 1
            continue
        while not n%t:
            c[t] += 1
            n //= t
    if n > 1:
        c[n] += 1
    return c

def comb(n, r):
    r = min(r, n-r)
    if n < 0 or r < 0:return 0
    ret = 1
    for i in range(r):
        ret = ret*(n-i)//(i+1)
    return ret

n = int(input())
d = Counter()
for i in range(1, n+1):
    c = facrorize(i)
    for key, value in c.items():
        d[key] += value

e = {2:[],4:[],14:[],24:[],74:[]}
for key, value in d.items():
    for cnt in e:
        if value >= cnt:
            e[cnt].append(key)

ans = 0
# 3, 5, 5 → 2, 4, 4
for two in e[2]:
    if two not in e[4]:
        ans += comb(len(e[4]), 2)
    else:
        ans += comb(len(e[4])-1, 2)
    # 3, 25 → 2, 24
    if two not in e[24]:
        ans += len(e[24])
    else:
        ans += comb(len(e[24])-1,1)

# 5, 15 → 4, 14
for four in e[4]:
    if four not in e[14]:
        ans += len(e[14])
    else:
        ans += comb(len(e[14]) - 1, 1)
# 75 → 74
ans += len(e[74])
print(ans)

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vl vector<long>
#define P pair<int,int>
using namespace std;

main()
{
        int a,b; cin>>a>>b;
        if(a<=0&&b>=0)
        {
                cout<<"Zero"<<endl;
                return 0;
        }
        if(a>0)
        {
                cout<<"Positive"<<endl;
                return 0;
        }

        if((b-a)%2==0)
        {
                cout<<"Negative"<<endl;
                return 0;
        }
        cout<<"Positive"<<endl;
        return 0;
}


Measured memory_bytes: 256
def make_divisors(n):
    lsls=[]
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            lsls.append(i)
            if i!=n//i:
                lsls.append(n//i)
    lsls.sort()
    return lsls

N=int(input())

ans=1
for K in range(2,min(N,int(N**0.5)+2)):
    num=N
    while num%K==0:
        num//=K
    if num>=K:
        num%=K
    if num==1:
        ans+=1

lst=make_divisors(N-1)

for u in lst:
    if u>=int(N**0.5)+2:
        ans+=1
        
print(ans)

Measured memory_bytes: 40300
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ll a[222];
map<pair<vector<ll>,int> ,ll> ma;

void expand(vector<ll> v, ll moves=0, int sub=0)
{
	if(ma.find(mp(v,sub))==ma.end()) 
	{
		ma[mp(v,sub)]=moves;
	}
	else if(ma[mp(v,sub)]<=moves) return;
	else ma[mp(v,sub)]=moves;
	//for(ll x:v) cerr<<x<<' ';
	//cerr<<"SUB : "<<sub<<' ';
	//cerr<<" : "<<ma[mp(v,sub)]<<'\n';
	vector<ll> v2=v;
	for(int i=0;i<v.size();i++)
	{
		v2[i]--;
		if(v2[i]<0) v2[0]=-1;
	}
	for(int i=0;i<v.size();i++)
	{
		v[i]/=2;
	}
	expand(v,moves+1,0);
	if(!sub&&v2[0]>=0)
	{
		expand(v2,moves+1,1);
	}
}

map<vi,vector<ii> > M;

const int MOD=1e9+7;
ll add(ll a, ll b)
{
	a+=b;
	a%=MOD;
	if(a<0) a+=MOD;
	return a;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; ll k; cin>>n>>k;
	vector<ll> a(n);
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a.begin(),a.end());
	expand(a);
	for(auto X:ma)
	{
		vector<ll> V = X.fi.fi; ll d = X.se;
		//for(ll x:V) cerr<<x<<' ';
		//cerr<<"SUB : "<<X.fi.se<<' ';
		//cerr<<" : "<<d<<" | ";
		if(d>k) continue;
		//current state to k - d moves later		
		ll mn = ll(1e18);
		for(ll x:V) mn=min(mn,x);
		for(ll x=0;x<V.size();x++) V[x]-=mn;
		M[V].pb(mp(max(0LL,mn-(k-d)),mn));
		//cerr<<max(0LL,mn-(k-d))<<' '<<mn<<'\n';
	}
	ll ans = 0;
	for(auto X:M)
	{
		vector<ii> I = X.se;
		/*
		for(ll x:X.fi) cerr<<x<<' ';
		cerr<<" : ";
		for(ii x:I) cerr<<x.fi<<' '<<x.se<<" , ";
		cerr<<'\n';
		*/
		sort(I.begin(),I.end());
		ll l = -1; ll r = -2;
		for(ii x:I)
		{
			if(x.fi>r)
			{
				ans+=r-l+1;
				l=x.fi;r=x.se;
			}
			else
			{
				r=max(r,x.se);
			}
		}
		ans=add(ans,r-l+1);
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 47872
using System;

namespace ABC136B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var ans = 0;

            for (var i = 1; i <= N; i++)
            {
                if (((int)Math.Log10(i) + 1) % 2 != 0)
                    ans++;
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13140
def main():
    N = int(input())
    S = input()

    slist = list(S)
    result = slist

    for i in range(len(S)):
        if ord(slist[i]) + N > 90:         
            result[i] = chr(ord(slist[i]) + N - 26)
        else:
            result[i] = chr(ord(slist[i]) + N)

    print(''.join(result))

if __name__ == '__main__':
    main()

Measured memory_bytes: 39280
/*
	Samrat De
	NIT Durgapur
	A Noob Coder
*/

/*#include<iostream>
#include<functional>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>*/
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long int
#define vec(x) vector<x> 
#define st(x) set<x> 
#define mpp(x,y) map<x,y>
#define qq(x) queue<x>
#define pqq(x) priority_queue<x> 
#define min_heap(x) priority_queue<x, vector<x>, greater<x> >
#define pi(x,y) pair<x,y>
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define rel(i,x,y) for(ll i=x-1;i>=y;i--)
#define rev(x) reverse(x.begin(),x.end())
#define mem(x,a) memset(x,a,sizeof(x))
#define mod 1000000007
#define nxt_per(x) next_permutation(x.begin(),x.end())
#define pb push_back
#define pf push_front
#define vp(x,y) vec(pi(x,y) )
#define all(x) x.begin(),x.end()
#define indexof order_of_key
#define valueat find_by_order
#define myds tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> 

int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int dxx[8]={0,0,1,-1,-1,-1,1,1};
int dyy[8]={1,-1,0,0,-1,1,1,-1};

/*
unordered_map<ll,ll> um
um.reserve(1<<15);
um.max_load_factor(0.25);
*/

using namespace std;
//using namespace __gnu_pbds;

#define s second
#define f first

int32_t main()
{
	fastio;
// best of luck don't loose hope man	

    ll a,b;
    cin>>a>>b;
    ll ans1=0,ans2=0;
    if(a>0){
    	a-=1;
    	if(a%4==0)
    		ans1=a;
    	else if(a%4==1)
    		ans1=1;
    	else if(a%4==2)
    		ans1=a+1;
    	else
    		ans1=0;
    }
    if(b>0){
    	if(b%4==0)
    		ans2=b;
    	else if(b%4==1)
    		ans2=1;
    	else if(b%4==2)
    		ans2=b+1;
    	else
    		ans2=0;
    }
    ll ans=ans1^ans2;
    cout<<ans;
	return 0;
}

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

using namespace std;
#define INFS (1LL<<28)
#define INF (1LL<<60)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long
#define double long double


signed main(){
	string s;
	cin>>s;
	int k;
	cin>>k;
	bool ch=true;
	lp(i,s.size()){
		if(i==0)continue;
		if(s[i]!=s[i-1])ch=false;
	}
	if(ch){
		cout<<(s.size()*k)/2<<endl;
		return 0;
	}
	else{
		int ans=0;
		string af="";
		lp(i,s.size()){
			if(s[i]!=s[s.size()-1]){
				ans+=i/2;
				af=s.substr(0,i);
				s=s.substr(i,s.size()-i);
				break;
			}
		}
		int cnt=0;
		k--;
		lp(i,s.size()){
			if(i==0)continue;
			if(s[i]==s[i-1])cnt++;
			else{
				ans+=(cnt+1)/2;
				cnt=0;
			}
		}
		ans+=(cnt+1)/2;
		cnt=0;
		s=s+af;
		lp(i,s.size()){
			if(i==0)continue;
			if(s[i]==s[i-1])cnt++;
			else{
				ans+=(cnt+1)/2*k;
				cnt=0;
			}
		}
		ans+=(cnt+1)/2*k;
		cnt=0;
	cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 384
import sys
sys.setrecursionlimit(10**6)

N = int(input())
uvw = []
for _ in range(N-1):
    uvw.append(tuple(map(int, input().split())))


H=[[] for _ in range(N+1)]
for el in uvw:
    H[el[0]].append((el[1], el[2]))
    H[el[1]].append((el[0], el[2]))
#print(H)

seen=[False]*(N+1)

distance=[0]*(N+1)
def dfs(n):
    seen[n]=True
    for nxt in H[n]:
        if seen[nxt[0]] == False:
            distance[nxt[0]]=distance[n]+nxt[1]
            dfs(nxt[0])

dfs(1)
#print(distance)
#print(seen)

for val in distance[1:]:
    if val % 2 == 0:
        print(0)
    else:
        print(1)


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

int main()
{
    int N,M;
    cin >> N >> M;
    
    vector<vector<int>> G(N);
    for (int i=0; i<M; ++i)
    {
        int a, b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }

    vector<int> dist(N, -1);
    queue<int> que;

    dist[0] = 0;
    que.push(0);
    
    while (!que.empty())
    {
        int v = que.front();
        que.pop();

        for (int nv : G[v])
        {
            if (dist[nv]!=-1) continue;

            dist[nv] = v;
            que.push(nv);
        }
    }
    cout << "Yes" << endl;
    for (int v = 1; v < N; v++) cout << dist[v]+1 << endl;
    
}

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

int main(){
    int X,Y,A,B,C;
    cin >> A >> B >> C >> X >> Y;
    int ans = A*X+B*Y;
    for(int i=0;max(X,Y)*2>=i;i+=2){
        int x,y;
        x=max(0,X-i/2);
        y=max(0,Y-i/2);
        ans=min(ans,A*x+B*y+C*i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3580
n=gets.to_i
x=Array.new(n,0)
y=Array.new(n,0)
n.times do |i|
  x[i],y[i]=gets.split.map(&:to_f)
end

dist=0
sum=0
count=0
[*1..n].permutation.each do |p|
  dist=0
  (n-1).times do |i|
    dist+=((x[p[i+1]-1]-x[p[i]-1])**2+(y[p[i+1]-1]-y[p[i]-1])**2)**0.5
  end
  sum+=dist
  count+=1
end
ave=sum/count
puts sprintf("%.6f", ave)


Measured memory_bytes: 15000