akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <cstdlib>
#include <algorithm>
#define INF (long long)1e9 + 7

//コメントアウトするとdebug()を実行しない
#define DEBUG

using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

ll N,ans = 1,inf = INF;

void solve(){

}

void debug(){

}

void answer(){
	cout << ans << "\n";
}

int main(){
	ios::sync_with_stdio(false);
	cin >> N;
	// cout << "INF " << INF  << "\n";
	for (long long i = 2; i < N+1; ++i)
	{
		ans = ans*i;
		// cout << i << ":" << ans << "\n";
		ans = ans % inf;
	}
	solve();
	#ifdef DEBUG
	debug();
	#endif
	answer();

	return 0;
}

Measured memory_bytes: 256
/*  ex9_1
	masaaki52	*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define SIZE 100

//スタックの定義
typedef  struct stack{
  int size;
  int count;
  char data[SIZE];
  char *top;
}stack;

//スタックの初期化
void initialize_stack(stack *stk){
  stk->count = 0;
  stk->size = SIZE;
  stk->top = &(stk->data[SIZE]);
}

//データの追加
void push(stack *stk,char elem){
  if(stk->count >= stk->size){
    exit(1);
  }
  else{
    stk->top--;
    *(stk->top) = elem;
    stk->count++;
  }
}

//データの取り出し
char pop(stack *stk){
  char latest;
  latest = *(stk->top);
  stk->top++;
  stk->count--;
  return latest;
}
    
int main(void){
  char string[11];
  stack stk;
  int i;
  initialize_stack(&stk);//stkの初期化
  scanf("%s",string);
  //Bでなかったらその文字をstkに入れ、Bだったらstkから1文字取る
  for(i=0;i<strlen(string);i++){
    if(string[i] != 'B'){
      push(&stk, string[i]);
    }
    else if(stk.count > 0){
      pop(&stk);
    }
  }
  //stk内の文字列の出力
  for(i=0;i<stk.count;i++){
    printf("%c",stk.data[SIZE-1-i]);
  }
  return 0;
}

Measured memory_bytes: 1640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////

#define N 10000
bool check(vector<ll>v,ll sum){
    //for(auto x:v)cout<<x<<" ";cout<<endl;
    //cout<<sum<<endl;
    ll n=v.size();
    bool dp[n+1][2*N];
    memset(dp,false,sizeof(dp));
    dp[0][N]=1;
    rep(i,0,n-1){
        rep(j,0,2*N-1){
            if(j-v[i]>=0)dp[i+1][j]|=dp[i][j-v[i]];
            if(j+v[i]<=2*N-1)dp[i+1][j]|=dp[i][j+v[i]];
        }
    }
    /*
    rep(i,0,n){
        rep(j,0,2*N-1){
            cout<<dp[i][j]<<" ";
        }cout<<endl;
    }*/
    if(dp[n][N+sum])return true;
    return false;
}



int main(){fastio
    string s;cin>>s;
    ll n;n=s.size();
    ll c=0;
    rep(i,0,n-1){
        if(s[i]=='F')c++;
        else break;
    }
    vector<ll>a,b;
    bool f=true;
    //cout<<c<<endl;
    rep(i,c+1,n-1){
        ll k=0;
        while(i<=n-1&&s[i]=='F'){
            k++;i++;
        }
        if(f)b.pb(k);
        else a.pb(k);
        f=1-f;
    }
    //for(auto x:a)cout<<x<<" ";cout<<endl;
    //for(auto x:b)cout<<x<<" ";cout<<endl;
    
    ll x,y;cin>>x>>y;
    x-=c;
    if(!check(a,x)){
        cout<<"No"<<endl;
    }else if(!check(b,y)){
        cout<<"No";
    }else{
        cout<<"Yes"<<endl;
    }
    
    
    
    return 0;
}


