akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
using namespace std;
ll power(ll a,ll n)
{
          ll result=1;
          while(n>0)
          {
               if(n&1)
                    result=result*a;
               a=a*a;
               n=n>>1;
          }
          return result;
}
ll lcm(ll a,ll b)
{
          return ((a*b)/__gcd(a,b));
}
bool ispow2(ll n)
{
          return (ceil(log2(n))==floor(log2(n)));
}
bool isprime(ll n)
{
          if(n==1)
               return false;
          else if(n==2)
               return true;
          else
          {
               for(ll i=2;i*i<=n;++i)
               {
                    if(n%i==0)
                         return false;
               }
               return true;
          }
}

ll ncr(ll n,ll r)
{
    if(r > n - r)
          r = n - r;
    ll ans = 1;
    ll i;

    for(i = 1; i <= r; i++)
     {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
int main()
{
          ios_base::sync_with_stdio(0);
          cin.tie(0);

          int t=1;
          //cin>>t;
          while(t--)
          {
                         int n,k;
                         cin>>n>>k;
                         ll a[n+1];
                         ll mod = 1000000000000000000;
                         for(int i=1;i<=n;++i)
                              cin>>a[i];
                         ll prod=1;
                         ll left=0,right=0;
                         left = a[1];
                         right = a[k];
                         int j=2;
                         for(int i=k+1;i<=n;++i)
                         {
                              if(a[i]>left)
                                   cout<<"Yes\n";
                              else
                                   cout<<"No\n";
                              left = a[j++];
                              right = a[i];
                         }
          }
          return 0;
}


Measured memory_bytes: 5264
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(b<10)
    a*=10;
  else if(b<100)
    a*=100;
  else
    a*=1000;
  a+=b;
  for(int i=1;;i++){
    if(i*i==a){
      cout<<"Yes";
      break;
    }else if(i*i>a){
      cout<<"No";
      break;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
int main ()
{
    string S ;
    cin >> S ;
    bool s= true;
    for(int i =0 ; i< S.size() ; i++)
    {
        if(i%2 !=0 && S[i]=='R')
            s=false;
        else if(i%2 ==0  && S[i]=='L')
            s = false;}
        if(s)
            cout << "Yes";
        else
            cout << "No";

        return 0 ;
    }


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

int n,q,c,x,y,p[10010];

void init(int n){
    for(int i=0;i<n;i++){p[i]=i;}
}

int root(int a){
    if(p[a]==a){return a;}
    return (p[a]=root(p[a]));
}

bool is_same_set(int a,int b){
    return root(a)==root(b);
}

void unite(int a,int b){
    p[root(a)]=root(b);
}

int main(){
    cin>>n>>q;
    init(n);
    for(int i=0;i<q;i++){
        cin>>c>>x>>y;
        if(c){cout<<is_same_set(x,y)<<endl;}
        else{unite(x,y);}
    }
}


Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;
const int inf=1e18;

int32_t main(){
	IOS;
	int n,k;
	cin>>n>>k;
	if(n*500>=k) cout<<"Yes";
	else cout<<"No";
} 

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define Rep(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define Repr(i, b, e) for(int (i) = (b) - 1; (i) >= (e); --(i))
#define Print(x) cout << (x) << endl 
#define Min2(a, b) ((a) < (b)) ? (a) : (b)
#define Max2(a, b) ((a) > (b)) ? (a) : (b)

typedef long long ll;

using namespace std;

class UnionFind{
    public:
        UnionFind(int N) : parent(N), rank(N){
            for(int i = 0; i < N; i++){
                parent[i] = i;
                rank[i] = 1;
            }
        }

        int find(int n){
            if(parent[n] == n){
                return n;
            }
            return parent[n] = find(parent[n]);
        }

        void merge(int m, int n){
            int root_x = find(m);
            int root_y = find(n);
            if(root_x == root_y){
                return;
            }
            if(rank[root_x] < rank[root_y]){
                parent[root_x] = root_y;
            }else if(rank[root_x] > rank[root_y]){
                parent[root_y] = root_x;
            }else{
                parent[root_y] = root_x;
                rank[root_x]++;
            }
        }

        bool equivalent(int x, int y){
            return find(x) == find(y);
        }

    private:
        vector<int> parent;
        vector<int> rank;

};

int N, M;
int X[100000], Y[100000], Z[100000];
int group[100000];

int main(){
    cin >> N >> M;
    Rep(i, 0, M) cin >> X[i] >> Y[i] >> Z[i];
    Rep(i, 0, N) group[i] = 0;
    UnionFind tree(N);
    Rep(i, 0, M){
        tree.merge(X[i] - 1, Y[i] - 1);
    }
    int cnt = 0;
    Rep(i, 0, N){
        int p = tree.find(i);
        if(group[p] == 0) cnt++;
        group[p]++;
    }
    Print(cnt);
    return 0;
}

Measured memory_bytes: 2560
def min_k_shift(k, a, N, x, range_min):
    cost = k*x
    for j in range(N):
        cost += range_min[(j-k)%N][j] #min(a[(j-sj)%N] for sj in range(k))
    return cost

N, x = [int(s) for s in raw_input().split()]

a = [int(s) for s in raw_input().split()]

range_min = [[0]*N for st in range(N)]
for st in range(N):
    range_min[st][st] = a[st]

for k in range(1,N):
    for st in range(N):
        range_min[st][(st+k)%N] = min(range_min[st][(st+k-1)%N],a[(st+k)%N])

print(min(min_k_shift(k,a,N,x,range_min) for k in range(N)))

Measured memory_bytes: 54300
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int A,B,K;
    cin >> A >> B >> K;
    vector<int> C(K);
    int i = 0;
    int j = min(A,B);
    while(i < K){
        if(A % j == 0 && B % j == 0){
            C[i] = j;
            //cout << C[i] << endl;
            i++;
        }
        j--;
    }
    cout << C[K-1] << endl;
}


Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.buffer.readline
    N = int(input())
    AB = [[int(i) for i in input().split()] for j in range(N)]
    ans = [0]
    for a, b in AB[::-1]:
        a += ans[-1]
        if a % b != 0:
            ans.append(b - (a % b) + ans[-1])
    print(ans[-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 62860
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
inline int read() {
	int x = 0, fh = 1;
	char c = getchar();
	while (c < '0' || c > '9') {
		if (c == '-') fh = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9') {
		x = (x << 1) + (x << 3) + c - '0';
		c = getchar();
	}
	return x * fh;
}
const int N = 1e6 + 10;
struct node { int y, nxt; LL d; } a[N];
priority_queue<pair<LL, int>, vector<pair<LL, int> >, greater<pair<LL, int> > > heap;
int n, q, k, x, y, d, len, i, lst[N], vis[N];
LL dist[N]; 
void ins(int x, int y, int d) {
	a[++len].y = y;
	a[len].d = d;
	a[len].nxt = lst[x];
	lst[x] = len;
}
void dij(int s) {
	memset(dist, 0x3f3f3f3f, sizeof(dist));
	int x, y, i;
	LL d;
	dist[s] = 0;
	heap.push(make_pair(0, s));
	while (!heap.empty()) {
		d = heap.top().first;
		x = heap.top().second;
		heap.pop();
		if (vis[x]) continue;
		vis[x] = 1;
		for (i = lst[x]; i; i = a[i].nxt) {
			y = a[i].y;
			if (dist[y] > d + a[i].d) {
				dist[y] = d + a[i].d;
				if (!vis[y]) heap.push(make_pair(dist[y], y));
			}
		}
	}
	return;
}
int main() {
	n = read();
	for (i = 1; i < n; i++) {
		x = read(); y = read(); d = read();
		ins(x, y, d);
		ins(y, x, d);
	}
	q = read(); k = read();
	dij(k);
	while (q--) {
		x = read(); y = read();
		cout << dist[x] + dist[y] << '\n';
	}
	return 0;
}

Measured memory_bytes: 16684
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  string s;
  cin>>s;
  stack<int> s1;
  stack<pair<long long int,long long int>> s2;
  long long int sum=0;
  for(int i=0; i<s.length(); i++){
    if(s[i]=='\\'){
      s1.push(i);
    }
    if(s[i]=='/'&&s1.size()>0){
      int j=s1.top();
      sum+=i-j;
      s1.pop();
      int a=i-j;
      while(s2.size()>0&&s2.top().first>j){
        a+=s2.top().second;
        s2.pop();
      }
      s2.push(make_pair(j,a));
    }
  }

  vector<int> ans;
  while(s2.size()>0){
    ans.push_back(s2.top().second); s2.pop();
  }
  reverse(ans.begin(),ans.end());
  cout<<sum<<endl;
  cout<<ans.size();
  for(int i=0; i<ans.size(); i++){
    cout<<" ";
    cout<<ans[i];
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 3304
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R

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

	cin >> N;
	vector<int>v(N + 2);
	for (int i = 1; i <= N; i++)cin >> v[i];
	v[N + 1] = 2020;
	cin >> M;
	for (int i = 0; i < M; i++) {
		cin >> K;
		if (v[K + 1] - v[K] != 1)v[K]++;
	}
	for (int i = 1; i <= N; i++) {
		cout << v[i] << endl;
	}
}


Measured memory_bytes: 3164
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mp(x,y)     make_pair(x,y) 
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,a,n)   for(ll i=a;i<n;i++)
#define frr(i,a,n)  for(ll i=n-1;i>=a;i--)


const ll N   =  500005;
const ll mod = 1e9 + 7;

using namespace std;


void solve()
{
// string s;
  ll n,m,k,x=0,y=0,c=0,q,ans=0;
  cin>>n>>m>>x;

  for (ll i = 0; i < 10; ++i)
  {
   x = n*x -m;
   c(x);
  }
  
}

signed main(){
    
      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      ll T=1;
      //cin>>T;
      while(T--)
      {
      solve();
      }
      return 0;
    }


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

fn main() {
    input! {
        n: usize,
        k: usize,
        h: [usize; n],
    }
    println!(
        "{}",
        h.into_iter().filter(|&x| x >= k).collect::<Vec<_>>().len()
    );
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <array>

using namespace std;

auto main()-> int
{   
    string str;
    cin >> str;

        auto n = stoi(str.substr(0, 2));
        auto m = stoi(str.substr(2, 2));
        
        if (1 <= n && n <= 12)
        {
            if (1 <= m && m <= 12)
                cout << "AMBIGUOUS" << endl;
            else
                cout << "MMYY" << endl;
        }
        else
        {
            if (1 <= m && m <= 12)
                cout << "YYMM" << endl;
            else
                cout << "NA" << endl;
        }
}


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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int N;
    cin >> N;

    int k=1;
    while(k*(k-1)/2<=N){
        if(k*(k-1)/2==N){
            break;
        }
        ++k;
    }

    if(k*(k-1)/2!=N){
        cout << "No" << endl;
        return;
    }

    cout << "Yes" << endl;
    vector<pair<int,int>> x(N);
    int j=0;
    rep(i,0,k){
        rep(l,i+1,k){
            x[j]=make_pair(i,l);
            ++j;
        }
    }

    cout << k << endl;

    vector<vector<int>> ans(k);
    rep(i,0,N){
        ans[x[i].first].push_back(i+1);
        ans[x[i].second].push_back(i+1);
    }

    rep(i,0,k){
        cout << ans[i].size();
        for(int j:ans[i]){
            cout << " "<< j;
        }
        cout << endl;
    }
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


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

using namespace std;

#define REP(i, N) for (int (i) = 0; (i) < (N); ++(i))
#define READALL(c) for (auto &e : c) { cin >> e; }
#define PRINTALL(c) for (const auto &e : c) { cout << e << "\t"; } cout << "\n";

template <typename T>
using V = vector<T>;

typedef long double ld;


int main() {

	string S;
	cin >> S;

	int l = 0, r = S.size()-1, ans = 0;

	while (l < r) {
		if (S[l] == S[r]) ++l, --r;
		else if (S[l] == 'x') ++ans, ++l;
		else if (S[r] == 'x') ++ans, --r;
		else {
			cout << -1 << endl;
			return 0;
		}
	}

	cout << ans << endl;
	
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
ll N,D;
  cin>>N>>D;
  vector<vector<ll>> vec(N,vector<ll>(D));
  for(ll i=0;i<N;i++) {
for(ll j=0;j<D;j++) {
cin>>vec[i][j];
}
  }
  
  ll ans=0;
  for(ll i=0;i<N-1;i++) {
  
for(ll j=i+1;j<N;j++) {
  ll kyori=0;
  for(ll h=0;h<D;h++) {
kyori+=(vec[i][h]-vec[j][h])*(vec[i][h]-vec[j][h]);
  }
  
  for(ll k=1;k<1000;k++) {
if(k*k==kyori) {
ans++;
  break;
}
  }
}
  }
  
  cout<<ans<<endl;
}
  
  
  


Measured memory_bytes: 3600
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << endl;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
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;}

// 0 false, 1 true 
// stringの数字をint型にしてアスキーコードになったら -48する
// 切り上げ　ceil(a)
// コンパイル　g++ -std=c++17 a.cpp

int main() {
    ll n;
    cin >> n;
    vector<ll> vec(n);
    rep(i, n) cin >> vec.at(i);

    ll dp[n+1][2] = {0};
    dp[0][0] = vec.at(0);
    dp[0][1] = vec.at(0) * (-1);
    rep(i,n-1){
        dp[i+1][0] = max(dp[i][0] + vec.at(i+1), dp[i][1] - vec.at(i+1));
        dp[i+1][1] = max(dp[i][0] - vec.at(i+1), dp[i][1] + vec.at(i+1));
    }

    cout << dp[n-1][0] << endl;

}

Measured memory_bytes: 2560
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using L64 = int64_t;

/* {x,y}という表現で格納される[x^y] */
inline vector<pair<L64, int>> prime_factorize(L64 N) {
  vector<pair<L64, int>> res;
  for (int a = 2; a * a <= N; ++a) {
    if (N % a != 0) {
      continue;
    }
    int ex = 0;
    while (N % a == 0) {
      ex++;
      N /= a;
    }
    res.push_back({a, ex});
  }
  if (N != 1) res.push_back({N, 1});
  return res;
}

int main(void) {
  int N, K;
  double res = 0;
  cin >> N >> K;
  for (int i = 1; i <= N; i++) {
    int count = 0;
    int a = i;
    while (a < K) {
      a *= 2;
      count++;
    }
    res += 1 / (pow(2, count));
  }
  res /= N;
  cout << fixed << setprecision(15) << res;
  return 0;
}

Measured memory_bytes: 4116
n = gets.chomp.to_i
a = gets.chomp.split(" ").map!{|item| item.to_i}
num = 1
ans = 1
th = 10**18
a.sort{|a,b| (-1)*(a <=> b)}
if a.include?(0) then
    puts 0
    exit
end
for num in 1..n do
    ans = ans * a[num-1]
    num = num + 1
    if ans > th
        ans = -1
        break
    end
end
puts ans

Measured memory_bytes: 24292
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto nab = readln.split.to!(int[]);
    auto N = nab[0];
    auto A = nab[1];
    auto B = nab[2];
    writeln(min(N*A, B));
}

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

int main(){
    std::string S;
    std::cin >> S;
    std::size_t n = S.size();
    if(S[0] != 'A'){
        std::cout << "WA" << std::endl;
        return 0;
    }

    int cnt = 0;
    int index;
    for(int i = 2; i < n - 1; i++){
        if(S[i] == 'C'){
            cnt++;
            index = i;
            if(cnt > 1){
                std::cout << "WA" << std::endl;
                return 0;
            }
        }
    }
    if(cnt == 0){
        std::cout << "WA" << std::endl;
        return 0;
    }

    for(int i = 1; i < n; i++){
        if(i == index) continue;
        if('a' <= S[i] && S[i] <= 'z') continue;
        else{
            std::cout << "WA" << std::endl;
            return 0;
        }
    }

    std::cout << "AC" << std::endl;


    return 0;
}


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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
  int s;
  cin >> s;
  vector<mint> dp(s+1);
  dp[0] = 1;
  mint sm = 0;
  rrep(i, s){
    if (i >= 3) sm += dp[i-3];
    dp[i] = sm;
  }
  cout << dp[s] << endl;
  return 0;
}


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

int main()
{
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i]=='1')
		{
			s[i] = '9';
		}
		else
		{
			s[i] = '1';
		}
	}
	cout << s << endl;
	return 0;
}

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

