akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(2147483647)
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.readline().rstrip()

class modfact(object):
    def __init__(self, n):
        fact, invfact = [1] * (n + 1), [1] * (n + 1)
        for i in range(1, n + 1): fact[i] = i * fact[i - 1] % MOD
        invfact[n] = pow(fact[n], MOD - 2, MOD)
        for i in range(n - 1, -1, -1): invfact[i] = invfact[i + 1] * (i + 1) % MOD
        self._fact, self._invfact = fact, invfact

    def inv(self, n):
        return self._fact[n - 1] * self._invfact[n] % MOD

    def fact(self, n):
        return self._fact[n]

    def invfact(self, n):
        return self._invfact[n]

    def comb(self, n, k):
        if k < 0 or n < k: return 0
        return self._fact[n] * self._invfact[k] % MOD * self._invfact[n - k] % MOD

    def perm(self, n, k):
        if k < 0 or n < k: return 0
        return self._fact[n] * self._invfact[n - k] % MOD

def resolve():
    m, n, k = map(int, input().split())
    mf = modfact(m * n - 2)
    res = 0
    for s in range(1, m):
        res += n * n * (m - s) * s
        res %= MOD
    for t in range(1, n):
        res += m * m * (n - t) * t
        res %= MOD
    res *= mf.comb(m * n - 2, k - 2)
    res %= MOD
    print(res)
resolve()

Measured memory_bytes: 41968
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  int l=s.size();
  if(s[l-1]=='s')
    cout<<s+"es"<<endl;
  else if(s[l-1]!='s')
    cout<<s+'s'<<endl;
  return 0;
}