Measured memory_bytes: 77824
def f(a,b,c):
  if a%2 + b%2 + c%2 > 0:
    return 0 
  elif a == b and b == c:
    return -1
  else:
    return f((b+c)//2,(a+c)//2,(a+b)//2)+1
    
    
x,y,z = map(int,input().split())
print(f(x,y,z))

Measured memory_bytes: 3060
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{  static int hcf(int a, int b) {
		if (b == 0)
			return a;
		else
			return hcf(b, a % b);
	}

 static int hcf(int a, int b, int c) {

		return hcf(hcf(a, b), c);

	}
  public static void main (String[] args) throws java.lang.Exception
   {
	try{
	    Scanner sc=new Scanner(System.in);
		  int n=sc.nextInt();
		  long sum=0;
		  for(int i=1;i<=n;i++)
		    {
		       for(int j=1;j<=n;j++)
		         {
		            for(int k=1;k<=n;k++)
		              sum+=hcf(i,j,k);
		           }
		    }
		 System.out.println(sum); 
	   }     
	catch(Exception e)
		 {}
	}
}


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

void dfs(int v,ll a,int signT,ll &maxT,ll &minT,
    vector<P> &visited,vector<vector<P>> &g){
    if(visited[v] != P(0,0)){
        ll b = visited[v].first;
        int sign = visited[v].second;
        if(sign==signT && a!=b) maxT = 0;
        if(sign!=signT){
            if(abs(a-b)&1) maxT = 0;
            minT = max(minT, abs(a-b)/2);
            maxT = min(maxT, abs(a-b)/2);
        }
        return;
    }
    visited[v] = {a,signT};
    if(signT == +1) minT = max(minT, 1-a);
    if(signT == -1) maxT = min(maxT, a-1);
    for(P &e : g[v]){
        ll sum = e.first;
        int to = e.second;
        dfs(to,sum-a,-signT,maxT,minT,visited,g);
    }
}

int main(void){
    int n,m;
    cin>>n>>m;
    vector<vector<P>> g(n); // <sum,to>
    rep(i,m){
        int u,v;
        ll s;
        cin>>u>>v>>s;
        u--, v--;
        g[u].push_back({s,v});
        g[v].push_back({s,u});
    }
    ll maxT = INF, minT = 0;
    vector<P> visited(n); // <a,sign> (a + sign*t)
    dfs(0,0,+1,maxT,minT,visited,g);
    cout<<max(maxT-minT+1, 0LL)<<endl;
    return 0;
}



Measured memory_bytes: 18816
def fur(n, r, mod=10**9+7):
    work = (n-r+1)*r + 1
    return work%mod

N, K = map(int, input().split())
result = 0
mod = 10**9 + 7
for k in range(K, N+2):
    result += fur(N, k)
    result %= mod
print(result%mod)

Measured memory_bytes: 9192
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 1000000000
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, K, Q, A[2222], dm = INF;
  
  std::cin >> N >> K >> Q;

  std::map<int, std::vector<int>> map;

  for (int i = 0; i < N; i ++) {
    std::cin >> A[i];

    map[A[i]].push_back(i);
  }

  for (const auto& kv : map) {
    int m = kv.first;

    std::vector<int> a, b;

    for (int i = 0, j = 0; i < N; )
      if (A[i] < m) {
        std::sort(ALL(b));

        for (int k = 0; k < static_cast<int>(b.size()) - K + 1; k ++)
          a.push_back(b[k]);

        b.clear();
        
        i = j = i + 1;
      }
      else {
        b.push_back(A[i]);

        i ++;
      }

    if (! b.empty()) {
      std::sort(ALL(b));

      for (int k = 0; k < static_cast<int>(b.size()) - K + 1; k ++)
        a.push_back(b[k]);
    }

    std::sort(ALL(a));
      
    if (a.size() >= Q) {
      int d = a[Q - 1] - a[0];

      dm = std::min(d, dm);
    }
  }

  std::cout << dm << std::endl;
  
  return 0;
}
 


Measured memory_bytes: 640
n = int(input())
ans = 0
def dfs(s):
    global ans
    if int(s) > n:
        return
    seven = 0
    five = 0
    three = 0
    for i in range(len(s)):
        if s[i] == "7":
            seven = 1
        elif s[i] == "5":
            five = 1
        elif s[i] == "3":
            three = 1
    if seven == 1 and five == 1 and three == 1:
        ans += 1

    dfs(s + "7")
    dfs(s + "5")
    dfs(s + "3")
    return
dfs("7")
dfs("5")
dfs("3")
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
	long long n,m,sum;
	while(scanf("%lld%lld",&n,&m)!=EOF)
	{
		if(n*2>=m)
		{
			sum=m/2;
			printf("%lld\n",sum);
			continue;
		}
		sum=n;
		m=m-2*n;
		sum=sum+m/4;
		printf("%lld\n",sum);
	}
	return 0;
}

Measured memory_bytes: 128
from math import sqrt
a,b=input().split()
a=int(a)
b=int(b)
ll=[]
ans=0
for i in range(a):
  x=input().split()
  x=[int(i) for i in x]
  ll.append(x)
for i in ll:
  s=0
  for j in ll:
    if i==j:
      s=1
      continue
    elif s==0:
      continue
    x=0
    for k in range(b):
      x+=(i[k]-j[k])**2
    if sqrt(x)%1==0:
      ans+=1
print(ans)



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

using namespace std;

const double EPS = 1e-7;
const int N = 1e3+5, M = 9e3+5, OO = 0x3f3f3f3f;
typedef long long ll;

int gcd(int a, int b){
    if(b)   return gcd(b, a%b);
    else return a;
}

//ll fixMod(ll a, ll b){
//    return (a%b + b)%b;
//}
//
//void pushBack(ll& h, ll base, ll mod, char c){
//    h = ((h*base)%mod + c)%mod;
//}
//
//void pushFront(ll& h, ll p, ll mod, char c){
//    h = (h + (c*p)%mod)%mod;
//}
//
//void popFront(ll& h, ll p, ll mod, char c){
//    h = fixMod((h - (p*c)%mod), mod);
//}
//
//void popBack(ll& h, ll inv, ll mod, char c){
//    h = (fixMod(h-c, mod)*inv)%mod;
//}
//
//ll power(ll a, ll b, ll m){
//    if(!b)  return 1;
//    ll t = power(a, b>>1, m);
//    return ((t*t)%m * (b&1 ? a : 1))%m;
//}

ll getDivisors(ll n){       //O(n)
    ll mx=0;
    for(ll i = 1 ; i <= n ; ++i)
        if(n%i == 0)   mx=max(mx, i);
    return mx;
}


