akhauriyash/Code-Regression huggingface dataset:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

r = ni()
print(r*r)

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

using namespace std;

#define ll long long

ll digits(ll n)
{
	int d = 1;
	while (n >= 10) {
		n /= 10;
		d++;
	}
	return d;
}

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

	ll ans = digits(N);

	for (ll i = 1; i * i <= N; i++) {
		if (N % i == 0) {
			ans = min(ans, digits(N / i));
		}
	}

	cout << ans << endl;

	return 0;
}


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 54;
int n, k;
int a[N];

void solve() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) scanf("%d", a+i);
  int ans = 0;
  for (int i = 0; i <= min(n, k); ++i) {
    for (int j = n-1; j >= max(i-1, n-(k-i)-1); --j) {
      set<pair<int, int>> s;
      for (int l = 0; l < n; ++l) {
	if (l >= i && l <= j) continue;
	s.emplace(a[l], l);
      }
      int bakk = k-s.size();
      int cur = 0;
      for (const auto &e: s) {
	if (e.first < 0 && bakk > 0) {
	  --bakk;
	  continue;
	}
	cur += e.first;
      }
      ans = max(ans, cur);
    }
  }
  printf("%d", ans);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3784
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
int main() {
	int n;
	cin >>n;
	vector<int> vec={1,1,1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << vec.at(n-1) <<endl;
		}
		


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


int main() {
    int n, m;
    cin >> n >> m;
    vector<int> h(n);
    vector<int> gr(n);
    rep(i,n){
        cin >> h[i];
        gr[i] = 1;
    }

    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        if(h[a] >= h[b]){
            gr[b] = 0;
        }
        if(h[b] >= h[a]){
            gr[a] = 0;
        }
    }

    int ans = 0;
    rep(i,n){
        if(gr[i] == 1){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	if(x + r <= W && x - r >= 0 && y + r <= H && y - r >= 0)
		cout << "Yes" << "\n";
	else
		cout << "No" << "\n";

	return 0;
}

Measured memory_bytes: 1128
#include <iostream>
using namespace std;
int main () {
    int i, j, x, y;
    cin >> x >> y;
    while (x != 0 || y != 0) {
        for (i = 1; i <= x; i++) {
            for (j = 1; j <= y; j++)
                cout << "#";
            cout << "\n";
        }
        cout << "\n";
        cin >> x >> y;
    }
}


Measured memory_bytes: 3084
#include<iostream>
#include<map>
#include<cmath>
#include<vector>
#define MAX 30000
using namespace std;
vector<int> prime;
bool isntprime[30001];
typedef pair<int,int> P;
typedef pair<P,int> Pi;
 
bool isTriangle(int a,int b,int c)
{
  if(a >= b+c || b >= a+c || c >= a+b)
    return false;
  return true;
}
 
int main()
{
  
  isntprime[0] = isntprime[1] = true;
  int j;
  for(int i=2;i<= MAX;i++)if(!isntprime[i])for(prime.push_back(i),j=2*i;j<=MAX;j+=i)isntprime[j] = true;
  
  int T;
  while(cin >> T,T)
    {
      int cnt = 0;
      for(int i=0;i<prime.size() && prime[i] < T;i++)
    for(int j=i;j<prime.size() && prime[i]+prime[j] < T;j++)  
      if(T-(prime[i]+prime[j]) >= prime[j] && !isntprime[T-(prime[i]+prime[j])] && isTriangle(prime[i],prime[j],T-(prime[i]+prime[j])))
        cnt++;
         
      cout << cnt << endl;
    }
  return 0;
}

Measured memory_bytes: 1276
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int x = sc.nextInt();
        if(a <= x && x <= a+b){
                 System.out.println("YES");   
        } else{
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 21972
n = int(input())
a = [int(number) for number in input().split(' ')]
b = [int(number) for number in input().split(' ')]
c = [int(number) for number in input().split(' ')]

point = 0
last_dish = 0

for i in range(len(a)):
  dish = a[i]
  point += b[dish-1]
  if 0 < i and (dish - last_dish) == 1:
    point += c[last_dish-1]
  last_dish = dish

print(point)

Measured memory_bytes: 38384
# -*- coding: utf-8 -*-


def main():
    """Function."""
    n, m = map(int, input().split())

    pic_n, pic_m = [], []
    for _ in range(n):
        pic_n.append(list(input()))
    for _ in range(m):
        pic_m.append(list(input()))

    flag = 0
    for i in range(n - m + 1):
        for j in range(n - m + 1):
            dum = []
            for x in range(m):
                if pic_n[i+x][j:j+m] != pic_m[x]:
                    dum.append(0)
                else:
                    dum.append(1)

            if 0 in dum:
                continue
            else:
                flag = 1
        if flag == 1:
            break

    if flag == 1:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main()
{
int n;
cin>>n;
vector<int> p2;
for(int i=0; i<=6; i++)
{
    p2.push_back(pow(2,i));
}
for(int i=6; i>=0; i--)
{
 if(p2[i]<=n)
 {
     cout<<p2[i]<<endl;
     break;
 }
}
}

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

#define VARNAME(x) #x
#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename T>
ostream& operator<<(ostream& os, const multiset<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = (ll)1e9 + 7LL;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 10;


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

    int N, Q;
    cin >> N >> Q;
    vector<ll> a(2 * N);
    vector<ll> b(2 * N);
    vector<ll> sa(2 * N);
    ll sum = 0;
    for (int i = 0; i < 2 * N; i++) {
        cin >> a[i];
        sum += a[i];
    }
    for (int i = 0; i < 2 * N; i++) {
        cin >> b[i];
    }
    ll psum = 0;
    multiset<ll> pos;
    multiset<ll> neg;
    for (int i = 0; i < 2 * N; i++) {
        sa[i] = b[i] - a[i];
    }
    for (int i = 1; i < 2 * N - 1; i++) {
        if (sa[i] > 0) {
            psum += sa[i];
            pos.insert(sa[i]);
        } else {
            neg.insert(sa[i]);
        }
    }
    for (int q = 0; q < Q; q++) {
        int p;
        ll x, y;
        cin >> p >> x >> y;
        p--;
        const ll old = sa[p];
        sum += x - a[p];
        a[p] = x;
        b[p] = y;
        sa[p] = y - x;

        if (p > 0 and p < 2 * N - 1) {
            if (old > 0) {
                auto it = pos.find(old);
                pos.erase(it);
                psum -= old;
            } else {
                auto it = neg.find(old);
                neg.erase(it);
            }
            if (sa[p] > 0) {
                pos.insert(sa[p]);
                psum += sa[p];
            } else {
                neg.insert(sa[p]);
            }
        }

        const int pnum = pos.size();
        if (pnum % 2 == 0) {
            cout << sum + psum << endl;
        } else {
            const ll pback = *pos.cbegin();
            if (neg.size() == 0) {
                cout << sum + psum - pback << endl;
            } else {
                const ll ntop = *neg.crbegin();
                cout << max(sum + psum + ntop, sum + psum - pback) << endl;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 15744
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
using namespace std;
char str[312312];
int main()
{
    while(scanf("%s",str)!=EOF)
    {
        int len=strlen(str);
        if(str[0]!=str[len-1])
        {
            if(len%2==1) printf("First\n");
            else printf("Second\n");
        }
        else
        {
            int sum=0,ans=0;
            for(int i=1;i<len-1;i++)
            {
                if(str[i]!=str[0]) sum++;
                else ans++;
            }
            int k=sum-ans;
            if(k%2==1) printf("Second\n");
            else printf("First\n");
        }
    }
    return 0;
}


Measured memory_bytes: 384
// #include {{{
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <random>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>

#ifdef DEBUG
#include <fmt/format.h>
#endif
// }}}

using namespace std;

// macros {{{
template<typename T, size_t N>
constexpr size_t NELEMS(T (&)[N]) { return N; }

template<typename InputIt>
void PRINT_RANGE(InputIt first, InputIt last)
{
    for(; first != last; ++first)
        cout << *first << (first==last ? "" : " ");
    cout << "\n";
}

template<typename T>
void PRINT_MATRIX(T mat, size_t nr, size_t nc)
{
    for(size_t r = 0; r < nr; ++r) {
        for(size_t c = 0; c < nc; ++c) {
            cout << mat[r][c] << (c==nc-1 ? "" : " ");
        }
        cout << "\n";
    }
}

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)
// }}}

// types {{{
using s64 = int64_t;
using u64 = uint64_t;
// }}}

s64 N;
s64 L;
s64 T;
vector<s64> X;
vector<s64> W;

s64 getpos(s64 x, s64 w)
{
    if(w == 1)
        return (x + T) % L;
    else
        return (x + L - T%L) % L;
}

void solve()
{
    // アリ0がT秒間に他のアリとすれ違う回数を求める
    // 他方のアリを固定し、アリ0が 2*T 進むと考える
    s64 cross = 0;
    FOR(i, 1, N) {
        if(W[0] == W[i]) continue;

        s64 d;
        if(W[0] == 1 && W[i] == 2) {
            d = X[i] - X[0];
        }
        else {
            d = L - (X[i] - X[0]);
        }

        s64 q = 2*T / L;
        s64 r = 2*T % L;
        cross += q;
        if(d < r)
            ++cross;
    }

    // すれ違った回数だけアリ0のインデックスが増減
    s64 idx0 = W[0] == 1 ? cross%N : (N-cross%N)%N;
    s64 pos0 = getpos(X[0], W[0]);

    // T 秒後の座標リスト
    vector<s64> pos(N);
    REP(i, N) {
        pos[i] = getpos(X[i], W[i]);
    }
    sort(begin(pos), end(pos));
#ifdef DEBUG
    fmt::print("idx0: {}\n", idx0);
    fmt::print("pos0: {}\n", pos0);
    PRINT_RANGE(begin(pos), end(pos));
#endif

    // アリ0がどこに行ったか調べてry
    // 同座標に2匹いることがあるが、その場合は
    // W[0] == 1 なら前、W[0] == 2 なら後ろ
    auto p = equal_range(begin(pos), end(pos), pos0);
    auto it = p.first;
    if(distance(p.first, p.second) == 2 && W[0] == 2) {
        ++it;
    }
    int k = distance(begin(pos), it);
    k += N - idx0;
    k %= N;
    REP(_, N) {
        cout << pos[k] << "\n";
        ++k;
        k %= N;
    }
}

int main()
{
    cin >> N >> L >> T;
    X.resize(N);
    W.resize(N);

    REP(i, N) {
        cin >> X[i] >> W[i];
    }

    solve();

    return 0;
}


Measured memory_bytes: 3584
#include<iostream> 
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main(){	
	long long l,r;
	cin>>l>>r;
	for(long long i=l;i<=r;i++){
		if(i%2019==0){
			cout<<"0";
			return 0;
		}
	}
	long long ans=1e18;
	for(long long i=l;i<r;i++){
		for(int j=i+1;j<=r;j++){
			ans=min(ans,i*j%2019);
		}
	}
	cout<<ans;
    return 0;
} 

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws IOException{
		Scanner sc = new Scanner(System.in);

		int x = sc.nextInt();
		int y = sc.nextInt();

		int[][] v = new int[x][y];
		int[] a = new int[y];

		for(int i=0;i<x;i++) {
			for(int j=0;j<y;j++) {
				v[i][j] = sc.nextInt();
			}
		}

		for(int i=0;i<y;i++) {
			a[i] = sc.nextInt();
		}

		int tmp = 0;

		for(int i=0;i<x;i++) {
			for(int j=0;j<y;j++) {
				tmp += v[i][j] * a[j];
			}
			System.out.println(tmp);
			tmp = 0;
		}
		sc.close();
	}
}


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

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

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

    map<string,int> mp;

    mp["SUN"] = 7;
    mp["SAT"] = 1;
    mp["FRI"] = 2;
    mp["THU"] = 3;
    mp["WED"] = 4;
    mp["TUE"] = 5;
    mp["MON"] = 6;

    string s; cin >> s;

    cout << mp[s] << endl;

    return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>
 
#define N (26)
 
int main(void)
{
    int a[N] = { 0 };       // ??¢?????????????????????'a'-'z'??????26??????
    // char ch[1201];       // ???????????????????????§??????????????????
    int ch, i;
 
    //input
    while ((ch = getchar()) != EOF) {
        //??°???
        if (islower(ch)) {
            a[ch - 'a']++;
        }
        if (isupper(ch)) {
            a[ch - 'A']++;
        }
    }
 
    //output
    for (i = 0; i < N; i++) {
        printf("%c : %d\n", i + 'a', a[i]);  //0+'a' = 'a' ?????????0=a, 1=b, 2=c, ... ?????????
    }
    return 0;
}

Measured memory_bytes: 2708
#include <cmath>
#include <iostream>
#include <string>
#include <time.h>
#include <stdio.h>
#include <iomanip>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

void printArr(vector<int> A)
{
    for (int i = 0; i < A.size(); i++)
    {
        if (i != A.size() - 1)
            cout << A[i] << " ";
        else
            cout << A[i];
    }
    cout << endl;
}

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

    bool flag = true;
    int count = 0;
    while (flag)
    {
        flag = false;
        for (int i = n - 1; i > 0; i--)
        {
            if (a[i] < a[i - 1])
            {
                int v = a[i];
                a[i] = a[i - 1];
                a[i - 1] = v;
                flag = true;
                count++;
            }
        }
    }
    printArr(a);
    cout << count << endl;

    return 0;
}



Measured memory_bytes: 3112
import sys
from itertools import product
from bisect import bisect_right as bi_r

cand = [int(''.join(p)) for i in range(3, 10) 
        for p in product('357', repeat=i) 
        if len(set(p)) == 3]

n = int(sys.stdin.readline().rstrip())

def main():
    print(bi_r(cand, n))

if __name__ ==  '__main__':
    main()

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

int main(void){
  int n;
  cin>>n;
  long int a[n];
  for (int i = 0; i < n; i++)
  {
    cin>>a[i];
  }
  long long int sum_1=0,sum_2=0;
  for (int i = 0; i < n; i++)
  {
    sum_1+=a[i];
  }
  sum_1%=1000000007;
  for (int i = 0; i < n; i++)
  {
    sum_1-=a[i];
    if(sum_1<0)sum_1+=1000000007;
    sum_2=(sum_2+a[i]*sum_1)%1000000007;
  }
  cout<<sum_2<<endl;
  return 0;
}

Measured memory_bytes: 4720
def modpow(a, n, mod)
  exp = Math.log(n, 2).floor
  rep = modpow_cl(a, n, exp, mod)
  return rep[0]
end

def modpow_cl(a, n, exp, mod)
  if exp < 0
    rep = [1, a]
  else
    if n >= 2**exp
      rep = modpow_cl(a, n-2**exp, exp-1, mod)
      rep[0] = rep[0]*rep[1] % mod
    else
      rep = modpow_cl(a, n, exp-1, mod)
    end
    rep[1] = rep[1]**2 % mod
  end
  return rep
end

def modcomb(n, k, mod)
  return 1 if k < 1 || n <= k
  nume = deno = 1
  for i in 1..k
    nume = nume*(n-i+1) % mod
    deno = deno*i % mod
  end
  return nume*modpow(deno, mod-2, mod) % mod
end

n, m = gets.split.map(&:to_i)
ans = 0
ans += modcomb(n, 2, 10**9+7) if n >= 2
ans += modcomb(m, 2, 10**9+7) if m >= 2
puts ans


Measured memory_bytes: 1788
s = input()

if (s == "RRR"):
    print(3)
elif (s[0] == s[1] == 'R' or s[1] == s[2] == 'R'):
    print(2)
elif (s[0] == 'R' or s[1] == 'R' or s[2] == 'R'):
    print(1)
else:
    print(0)

Measured memory_bytes: 8952
n=int(input())
a=list(map(int,input().split()))
a.sort()
ans=n
b=[0]*n
b[0]=a[0]
for i in range(1,n):
    b[i]=b[i-1]+a[i]
for i in range(n)[::-1]:
    if b[i]>3*b[i-1]:
        ans-=i
        break
print(ans)


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

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

    int ans = 100*100 ;
    int tmp = 0 ;
    for(int i=0;i<n;i++)
    {
        tmp+=w[i] ;
        int temp = SUM-tmp ;
        if(abs(temp-tmp)<ans) ans =  abs(temp-tmp) ;
    }
    
    cout << ans <<endl ;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define rep(i,s,N) for (int i=s;i<(N); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;


string ans;

int main(){
	string s;
    cin >> s;
    if(s=="Sunny"){
      ans = "Cloudy";
    }else if(s=="Cloudy"){
      ans = "Rainy";
    }else{
      ans = "Sunny";
    }
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

vector<int> G[100010];
int dp[100010];
int dfs(int x, int p = -1) {
    if(dp[x] != -1) return dp[x];
    int ret = 0;
    for(auto to: G[x]) {
        if(to == p) continue;
        ret = max(ret, dfs(to, x) + 1);
    }
    return dp[x] = ret;
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
    }
    rep(i, 100010) dp[i] = -1;
    int ans = 0;
    rep(i, N) ans = max(ans, dfs(i));
    cout << ans << endl;



    return 0;
}


Measured memory_bytes: 12140
N = int(input())
ans = [0] * 11000

for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            culc = x*x + y*y + z*z + x*y + y*z + z*x
            if culc <= 11000:
                ans[culc] += 1

for i in range(1,N+1):
    print(ans[i])

Measured memory_bytes: 68808
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <map>           // sorted map so O(logn)
#include <unordered_map> // O(1)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;

int main()
{
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
    {
        a[i] = k;
    }
    for (int i = 0; i < q; ++i)
    {
        int x;
        cin >> x;
        a[x - 1]++;
    }
    for (int i = 0; i < n; ++i)
    {
        a[i] -= q;
        if (a[i] > 0)
        {
            cout << "Yes"
                 << " ";
        }
        else
        {
            cout << "No"
                 << " ";
        }
    }
}

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

const int maxn = 2e5 + 10;

int cnt[2], ans[maxn];
vector<int> g[maxn], p[2];

void dfs(int o,int d,int pa = 0) {
	cnt[d&1] += 1;
	p[d&1].push_back(o);
	for(auto u : g[o]) if(u != pa) dfs(u, d + 1, o);
}
int main() {
	int n;
	scanf("%d", &n);
	for(int i = 1;i < n;++i) {
		int a , b;
		scanf("%d%d", &a, &b);
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(1, 0);
	int a = 0,b = 1;
	if(cnt[a] > cnt[b]) swap(a, b);
	int o = 1, t = 2, z = 3;
	if(cnt[a] <= (n / 3)) {
		for(auto u : p[a]) {
			if(z <= n) ans[u] = z, z += 3;
		}
		for(auto u : p[b]) {
			if(z <= n) ans[u] = z, z += 3;
			else if(o <= n) ans[u] = o, o += 3;
			else ans[u] = t,t += 3;
		}
	}
	else {
		
		for(auto u : p[a]) {
			if(o <= n) ans[u] = o, o += 3;
			else if(z <= n) ans[u] = z, z += 3;
		}
		for(auto u : p[b]) {
			if(t <= n) ans[u] = t,t += 3;
			else if(z <= n) ans[u] = z, z += 3;
			else ans[u] = o,o += 3;
		}
	}

	for(int i = 1;i <= n;++i) printf("%d%c", ans[i], i == n ?'\n' :' ');
}

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

const ll mod = 1e9+7;

int main(){
	string s;
	cin >> s;
	ll ans = 0;
	REP(i, s.size()){
		if (s[i] == '+'){ans++;}
		else {ans--;}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
x,y,a,b,c,=map(int,input().split())
red=sorted(list(map(int,input().split())),reverse=True)
green=sorted(list(map(int,input().split())),reverse=True)
clear=sorted(list(map(int,input().split())),reverse=True)
red=red[:x]
green=green[:y]

import heapq
heapq.heapify(red)
heapq.heapify(green)

for i in range(c):
    r=heapq.heappop(red)
    g=heapq.heappop(green)
    c=clear[i]
    
    if r>c and g>c:
        heapq.heappush(red,r)
        heapq.heappush(green,g)
    elif r>=g:
        heapq.heappush(red,r)
        heapq.heappush(green,c)
    else:
        heapq.heappush(green,g)
        heapq.heappush(red,c)

print(sum(red)+sum(green))

Measured memory_bytes: 23200
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#define PI 3.14159265358979323846264338327950288
//#include <bits/stdc++.h>
 
using namespace std;
double cos( double x );
double sqrt( double x );

int main()
{
  long long int i,j,k,l=0;
  double space,C,Z;
  double X,Y;
  double A,B,H,M;
  scanf("%lf %lf %lf %lf",&A,&B,&H,&M);
  
  X = 30.0*H + 0.5*M;
  Y = 6.0*M;
  Z = X - Y;
  if( Z<0 ){ Z *= -1.0; }
  if( Z>180 ){  Z = 360.0 - Z; }
  Z = (Z*PI/180.0);
  space = cos(Z);
  //printf("%f %f\n",Z,space);
  
  C = sqrt( (A*A) + (B*B) - (2*A*B*space) );
  printf("%.12f\n",C);
      
  return 0; 
  
}

Measured memory_bytes: 4220
#include <bits/stdc++.h>
using namespace std;
const int N = 505;
int n, sum, pt, num[N], p[N], ans[N * N], ex[N];
struct pr {
   	int x, i;
} a[N];
bool cmp (pr u, pr v) {return u.x < v.x;} 
struct pri {
	int i, x;
	pri () {}
	pri (int _i, int _x) :
		i(_i), x(_x) {}
	bool operator < (const pri &o) const {
		return p[i] - (i - num[i]) > p[o.i] - (o.i - num[o.i]);
	}
};
priority_queue <pri> q;
int main () {
	cin >> n, sum = 0;
	for (int i = 1; i <= n; ++i)
		cin >> a[i].x, p[i] = a[i].x, a[i].i = i, ans[a[i].x] = i;
	sort(a + 1, a + 1 + n, cmp);
	pt = n * n + 1;
	for (int i = 1; i <= n; ++i) if (a[i].i != 1) q.push(pri(a[i].i, a[i].x));
	for (int i = 1; i <= n * n; ++i) {
		if (!ans[i]) {
			if (q.empty()) {pt = i; break;}
			pri t = q.top(); q.pop();
			while (p[t.i] < i && !q.empty()) t = q.top(), q.pop();
			if (p[t.i] < i && q.empty()) break;
			ans[i] = t.i, ++num[t.i];
			if (p[t.i] < i || num[t.i] == t.i - 1) continue;
			q.push(t);
		} else ++num[ans[i]];
	}
	for (int i = pt; i <= n * n; ++i) {
		if (ans[i]) {++num[ans[i]]; continue;}
		for (int j = 1; j <= n; ++j) {
			if (num[j] < n && p[j] < i) {ans[i] = j; ++num[j]; break;}
		}
	}
	for (int i = 1; i <= n * n; ++i) ++ex[ans[i]];
	for (int i = 1; i <= n; ++i) if (ex[i] != n) return puts("No"), 0;
	for (int i = 1; i <= n; ++i) if (ans[p[i]] != i) return puts("No"), 0;
	for (int i = 1; i <= n; ++i) num[i] = 0;
	for (int i = 1; i <= n * n; ++i) {
		++num[ans[i]];
		if (i == p[ans[i]] && num[ans[i]] != ans[i]) return puts("No"), 0;
	}
	puts("Yes");
	for (int i = 1; i <= n * n; ++i)
		printf("%d%c", ans[i], i < n * n ? ' ' : '\n');
	return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <queue>
#include <string>

using namespace std;

int main() {
	string a, b, c;
	cin >> a >> b >> c;
	queue<char> qa, qb, qc;
	for (int i = 0; i < a.size(); i++) {
		qa.push(a[i]);
	}
	for (int i = 0; i < b.size(); i++) {
		qb.push(b[i]);
	}
	for (int i = 0; i < c.size(); i++) {
		qc.push(c[i]);
	}
	int k = 0;	
	while(true) {
		if (k == 0) {
			if (qa.empty()) {
				cout << 'A' << endl;
				break;
			} else {
				k = qa.front()-'a';
				qa.pop();
			}
		} else if (k == 1) {
			if (qb.empty()) {
				cout << 'B' << endl;
				break;
			} else {
				k = qb.front()-'a';
				qb.pop();
			}
		} else {
			if (qc.empty()) {
				cout << 'C' << endl;
				break;
			} else {
				k = qc.front()-'a';
				qc.pop();
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		String str1 = scan.next();
		char[] box = str1.toCharArray();
		String str2 = scan.next();
		char[] question = str2.toCharArray();
		int j;
		int k;
		boolean flg = false;
		
		for(int i = 0;i < box.length;i++)
		{
			if(question[0] == box[i])
			{
				j = 1;
				k = i + 1;
				if(k >= box.length){k = 0;}
				while(j < question.length && question[j] == box[k])
				{	
					j++;
					k++;
					
					if(k >= box.length){k = 0;}
				}
				if(j == question.length)
				{
					flg = true;
				}
			}
		}
		if(flg == true)
		{
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 17268
n = int(input())
input = input()
listA = list(map(int, input.split()))
listB = list(map(int, input.split()))
listB.sort()

index =0
sum=0
while index < len(listB):
    sum+=listB[index]
    index+=1

average = sum/len(listB)
minI =100
delta=1000

index2 =0
while index2 < len(listA):
    if abs(listA[index2]-average) < delta:
        minI = index2
        delta = abs(listA[index2]-average)
    index2+=1

print(minI)

Measured memory_bytes: 3064
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    long long int ans=0;
    long long int N;
    cin>>N;
    for(int i=1;i<=N;i++){
        long long int kosuu=N/i;
        ans+=kosuu*(kosuu+1)/2*i;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
  int N,K;
  vector<pair <int,int>>a(200000);
  for (int i(0);i<200000;i++){
    a[i].second = i;
    a[i].first = 0;
  }
  cin>>N>>K;
  for (int i(0);i<N;i++){
    int b;
    cin>>b;
    a[b-1].first++;
  }
  sort(a.begin(),a.end());
  for (int i(0);i<10;i++){
 //   cout << a[i].first << " "<<a[i].second<<endl;
  }
  int cnt(0);
  for (int i(0);i<200000;i++) if (a[i].first!=0)cnt++;
  int ans(0);
  int cnti(0);
  for (int i(0);i<200000;i++){
    if (cnti>=cnt-K) break;
    if (a[i].first!=0) {
      ans+=a[i].first;
      cnti++;
    }
  }
  cout << ans << endl;
}



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

int A[200];

int main(){
  int N, M;
  cin >> N >> M;
  rep(i, N) cin >> A[i];

  // とりあえず投票総数を計算
  int sums = 0;
  rep(i, N) sums += A[i];

  // 選べない商品の投票数の境目
  double thres = (double) sums / (4 * M);

  // 全探索
  int ans = 0;
  rep(i, N){
    if (A[i] >= thres) ans++;
  }

  // もし選べる商品がM個以上あればOK
  if (ans >= M) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int sum,n,m,tmp;
int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n>>m;
    for (int i = 1; i <= m ; i++){
        cin>>tmp;
        sum+=tmp;
    }
    n = n - sum;
    if (n >= 0) cout<<n;
    else cout<<-1;
}

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

int main()
{
    int n;
    cin >> n;
    int save = n;
    int digitSum = 0;
    while(save)
    {
        digitSum += save%10;
        save /= 10;
    }
    if(n%digitSum==0)
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}


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

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


	for (int i=1; i<2000; i++)
	{
		int pa = i*0.08;
		int pb = i*0.1;
		if (pa == a && pb == b)
		{
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}


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

using namespace std;

int beging[]={400,600,800,1000,1200,1400,1600,1800};
int endd[]={599,799,999,1199,1399,1599,1799,1999};
int kyu[]={8,7,6,5,4,3,2,1};
int main()
{
    int x;
   cin>>x;
   for(int i=0;i<=7;i++)
   {
       if(x>=beging[i] && x<=endd[i])
       {
           cout<<kyu[i];
           break;
       }
   }

}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0))
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0))
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a))
#define Reverse(a) reverse(All(a))
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define Lower(a,t) lower_bound(All(a),t)
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


signed main(){
    int n;
    cin >> n;
    string a,b,c;
    cin >> a >> b >> c;
    int ans = 0;
    REP(i,n){
        if(a[i] == b[i] && b[i] == c[i]){
            continue;
        }
        else if(a[i] == b[i] || b[i] == c[i] || a[i] == c[i]){
            ans++;
        }
        else{
            ans += 2;
        }
    }
    cout << ans << endl;

    return 0;
}



void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1000000007;
void solve(){
    ll h,w;
    cin>>h>>w;
    char a[h+1][w+1];
    for(ll i=1;i<=h;i++){
        for(ll j=1;j<=w;j++)
        {
            cin>>a[i][j];
        }
    }
    ll dp[h+1][w+1];
    memset(dp,0,sizeof(dp));
    dp[1][1]=1;
    for(ll j=2;j<=w;j++){
        if(a[1][j]=='.')
        dp[1][j]=1;
        else break;
    }
    for(ll i=2;i<=h;i++){
        if(a[i][1]=='.')
        dp[i][1]=1;
        else break;
    }
    for(ll i=2;i<=h;i++){
        for(ll j=2;j<=w;j++){
            if(a[i][j]=='#')
            continue;
            else
            dp[i][j]=(dp[i-1][j]%mod+dp[i][j-1]%mod)%mod;
        }
    }
    cout<<dp[h][w];
}
int main(){
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

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

int main() {
  int n;
  cin >>n;
  vector<int> vec1(n);
  vector<int> vec2(n);
  vector<int> vec3(n);
  int total =0;
  for(int i=0; i <n;i++){
    cin >>vec1.at(i);
  }
    for(int i=0; i <n;i++){
    cin >>vec2.at(i);
  }
    for(int i=0; i <n-1;i++){
    cin >>vec3.at(i);
  }
  for(int i=0; i<n; i++){
    total=total +vec2.at(i);
  }
  for(int i=0; i<n-1;i++){
   if(vec1.at(i) +1==vec1.at(i+1)){
     total= total+vec3.at(vec1.at(i)-1);
   }
  }
  cout << total <<endl;
}

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

main (){
  int N, D;
  int sum = 0, i;
  double d;
  int X[200001], Y[200001];
  scanf("%d%d", &N, &D);
  for(i = 0; i < N; i++){
    scanf("%d%d", &X[i], &Y[i]);
  }
  
  for(i = 0; i < N; i++){
    d = sqrt(pow(X[i],2) + pow(Y[i],2));
    if(d <= D){ sum++; }
  }
  
  printf("%d", sum);
  
}

Measured memory_bytes: 3696
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(in.readLine());
        int k = Integer.parseInt(st.nextToken()), x = Integer.parseInt(st.nextToken());
        k *= 500;
        if(k >= x) {
        	System.out.println("Yes");
        }else {
        	System.out.println("No");
        }
    }
}

Measured memory_bytes: 22484
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>   //PBDS
#include <ext/pb_ds/tree_policy.hpp>       //PBDS
#define int long long int
#define vi vector<int>
#define vii vector<pair<int,int>>
#define pi pair<int,int>
#define deb(x) cerr<<#x<<" : "<<x<<endl;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define mi map<int,int>
#define PI   3.141592653589
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define f(i,x,n) for(int i=x;i<n;i++)
#define rf(i,x,n) for(int i=n-1;i>=x;i--)
#define check(x)   cerr<<#x<<" : "<<x<<endl;
#define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
#define fbo find_by_order                    //return iterator PBDS
#define ook order_of_key                     //return number :)) PBDS
#define baar exit(0)
#define INF 1000000000000000000
using namespace __gnu_pbds;
using namespace std;
signed main()
{
	fast
	int n;
	cin>>n;
	int ans=0;
	for(int i=1;i<n;i++)
	{
		int val=n/i;
		ans+=val;
		if(n%i==0) ans--;
	}
	cout<<ans;
	return 0;
}



Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin >> a >> b;
    if(a <= 9 && b <= 9)
    {
        cout << a * b;
    }
    else
    {
        cout << "-1";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

    int a,b;
    
    scanf("%d %d", &a,&b);

    if(a<b){
    printf("a < b\n");

}else if(a>b){
    printf("a > b\n");
}else{
    printf("a == b\n");
    }

    return 0;
}

Measured memory_bytes: 580
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    H, W = LI()
    Ch, Cw = LI_()
    Dh, Dw = LI_()
    S = [SS() for _ in range(H)]

    d = ((1, 0), (0, 1), (-1, 0), (0, -1)) 
    dist = [[INF] * W for _ in range(H)]
    que = collections.deque()
    que.append((Ch, Cw, 0))
    dist[Ch][Cw] = 0
    while que:
        cy, cx, cost = que.popleft()
        for dy, dx in d:
            ny = cy + dy
            nx = cx + dx
            if 0 <= ny < H and 0 <= nx < W and S[ny][nx] == '.' and cost < dist[ny][nx] :
                dist[ny][nx] = cost
                que.appendleft((ny, nx, cost))
        for dy, dx in itertools.product(range(-2, 3), repeat=2):
            ny = cy + dy
            nx = cx + dx
            if 0 <= ny < H and 0 <= nx < W and S[ny][nx] == '.' and cost + 1 < dist[ny][nx] :
                dist[ny][nx] = cost + 1
                que.append((ny, nx, cost + 1))

    if dist[Dh][Dw] == INF:
        print(-1)
    else:
        print(dist[Dh][Dw])

if __name__ == '__main__':
    resolve()


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



int n, m;
ll x[maxn];
ll cc[maxn];
int par[maxn], siz[maxn];
int edge_deletes[maxn];

int parent(int v) {
    if (par[v]==v) return v;
    return par[v] = parent(par[v]);
}


void join(int u, int v, ll wei) {
    u = parent(u);
    v = parent(v);

    if (u == v) {
	if (wei > cc[u]) {
	    edge_deletes[u]++;
	} else {
	    edge_deletes[u]=0;
	}
    } else {
	if (siz[u]<siz[v]) swap(u,v);
	cc[u] += cc[v];
	siz[u] += siz[v];
	edge_deletes[u] += edge_deletes[v];
	par[v] = u;

	if (wei > cc[u]) {
	    edge_deletes[u]++;
	} else {
	    edge_deletes[u]=0;
	}
    }
}

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

    cin>>n>>m;
    for (int i=1; i<=n; i++) {
	cin>>x[i];
    }
    for (int i=1; i<=n; i++) {
	cc[i]=x[i];
	par[i]=i;
	siz[i]=1;
    }

    vector<pair<ll,pair<int,int>>> edges;
    for (int i=0; i<m; i++) {
	int a,b,w;
	cin>>a>>b>>w;
	edges.push_back({w,{a,b}});
    }

    sort(edges.begin(), edges.end());


    for (auto ed: edges) {
	ll wei = ed.first;
	int u = ed.second.first;
	int v = ed.second.second;
	join(u,v, wei);
    }

    cout<<edge_deletes[parent(1)]<<endl;
    
    
    return 0;
}


Measured memory_bytes: 7700
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define rv(s) reverse(s.begin(),s.end());
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
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 GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}

int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int n,m;
  cin>>n>>m;
  
  vi x(m);
  rep(i,m)cin>>x[i];
  
  if(m==1 || n>=m){
    cout(0); return 0;
  }
  
  vsort(x);
  vi diffs(m-1);
  rep(i,m-1)diffs[i]=x[i+1]-x[i];
  rvisort(diffs);
  ll ans=vtotal(diffs);
  rep(i,n-1){
    ans-=diffs[i];
  }
  cout(ans);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

ll gcd (ll a, ll b){
    ll k = a % b;
    while (k > 0){
        a = b;
        b = k;
        k = a % b;
    }
    return b;
}

int main() {
    int n; cin >> n;
    vector<bool> ar(n+1,true);
    vector<PL> al(n+1);
    rep(i,n+1) al[i] = P(i,1);
    int m = sqrt(n) + 1;
    int c = 2;
    while (c < m){
        if (!ar[c]) c++;
        else {
            int k = c;
            while (k < n+1){
                ar[k] = false;
                int cnt = 0;
                while (al[k].first % c == 0){
                    cnt++;
                    al[k].first /= c;
                }
                al[k].second *= cnt+1;
                k += c;
            }
        }
    }
    ll ans = 0;
    repp(i,n+1,1){
        if (al[i].first == 1) ans += i * al[i].second;
        else ans += i * al[i].second * 2LL;
    }
    cout << ans << endl;
}

Measured memory_bytes: 160868
N,M=map(int,input().split())
AB=list()
for i in range(N):
  AB.append(list(map(int,input().split())))
AB.sort()
ans=0
for i in range(N):
  if M>=AB[i][1]:
    M-=AB[i][1]
    ans+=AB[i][0]*AB[i][1]
  else:
    ans+=M*AB[i][0]
    M=0
print(ans)

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

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

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	int ans=1;
	if(b != a) ans++;
	if(c != b and c != a) ans++;
	cout << ans << endl;

	return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define MAX 130

using namespace std;

const int IINF = INT_MAX;
int m,n;
string G[MAX];
map<deque<int>,int> memo;

int dfs(const deque<int> &obj){
  if( obj.size() <= 1 ) return 0;
  if( memo.find(obj) != memo.end() ) return memo[obj];
  int ret = IINF;
  rep(i,m){
    deque<int> one,zero;
    rep(j,(int)obj.size()){
      if( G[obj[j]][i] == '1' )  one.push_back(obj[j]);
      else                      zero.push_back(obj[j]);
    }
    if( one.empty() || zero.empty() ) continue;
    ret = min(ret,max(dfs(one),dfs(zero))+1);
  }
  return memo[obj] = ret;
}

int main(){
  while(cin >> m >> n,n|m){
    rep(i,n)cin >> G[i];
    memo.clear();
    deque<int> obj(n);
    rep(i,n) obj[i] = i;
    cout << dfs(obj) << endl;
  }
  return 0;
}

Measured memory_bytes: 15156
N = int(input())
A_li = list(map(int, input().split()))
s_li = [0]
for i in range(N) :
    s_li.append(s_li[i] + A_li[i])
s_dic = {}
for s in s_li :
    if s in s_dic :
        s_dic[s] += 1
    else :
        s_dic[s] = 1
ans = 0
for sd in s_dic.values() :
    ans += sd * (sd - 1) // 2
print(ans)

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

using namespace std;

long long a, b, c, d, n, ans;

int main() {
    cin >> a >> b >> c >> d >> n;
    long long x;
    if (n % 2 == 0) {
        x = (n / 2) * d;
    }
    else {
        x = (n / 2) * d + min({4 * a, 2 * b, c});
    }
    ans = min({n * a * 4, n * 2 * b, n * c, x});
    cout << ans;
}


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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int inf = int (1e9) + int (1e5);
const ll infl = ll (2e18) + ll (1e10);
const ui M=1E9+7;
const double eps = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);i++)

int main()
{
    std::ios_base::sync_with_stdio (false);
    // freopen ("in.txt", "r", stdin);
    int N,M;
    cin >> N >> M;
    vi c[N];
    FOR(i,M) {
        int a,b;
        cin >> a >> b;
        a--;b--;
        c[a].push_back(b);
        c[b].push_back(a);
    }
    bool res=false;
    for (int cc : c[0]){
        for (int d : c[cc]) {
            if (d==N-1){
                res=true;
                break;
            }
        }
    }
    if (res)
        cout << "POSSIBLE";
    else
        cout << "IMPOSSIBLE";




    return 0;
}


Measured memory_bytes: 12016
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#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 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 n; cin >> n;
    vi l(n);
    rep(i, n) cin >> l[i];
    sort(all(l));
    ll ans = 0;

    for(long long i=0; i<n; i++){
        for(long long j=i+1; j<n; j++){
            for(long long k=j+1; k<n; k++){
                if(l[i] == l[j] || l[j] == l[k] || l[k] == l[i]) continue;
                if(l[i]+l[j]>l[k] && l[j]+l[k]>l[i] && l[k]+l[i]>l[j]) ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3660