Measured memory_bytes: 3636
H, W = map(int, input().split())
C = [list(map(int, input().split())) for _ in range(10)]
A = [list(map(int, input().split())) for _ in range(H)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            C[i][j] = min(C[i][j], C[i][k] + C[k][j])

ans = 0
for i in range(H):
    for j in range(W):
        if A[i][j] != -1:
            ans += C[A[i][j]][1]

print(ans)

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

bool cmp(char a, char b) {
	return a > b;
}

int main() {
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end(), cmp);
	cout << (s < t ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define iinf 2000000000
#define linf 1000000000000000000LL
#define ulinf 10000000000000000000ull
#define MOD1 1000000007LL
#define mpr make_pair
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned long UL;
typedef unsigned short US;
typedef pair < int , int > pii;
clock_t __stt;
inline void TStart(){__stt=clock();}
inline void TReport(){printf("\nTaken Time : %.3lf sec\n",(double)(clock()-__stt)/CLOCKS_PER_SEC);}
template < typename T > T MIN(T a,T b){return a<b?a:b;}
template < typename T > T MAX(T a,T b){return a>b?a:b;}
template < typename T > T ABS(T a){return a>0?a:(-a);}
template < typename T > void UMIN(T &a,T b){if(b<a) a=b;}
template < typename T > void UMAX(T &a,T b){if(b>a) a=b;}
int n,h,w,x[200005],y[200005],p[200005];
bool cmp(int a,int b){
	return mpr(y[a],x[a])<mpr(y[b],x[b]);
}
int main(){
    // inputting start
    // 数据结构记得初始化！ n，m别写反！
    int i,j,k,res;
	scanf("%d%d%d",&h,&w,&n);
	for(i=0;i<n;++i){
		scanf("%d%d",x+i,y+i);
		--x[i];--y[i];
		x[i]-=y[i];
	}
    #ifdef LOCAL
        TStart();
    #endif
    // calculation start
    // 数据结构记得初始化！ n，m别写反！
    for(i=0;i<n;++i) p[i]=i;
	sort(p,p+n,cmp);
	int tp=0;
	res=h;
	for(i=0;i<n;++i){
		int X=x[p[i]],Y=y[p[i]];
		if(tp<X)
			UMIN(res,X+Y);
		else if(tp==X)
			++tp;
	}
	printf("%d\n",res);
    #ifdef LOCAL
        TReport();
    #endif
    return 0;
}

Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		long x = n / k;
		long ans = x * x * x;
		if (k % 2 == 0) {
			long y = (n + k / 2) / k;
			ans += y * y * y;
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
const ll mod = 1e9+7;
const int MAX = 2e5+1;
vector<vector<int>> g(MAX);
vector<ll> dp1(MAX,0);
vector<ll> dp2(MAX,0);
vector<ll> ans(MAX,0);
vector<ll> per(MAX,1);
int n;

ll Pow(ll x, ll n){
  if(n == 0) return 1;
  if(n % 2 == 0) return Pow(x*x % mod, n/2);
  else return x * Pow(x,n-1) % mod;
}

ll mod_inverse(ll a) {
  return Pow(a,mod-2);
}

ll dfs1(int u, int p) {
  ll res = 1;
  for(auto e : g[u]) {
    if(e != p) res += dfs1(e,u);
  }
  return dp1[u] = res;
}

ll dfs2(int u, int p) {
  ll res = 1;
  for(auto e : g[u]) {
    if(e != p) {
      (res *= dfs2(e,u)) %= mod;
      (res *= mod_inverse(per[dp1[e]])) %= mod;
    }
  }
  return dp2[u] = (res * per[dp1[u]-1]) % mod;
}

void dfs3(int u, int p, int q, ll r) {
  ll res = r;
  (res *= mod_inverse(per[q])) %= mod;
  for(auto e : g[u]) {
    if(e != p) {
      (res *= dp2[e]) %= mod; 
      (res *= mod_inverse(per[dp1[e]])) %= mod; 
    } 
  }
  ans[u] = (per[n-1] * res) % mod;
  for(auto e : g[u]) {
    if(e != p) {
      ll a = ans[u];
      (a *= per[dp1[e]]) %= mod;
      (a *= mod_inverse(per[n-1])) %= mod;
      (a *= per[n-1-dp1[e]]) %= mod;
      (a *= mod_inverse(dp2[e])) %= mod;
      dfs3(e,u,n-dp1[e],a);
    }
  }
}

int main(){
  cin >> n;
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for(ll i = 1; i < MAX; i++) per[i] = (per[i-1] * i) % mod; 
  dfs1(0,-1);
  dfs2(0,-1);
  dfs3(0,-1,0,1);
  rep(i,n) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 20212
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ARC098C - Attension
  // リーダーの方向を向かせる場合、最小値
  // 向きが変わる人を全て求めておく
  // vector<pair<int, int> >で両サイドからカウントwest, eastの順
  // リーダーの左側のW、右側のEをカウント
  // 自身も含めてよい。どうせ最後に1を引くから
  int N; cin >> N;
  string S; cin >> S;
  vector<pair<int, int> > cnt(N, pair<int, int>());
  if(S[0] == 'W'){
    cnt[0].first = 1;
  }
  if(S[N-1] == 'E'){
    cnt[N-1].second = 1;
  }
  for(int i = 1; i < N; i++){ // 1からスタートして、最後まで
    if(S[i] == 'W'){
      cnt[i].first = cnt[i-1].first + 1;
    }else{
      cnt[i].first = cnt[i-1].first;
    }
    if(S[N-1-i] == 'E'){
      cnt[N-1-i].second = cnt[N-i].second + 1;
    }else{
      cnt[N-1-i].second = cnt[N-i].second;
    }
  }
  int ans = 1e9;
  REP(i,N){
    ans = min(ans, cnt[i].first + cnt[i].second - 1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 2964
import numpy as np
def resolve():
    N = int(input())
    A = np.zeros(N)
    B = np.zeros(N)
    for i in range(N):
        A[i],B[i] = map(int,input().split())
    Amed = np.median(A)
    Bmed = np.median(B)
    if N % 2 == 0:
        print(int((Bmed - Amed) * 2 + 1))
    else:
        print(int(Bmed - Amed +1))
resolve()

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

int main() {
  int N,M;
  cin>>N>>M;
  vector<int>A(M);
  vector<int>B(M);
  for(int i=0;i<M;i++){
    cin>>A.at(i)>>B.at(i);
  }
  vector<vector<int>>a(N,vector<int>(1));
  for(int i=0;i<M;i++){
    A.at(i)--;B.at(i)--;
    a.at(A.at(i)).at(0)++;
    a.at(B.at(i)).at(0)++;
  }
  for(int i=0;i<N;i++){
    cout<<a.at(i).at(0)<< endl;
  }
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

n, q = map(int, input().split())
edge = [[] for i in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    edge[a].append(b)
    edge[b].append(a)

imos = [0 for i in range(n)]
for i in range(q):
    p, x = map(int, input().split())
    p -= 1
    imos[p] += x

def dfs(v, p):
    for u in edge[v]:
        if u == p:
            continue
        imos[u] += imos[v]
        dfs(u, v)

dfs(0, -1)
print(' '.join([str(x) for x in imos]))


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

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

    int n;
    cin >> n;
    vector<pair<string, int>> m;
    m.push_back({"AC", 0});
    m.push_back({"WA", 0});
    m.push_back({"TLE", 0});
    m.push_back({"RE", 0});
    while (n--) {
    	string s;
    	cin >> s;
    	if (s == "AC") {
    		m[0].second++;
    	} else if (s == "WA") {
    		m[1].second++;
    	} else if (s == "TLE") {
    		m[2].second++;
    	} else {
    		m[3].second++;
    	}
    }

    for (auto e : m) {
    	cout << e.first << " x " << e.second << "\n";
    }

    
    return 0;
}


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
  gearup;
  string s; cin >> s;
  if(s=="AAA" || s == "BBB")out("No");
  else out("Yes");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool pr(int x){
  bool ok=true;
  if(x%2==0&&x!=2) return false;
  for(int i=3; i<(x/2); i+=2){
    if(x%i==0){
      ok =false;
      break;
    }
  }
  return ok;
}
int main(){
  int x;
  cin>>x;
  int p=0;
  int i=x;
  while(p==0){
    if(pr(i)) p=i;
    else i++;
  }
  cout<<p<<endl;
}
    


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

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if (a == b){
        cout << "a == b";
    } else if (a < b){
        cout << "a < b";
    } else {
        cout << "a > b";
    }
    cout << endl;
}


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

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


  int id = 1;

  for (int i = 0; i < n; i++){
    if (a[i] == id)
      id++;
  }


  if (id == 1)
    cout << -1 << endl;
  else
    cout << n - id + 1 << endl;


  return 0;
}


Measured memory_bytes: 1024
from collections import defaultdict
s = input()
t = input()
n = len(s)

d = defaultdict(str)
# ダメな場合
# 1. 同じtが違うsに対応
# 2. 同じsが違うtに対応
for i in range(n):
    if d[t[i]] == "":
        d[t[i]] = s[i]
    elif d[t[i]] != s[i]:
        print("No")
        exit()
d.clear()
for i in range(n):
    if d[s[i]] == "":
        d[s[i]] = t[i]
    elif d[s[i]] != t[i]:
        print("No")
        exit()

print("Yes")


Measured memory_bytes: 9516
//ABC160 A

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

string S;
long long P;
int ans = 0;

int main() {
  cin >> S;
  if(S[2] == S[3] && S[4] == S[5]){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }

  

}


Measured memory_bytes: 256
h, w, k = map(int, input().split())
f = [input() for _ in range(h)]

ans = 0
for i in range(1 << h):
    for j in range(1 << w):
        black = 0
        for x in range(h):
            for y in range(w):
                if (i >> x) & 1 or (j >> y) & 1:
                    continue
                if f[x][y] == "#":
                    black += 1
        if black == k:
            ans += 1

print(ans)


Measured memory_bytes: 73736
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;
const int INF = (int)1e8;

bool t[5*1000][5];

int GetUnder(int x){
	for(int i = 5000-1; i >= 0; i--){
		if(t[i][x]) return i+1;
	}
	return 0;
}

int GetUnder(int d,int p,int q){
	int under = -1;
	if(d==2){
		under = GetUnder(q);
	}
	else {
		FOR(i,p){
			under = max(under,GetUnder(q+i));
		}
	}
	return under;
}

int main(){
	int n;
	while(cin>>n,n){
		memset(t,0,sizeof(t));
		FOR(i,n){
			int d,p,q; cin>>d>>p>>q;
			q--;

			int under = GetUnder(d,p,q);

			if(d==2){
				FOR(i,p) t[under+i][q] = true;
			} else {
				FOR(i,p) t[under][q+i] = true;
			}

			int c = 0;
			FOR(i,5000){
				if(accumulate(t[i],t[i]+5,0) == 5) continue;
				memcpy(t[c++],t[i],5);
			}
			for(int i = c; i < 5000; i++) FOR(j,5) t[i][j] = false;
		}
		int ans = 0;
		FOR(i,5000) FOR(j,5) ans += t[i][j];

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

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	int cnt = 0, c = 0;
	for (int i = 0; i < S.size(); i++) {
		if (!i) {
			if (S.at(i) != 'A') {
				cout << "WA" << endl;
				return 0;
			}
		}
		else if ((i >= 2) && (i <= S.size() - 2)) {
			if (S.at(i) == 'C') c++;
		}

		if ((S.at(i) >= 'A') && (S.at(i) <= 'Z')) {
			cnt++;
		}
	}

	if ((cnt != 2) || (c != 1)) {
		cout << "WA" << endl;
	}
	else {
		cout << "AC" << endl;
	}
}

Measured memory_bytes: 3632
// Jai Mata Di
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define modmax 1000000007
void solveTest(){
   int n;
   cin>>n;
   lli a[n];
   for(int i=0; i<n; i++){
     cin>>a[i];
   }
   lli sum = a[n-1];
   lli ans = 0;
   for(int i=n-2; i>=0; i--){
     sum = sum % modmax;

     ans = (ans + (a[i]*sum)%modmax)%modmax;
     sum = sum + a[i];
     sum = sum % modmax;
   }
   cout<<ans<<"\n";
}
int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t=1, i=1;
  //cin>>t;//Comment if only one test case
  while(i<=t){
    //cout<<"Case #"<<i<<": ";
    solveTest();
    i++;
  }
  return 0;
}


Measured memory_bytes: 5204
#include<iostream>
using namespace std;
int main(){
	int a,b,c,ans=0;
  	cin>>a>>b>>c;
  
  	if((a+b)>=c){
    	ans=b+c;
    }else if((a+b)<c){
      	ans=b*2+1+a;    
    }
  	cout<<ans;
  return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)
#define pow10(n) int(1e##n + n)

typedef long long LL;
typedef pair<int, int> P;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;

void solve()
{
    string S, T;
    cin >> S >> T;
    bool isok = true;
    REP0 (i, S.length())
    {
        if (S[i] != T[i])
        {
            isok = false;
        }
    }

    std::cout << (isok ? "Yes" : "No") << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(20);
    solve();
    return 0;
}


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

using namespace std;

#define int long long
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define fr(i,j,k) for(i = j; i < (k); i++)
#define all(x) x.begin(), x.end()
#define el '\n'
#define remax(a,b) a = max(a, b)
#define remin(a,b) a = min(a, b)
#define sz(x) int32_t(x.size())

typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpi;
// --------------------------------------------------------------------

const pii dxy[] = { {-1, 0}, {1, 0}, {0, 1}, {0, -1} };
const int mod = 998244353;
const int inf = 2e18;
const ld eps = 1e-9;
const int NN = 1e5 + 2;

const int S = 3003;
int dp[S][S][3];

string to_string(string s) {
	return '"' + s + '"';
}
string to_string(const char* s) {
	return to_string((string) s);
}
string to_string(bool b) {
	return (b ? "true" : "false");
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
	bool first = true;  string res = "{";
	for (const auto &x : v) {
		if (!first) { res += ", "; }
		first = false; res += to_string(x);
	}
	res += "}";	  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

// #define TRACE

#ifdef TRACE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void solve() {
      int i = 0, j = 0, k = 0, n = 0, s = 0; 
      cin >> n >> s;
      vi a(n);
      fr(i, 0, n) {
            cin >> a[i];
      }
      debug(a);
     fr(k, 0, 3) dp[0][a[0]][k] = 1;
      debug(s, a[0], dp[0][s][2]);
      for(i = 1; i < n; i++) {
            // copy prev states
            fr(j, 0, s+1) {
                  fr(k, 0, 3) { 
                        dp[i][j][k] = dp[i - 1][j][k];
                        if(k == 2) dp[i][j][k] = (dp[i][j][k] + dp[i - 1][j][1]) % mod;
                  }
            }
            // dp transitions
            for(j = 0; j <= s - a[i]; j++) {
                  // Dim 0
                  dp[i][j + a[i]][0] += dp[i - 1][j][0];  dp[i][j + a[i]][0] %= mod;
                  // Dim 1
                  dp[i][j + a[i]][1] += dp[i - 1][j][1]; dp[i][j + a[i]][1] %= mod;
                  // Dim 2
                  dp[i][j + a[i]][2] += dp[i - 1][j][1]; dp[i][j + a[i]][2] %= mod;
            }

            dp[i][a[i]][0]++;
            dp[i][a[i]][1] += i+1; 
            dp[i][a[i]][2] += i+1;
            debug(i,dp[i][s][2]);
      }
      // cerr << dp[n-1][s][0] << ' ' << dp[n-1][s][1]<<endl;
      cout << (dp[n - 1][s][2] % mod) << el;
}

int32_t main() {
      ios::sync_with_stdio(false); cin.tie(0); 
      int T = 1; 
      // cin >> T;
      for(int tc = 1; tc <= T; tc++) {
            solve();
       }

      return 0;
}


Measured memory_bytes: 211328
#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define LOCAL 1

#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define dbg(...) cout<<#__VA_ARGS__ ": ["; for(auto e: __VA_ARGS__){cout<<e<<", ";} cout<<"]\n"
#define dbg1(...) cout<<#__VA_ARGS__ " "<< __VA_ARGS__ 
#else
#define dbg(...) 1;
#define dbg1(...) 1;
#endif

typedef long long ll;
typedef unsigned long long ull;
constexpr int R=5e3+69, INF=2e9+6969;

int qq;
int n,k,ans;
	int t[R];
	
int main()
{
	
	cin>>n>>k;
	for(int i=0;i<n;++i)
	{
		cin>>t[i];
	}
	sort(t,t+n);
	for(int i=0;i<k;++i)
	{
		ans+=t[i];
	}
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<=n;i++)
#define rep2(i,k,n) for(int i=k;i>=n;i--)
using namespace std;
const int N=505;
const int M=3e5+7;
int a[M],n,m,vis[N];
queue<int> Q;
int main(){
	scanf("%d",&n);
	rep(i,1,n){
		int x;scanf("%d",&x);
		a[x]=i;
	}
	m=n*n;
	rep(i,1,m){
		if(a[i]){
			rep(j,1,a[i]-1){
				if(Q.empty()){
					puts("No");
					return 0;
				}
				a[Q.front()]=a[i];
				Q.pop();
			}
		}
		else Q.push(i);
	}
	while(!Q.empty())Q.pop();
	rep2(i,m,1){
		if(a[i] && !vis[a[i]]){
			vis[a[i]]=1;
			rep(j,1,n-a[i]){
				if(Q.empty()){
					puts("No");
					return 0;
				}
				a[Q.front()]=a[i];
				Q.pop();
			}
		}
		else Q.push(i);
	}
	puts("Yes");
	rep(i,1,m)printf("%d ",a[i]);
}

Measured memory_bytes: 2944
# coding: utf-8
# Your code here!
import array

SIZE=300000; MOD= 998244353
#inv = array.array('q',[0]*(SIZE+1))# inv[j] = j^{-1} mod M
#fac = array.array('q',[0]*(SIZE+1))# inv[j] = j! mod M
#finv = array.array('q',[0]*(SIZE+1))# inv[j] = (j!)^{-1} mod M
inv = [0]*(SIZE+1)# inv[j] = j^{-1} mod M
fac = [0]*(SIZE+1)# inv[j] = j! mod M
finv = [0]*(SIZE+1)# inv[j] = (j!)^{-1} mod M
inv[1] = 1
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
for i in range(2,SIZE+1):
    inv[i] = MOD -(MOD//i)*inv[MOD%i]%MOD
    fac[i] = fac[i-1]*i%MOD
    finv[i]= finv[i-1]*inv[i]%MOD

def choose(n,r): # nCk mod MOD の計算
    if r < 0 or r > n:
        return 0
    else:
        return (fac[n]*finv[r]%MOD)*finv[n-r]%MOD
    

n,a,b,k = [int(i) for i in input().split()]
ans=0
for i in range(n+1):
    if (k-i*a)%b == 0:
        ans = (ans + choose(n,i)*choose(n,(k-i*a)//b)%MOD)%MOD
print(ans)












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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
//constexpr int INF = 1001001001;
constexpr ll INF = 1001001001001001001ll;
constexpr double EPS = 1e-10;
using number = long long;

vector<int> buildFail(string p) {
    int m = p.size();
    vector<int> fail(m + 1);
    int j = fail[0] = -1;
    for (int i = 1; i <= m; ++i) {
        while (j >= 0 && p[j] != p[i - 1]) j = fail[j];
        fail[i] = ++j;
    }
    return fail;
}
vector<int> matching(string t, string p, vector<int> fail) {
    int n = t.size(), m = p.size();
    vector<int> res;
    for (int i = 0, k = 0; i < n; ++i) {
        while (k >= 0 && p[k] != t[i]) k = fail[k];
        if (++k >= m) {
            res.push_back(i - m + 1);
            k = fail[k];
        }
    }
    return res;
}

int main() {
    string T, P;

    cin >> T;
    cin >> P;
    vi fail = buildFail(P);
    vi res = matching(T, P, fail);
    for (auto x : res) cout << x << endl;
}


Measured memory_bytes: 10036
a,b,k=map(int, input().split())

if a+k-1>=b-k+1:
    for i in range(a,b+1):
        print(i)
    quit()

ans=set()
for i in range(a,a+k):
    ans.add(i)

for i in range(b-k+1,b+1):
    ans.add(i)

for i in sorted(ans):
    print(i)


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

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

  if (A >= N) {
    cout << "Yes" << endl;
  } else if (A >= N%500) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
int B[MAX_N];

void solve() {
	cin >> N;
	rep(i, 0, N - 1) cin >> B[i];
	ll res = B[0] + B[N - 2];
	rep(i, 0, N - 2) {
		res += min(B[i], B[i + 1]);
	}
	cout << res << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define MAX 1e9+7
#define MIN -1e9-7
#define int long long
#define endl "\n"
#define max(x,y) (x>y)?x:y
#define min(x,y) (x<y)?x:y
#define s(n) scanf("%d",&n)
#define mem memset(a, 0, sizeof(a))
#define minimum(a)	*min_element(a.begin(), a.end())
#define maximum(a)	*max_element(a.begin(), a.end())
typedef vector<int> vi;
typedef vector<string> vs;


int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   
   int t;
   cin>>t;
   if(t>=30)
   {
       cout<<"Yes"<<endl;
   }
   else
   {
       cout<<"No"<<endl;
   }
   
  
return 0;
}


Measured memory_bytes: 3632
#include <iostream>

void print_array(int a[], int n)
{
    for (int i = 0; i < n; ++i)
    {
        if (0 < i)
        {
            std::cout << " ";
        }

        std::cout << a[i];
    }

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

template <class T>
void swap(T& left, T& right)
{
    T temp = left;
    left = right;
    right = temp;
}

int bubble_sort(int a[], int n)
{
    auto swap_count = 0;

    auto flag = true;
    while (flag)
    {
        flag = false;
        for (int j = n - 1; 0 < j; --j)
        {
            if (a[j] < a[j - 1])
            {
                swap_count++;
                swap(a[j], a[j - 1]);
                flag = true;
            }
        }
    }
    return swap_count;
}


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

    auto swap_count = bubble_sort(a, n);
    print_array(a, n);
    std::cout << swap_count << std::endl;

    return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define SPEED ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define RFOR(i, b, a) for (ll i = b; i >= a; --i)
#define ALL(x) x.begin(), x.end()
#define DEBUG(args...) { string _s = #args; replace(ALL(_s), ' ', '\0');\
replace(ALL(_s), ',', ' ');\
stringstream _ss(_s); istream_iterator<string> _it(_ss); _debug(_it, args);}
#define endl "\n"
#define F first
#define S second
#define pb(x) push_back(x)a
#define mp(x, y) make_pair(x, y)

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void _debug(istream_iterator<string>) {}
template<typename T, typename... Args>
void _debug(istream_iterator<string> it, T first, Args... args) {
    cerr << ">> " << *it << " : " << first << endl; _debug(++it, args...);
}
template <typename T1, typename T2>
inline ostream& operator << (ostream& out, const pair<T1, T2>& p) {
    return out << "(" << p.F << ", " << p.S << ")";
}
template<typename T>
inline ostream& operator << (ostream& out, const vector<T>& v) {
    if (v.empty()) return out << "[]";
    else { out << '['; for (auto& e : v) { out << e << ", "; } return out << "\b\b]"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const set<T>& s) {
    if (s.empty()) return out << "{}";
    else { out << '{'; for (auto& e : s) { out << e << ", "; } return out << "\b\b}"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const unordered_set<T>& s) {
    return out << set<T>(ALL(s));
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const map<T1, T2>& m) {
    if (m.empty()) return out << "{}";
    out << '{'; for (auto& p : m) { out << p << ", "; } return out << "\b\b}";
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const unordered_map<T1, T2>& m) {
    return out << map<T1, T2>(ALL(m));
}
template<typename T>
inline ostream& operator << (ostream& out, const ordered_set<T>& s) {
    return out << set<T>(ALL(s));
}

typedef long long ll;
typedef long double ld;
typedef vector<long long> vll;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
typedef unordered_map<ll, ll> STll;
/************************************** MAIN PROGRAM ********************************************/

int main()
{
    //freopen("input.txt", "r", stdin);
    SPEED
    ll a; ld b;
    cin >> a >> b;
    b *= 100;
    b = round(b);
    ll B = b;
    ll ans = a * B / 100;
    cout << ans;
}
/************************************** END OF PROGRAM ******************************************/
/** Stuff you should look for:
 * int overflow, array bounds, over-counting
 * special cases (n=1?), set/unordered_set TLE, multi-set/set error
 * do something instead of nothing and stay organized
 */


Measured memory_bytes: 3768
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    if(k <= a)cout << k << endl;
    else if(k <= a + b)cout << a << endl;
    else cout << a - (k - a - b) << endl;
    
}

Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>

const int MOD = 1000000007;
typedef long long ll;
using namespace std;

int main() {
  int N, sa[52], ka[52], idx = 0;
  string s1, s2;
  cin >> N >> s1 >> s2;
  for (int i=0; i<N; i++) {
    if (s1[i] == s2[i]) {
      sa[idx++] = 1;
    } else {
      sa[idx++] = 2;
      i++;
    }
  }

  int pre = sa[0];
  ll ans = pre * 3, k;
  for (int i=1; i<idx; i++) {
    if (pre == 1) {
      k = 2;
    } else if (pre == 2) {
      if (sa[i] == 1) {
        k = 1;
      } else if (sa[i] == 2) {
        k = 3;
      }
    }
    pre = sa[i];
    ans *= k;
    ans %= MOD;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
vector<bool>visited;
vector<vector<int>>l;
vector<int>deg;
int isprime(ll n)
{
    ll i;
    for(i=2;i*i<=n;i++)
    {
        if(n%i==0)
            return 0;
    }
    return 1;

}
int isperfectsq(ll n)
{


    long double x;
    x=(long double)(sqrt((long double )(n)));
    ll y=sqrt(n);
    if(x==y)
        return 1;
        else
            return 0;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);


    char s;
    cin>>s;
    if(isupper(s))
    {
        cout<<'A';
    }
    if(islower(s))
    {
        cout<<'a';
    }



   }










Measured memory_bytes: 3664
#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 equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

const string a[4] = {"aabc",
                     "ccbc",
                     "abaa",
                     "abcc"};

const string b[5] = {"aabba", 
                     "bc..a",
                     "bc..b",
                     "a.ccb",
                     "abbaa"};

const string c[6] = {"aabb.a",
                     "bc...a",
                     "bc..bb",
                     "..bcaa",
                     "..bcb.",
                     "bbaab."}; 

const string d[7] = {"a..a..b",
                     "a..a..b",
                     ".aa.aac",
                     "a..a..c",
                     "a..a..b",
                     ".aa.aab",
                     "bbccbb."};

void print(int n) {
  if (n == 2) cout << "-1\n";
  else if (n == 3) {
    cout << "a..\n";
    cout << "a..\n";
    cout << ".aa\n";
  }
}

vector<vector<char>> s;

void solve(int n) {
  int res = 4 + n % 4;
  if (n % 4 == 0) rep(i, 4 + n % 4) rep(j, 4 + n % 4) s[i][j] = a[i][j];
  if (n % 4 == 1) rep(i, 4 + n % 4) rep(j, 4 + n % 4) s[i][j] = b[i][j];
  if (n % 4 == 2) rep(i, 4 + n % 4) rep(j, 4 + n % 4) s[i][j] = c[i][j];
  if (n % 4 == 3) rep(i, 4 + n % 4) rep(j, 4 + n % 4) s[i][j] = d[i][j];
  while (res < n) {
    rep(i, 4) rep(j, 4) s[i + res][j + res] = a[i][j];
    res += 4;
  }
  rep(i, n) {
    rep(j, n) cout << s[i][j];
    cout << '\n';
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  int n;
  cin >> n;

  if (n <= 3) {
    print(n);
    return 0;
  }
  s.resize(n, vector<char>(n, '.'));
  solve(n);






  
  return 0;
}

Measured memory_bytes: 4268
#include<bits/stdc++.h>
#define INF 0x7fffffff
const int N=200010;
using namespace std;
 
inline int read(){
	char ch=getchar();int x=0,f=1;
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
} 
//180W点 520W条边 n+m 20W 
struct edge{
	int v,nxt,w;
}e[N*40];
int head[N<<4],cnt;
long long inf;
int n,m,s;
 
void add(int u,int v,int w){
	e[++cnt].v=v;
	e[cnt].w=w;
	e[cnt].nxt=head[u];
	head[u]=cnt;
}
 
int tin[N<<4],tout[N<<4],temp;
long long dis[N<<4];
 
void build(int k,int l,int r){
	if(l==r){
		tin[k]=tout[k]=l;
		return ;
	}
	int mid=(l+r)>>1;
	build(k<<1,l,mid);
	build(k<<1|1,mid+1,r);
	tin[k]=++temp;tout[k]=++temp;
	add(tout[k<<1],tout[k],0);
	add(tout[k<<1|1],tout[k],0);
	add(tin[k],tin[k<<1],0);
	add(tin[k],tin[k<<1|1],0);
}
 
void update1(int k,int l,int r,int L,int R,int u,int w){
	if(L<=l&&r<=R){
		add(u,tin[k],w);
		return ;
	}
	int mid=(l+r)>>1;
	if(mid>=L){
		update1(k<<1,l,mid,L,R,u,w);
	}
	if(mid<R){
		update1(k<<1|1,mid+1,r,L,R,u,w);
	}
}
 
void update2(int k,int l,int r,int L,int R,int u,int w){
		if(L<=l&&r<=R){
		add(tout[k],u,w);
		return ;
	}
	int mid=(l+r)>>1;
	if(mid>=L){
		update2(k<<1,l,mid,L,R,u,w);
	}
	if(mid<R){
		update2(k<<1|1,mid+1,r,L,R,u,w);
	}
}
 
struct node{
	int u;
	long long d;
	bool operator<(const node&h)const{return d>h.d;};
};
 
void dij(){
	memset(dis,0x3f,sizeof(dis));
	inf=dis[1];
	priority_queue<node> q;
	dis[s]=0;
	q.push((node){s,0});
	while(!q.empty()){
		node now=q.top();
		int u=now.u;
		long long d=now.d;
		q.pop();
		if(d!=dis[u])continue;
		for(int i=head[u];i;i=e[i].nxt){
			int v=e[i].v,w=e[i].w;
			if(dis[v]>dis[u]+w){
				dis[v]=dis[u]+w;
				q.push((node){v,dis[v]});
			}
		}
	}
}
 
int main(){
	
	n=read(),m=read(),s=1;
	temp=n+m; 
	
	build(1,1,n+m);
	for(int i=1;i<=m;i++){
		int l=read(),r=read(),w=read();
		update1(1,1,n+m,l,r,n+i,0);
		update2(1,1,n+m,l,r,n+i,w);
	}
	dij(); 
	//cout<<inf<<endl;
	if(dis[n]!=inf){
		printf("%lld ",dis[n]);
	}
	else printf("-1 ");
	return 0;
}

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

int main(){
  int n,ans=0;
  cin>>n;
  for(int i=1;i>=0;i++){
    ans=i*1000-n;
    if(ans>=0&&ans<1000){
      cout<<ans<<endl;
      break;
    }
  }
}

Measured memory_bytes: 3620
main = do
  [hs,ms,h,m] <- map read . words <$> getLine :: IO [Double]
  putStrLn $ show $ nagasa hs ms h m
-- a2 + b2 - 2ab csin c
-- 度 × 円周率 ÷ 180

mpos m = (360 / 60) * m
hpos h m = ((360 / 12) * h) + (30 / 60) * m
kakudo h m = abs ( (mpos m) - (hpos h m) )
mCos h m = (kakudo h m) * pi / 180

nagasa hs ms h m = sqrt $ (hs ** 2) + (ms ** 2) - ( 2 * hs * ms * (cos (mCos h m)) )

Measured memory_bytes: 4420
#include<stdio.h>
int main(){int n,a,b,c,s;scanf("%d",&n);while(n--){scanf("%d %d %d",&a,&b,&c);if(a>b){s=a;a=b;b=s;}if(b>c){s=b;b=c;c=s;}printf("%s\n",a*a+b*b==c*c?"YES":"NO");}return 0;}

Measured memory_bytes: 1008
import sys
sys.setrecursionlimit(10**7)

n,m = map(int,input().split())

xy = [[] for i in range(n)]

for i in range(m):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    xy[x].append(y)
    #xy[y].append(x)
    
#xy = [[int(i)-1 for i in input().split()] for j in range(m)]
chk = [0]*n
dp = [0]*n

#print(xy)

def f(x):
    #global dp,chk
    if chk[x] == 1:
        return dp[x]
    fans = 0
    chk[x] = 1
    for i in range(len(xy[x])):
        fans = max(fans,f(xy[x][i])+1)
    dp[x] = fans
    #print(dp,chk)
    return dp[x]

ans = 0

for i in range(n):
    ans = max(ans,f(i))
    #print(f(i))
    
#print(dp)
print(ans)

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

int main() {
	
	string s; cin >> s;
	stack<char> st;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'B') {
			if (st.empty()) {}
			else {
				st.pop();
			}
		}
		else {
			st.push(s[i]);
		}
	}
	string ans = "";
	while (!st.empty()) {
		ans += st.top();
		st.pop();
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mp(x,y) make_pair(x,y)
const int nax=1e6+5;

void solve(){
    int n;
    cin>>n;
    n=n%10;
    if(n==3) cout<<"bon\n";
    else if(n==0 || n==1 || n==6 || n==8) cout<<"pon\n";
    else cout<<"hon\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int tc;
    tc=1;
    while(tc--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define N 10005
using namespace std;
typedef pair<int,int> P;
typedef pair<double,P> P1;
int n,m,x[N],y[N],p,q;
double cost,ans;
vector<P1> e;
int rank[N];
int par[N];
 
void init(){
  for(int i=0;i<n;i++)par[i]=i,rank[i]=0;
}
 
int find(int u){
  if(par[u]==u)return u;
  return par[u]=find(par[u]);
}
 
void unite(int u,int v){
  u=find(u);
  v=find(v);
  if(u==v)return;
  if(rank[u]<rank[v])par[u]=v;
  else{
    par[v]=u;
    if(rank[u]==rank[v])rank[u]++;
  }
}
 
bool same(int u,int v){
  return find(u)==find(v);
}
 
double getlen(int a,int b){
  double X=x[a]-x[b],Y=y[a]-y[b];
  return sqrt(X*X+Y*Y);
}
 
double kruskal(){
  sort(e.begin(),e.end());
  init();
  double res=0;
  for(int i=0;i<(int)e.size();i++){
    int u=e[i].second.first;
    int v=e[i].second.second;
    if(!same(u,v))unite(u,v),res+=e[i].first;
  }
  return -res;
}
 
int main(){
  cin>>n>>m;
  for(int i=0;i<n;i++)cin>>x[i]>>y[i];
  for(int i=0;i<m;i++){
    cin>>p>>q;
    e.push_back(P1(-getlen(--p,--q),P(p,q)));
    ans+=getlen(p,q);
  }
  ans-=kruskal();
  printf("%.8f\n",ans);
  return 0;
}

Measured memory_bytes: 1868
/*
 _     _    ___  ___  __ __ 
| |   | |  |__ \|__ \/_ /_ |
| |__ | |__   ) |  ) || || |
| '_ \| '_ \ / /  / / | || |
| |_) | |_) / /_ / /_ | || |
|_.__/|_.__/____|____||_||_|

*/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		ll n;
		cin>>n;
		cout<<(n-1)*n/2<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;

#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define emb emplace_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <typename T> inline T range(T l, T r) {
    return uniform_int_distribution<T>(l, r)(rng);
}

inline void setin(string s) {
    freopen(s.c_str(), "r", stdin);
}

inline void setout(string s) {
    freopen(s.c_str(), "w", stdout);
}

template <typename T> void Min(T &a, T b) {
    a = min(a, b);
}

template <typename T> void Max(T &a, T b) {
    a = max(a, b);
}

const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const int N = 2e3 + 15;
const int Q = 2e5 + 15;
int n, m, q, a[N][N];

struct query {
    int x1, y1, x2, y2;
} qs[Q];

inline bool lie(int l, int x, int r) {
    return l <= x && x <= r;
}

inline bool check(int x, int y) {
    return lie(1, x, n) && lie(1, y, m);
}

int p[N][N], hor[N][N], ver[N][N];

inline int get(int x1, int y1, int x2, int y2, int s) {
    if(x1 > x2 || y1 > y2)
        return 0;
    --x1, --y1;
    if(s == 0)
        return p[x2][y2] - p[x1][y2] - p[x2][y1] + p[x1][y1];
    if(s == 1)
        return hor[x2][y2] - hor[x1][y2] - hor[x2][y1] + hor[x1][y1];
    return ver[x2][y2] - ver[x1][y2] - ver[x2][y1] + ver[x1][y1];
}

main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // setin("input.txt");
    cin >> n >> m >> q;
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= m; ++j) {
            char c;
            cin >> c;
            a[i][j] = c - '0';
            p[i][j] = p[i-1][j] + p[i][j-1] - p[i-1][j-1] + a[i][j];
            hor[i][j] = hor[i-1][j] + hor[i][j-1] - hor[i-1][j-1] + (a[i][j] && a[i][j-1]);
            ver[i][j] = ver[i-1][j] + ver[i][j-1] - ver[i-1][j-1] + (a[i][j] && a[i-1][j]);
        }
    }
    for(int i = 1; i <= q; ++i) {
        cin >> qs[i].x1 >> qs[i].y1 >> qs[i].x2 >> qs[i].y2;
        int val = get(qs[i].x1, qs[i].y1, qs[i].x2, qs[i].y2, 0);
        val -= get(qs[i].x1, qs[i].y1 + 1, qs[i].x2, qs[i].y2, 1);
        val -= get(qs[i].x1 + 1, qs[i].y1, qs[i].x2, qs[i].y2, 2);
        cout << val << endl;
    }
    return 0;
}

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

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

    std::vector<long long> D;
    D.reserve(N);
    {
        long long d;
        for (int i = 0; i < N; ++i) {
            std::cin >> d;
            D.push_back(d);
        }
    }

    std::sort(D.begin(), D.end());

    const int idx = N / 2;
    const auto ret = D[idx] - D[idx - 1];
    
    std::cout << ret << std::endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define debug(x) cerr<<#x<<" = "<<x<<'\n'

using namespace std;

int n,vis[400],tot,dis[400],ans;
vector<int> g[400];
void bfs(int i) {
    queue<int> q;
    q.push(i);
    vis[i] = ++tot, dis[i] = 0;
    while(!q.empty()) {
        i = q.front(), q.pop();
        ans = max(ans,dis[i]);
        for(int j:g[i]) {
            if(vis[j] < tot) vis[j]=tot, dis[j]=dis[i]+1, q.push(j);
            else if((dis[i]&1) == (dis[j]&1)) cout << -1 << '\n', exit(0);
        }
    }
}
signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> n;
    for(int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for(int j = 0; j < n; j++) if(s[j]=='1') g[i].push_back(j);
    }
    for(int i = 0; i < n; i++) bfs(i);
    cout << ans+1 << '\n';
}


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


int main() {
    int N;
    cin >> N;
    vector<int> V(N);
    rep(i,N) {
        cin >> V[i];
    }
    sort(V.begin(),V.end());
    int ans = 0; 
    rep(j,N) {
        if (j != N - 1) {
            ans += V[j];
        }
        else {
            ans += V[j]/2;
        }
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 3592
n=int(input())
t=list(map(int,input().split()))
ans=0
for i in range(n-2):
    if t[i]<t[i+1] and t[i+1]<t[i+2]:
        ans+=1
    elif t[i+2]<t[i+1] and t[i+1]<t[i]:
        ans+=1
print(ans)

Measured memory_bytes: 3060
import math
from functools import reduce
K = int(input())
ans = 0

def gcd(*numbers):
    return reduce(math.gcd, numbers)
for a in range(1,K+1):
  for b in range(1,K+1):
    for c in range(1,K+1):
      ans = ans + gcd(a,b,c)
print(str(ans))

Measured memory_bytes: 74732