vector<pair<ll, ll>> factorize(ll n){
    vector<pair<ll, ll> > ret;
    for(ll p = 2 ; p <= n/p ; ++p){
        int e = 0;
        while(n%p == 0){
            n /= p;
            ++e;
        }
        if(e)   ret.push_back({p, e});
    }
    if(n > 1)   ret.push_back({n, 1});
    return ret;
}
vector <int> adj[N];
int n,m,A[N];
int x,y,u;
int bit;

int mem[N][M];
int solve(int lst, int sum){
    if(sum == bit) return 0;
    if(lst<0) return OO;

    int& ret= mem[lst][sum];
    if(~ ret) return ret;

    ret = solve(lst-1, sum);

    for(int x: adj[lst]){
        int z = 1<<x;
        sum |= z;
    }
    return ret = min(ret, (solve(lst-1 , sum) + A[lst]));


}



int main(){
//    freopen("araf_bara.txt", "wt", stdout);
    cin>>n>>m;
    for(int i=1 ; i<=n; i++){
        bit |= 1<<i;

    }
    memset(mem, -1, sizeof mem);
    for(int i=0; i<m; i++){
        cin>>x>>y;
        A[i]=x;
        for(int j=0; j<y; j++){
            cin>>u;
            adj[i].push_back(u);
        }
    }
    int ans =solve( m-1, 0);
    if(ans<OO)cout<<ans<<endl;
    else cout<<-1<<endl;

}


Measured memory_bytes: 35712
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        //static long Mod = (long)1e9 + 7;
        static List<long>[] tree;
        static long[] query;
        static bool[] cmp;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NQ = Sarray();
            var N = NQ[0];
            var Q = NQ[1];
            tree = new List<long>[N];
            for (var i = 0; i < N; ++i)
                tree[i] = new List<long>();
            for (var i = 0; i < N - 1; ++i)
            {
                var ab = Sarray();
                var a = ab[0] - 1;
                var b = ab[1] - 1;
                tree[a].Add(b);
                tree[b].Add(a);
            }
            query = new long[N];
            for (var i = 0; i < Q; ++i)
            {
                var px = Sarray();
                var p = px[0] - 1;
                var x = px[1];
                query[p] += x;
            }
            cmp = new bool[N];
            dfs(0);
            WriteLine(string.Join(" ", query));
            //Out.Flush();
        }
        static void dfs(long r)
        {
            cmp[r] = true;
            for (var i = 0; i < tree[r].Count; ++i)
            {
                var c = tree[r][i];
                if (cmp[c]) continue;
                query[c] += query[r];
                dfs(c);
            }
        }
    }
}


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

const int MOD = 1000000007;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define PI 3.14159265359
int main()
{
    /*A
    int n;
    cin>>n;
    int x = n%10;
    if(x==2||x==4 ||x==5|| x==7|| x==9)
    {
        cout<<"hon"<<endl;
    }
    else if(x==0||x==1||x==6||x==8)
    {
        cout<<"pon"<<endl;
    }
    else
    {
        cout<<"bon"<<endl;
    }
    */
    /*B
    int k;
    string s;
    cin>>k>>s;
    if(s.size()>k)
    {
        for(int i=0;i<k;i++)
        {
            cout<<s[i];
        }
        cout<<"..."<<endl;
    }
    else
    {
        cout<<s<<endl;
    }
    */
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    double m_angle=m*6;   //分針の真上からの角度(時計回り)
    double h_angle=30*h+m/2;  //時針の真上からの角度(時計回り)
    double hm_angle =0;
    if(m_angle>=h_angle)
    {
        hm_angle=m_angle-h_angle;
    }
    else
    {
        hm_angle=h_angle-m_angle;
    }
    
    cout<<setprecision(14)<<sqrt(a*a+b*b-2*a*b*cos(hm_angle*2*PI/360))<<endl;;

    return 0;
}

Measured memory_bytes: 4212
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e18);
const ll mod = ll(1e9+7);
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")
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; }
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,1,-1};

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll ans = 1;
    rep1(i, n){
        ans *= i;
        ans %= mod;
    }
    return ans;
}

ll power(ll a, ll b){
    ll ans = 1;
    a %= mod;
    while(b) {
        if(b & 1LL) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans % mod;
}

std::ostream &operator<<(std::ostream &dest, __int128_t value) {
  std::ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = std::end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = std::end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(std::ios_base::badbit);
    }
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < s.length(); i++)
    if ('0' <= s[i] && s[i] <= '9')
      ret = 10 * ret + s[i] - '0';
  return ret;
}

//modの値の確認をすること
int main(){
    ll n,N,ans = 0;
    cin >> n;
    N = n;
    if(n == 1){
        pf(0);
        return 0;
    }
    
    for (ll i = 2; i * i <= n; i++){
        ll cnt = 0;
        while (n % i == 0){
            n /= i;
            ++cnt;
        }
        rep1(i, cnt){
            ++ans;
            cnt -= i;
        }
    }
    if(n != 1)++ans;
    pf(ans);
    return 0;
}


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

int main(){
  constexpr int Nbit= 1e5;
  int N,M;
  cin >> N >> M;

  bitset<Nbit> ACs;
  vector<int> WAs(N);

  int prob; string status;
  for(int i=0; i<M; i++){
    cin >> prob >> status;
    prob--; // 1-indexed -> 0-indexed
    if(status=="AC"){
      ACs.set(prob);
    }
    else if(!ACs.test(prob)){
      WAs.at(prob)++;
    }
  }

  int penalty= 0;
  for(int i=0; i<N; i++){
    if(ACs.test(i)){
      penalty+= WAs.at(i);
    }
  }
  
  cout << ACs.count() <<" "<< penalty << endl;
}