using namespace std;

const int maxn = 1e5 + 10;
int x[maxn];
int main() {
    int n;
    long long a,b;
    cin >> n >> a >> b;
    for(int i = 1; i <= n; i++) scanf("%d",&x[i]);
    long long ans = 0;
    for(int i = 2; i <= n; i++) {
        long long offset = x[i] - x[i-1];
        if(offset * a <= b) ans += offset * a;
        else ans += b;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

template <typename T>
inline T gi()
{
	T f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int INF = 0x3f3f3f3f, N = 100003, M = N << 2;

int n;
int h[N], dp[N];

int main()
{
	//File("");
	n = gi <int> ();
	for (int i = 1; i <= n; i+=1) h[i] = gi <int> ();
	memset(dp, 0x3f, sizeof dp);
	dp[1] = 0;
	for (int i = 1; i < n; i+=1)
	{
		dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
		dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
	}
	printf("%d\n", dp[n]);
	return 0;
}


Measured memory_bytes: 4544
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int N = 100005;

int n, i, kol[N], a[N], b[N];
LL res;


bool cmp(int a1, int a2) {
	return a[a1] + b[a1] > a[a2] + b[a2];
}

int main() {
scanf("%d", &n);
for (i=0;i<n;i++) {
	scanf("%d %d", &a[i], &b[i]);
	kol[i] = i;
}
sort(kol, kol + n, cmp);
res = 0;
for (i=0;i<n;i++) if (i % 2) res -= b[kol[i]]; else res += a[kol[i]];
cout << res << endl;
return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
#include <math.h>
using namespace std;
int main(){
    int n,m,x,f=0,ans=-1;
    cin>>n>>m>>x;
    vector<vector<int>> a(12, vector<int>(13));
    vector<int> b(13);
    vector<int> c(13);

    for(int i=0;i<n;i++){
        for(int j=0;j<m+1;j++){
            cin>>a[i][j];
        }
    }
    for(int i=0;i<pow(2,(n));i++){
        for(int j=0;j<n;j++){
            if(b[j]==1){
                for(int k=0;k<m+1;k++){
                    c[k]+=a[j][k];
                }
            }
        }
        for(int j=1;j<m+1;j++){
            if(c[j]<x){
                f=1;
            }
        }
        if(f==0&&(c[0]<ans||ans==-1)){
            ans=c[0];
        }
        f=0;
        for(int j=0;j<m+1;j++){
           c[j]=0;
        }
        b[0]++;
        for(int j=0;j<n;j++){
            if(b[j]>1){
                b[j]=0;
                b[j+1]++;
            }
        }
        

    }
    cout<<ans<<endl;


    return 0;
}


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

int main()
{
  int n;
  cin >> n;
  int nb[11];
  int i = 0;
  while(n > 0)
  {
    nb[i] = n % 10;
    n = n / 10;
  	i++;
  }
  if(nb[1] == nb[2] && ((nb[0] == nb[1]) || (nb[3] == nb[1])))
 	cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

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

	int kkt = 89;
	while (kkt) {
		ll D, E; cin >> D >> E; if (D == 0) break;
		double sa = 1e9;
		for (int i = 0; i <= D; i++) {
			chmin(sa, abs(sqrt(i * i + (D - i) * (D - i)) - E));
		}
		cout << fixed << setprecision(12) << sa << "\n";
	}
	return 0;

}


Measured memory_bytes: 3220
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n = I()
cnt = Counter(LI())
L = []
for k, v in cnt.items():
    if v >= 4:
        L += [k] * 2
    elif v >= 2:
        L += [k]


L.sort(reverse=True)


if len(L) < 2:
    print(0)
else:
    print(L[0] * L[1])


Measured memory_bytes: 65688
n  = int(input())
m  = 10 ** 9 + 7
xs = [int(x) for x in input().split()]
bs = [0] * 60
b  = 1

for x in xs:
	e = 0
	
	while 0 < x:
		if x % 2 == 1:
			bs[e] += 1
			
		e  += 1
		x //= 2

b = 1
r = 0

for i in range(0, 60):
	r  += ((n - bs[i]) * bs[i]) * b
	b <<= 1
	
print(r % m)


Measured memory_bytes: 122808
package main

import "fmt"

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_8_B&lang=jp>
 */

func init() {
}

func main() {
	var p, s string
	fmt.Scanf("%s", &p)
	fmt.Scanf("%s", &s)
	p += p
	for i := 0; i < len(p)/2; i++ {
		f := false
		for j:=0; j < len(s);j++{
			if p[i+j] != s[j]{
				f = true
				break
			}
		}
		if f == false {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}

Measured memory_bytes: 1148
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
//constexpr long long mod = 1000000007LL;
constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;


using Real = double;
using Point = complex<Real>;
const Real EPS = 1e-8;

bool eq(Real a, Real b) { return abs(a - b) < EPS; }
struct Circle {
    Point p;
    Real r;
    Circle() :p(Point(0, 0)), r(0) {}
    Circle(Point _p, Real _r) :p(_p), r(_r) {}
};

int intersect(Circle c1, Circle c2) {
    if (c1.r < c2.r) swap(c1, c2);
    Real d = abs(c1.p - c2.p);
    if (c1.r + c2.r > d) return 4;
    if (eq(c1.r + c2.r, d)) return 3;
    if (c1.r - c2.r < d) return 2;
    if (eq(c1.r - c2.r, d)) return 1;
    return 0;
}

pair<Point, Point> crosspoint(Circle c1, Circle c2) {
    Real d = abs(c1.p - c2.p);
    Real a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
    Real t = arg(c2.p - c1.p);
    Point p1 = c1.p + polar(c1.r, t + a);
    Point p2 = c1.p + polar(c1.r, t - a);
    return { p1, p2 };
}
int main()
{
    /*
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    */
    int c1x, c1y, c1r; scanf("%d %d %d", &c1x, &c1y, &c1r);
    int c2x, c2y, c2r; scanf("%d %d %d", &c2x, &c2y, &c2r);
    Circle c1(Point(c1x, c1y), c1r);
    Circle c2(Point(c2x, c2y), c2r);
    auto res = crosspoint(c1, c2);
    if (res.first.real() > res.second.real()) swap(res.first, res.second);
    else if (eq(res.first.real(), res.second.real()) and res.first.imag() > res.second.imag()) swap(res.first, res.second);

    cout << fixed << setprecision(12)<< res.first.real() << " " << res.first.imag() << " " << res.second.real() << " " << res.second.imag() << endl;
    return 0;
}



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

int main(void){

  //変数の準備
  int N;
  
  //入力
  cin >> N;
  
  //処理
  int ans = 0;
  int max = 0;
  for(int i = 1; i <= N; i++){
    int count = 0;
    int n = i;
    while(n%2 == 0){
      count++;
      n /= 2;
    }
    if(count >= max){
      max = count;
      ans = i;
    }
  }
  
  cout << ans << endl;

  return 0;
}

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

#define DEBUG if(0)
#define INF 1 << 20

typedef long long int lli;
typedef long double ldouble;

const ldouble eps = 1e-10;
const ldouble pi = acos(-1);

ldouble toDeg(ldouble tg) { return (tg * 180) / pi; }

int main() {
    ldouble a, b, c, x, tg;
    scanf("%Lf%Lf%Lf", &a, &b, &c);
    if(a*a*b/2 >= c) {
        x = (2*c)/(a*b);
        tg = atan(b/x);
    }
    else {
        x = (2*c - (a*a*b)) / (a*a);
        tg = atan((b-x)/a);
    }
    tg = toDeg(tg);
    printf("%.10Lf\n", tg);
    return 0;
}


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

int main() {
  long long n, d, x, y;
  int ans(0);
  cin >> n >> d;
  while (n--) {
    cin >> x >> y;
    if (x * x + y * y <= d * d) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

    void solve() {
        string s; ll n, q;
        cin >> n >> s >> q;
        set<ll> st[30];
        for(ll i = 0; i < n; i++)   st[s[i] - 'a'].insert(i);
        for(ll i = 0; i < q; i++) {
            ll x; cin >> x;
            if(x == 1){
                ll ind; char c;
                cin >> ind >> c; ind--;
                if(s[ind] == c) continue;
                st[s[ind] - 'a'].erase(ind);
                s[ind] = c;
                st[c - 'a'].insert(ind);
            } else {
                ll l, r;
                cin >> l >> r; --l, --r;
                ll cnt = 0;
                for(ll i = 0; i < 26; i++){
                    if(*st[i].lower_bound(l) <= r  && st[i].lower_bound(l) != st[i].end()) cnt++;
                }
                cout << cnt << endl;
            }
        }
    }

    int main() {
      cin.sync_with_stdio(0); cin.tie(0);
      cin.exceptions(cin.failbit);
      //ll ti;   cin >> ti;  while(ti--)
      solve();
      return 0;
    }


Measured memory_bytes: 24220
#include <iostream>
using namespace std;
#include <cstdio>
#include <cstdlib>
#include <algorithm>

int n;
int r[100],c[100],dp[100][100]={0},ans=0;

int cal(int i,int j,int k)
{
	return r[i]*c[j]*c[k];
}

int main(void)
{
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		cin>>r[i]>>c[i];
	}
	for (int l=2;l<=n;l++)
	{
		for (int i=1;i+l-1<=n;i++)
		{
			//cout<<"i:"<<i<<" l:"<<l<<endl;
			if (l==2) dp[i][i+l-1]=dp[i+l-1][i]=r[i]*c[i]*c[i+l-1];
			else {
				int m=0x7fffff;
				for (int j=i;j<i+l-1;j++)
				{
					int n=dp[i][j]+dp[j+1][i+l-1]+r[i]*c[j]*c[i+l-1];
					m=m<n?m:n;
				}
				dp[i][i+l-1]=m;
			}
			//cout<<"dp[i][i+l-1]="<<dp[i][i+l-1]<<endl;
		}
	}
	/*for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=n;j++)
		{
			cout<<"i:"<<i<<" j:"<<j<<"dp[i][j]:"<<dp[i][j]<<endl;
		}
	}*/
	cout<<dp[1][n]<<endl;
	return 0;
}


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


int main(){

    int N, K;
    int x[100000];
    cin >> N >> K;
    for( int i = 0; i < N; i++ ) cin >> x[i];

    
    /* 連続したK個を訪れるのが最短で、N個から連続したK個の選び方はN-K+1通り
       一気に+行って-に行くかその逆が最小値なのでN-K+1通りについて全探索*/
    
    int ans = 1e+9;

    // -に行ってから+に行く場合
    for( int i = 0; i < N-K+1; i++ ){
        ans = min( ans, abs(x[i]) + x[i+K-1] - x[i] );
    }
    // +に行ってから-に行く場合
    for( int i = N-1; i >= K-1; i-- ){
        ans = min( ans, abs(x[i]) + x[i] - x[i-K+1] );
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 640
import java.util.*;

/**
 * Created by Seiya on 2016/10/16.
 */
public class Main {


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long N  = scanner.nextLong();
        long amari = N % 11;
        long ans = 0;
        if(amari > 6)ans += 1;
        if(amari == 0)ans-= 1;


        System.out.println(2 * (N / 11) + ans + 1);
    }

}




Measured memory_bytes: 9808
import itertools
K = int(input())
l = list(range(1,K+1))
c = itertools.combinations_with_replacement(l, 3)
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
result = 0
for i in c:
    if i[0] == i[1] and i[2] == i[1]:
        result += gcd(*i)
    elif i[0] == i[1] or i[2] == i[1] or i[0] == i[2]:
        result += (gcd(*i)*3)
    else:
        result += (gcd(*i)*6)
print(result)




Measured memory_bytes: 9592
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<set>
using namespace std;

int ta[20],c[25000];
int dp[20003][256];
const int INF=1800000000;
int main(){
	int n,m;
	while(cin>>n>>m,n+m){
	for(int i=0;i<m;i++)cin>>ta[i];
	for(int j=0;j<n;j++)cin>>c[j];
	
	for(int i=0;i<20003;i++)fill(dp[i],dp[i]+256,INF);
	dp[0][128]=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<256;j++){
			if(dp[i][j]!=INF){
				int tmp=j;
				for(int k=0;k<m;k++){
					if(j+ta[k]<0)tmp=0;
					else if(j+ta[k]>255)tmp=255;
					else tmp=j+ta[k];
					dp[i+1][tmp]=min( dp[i+1][tmp] ,dp[i][j]+ (c[i]-tmp)*(c[i]-tmp) );
				}
			}//endif
		}
	}
	/*for(int i=0;i<=n;i++){
		for(int j=120;j<=140;j++){
		cout<<dp[i][j]<<" ";
		}
		cout<<"\n";
	}*/
	int ans=INF;
	for(int i=0;i<256;i++)ans=min(ans,dp[n][i]);
	cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 21244
#include <cstdio>
#include <algorithm>
#include <set>
using namespace std;
int main() {
	int N, K, C;
	scanf("%d %d %d", &N, &K, &C);
	char S[N];
	for (int i = 0; i < N; ++i) scanf(" %c", &S[i]);
	int l[K], u[K], b = N, f = K - 1;
	for (int i = N - 1; i >= 0; --i) {
		if (S[i] == 'o' && i < b) u[f] = i, b = i - C, --f;
	}
	f = 0, b = -1;
	for (int i = 0; i < N; ++i) {
		if (S[i] == 'o' && i > b) l[f] = i, b = i + C, ++f;
	}
	for (int i = 0; i < K; ++i) {
		if (l[i] == u[i]) printf("%d\n", l[i] + 1);
	}
	return 0;
}

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

int main() {
  long int n, a, b;
  cin >> n >> a >> b;
  long int ans;
  ans = 0;
  ans += (n / (a+b)) * a;
  ans += min((n % (a+b)), a);
  cout << ans << endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
X = list(map(int, input().split()))
ans = [0 for _ in range(n-k+1)]

for i in range(n-k+1):
    if X[i+k-1] < 0:
        ans[i] = abs(X[i])
    elif X[i] >= 0:
        ans[i] = X[i+k-1]
    else:
        if abs(X[i]) < abs(X[i+k-1]):
            ans[i] = abs(X[i]) * 2 + X[i+k-1]
        else:
            ans[i] = X[i+k-1] * 2 + abs(X[i])
print(min(ans))


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

using namespace std;
using namespace __gnu_pbds; 
  
#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int MOD = (int)1e9 + 7;
const int MX = (int)1e5 + 10;

void add_self(int &x, int y, int md = MOD){x += y; if(x >= md) x -= md;}
void sub_self(int &x, int y, int md = MOD){x -= y; if(x < 0) x += md;}
void mul_self(int &x, int y, int md = MOD){x = x * 1LL * y % md;}
inline int mul(int x, int y, int md = MOD){return x * 1LL * y % md;}
inline int add(int x, int y, int md = MOD){x += y; if(x >= md) x -= md; return x;}
inline int sub(int x, int y, int md = MOD){x -= y; if(x < 0) x += md; return x;}

void pre(){
}	


void solve(){
	int n;
	cin >> n;
	vector<int> vec(n);
	for(auto &x : vec) cin >> x;
	ll res = 0;
	for(int i = 1; i < n; ++i){
		int delta = max(0, vec[i - 1] - vec[i]);
		res += delta;
		vec[i] += delta;
	}
	cout << res << "\n";
	return;
}

int main(){

	cin.tie(0); cout.tie(0);
	ios_base::sync_with_stdio(0);

	// freopen("input.in", "r", stdin);
	// freopen("output.out", "w", stdout);

	int t;
	t = 1;
	// cin >> t;
	// pre();
	for(int i = 1; i <= t; ++i){
		// cout << "Case #" << i << ": ";
		solve();
		// cout << '\n';
		// cout << endl;
	}

	return 0;
}


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

int main(){
   int N;
   cin >> N;
    vector<int> d(N);
    for (int i = 0; i < N; i++){
        cin >> d.at(i);
    }

    int sum = 0;

    for (int i = 0; i < N; i++){
        for (int j = i + 1; j < N; j++){
            sum += d.at(i) * d.at(j);
        }
    }

    cout << sum << endl;

}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void uniq(vector<int> &vec){sort(vec.begin(), vec.end());vec.erase(unique(vec.begin(), vec.end()), vec.end());}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}

signed main(){start();
    int n,k;
    cin>>n>>k;
    Vi t(n),d(n);
    VVi s(n);
    REP(i,0,n){
        cin>>t[i]>>d[i];
        t[i]--;
        s[t[i]].pb(d[i]);
    }
    
    REP(i,0,s.size()){
        sort(ALL(s[i]),greater<int>());
        if(s[i].size()==0) s[i].pb(-MOD);
    }
    sort(ALL(s),[](Vi a,Vi b){return a[0]>b[0];});
    
//    REP(i,0,s.size()) cout<<s[i][0]<<endl;
    int tans=0;
    priority_queue<int> q;
    REP(i,0,n){
        if(i<k){
            tans+=s[i][0];
            REP(j,1,s[i].size()) q.push(s[i][j]);
        }else{
            REP(j,0,s[i].size()) q.push(s[i][j]);
        }
    }
    int ans=tans+k*k;
//    cout<<ans<<endl;
    REPR(i,k-1,0){
        int mini = s[i][0];
        int maxi = q.top();
//        cout<<mini<<" "<<maxi<<endl;
        if(mini>=maxi) break;
        tans -= mini;
        tans += maxi;
        q.pop();
        chmax(ans,tans + i*i);
    }
    cout<<ans<<endl;
    return 0;
}


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

   int count=0;
   for(int i=1;i<N+1;i++){
      string s=to_string(i);
      if(s.size()%2==1)
         count++;
   }
   cout<<count<<endl;
}

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

class Dice {
private:
    int numbers[7];
    int T_label, S_label, E_label;

public:
    Dice(int n1, int n2, int n3, int n4, int n5, int n6) {
        numbers[1] = n1;
        numbers[2] = n2;
        numbers[3] = n3;
        numbers[4] = n4;
        numbers[5] = n5;
        numbers[6] = n6;
        T_label = 1;
        S_label = 2;
        E_label = 3;
    }

    void roll_N() {
        int B_label = 7 - T_label;
        T_label = S_label;
        S_label = B_label;
    }

    void roll_S() {
        int N_label = 7 - S_label;
        S_label = T_label;
        T_label = N_label;
    }

    void roll_E() {
        int W_label = 7 - E_label;
        E_label = T_label;
        T_label = W_label;
    }

    void roll_W() {
        int B_label = 7 - T_label;
        T_label = E_label;
        E_label = B_label;
    }

    int T() {
        return numbers[T_label];
    }
};

int main() {
    int n1, n2, n3, n4, n5, n6;
    std::cin >> n1 >> n2 >> n3 >> n4 >> n5 >> n6;
    Dice dice = Dice(n1, n2, n3, n4, n5, n6);
    
    std::string line;
    std::cin >> line;

    for (char direction : line) {
        switch(direction) {
            case 'N':
                dice.roll_N();
                break;
            case 'E':
                dice.roll_E();
                break;
            case 'S':
                dice.roll_S();
                break;
            case 'W':
                dice.roll_W();
                break;
        }
    }

    std::cout << dice.T() << std::endl;
}



Measured memory_bytes: 3160
k, n = map(int, input().split())
a = list(map(int, input().split()))

result = a[0] + (k - a[-1])

for i in range(n - 1):
  if result < a[i+1] - a[i]:
    result = a[i+1] - a[i]
    
print(k-result)

Measured memory_bytes: 26444
#include<bits/stdc++.h>
using namespace std;
long long i,j,a,n,m,c;
int main()
{
  for(cin>>n;i<n;i++){
    cin>>a;
    c+=a;
    m=max(m,a);
  }
  cout<<(2*m<c?"Yes":"No");  
}

Measured memory_bytes: 256
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest
import math

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    #n,m,k=map(int, readline().rstrip().split())
    #arr=list(map(int, readline().rstrip().split()))
    n=int(readline())
    #ss=readline().rstrip()
    #yn(1)
    print(n*2*math.pi)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Measured memory_bytes: 70996
// ------------------------------------
// Date:2018/ 3/17
// Problem:H S I c.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int MOD = 1000000007;

ll power(int x, int n)
{
  ll res = 1ll;
  while (n > 0) {
    if (n & 1) {
      res = x * res;
    }
    x *= x;
    n >>= 1;
  }
  return res;
}

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

  int N, M;
  cin >> N >> M;

  ll tmp = 1900 * M + (N - M) * 100;
  ll tmp2 = power(2, M);
  //debug(tmp2);
  
  ll ans = tmp * tmp2;
  cout << ans << endl;
  
  return 0;
}



Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define addf(T) [](T a, T b){return (a + b);}
#define minf(T) [](T a, T b){return min(a, b);}
#define maxf(T) [](T a, T b){return max(a, b);}


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acos(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

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

ll lcm(ll number1, ll number2) {//lcmを求める
	return number1 / gcd(number1, number2) * number2;
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int n, m, x;
	scanf("%d%d%d", &n, &m, &x);
	vector<int> a(m);
	rep(i, m)scanf("%d", &a[i]);
	int ans1 = 0, ans2 = 0;
	rep(i, m) {
		ans1 += (x < a[i] && a[i] < n);
		ans2 += (0 < a[i] && a[i] < x);
	}
	printf("%d\n", min(ans1, ans2));

	Please AC;
}


Measured memory_bytes: 888