Measured memory_bytes: 3784
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N; cin>>N;
  vi A(N);
  rep(i,0,N) cin>>A[i];
  int ans=0;
  rep(i,0,N){
    if(A[A[i]-1]-1==i) ans++;
  }
  cout<<ans/2<<endl;
  }


Measured memory_bytes: 1024
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
#include <vector>

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

using namespace std;

template <class T>
T peak_and_pop(std::queue<T>& q)
{
    assert(!q.empty());
    T t = move(q.front());
    q.pop();
    return t;
}

struct edge_t {
    edge_t(int n, int d):next(n),distance(d){}
    int next = 0;
    int distance = 0;
};

constexpr int no_color = 2;

struct node_t {
    int color = no_color;
    vector<edge_t> edges;
};

void solution()
{
    int n;
    cin >> n;
    vector<node_t> nodes(n);

    const auto connect = [&](int u, int v, int w){
        nodes[u].edges.emplace_back(v, w);
        nodes[v].edges.emplace_back(u, w);
    };

    rep(i,n-1){
        int u,v,w;
        cin >> u >> v >> w;
        connect(u-1, v-1, w);
    }

    queue<int> visit_queue;
    visit_queue.push(0);
    nodes[0].color = 0;
    while(!visit_queue.empty()){
        auto& node = nodes.at(peak_and_pop(visit_queue));
        assert(node.color != no_color);
        for(auto& e : node.edges){
            if(nodes[e.next].color == no_color){
                if(e.distance % 2 == 0){
                    nodes[e.next].color = node.color;
                }
                else{
                    nodes[e.next].color = 1 - node.color;
                }
                visit_queue.push(e.next);
            }
        }
    }
    rep(i,n){
        cout << nodes[i].color << '\n';
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solution();
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  
  int i;
  string a;
  int b, c;
  vector<tuple<string, int, int>> t(n);
  for(i = 0; i < n; i++){
    c = i + 1;
    cin >> a >> b;
    b *= -1;
    t.at(i) = make_tuple(a, b, c);
  }
  
  sort(t.begin(), t.end());
  
  for(i = 0; i < n; i++){
    tie(a, b, c) = t.at(i);
    cout << c << endl;
  }
}

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

int main()
{
    int a, b, c, d;
    
    cin >> a >> b >> c >> d;
    
    if((a+b) > (c+d)) {
        cout << "Left\n";
    } else if((a+b) < (c+d)) {
        cout << "Right\n";
    } else {
        cout << "Balanced\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint(), M = getint();

	int kosuu[100001];
	bool joutai[100001] = {};
	rep1(i, N) kosuu[i] = 1;
	joutai[1] = 1;

	rep(i, M) {
		int x = getint(), y = getint();

		kosuu[x]--;
		joutai[y] |= joutai[x];
		if (!kosuu[x]) joutai[x] = 0;
		kosuu[y]++;
	}

	int kotae = 0;
	rep1(i, N) if (joutai[i]) kotae++;
	printf("%d", kotae);

	Would you please return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;
const int MOD = 1000000007; // 計算してからmodで割る ans = (ans * a) % mod
#define int long long
template <typename T = long long > T in () { T x; cin >> x; return(x);}
// int a = in() のように使うlong long以外の型の時はstirng s = in<string>()のように型を指定する

signed main(void){
    int n, m; cin >> n >> m;
    int kakuritsu = pow(2, m);
    int ans = (n - m) * 100 + m * 1900;
    ans *= kakuritsu;
    cout << ans << endl;
}

Measured memory_bytes: 256
H,W,K = map(int,input().split())
MOD = 10**9+7

if W == 1:
    print(1)
    exit()

dp = [[0]*W for i in range(H+1)]
dp[0][0] = 1
for i in range(H):
    for b in range(2**(W-1)):
        if '11' in bin(b): continue
        b *= 2
        for j in range(W):
            if b&(1<<j):
                dp[i+1][j-1] += dp[i][j]
            elif b&(1<<(j+1)):
                dp[i+1][j+1] += dp[i][j]
            else:
                dp[i+1][j] += dp[i][j]
print(dp[-1][K-1] % MOD)

Measured memory_bytes: 3064
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


def is_yymm(f, l):
    if 1 <= l <= 12:
        return True
    return False


def is_mmyy(f, l):
    if 1 <= f <= 12:
        return True
    return False


s = S()
f = int(s[:2])
l = int(s[2:])

if is_yymm(f, l) and is_mmyy(f, l):
    print('AMBIGUOUS')

elif is_yymm(f, l) and not(is_mmyy(f, l)):
    print('YYMM')

elif not(is_yymm(f, l)) and is_mmyy(f, l):
    print('MMYY')

else:
    print('NA')


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

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

fn main() {
    let a: u32 = read();
    let b: u32 = read();

    println!("{} {}", a*b, a*2+b*2);
}



Measured memory_bytes: 5020
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

int main(){
    int w,h,x,y;
    cin>>w>>h>>x>>y;
    cout<<fixed << setprecision(10) << (double)w * h / 2<<" "<<(x*2==w&&y*2==h?1:0)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<climits>

using namespace std;
typedef unsigned long long ll;

const int mod=1000000007;

int n,m,u,v,f;
int ma[102][102];
int invite[102];

int dfs(int cur, int in){
    if(cur==n){
        if(in<2)return 0;
        int tot=0;
        for(int i=0;i<in;i++){
            int t=INT_MAX;
            for(int j=0;j<in;j++){
                if(i!=j){
                    t=min(t,ma[invite[i]][invite[j]]);
                }
            }
            tot+=t;
        }
        return tot;
    }
    int ret=dfs(cur+1,in);
    bool ok=true;
    for(int i=0;i<in;i++){
        if(ma[cur][invite[i]]==0){
            ok=false;
        }
    }
    if(ok){
        invite[in]=cur;
        ret=max(dfs(cur+1,in+1),ret);
    }
    return ret;
}

int main(){
    cin>>n>>m;
    memset(ma,0,sizeof(ma));
    for(int i=0;i<m;i++){
        cin>>u>>v>>f;
        ma[u-1][v-1]=f;
        ma[v-1][u-1]=f;
    }
    cout<<dfs(0,0)<<endl;
}

Measured memory_bytes: 1212
from itertools import permutations
from math import ceil

times = list(int(input()) for _ in range(5))
orders = list(permutations(times, 5))
minimum = sum(ceil(time/10)*10 for time in times)

for order in orders:
    cnt = order[0]
    for i in range(1, 5):
        cnt += ceil(order[i]/10)*10
    minimum = min(minimum, cnt)
print(minimum)


Measured memory_bytes: 9040
#include "bits/stdc++.h"
using namespace std;

long long MOD = 1000 * 1000 * 1000 + 7;

int main() {
 
	long long n, k;
	cin >> n >> k;
	
	long long arr[n];
	for (int i=0; i<n; i++) cin >> arr[i];
	
	long long within = 0;
	for (int i=0; i<n; i++) {
		for (int j=i+1; j<n; j++) {
			if (arr[j] < arr[i]) {
				within++;
			}
		}
	}
	
	long long fully = 0;
	for (int i=0; i<n; i++) {
		int at = arr[i];
		for (int j=0; j<n; j++) {
			if (at > arr[j]) {
				fully++;
			}
		}
	}
	
	long long app = ((k - 1) * k / 2) % MOD;
	long long res = (fully * app) % MOD;
	long long res2 = (within * k) % MOD;
	
	cout << (res + res2) % MOD << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip> // 文字幅の指定 setw(int), 詰めたい文字の指定 setfill(char)
#include <algorithm> // sort
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define p(x) cout << (x) << endl
#define FOR(i,r,n) for(ll i=(ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n); i>=r; i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) REP(i,0,n)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pb push_back

// 定義する？→左揃えで0埋め
// cout << setfill('0') << left << setw(4) << 12; // "0012"
// http://marycore.jp/prog/cpp/padding-left-right-zero/

const int inf = (int)1e9;
const ll INF = (ll)1e18;

// vectorの中身をcout << vs;で表示
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v)
{
    o << "{";
    for (int i = 0; i < (int)v.size(); i++) o << (i > 0 ? ", " : "") << v[i];
    o << "}";
    return o;
}

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

ll lcm (ll a, ll b) {
	return (a / gcd (a, b)) * b;
}

bool is_prime (ll n) {
		if (n < 2) return false;
		else if (n == 2) return true;
		else if (n % 2) return false;
		
		double sqrtn = sqrt(n);
		for (ll i = 3; i < sqrtn; i += 2) {
			if (n % i == 0) return false; 
		}
		return true;
}

ll ctoi(char c) {
	return (ll)(c - 48);
}

ll n, k, cnt=0, ans=0;
string s,t;

// ==================== template ============================

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

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

	ll c = a + k -1;
	ll d = b - k + 1;
	if (c < d) {
		FOR(i, a, c+1) {
			p(i);
		}
		FOR(i, d, b+1) {
			p(i);
		}
	} else {
		FOR(i, a, b+1) {
			p(i);
		}

	}
}



Measured memory_bytes: 256
n ,m, c = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int,input().split())) for i in range(n)] 
    

count = 0
for i in A:
    numberSum = c
    for a, b in zip(i, B):
      numberSum += (a * b)  
    if numberSum > 0:
        count += 1
print(count)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
 
#define rep(i,n) for(int i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;

int n,m,q;
vector<int> a,b,c,d;
int ans;

void dfs(vector<int> A){
    if(A.size() == n){
        int now = 0;
        rep(i,q) {
            if(A[b[i]-1] - A[a[i]-1] == c[i]) now += d[i];
        }
        ans = max(ans,now);
        return;

    }

    A.push_back(A.back());
    while(A.back() <= m){
        dfs(A);
        A.back()++;
    }

}

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

    cin >> n >> m >> q;
    a = b = c = d = vector<int> (q);

    rep(i,q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    dfs(vector<int> (1,1));
    cout << ans << endl;

    cout << endl;
    return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define MOD 1000000007
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(v) (v).begin() , (v).end()
#define sumof(v) accumulate(all(v), 0LL, plus<ll>())
#define maxof(v) max_element(all(v))
#define minof(v) min_element(all(v))
#define inf INT_MAX

int main(){
    FASTIO
    int n; cin>>n;
    string s; cin>>s;
    int rCount = 0;
    for(int i=0; i<s.length(); ++i){
        if(s[i]=='R') rCount++;
    }
    int changes = 0;
    for(int i=0; i<rCount; ++i){
        if(s[i]=='W') changes++;
    }
    cout<<changes<<endl;
}

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

typedef long long ll;
typedef pair<int,int> pii;

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  int N; cin >> N;

  int k = 0;
  for(int i = 1; i <= N + 1; i++){
    if(i * (i-1) == 2 * N){
      k = i;
    } 
  }

  if(k==0){
    cout << "No" << endl;
    return 0;
  }

  vector<vector<int>> v(k);

  int index = 1;
  for(int i = 0; i < k; i++){
    for(int j = i+1; j < k; j++){
      v[i].push_back(index);
      v[j].push_back(index);
      index++;
    }
  }

  cout << "Yes" << endl;
  cout << k << endl;
  for(int i = 0; i < k; i++){
    cout << v[i].size() << " ";
    for(int j = 0; j < v[i].size(); j++){
      if(j == v[i].size()-1){
        cout << v[i][j] << endl;
      } else {
        cout << v[i][j] << " ";
      }
    }
  }
}


Measured memory_bytes: 4436
#include <iostream>

using namespace std;

int main(){
    int H, W;
    int N;
    cin >> H >> W;
    cin >> N;
    int a[10000];
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    int c[100][100];
    int cnt = a[0];
    int tmp = 1;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(i%2 == 0){
                c[i][j] = tmp;
            }else{
                c[i][W-j-1] = tmp;
            }
            cnt--;
            if(cnt == 0){
                tmp++;
                cnt = a[tmp-1];
            }
        }
    }
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cout << c[i][j];
            if(j < W-1) cout << ' ';
        }
        cout << endl;
    }
}

Measured memory_bytes: 384
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
    x1, y1, x2, y2, x3, y3 = map(int, readline().split())
    if x1 == y1 == x2 == y2 == x3 == y3 == 0:
        return False
    d12 = ((x1-x2)**2 + (y1-y2)**2)**.5
    d23 = ((x2-x3)**2 + (y2-y3)**2)**.5
    d31 = ((x3-x1)**2 + (y3-y1)**2)**.5
    e1 = ((x1, y1), ((x2-x1)/d12, (y2-y1)/d12), ((x3-x1)/d31, (y3-y1)/d31))
    e2 = ((x2, y2), ((x3-x2)/d23, (y3-y2)/d23), ((x1-x2)/d12, (y1-y2)/d12))
    e3 = ((x3, y3), ((x1-x3)/d31, (y1-y3)/d31), ((x2-x3)/d23, (y2-y3)/d23))
    def calc(e, x):
        p0, p1, p2 = e
        x0, y0 = p0; x1, y1 = p1; x2, y2 = p2
        xc = (x1 + x2)/2; yc = (y1 + y2)/2; dc = (xc**2 + yc**2)**.5
        cv = (x1*xc + y1*yc)/dc
        sv = (x1*yc - y1*xc)/dc
        d = x / cv
        return (x0 + xc * d / dc, y0 + yc * d / dc), x * sv / cv

    EPS = 1e-8
    def check(p0, r0):
        x0, y0 = p0
        left = 0; right = min(d12, d23)
        while right - left > EPS:
            mid = (left + right) / 2
            (x1, y1), r1 = calc(e2, mid)
            if (x0-x1)**2 + (y0-y1)**2 < (r0+r1)**2:
                right = mid
            else:
                left = mid
        (x1, y1), r1 = calc(e2, left)
        left = 0; right = min(d23, d31)
        while right - left > EPS:
            mid = (left + right) / 2
            (x2, y2), r2 = calc(e3, mid)
            if (x0-x2)**2 + (y0-y2)**2 < (r0+r2)**2:
                right = mid
            else:
                left = mid
        (x2, y2), r2 = calc(e3, left)
        return (x1-x2)**2 + (y1-y2)**2 < (r1+r2)**2, r1, r2

    left = 0; right = min(d12, d31)
    while right - left > EPS:
        mid = (left + right) / 2
        p0, r0 = calc(e1, mid)
        if check(p0, r0)[0]:
            left = mid
        else:
            right = mid
    p0, r0 = calc(e1, right)
    e, r1, r2 = check(p0, r0)

    write("%.16f %.16f %.16f\n" % (r0, r1, r2))
    return True
while solve():
    ...


Measured memory_bytes: 5724
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    string s;
    cin >> s;
    int n = s.size();

    int t = n-1;
    ll ans = 0;
    for(int i = n-1; i >= 0; i--) {
        if(s[i] == 'B') {
            ans += t-i;
            t--;
        }
    }

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

Measured memory_bytes: 640
N,M=map(int,input().split())
A=[]
for i in range (N):
	A.append(list(map(int,input().split())))
B=[]
count=0
ans=0
for i in range (N):
	for j in range (1,A[i][0]+1):
		B.append(A[i][j])
for i in range (M+1):
	count=0
	for j in range (len(B)):
		if B[j]==i:
			count+=1
	if count==N:
		ans+=1
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
#include<tuple>
#include<numeric>
#include<map>
#include<cmath>
#define ll long long
#define rep(i,n) for(int i=0;i<(int) (n);i++)
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
using namespace std;
int main(){
  int n,ac=0,wa=0,tl=0,re=0;
  cin>>n;
  rep(i,n){
    string s;
    cin>>s;
    if(s=="AC")ac++;
    if(s=="WA")wa++;
    if(s=="TLE")tl++;
    if(s=="RE")re++;
  }

  cout<<"AC x "<<ac<<endl;
  cout<<"WA x "<<wa<<endl;
  cout<<"TLE x "<<tl<<endl;
  cout<<"RE x "<<re<<endl;

  return 0;
}


Measured memory_bytes: 3628
#include <cstdio>
#define FOR(i,a,b) for(int i=a;i<=b;++i)

const int N=2005;
const int P=924844033;
int n,k,a[N],fac[N];
long long f[N][N][2][2];
bool vis[N];

int main() {
	scanf("%d%d",&n,&k);
	fac[0]=1;
	FOR(i,1,n) fac[i]=1LL*fac[i-1]*i%P;
	int tot=0;
	FOR(i,1,n) if(!vis[i]) for(int j=i;j<=n;j+=k) vis[j]=1,a[++tot]=j;
	f[0][0][0][0]=1;
	a[0]=-k-1; a[n+1]=k-1;
	FOR(i,1,n) {
		f[i][0][0][0]=1;
		FOR(j,1,i) {
			f[i][j][0][0]=(f[i-1][j][1][0]+f[i-1][j][0][0]+(a[i]-a[i-1]==k)*f[i-1][j-1][0][0])%P;
            f[i][j][0][1]=(a[i+1]-a[i]==k)*(f[i-1][j-1][1][0]+f[i-1][j-1][0][0])%P;
            f[i][j][1][0]=(f[i-1][j][0][1]+f[i-1][j][1][1]+(a[i]-a[i-1]==k)*f[i-1][j-1][0][1])%P;
            f[i][j][1][1]=(a[i+1]-a[i]==k)*(f[i-1][j-1][0][1]+f[i-1][j-1][1][1])%P;
		}
	}
	int ans=0;
	FOR(i,0,n) {
		int sum=(f[n][i][0][0]+f[n][i][0][1]+f[n][i][1][0]+f[n][i][1][1])%P;
		if(i&1) (ans+=P-1LL*sum*fac[n-i]%P)%=P;
		else (ans+=1LL*sum*fac[n-i]%P)%=P;
	}
	printf("%d\n",ans);
	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(int i=x;i<y;i++)
#define frr(i,x,y) for(int i=x-1;i>=y;i--)
#define inf 1e18+1
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

void solve()
{
    ll n;
    cin>>n;
    map<PLL,ll>mp;
    ll ct=0;
    fr(i,1,n+1){
        ll x=i;
        ll last=x%10;
        ll first=-1;
        while(x>0)
        {
            first=x%10;
            x/=10;
        }
        if(first!=0&&last!=0){
        ct+=2*mp[{last,first}];
        if(first==last)
            ct++;
        mp[{first,last}]+=1;
        }
    }
    cout<<ct<<endl;
    return;
}
int main()
{
    IOS;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        //cout<<"Case #"<<pp-t<<":\n";
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
*/
/*
recursion - matrix exponential

*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithm

Measured memory_bytes: 3652
/*
 * cpp_filepath
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }


void solve() {
  int n, x;
  cin >> n >> x;
  vector<int> M(n);
  loop(i,0,n) cin >> M[i];
  loop(i,0,n) x -= M[i];
  int min_ = M[0];
  loop(i,1,n) if (min_ > M[i]) min_ = M[i];
  cout << n + (x / min_) << endl;
}


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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

#define all(a) (a).begin(),(a).end()
#define loop(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) for(ll i=0;i<(n);++i)
#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int N, K; in(N); in(K);

  vvi neta(N);
  vi max_of(N, -1), rest;
  rep(i, N) {
    int t, d; in(t); in(d);
    --t;
    neta[t].push_back(d);
  }

  rep(i, N) {
    if (neta[i].size() == 0)
      continue;
    sort(neta[i].rbegin(), neta[i].rend());
    max_of[i] = neta[i][0];
    loop(j, 1, neta[i].size()) {
      rest.push_back(neta[i][j]);
    }
  }

  sort(max_of.rbegin(), max_of.rend());
  sort(rest.rbegin(), rest.rend());

  ll ans = 0, now = 0;
  rep(i, min((int)rest.size(), K))
    now += rest[i];

  rep(i, K) {
    if(max_of[i] == -1)
      break;
    now += max_of[i];
    if (K - (i+1) < rest.size())
      now -= rest[K - (i+1)];
    chmax(ans, (ll)now + (i+1)*(i+1));
  }
  out(ans);
  return 0;
}


Measured memory_bytes: 6144
#include <cstdio>
#include <utility>
#include <set>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
//_sc(string &s){int c;s="";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
//_vo(string &s){for(char c:s)pcu(c);}
//_vo(string s){for(char c:s)pcu(c);}
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
//_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	multiset<int> A;
	for (int i = in(); i; i--)
		switch(in()) {
		case 0:
			A.insert(in());
			outl(A.size());
			break;
		case 1:
			outl(A.count(in()));
			break;
		case 2:
			A.erase(in());
			break;
		default:
			auto i = A.lower_bound(in()), e = A.upper_bound(in());
			for (; i != e; i++)
				outl(*i);
		}
}


Measured memory_bytes: 11748
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
//#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const ll M=1000000007;
const ll MM=998244353;
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";

 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  if(a<=0)return 0;
  a%=m;
  if(!b)return 1;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}


 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;

}

template<typename T,typename F>
void chmax( T &a,F b){
  if(b>a)a=b;
}

template<typename T,typename F>
void chmin( T &a,F b){
  if(b<a)a=b;
}




const ll N=1e5+5;

ll sp[N];

void sieve(){
  for(int i=1;i<N;i++)sp[i]=i;

    for(int i=2;i<N;i++){
      if(sp[i]==i){
        for(int j=i*i;j<N;j+=i){
          if(sp[j]==j)sp[j]=i;
        }
      }
    }
}

  

int main()
{ 

IOS;

ll n;
cin>>n;

vl a(n+5);

FOR(i,n)cin>>a[i+1];

ll tot=1000;

a[0]=500000;

a[n+1]=-1;

ll x=0;

ll ans=1000;


for(int i=1;i<=n;i++){
  if(a[i]<=a[i-1]&&a[i]<a[i+1]&&!x){
       x=tot/a[i];
    ll spent=x*a[i];
    tot-=spent;
    assert(tot>=0);
  }
  else if(a[i]>=a[i-1]&&a[i]>a[i+1]){
       tot+=x*a[i];
       x=0;
  }
  ans=max(ans,tot);
//d2(x,tot);
}



cout<<ans;


//end_routine();

return 0;
 
}


Measured memory_bytes: 3660
let rec gcd (a : int64) (b : int64) =
    match b with
    | 0L -> a
    | _ -> gcd b (a % b)

let a, b = stdin.ReadLine().Split() |> fun x -> int64 x.[0], int64 x.[1]
a * b / gcd a b |> printfn "%d"

Measured memory_bytes: 14044
#include<stdio.h>
#include<stdlib.h>
#define MAX 100001
#define NIL -1
typedef struct{
  int p;
  int l;
  int r;
}Node;
Node T[MAX];
int n,D[MAX];
int rec(int,int);
void print(int);

int main()
{
  int i,j,d,v,c,l,r;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      T[i].p=T[i].l=T[i].r=NIL;
    }
  for(i=0;i<n;i++)
    {
      scanf("%d%d",&v,&d);

      for(j=0;j<d;j++)
        {
          scanf("%d",&c);
          if(j==0)T[v].l=c;
          else T[l].r=c;
          l=c;
          T[c].p=v;
        }
    }


  for(i=0;i<n;i++)
    {
      if(T[i].p==NIL)r=i;
    }
  rec(r,0);
  for(i=0;i<n;i++)print(i);
  return 0;
}

void print(int u)
{
  int i,c;
  printf("node %d: parent = %d, depth = %d",u,T[u].p,D[u]);

  if(T[u].p==NIL)printf(", root");
  else if(T[u].l==NIL)printf(", leaf");
  else printf(", internal node");
  printf(", [");
  for(i=0,c=T[u].l ; c!=NIL ; i++,c=T[c].r)
    {
      if(i)printf(", ");
      printf("%d",c);
    }
  printf("]\n");
}
int rec(int u,int p)
{
  D[u]=p;
  if(T[u].r!=NIL)rec(T[u].r,p);
  if(T[u].l!=NIL)rec(T[u].l,p+1);
}


Measured memory_bytes: 6428
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=3005;
int r,c,k;
int val[M][M];
int dp[M][M][4];
int solve(int x,int y,int cnt)
{
    if(x>r || y>c)return 0;
    if(x==r && y==c)
    {
        if(cnt<3)return val[r][c];
        else return 0;
    }
    int &ret=dp[x][y][cnt];
    if(ret!=(-1))return ret;
    ret=solve(x+1,y,0);
    ret=max(ret,solve(x,y+1,cnt));
    if(cnt<3)
    {
        ret=max(ret,solve(x,y+1,cnt+1)+val[x][y]);
        ret=max(ret,solve(x+1,y,0)+val[x][y]);
    }
    return ret;
}
 main()

{
    fast
    memset(dp,-1,sizeof dp);
    cin>>r>>c>>k;
    f(i,1,k)
    {
        int x,y,v;
        cin>>x>>y>>v;
        val[x][y]=v;
    }
    int ses=solve(1,1,0);
    cout<<ses<<endl;
    return 0;

}





































Measured memory_bytes: 356696
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
  int tt=1,rr=0;
  int r[672];
  long long n,i,res=0;
  long long t[2019];
  string s;
  cin >> s;
  n=s.size();
  fill(t,t+2019,0);
  for(i=0;i<672;i++){
    r[i]=tt%2019;
    tt=r[i]*10;
  }
  for(i=0;i<n;i++){
    tt=stoi(s.substr(n-1-i,1));
    rr+=tt*r[i%672];
    rr%=2019;
    t[rr]++;
  }
  res=t[0]*(t[0]+1)/2;
  for(i=1;i<2019;i++)
    res+=t[i]*(t[i]-1)/2;
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3280