akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define N 100  

int main(){
  int i,comp,j,k,s,count,m[N+1],p[N+1][N+1];
  
  scanf("%d",&count);

  for(i=1;i<=count;i++){
    scanf("%d%d",&m[i-1],&m[i]);
  }

  for(i=1;i<=count;i++) p[i][i]=0;
  
  for(i=2;i<=count;i++){
    for(j=1;j<=count-i+1;j++){
      s=i+j-1;
      
      for(k=j;k<s;k++){
	if(j!=k) {
	  comp=(p[j][k]+p[k+1][s]+m[j-1]*m[k]*m[s]);
	  if(p[j][s]>comp) p[j][s]=comp;
	} 
	else p[j][s]=(p[j][k]+p[k+1][s]+m[j-1]*m[k]*m[s]); 
      }
    }
  }

  printf("%d\n",p[1][count]);

  return 0;
}
	  



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

using namespace std;

#define ll       long long

#define  sci(x)   scanf("%d", &x)
#define  scl(x)   scanf("%lld", &x)
#define  scd(x)   scanf("%lf", &x)

#define  pfi(x)   printf("%d", x)
#define  pfl(x)   printf("%lld", x)
#define  pfd(x)   printf("%lf", x)
#define  pfc(x)   printf("Case %d: ", x++)
#define  ps       printf(" ")
#define  pn       printf("\n")

#define  pb       push_back
#define  ppb      pop_back
#define  pf       push_front
#define  ppf      pop_front
#define  In       insert
#define  All(a)   a.begin(), a.end()

double dp[3000][1505], p[3005];
int n;
bool done[3000][1505];

double solve(int pos, int cnt)
{
	if(pos == n)
	{
		if(cnt * 2 < n)
			return 1;
		else
			return 0;
	}
	if(cnt * 2 >= n)
		return 0;

	if(done[pos][cnt])
		return dp[pos][cnt];

	done[pos][cnt] = true;
	return dp[pos][cnt] = p[pos] * solve(pos + 1, cnt) + (1 - p[pos]) * solve(pos + 1, cnt + 1);
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    sci(n);

    for(int i = 0; i < n; i++)
    	scd(p[i]);

    printf("%.10lf\n", solve(0, 0));

    return 0;
}

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

#define f0(i,a,b) for(int i= a; i<= b; ++i)
#define f1(i,a,b) for(int i= a; i>= b; --i)
#define DEBUG(x) cerr << #x << " = " << x << endl
#define X first
#define Y second
using namespace std;
const int base=1e9+7;
typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ll, ii> iii;
const long long MAX_N = 100011;
vector<ll> edge[MAX_N];
bool visited[MAX_N];
ll in_degree[MAX_N];
ll dp[MAX_N];
void dfs(int n) {
    visited[n] = true;
    for(ll i: edge[n]) {
        in_degree[i] --;
        dp[i] = max(dp[i], dp[n] + 1);
        if(in_degree[i] == 0) {
            dfs(i);
        }
    }
}
int Solves() {
    ll n,m;
    cin >> n >> m;
    for(int i = 1; i <= m;i++) {
        ll x,y;
        cin >> x >> y;
        edge[x].push_back(y);
        in_degree[y] ++;
    }

    for(int i = 1; i <= n;i++) {
        if(!visited[i] && in_degree[i] == 0) {
            dfs(i);
        }
    }
    ll maxx = 0;
    for(int i = 1; i <= n;i++) {
        maxx = max(maxx, dp[i]);
    }
    cout << maxx;
}

int main() {
    Solves();
}


Measured memory_bytes: 10496
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>  // min, max
#include <fstream>  // ifstream
#include <iomanip>  // setprecision
using namespace std;
typedef long long ll;

int main(void)
{
#ifdef FILE_DEBUG
    ifstream inputFile("data/input.txt");
    cin.rdbuf(inputFile.rdbuf());
#endif
    // これより下にコードを書く

    int N, K;
    cin >> N >> K;

    if (N % K == 0)
        cout << 0 << endl;
    else
        cout << 1 << endl;

    return 0;
}


Measured memory_bytes: 256
#import pysnooper
#import numpy
#import os,re,sys,operator
#from collections import Counter,deque
#from operator import itemgetter,mul
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left,bisect_right
#from copy import deepcopy
#import heapq
#import math
#import string
#from time import time
#from functools import lru_cache,reduce
#from math import factorial,hypot
#import sys
#from fractions import gcd
setrecursionlimit(10**6+1)
input=stdin.readline

s=input().rstrip()
print("Yes" if s[2]==s[3] and s[4]==s[5] else "No")

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

using namespace std;

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

typedef long long ll;

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

 string s;
  cin >> s;
  
  vector<ll> num(26,0);
  
  rep(i,0,s.size()) num[s[i]-'a']++;
  
  ll res=s.size()*(s.size()-1)/2;
  
  rep(i,0,26) res-=num[i]*(num[i]-1)/2;
  
  cout << res+1 << endl;
  
 
  }
  

Measured memory_bytes: 720
sx,sy,i,x,y,n;
xx[12],yy[12];
q[9999],t,h,p,ok,c,k;
dx1[]={2,2,2,1,0,-1,-2,-2,-2,-1,0,1};
dy1[]={-1,0,1,2,2,2,1,0,-1,-2,-2,-2};
main()
{
  for(;scanf("%d%d",&sx,&sy),sx;puts(ok?"OK":"NA")){
    for(i=scanf("%d",&n);i<=n;)scanf("%d%d",xx+i++,yy+i);
    for(ok=t=h=0,q[t++]=sx*10+sy;t!=h;){
      p=q[h++];
      c=p/100;
      if(c&&(abs(xx[c]-p/10%10)>1||abs(yy[c]-p%10)>1))continue;
      if(c==n){ok=1;break;}
      for(i=0;i<12;i++){
        x=p/10%10+dx1[i];
        y=p%10+dy1[i];
        k=(c+1)*100+x*10+y;
        if(x>=0&x<10&y>=0&x<10)q[t++]=k;
      }
    }
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll n, l, mi = inf, ans = 0;
    cin >> n >> l;
    REP(i, n){
        if(abs(mi) > abs(l+i-1))mi = l+i-1;
        ans += l+i-1;
    }
    cout << ans - mi << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
  vector<int> c(3);
  for(int i=0;i<3;i++) cin>>c.at(i);
  sort(c.begin(),c.end());
  if(c.at(0)==c.at(1)) cout<<c.at(2)<<endl;
  else if(c.at(0)==c.at(2)) cout<<c.at(1)<<endl;
  else cout<<c.at(0)<<endl;
}


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

int main() {
    char c;
    int counter[26] = {};

    while (cin >> c) {
        c = tolower(c);
        if (isalpha(c)){
            int num = c - 'a';
            counter[num]++;
        }
    }

    rep(i,26) {
        printf("%c : %d\n", i+'a', counter[i]);
    }
}


Measured memory_bytes: 3164
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define int long long
#define FILE_IO freopen("input.txt","r",stdin)/#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1000000000;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

bool cmp(pair<int, int> p1, pair<int, int> p2){
   return p1.f < p2.f;	
}

void solve(){
   int n, m;
   cin >> n >> m;
   vector< pair<int, int>> v;
   
   for (int i = 0; i < n; i++){
	    int x, y;
	    cin >> x >> y;
	    v.push_back({x, y});
	 }	
   sort(all(v), cmp);
   int ret = 0, cnt = 0;
   for (auto it : v){
	   cnt = min(m, it.s);
	   ret += cnt * it.f;
	   m -= cnt;
	 }
   cout << ret << endl;
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}


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

typedef long long ll;
typedef long double ld;

#define imx INT_MAX
#define imn INT_MIN
#define llmx LLONG_MAX
#define llmn LLONG_MIN

#define fi first
#define se second
#define pb push_back
#define f_s(a) sort(a.begin(), a.end())
#define b_s(a) sort(a.rbegin(), a.rend())
#define p(a) cout<<a<<"\n"


// ll mod = 1000000007;
// #define l(i, )
// #define rl(i, a, b) for(int i = a; i < b; i++)

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


ll extended_gcd(ll a, ll b, ll& x, ll& y)
{
	if(b==0)
	{
		x=1;
		y=0;
		return a;
	}
	ll x1, y1;
	ll d = extended_gcd(b, a%b, x1, y1);
	x=y1;
	y=x1-y1*(a/b);
	return d;
}

////////////////////SIEVE OF ERATOSTHENES//////////////////////
vector<int> sieveoferatosthenes(int n)
{
	vector<bool> prime(n+1, true);
	for(int i = 2; i <= sqrt(n); i++)
	{
		if(prime[i])
		{
			for(int j = i*i; j<=n; j+=i)
			{
				prime[j]=false;
			}
		}
	}
	vector<int> all_primes;
	for(int i = 2; i <=n; i++)
	{
		if(prime[i]) all_primes.pb(i);
	}
	return all_primes;
}

////////////////////BINARY EXPONENTIATION///////////////////////
ll bin_exp(ll a, ll b, ll mod)
{
	ll ans = 1;
	while(b)
	{
		if(b%2)
		{
			b--;
			ans = (ans%mod*a%mod)%mod;
		}
		b/=2;
		a = (a%mod*a%mod)%mod;
	}
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll a, b, c, k, ans = 0;
	cin>>a>>b>>c>>k;


	if(a>=k)
	{
		ans = k;
	}
	else
	{
		ans+=a;
		k-=a;
		if(b>=k)
		{
			// k-=b;
			ans+=0;
		}
		else
		{
			k-=b;
			if(c>=k)
			{
				ans-=k;
			}
			else
			{
				;
			}
		}
	}
	cout<<ans<<endl;
	// if(k>=a)
	// {
	// 	ans+=a;
	// 	k-=a;
	// 	if(k>=b)
	// 	{
	// 		// ans+=b*0;
	// 		k=k-b;
	// 		// cout<<"k "<<k<<endl;
	// 		// cout<<ans<<endl;
	// 		if(c>=k)
	// 		{
	// 			ans-=k;
	// 		}
	// 	}
	// 	else
	// 	{
	// 		// ans+=;

	// 	}
	// }
	// else
	// {
	// 	ans = a;
	// }
	// // ll ans = min(k, a);
 // // 	ans+=min(k-min(k, a), b);
 // // 	ans-=min(k-min(	b, k-a)-c, c);
	// // if(a>=k)
	// // {

	// // }
	// cout<<ans;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int r,g,b;
  cin>>r>>g>>b;
  if((r*100+g*10+b)%4==0)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int n; cin>>n;
    vector<int> p2index(n);
    for(int i=0; i<n; i++){
        int p; cin>>p;
        p2index[--p] = i;
    }

    int ans = 1;
    int sum = 1;
    for(int i=0; i+1<n; i++){
        if(p2index[i] < p2index[i+1]) sum++;
        else sum = 1;

        chmax(ans, sum);
    }

    cout << n - ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string Yes="Yes";
string YES="YES";
string NO="NO";
string No="No";
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
 
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 9223372036854775806ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
//-0.4620981203755741
int main(){
    string s;
    std::cin >> s;
    int n=s.size();
    
    bool han=1;
    rep(i,n-1){
        if(s.substr(i,2)!="hi")han=0;
        i++;
    }if(n%2==1)han=0;
    if(han)std::cout << Yes << std::endl;
    else std::cout << No << std::endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int N,K;
    int *D;
    int num;
    int i,j;
    bool flag;
    cin >> N >> K;
    D = new int[K];
    for(i=0;i<K;i++){
        cin >> D[i];
    }
    i = N;
    while(1){
        num = i;
        flag = false;
        while(num>0){
            for(j=0;j<K;j++){
                if(num%10 == D[j]){
                    flag = true;
                    break;
                }
            }
            if(flag) break;
            num = num/10;
        }
        if(num ==  0) break;
        i++;
    }
    cout << i << endl;
    delete[] D;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
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; }
typedef long long ll;
typedef pair<int,int> P;

template <typename T>
void warshall_floyd(vector<vector<T>> &g) {
  for (int k = 0; k < g.size(); k++) {
    for (int i = 0; i < g.size(); i++) {
      for (int j = 0; j < g.size(); j++) {
        if (g[i][k] == INF || g[k][j] == INF) continue;
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
}

int main(){
  int n,m,r;
  cin >> n >> m >> r;
  vector<vector<int>> to(n,vector<int>(n,INF));
  rep(i,n)to[i][i]=0;
  int d[r];
  rep(i,r){
    cin >> d[i];
    d[i]--;
  }
  sort(d,d+r);
  rep(i,m){
    int a,b,c;
    cin >> a >> b >> c;
    a--;b--;
    to[a][b] = c;
    to[b][a] = c;
  }
  warshall_floyd(to);
  ll ans = LINF;
  do {
    ll res = 0;
    rep(i,r-1){
      res += to[d[i]][d[i+1]];
    }
    chmin(ans,res);
  } while(next_permutation(d, d + r));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		sc.close();

		if (A >= 10 || B >= 10) {
			System.out.println("-1");
		} else {
			System.out.println(A * B);
		}
	}
}


Measured memory_bytes: 25300
use std::io;
use std::cmp;

fn gets() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    return buf
}

fn main() {
  let line = gets();
  let mut it = line.split_whitespace().map(|x| x.parse::<i64>().unwrap());
  let (q, h, s, d) = (it.next().unwrap(), it.next().unwrap(), it.next().unwrap(), it.next().unwrap());
  let line = gets();
  let n = line.trim().parse::<i64>().unwrap();
  let p1 = cmp::min(cmp::min(q * 4, h * 2), s);
  let p2 = cmp::min(p1 * 2, d);
  if n == 1 {
    println!("{}", p1);
  } else {
    println!("{}", (n / 2) * p2 + (n % 2) * p1);
  }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    /* ll t;
    cin>>t;
    while(t--) */
    {
        ll i,j,k,l,m,n,a,b,c,d,cnt=0,p=0,q;
        cin>>n>>k;
        vector <ll> vec[n+1];
        ll arr[n];
        for(i=0;i<n;i++)
            cin>>arr[i];

        for(i=0;i<k;i++)
        {
            cin>>a>>b;
            vec[a].push_back(b);
            vec[b].push_back(a);
        }

        for(i=1;i<=n;i++)
        {
            if(vec[i].size()==0)
                {cnt++;}
            else
            {
                for(j=0;j<vec[i].size();j++)
                {
                    if(arr[vec[i][j]-1]<arr[i-1])
                    {p++;

                    }
                }

                if(p==vec[i].size())
                    {cnt++; }
            p=0;

            }


        }
        cout<<cnt<<endl;



    }
}


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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int a,b;
cin>>a>>b;
cout<<a*b<<endl;
return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long n,k,ans,l;
  ans=100000000000;
  cin>>n>>k;
  vector<long> vec(n);
  for(int i=0; i<n; i++){
    cin>>vec.at(i);
  }
  for(int i=0; i+k-1<n; i++){
    if(vec.at(i+k-1)<=0){
      ans=min(ans,-vec.at(i));
    }
    else if(vec.at(i)>=0){
      ans=min(ans,vec.at(i+k-1));
    }
    else{
      l=min(vec.at(i+k-1)*2-vec.at(i),vec.at(i+k-1)-2*vec.at(i));
      ans=min(ans,l);
    }
  }
  cout<<ans;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll h,w;
ll direction2[4][2]={{1,0},{0,1},{0,-1},{-1,0}};
bool valid(int a,int b)
{
    if(a>=1&&a<=h&&b>=1&&b<=w)return true;
    else return false;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x=1,y,s=0;
    cin>>n;
    ll l1[n+1];
    for(int i=1;i<=n;i++){
        cin>>l1[i];
        s+=l1[i];
//        if(i>=1){
//            y=x;
//            x=__gcd(x,l1[i]);
//            x=(ll)(l1[i]*(y/x));
//        }
    }//cout<<x<<endl;
//    for(int i=1;i<=n;i++){
//        s+=(x-1)%l1[i];
//    }
    cout<<s-n;
}


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

using namespace std;

int main(){
  int N;
  string S;
  cin >> N;
  cin >> S;
  string X, Y;
  X = Y = "";
  //cout << 122-(int)'a' << endl;

  int bx[26];
  int by[26];
  int ans = 0;

  for(int brd = 0 ; brd < N-1 ; brd++){
    string X, Y;
    X = Y = "";
    for(int i = 0 ; i <= brd ; i++){
      X +=S[i];
      bx[122-(int)S[i]] = 1;
    }
    
    for(int i = brd+1 ; i < N ; i++ ){
      Y +=S[i];
      by[122-(int)S[i]] = 1;
    }
    
    //cout << "ok" << endl;
    
    int ansk = 0;
    for(int i = 0 ; i < 26 ; i++){
      if(bx[i] == 1 && by[i] == 1){
	ansk++;
      }
      bx[i] = by[i] = 0;
    }
    if(ansk > ans){
      ans = ansk;
    }

    
    //cout << brd << endl;
    //cout << "X is " << X << "Y is " << Y << ans <<endl;


      
  }
  cout << ans << endl;
}


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

int main() {
  int n;
  cin >> n;
  n += n;
  vector<int> vi;
  vi.resize(n);
  for (int i = 0; i < n; i ++) cin >> vi[i];
  sort(vi.begin(), vi.end());
  int ret = 0;
  for(int i = 0; i < n;  i += 2) ret += vi[i];
  cout << ret << endl;
}

Measured memory_bytes: 256
S = list(input().strip())
flag = False

if S[0] == "A" and "C" in S[2:-1]:
    count = 0
    for s in S:
        #if s < "a":
        if "A" <= s <= "Z":
            count += 1
    if count == 2:
        flag = True
if flag:
    print("AC")
else:
    print("WA")

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
const int N = 2e5 + 10;
const ll inf = 1e15 + 42;
#define endl "\n"
const ll mod = 1000000007;

typedef tree<pair<ll, int>, null_type, less<pair<ll, int>>, rb_tree_tag, tree_order_statistics_node_update> pbds;

//Ordered set
//pbds s1
 
void testCase() {
    string s;
    cin >> s;
    int n = s.size();
    n--;
    if (s[n]!='s') {
        s += 's';
    }
    else {
        s += "es";
    }
    cout << s << endl;
}
 
int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    testCase();
    return 0;
}

Measured memory_bytes: 3644
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};
//約数の列挙O(√n)
vector<ll>divisor(ll n){
  vector<ll>res;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      res.push_back(i);
      if(i != n/i) res.push_back(n/i);
    }
  }
  return res;
}
int main(){
  ll n,m;cin>>n>>m;
  vl vec=divisor(m);
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  rep(i,vec.size()){
    if(vec[i]*n<=m){
      cout<<vec[i]<<endl;
      return 0;
    }
    
  }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var S = Read();
            var set = new HashSet<char>();
            foreach (var s in S)
            {
                set.Add(s);
            }

            var l = set.ToList();
            if (l.Count != 2)
            {
                Println("No");
                return;
            }

            if (S.Count(x => x == l[0]) == 2 && S.Count(x => x == l[1]) == 2)
            {
                Println("Yes");
                return;
            }

            Println("No");
        }

        static List<int> ReadLines(int n)
        {
            var l = new List<int>();
            for (int i = 0; i < n; i++)
            {
                l.Add(ReadInt());
            }
            return l;
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b);
        static long Lcm(long a, long b) => a * b / Gcd(a, b);

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;


const int INF = 10000000;
const long long INFL = (1LL<<40);
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

template< typename T >
struct edge{
    int src, to;T cost;
    edge(int to,T cost) :src(-1),to(to),cost(cost){}
    edge(int src, int to, T cost) :src(src),to(to),cost(cost){}edge
    &operator=(const int &x){
        to =x;
        return *this;
    }
    operator int() const{ return to;}
};

double dist (double a, double b,  double c, double d){
    
    return sqrt((a-c)*(a-c) + (b-d)*(b-d));
    
}

int main() {
    ll N,K; cin>>N>>K;
    
    ll ans = K;
    
    for(auto i = 2; i<=N;i++){
        ans *= (K-1);
    }
    
    cout << ans << endl;
    
    return 0;
}






Measured memory_bytes: 256
n=int(input())
l=[]
for i in range(n):
    l.append(list(input().split())+[i+1])
l=sorted(l, key=lambda x: x[0])
s=sorted(set([x[0] for x in l]))
for c in s:
    x=sorted([a for a in l if a[0]==c], key=lambda x: int(x[1]))[::-1]
    for a in x:
        print(a[2])
        

Measured memory_bytes: 3060
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

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

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{
	int n,k;
	int x[103];
	int sum = 0;
	scanf("%d %d",&n,&k);
	for (int i = 0; i < n; ++i)
	{
		scanf("%d",&x[i]);
		sum += (abs(k - x[i]) < abs(x[i]) ? (2 * abs(k - x[i])) : (2 * abs(x[i])));
	}
	printf("%d\n", sum);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <math.h>
#include <string>
#include <math.h>

using namespace std;

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

const ll mod = 1000000007;
const ll INF = 1000000000000;

ll a;
string s;



int main()
{
	cin >> a >> s;

	if (a >= 3200)
	{
		cout << s << endl;
	}
	else
	{
		cout << "red" << endl;
	}

	

	int www;
	cin >> www;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxx = 2e5 + 7;
const int Inf = 1 << 30;
const LL INF = 1LL << 60;
int a, b, c, d;

int main() {
	scanf("%d %d %d %d", &a, &b, &c, &d);
	bool flg = 0;
	for(int i = 0, j = 0; ; i += b, j += d) {
		if(i >= c) {
			flg = 1;
			break;
		}
		if(j >= a) break;
	}
	if(flg) puts("Yes");
	else puts("No");
	return 0;
}

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

using namespace std;

int getTotalScore(const multiset<int> &info) {
	int sum;
	multiset<int>::iterator curPos;
	
	sum = 0;
	curPos = info.begin();
	for (int i = 0; i < 3; ++i) {
		sum -= *curPos;
		++curPos;
	}

	return sum;
}

int main() {
	int score;
	multiset<int> scoreW, scoreK;
	
	for (int i = 0; i < 10; ++i) {
		cin >> score;
		scoreW.insert(-score);
	}
	for (int i = 0; i < 10; ++i) {
		cin >> score;
		scoreK.insert(-score);
	}	
	cout << getTotalScore(scoreW) << " " << getTotalScore(scoreK) << endl;

	return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define INF 1000000000000000000
#define all(x) x.begin(), x.end()

int main() {
    int N;
    cin >> N;
    string s;
    cin >> s;
    vector<int> A(N + 1);
    ll sum_a = 0, sum_b = 0, sum_c = 0;
    rep(i, s.size()) {
        if (s[i] == 'R')
            A[i + 1] = -1, sum_a++;
        if (s[i] == 'G')
            A[i + 1] = 0, sum_b++;
        if (s[i] == 'B')
            A[i + 1] = 1, sum_c++;
    }

    ll sum = sum_a * sum_b * sum_c;

    ll dummy = 0, res = 0;
    for (int i = 1; i <= N; i++) {
        for (int j = i + 1; j <= N; j++) {
            int k = 2 * j - i;
            if (A[i] != A[j] && A[j] != A[k] && A[i] != A[k] && k > j && k <= N)
                dummy++;
        }
    }

    res = sum - dummy;

    cout << res << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef vector<pll> vpll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

template <typename CLASS1, typename CLASS2>
bool operator==(const HOGE<CLASS1, CLASS2> &hoge1, const HOGE<CLASS1, CLASS2> &hoge2){
  return hoge1.value == hoge2.value;
};

template <typename CLASS1, typename CLASS2>
bool operator<(const HOGE<CLASS1, CLASS2> &hoge1, const HOGE<CLASS1, CLASS2> &hoge2){
  return hoge1.value < hoge2.value;
};

template <typename CLASS1, typename CLASS2>
bool operator>(const HOGE<CLASS1, CLASS2> &hoge1, const HOGE<CLASS1, CLASS2> &hoge2){
  return hoge1.value > hoge2.value;
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll W, H, x, y;
  IN(W,H,x,y);

  double S = W*H;
  S /= 2.0;

  ll ans = 0;

  if(x*2==W && y*2==H) ans = 1;

  printf("%.12lf %lld\n", S, ans);

  return 0;
}

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

int main(){
  int n;
  int ans = 0;
  cin >> n;
  for(int i=1;i<=n;i++){
    int count = 0;
    for(int j=1;j<=n;j+=2){
      if(i % j==0) count++;
    }
    if(count == 8) ans++;  
  }
  cout << ans << endl; 
}


Measured memory_bytes: 256
def abc171c_one_quadrillion():
    n = int(input())
    s = ''
    while n > 26:
        i = 0
        total = 1
        while total <= n:
            i += 1
            total += pow(26, i)
        total -= pow(26, i)
        i -= 1

        val = min(25, (n - total) // pow(26, i))
        s += chr(64 + val + 1)
        n -= (val + 1) * pow(26, i)

    s += chr(64 + n)
    s = s.lower()
    print(s)

abc171c_one_quadrillion()

Measured memory_bytes: 9144
n,m = map(int, input().split())
l = []
for _ in range(m):
    data = list(map(int,input().split()))
    l.append(data)

l_max=0
r_min=10**9
for tmp in l:
    l=tmp[0]
    r=tmp[1]
    if l_max < l:
        l_max=l
    if r_min > r:
        r_min=r
ans = r_min-l_max+1
if ans >= 0:
    print(ans)
else:
    print(0)

Measured memory_bytes: 27336
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
 
using namespace std;
 
int main(){
	int n;
	cin >> n;
	vector<int> a1(n), a2(n);
	for(int i = 0; i < n; ++i){ cin >> a1[i]; }
	for(int i = 0; i < n; ++i){ cin >> a2[i]; }
	for(int i = 1; i < n; ++i){ a1[i] += a1[i - 1]; }
	for(int i = n - 2; i >= 0; --i){ a2[i] += a2[i + 1]; }
	int answer = 0;
	for(int i = 0; i < n; ++i){
		answer = max(answer, a1[i] + a2[i]);
	}
	cout << answer << endl;
	return 0;
}

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

int main()
{
 int x;
 double a,b,bmi;
char q,r;
 while(cin>>x>>q>>a>>r>>b)
{
bmi=a/(b*b);
if(bmi>=25)
{
 cout<<x<<endl;
}
}
return 0;
}

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

int main(void){
	int N, Y;
	int i = 0, j = 0, k = 0, ret = -1;
	
	cin >> N >> Y;
	
	for(i=0;i<=N;i++)
	{
		for(j=0;j<=N-i;j++)
		{
			k = N - i - j;
			if( i * 10000 + 5000 * j + 1000 * k == Y)
			{
				ret = 0;
				break;
			}
		}
		if(ret == 0)
		{
			break;
		}
	}
	if(ret == 0)
	{
		cout << i << " " << j << " " << k;
	}else
	{
		cout << -1 << " " << -1 << " " << -1;
	}
}

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

int main() {
  int n,m;
  cin>>n>>m;
  int a,b;
  std::vector<int> tt(n,0);
  for(int i=0;i<m;i++){
    cin>>a>>b;
    tt[a-1]++;
    tt[b-1]++;
  }
  for(int i=0;i<n;i++)cout<<tt[i]<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
void solve() {
	string s, ans; cin >> s;
	ans = s[0];
	int n = 0;
	for (int i = 1; i < s.size(); i += 3) {
		if (s[i] == '-') {//->
			n++;
			if (n == ans.size()) {
				ans += s[i + 2];
			}
		}
		else{
			n--;
			if (n < 0) {
				n = 0;
				ans = s[i + 2] + ans;
			}
		}
	}
	cout << ans << endl;
}
int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		solve();
	}
}

Measured memory_bytes: 3160
#include <iostream>

int A[200020];

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


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

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

    b = a / 3600;
    a %= 3600;
    c = a / 60;
    a %= 60;

    cout << b << ":" << c << ":" << a << endl;

    return 0;
}

Measured memory_bytes: 3072
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        int p[] = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = in.nextInt();
        }

        Arrays.sort(p);
        int total = 0;
        for (int i = 0; i < k; i++) {
            total += p[i];
        }

        System.out.println(total);
    }
}

Measured memory_bytes: 39008
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // トポロジカルソート
  int V, E; cin >> V >> E;
  vector<vector<int> > edge(V, vector<int>());
  vector<int> h(V, 0);
  REP(i, E){
    int x, y; cin >> x >> y;
    edge[x].push_back(y);
    h[y]++;
  }
  queue<int> q;
  REP(i, V){
    if(h[i] == 0) q.push(i);
  }
  vector<int> ans;
  while(!q.empty()){
    int i = q.front(); q.pop();
    ans.push_back(i);
    for(auto j : edge[i]){
      h[j]--;
      if(h[j] == 0) q.push(j);
    }
  }
  for(auto &i : ans) cout << i << endl;
}


Measured memory_bytes: 3876
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;

int main(){
  int k;
  cin >> k;
  vector<ll> ans(9);
  rep(i,9) ans[i] = i+1;
  for(int i=0;i<100000;i++){
    int m = ans[i]%10;
    if(m > 0) ans.push_back(10*ans[i] + m - 1);
    ans.push_back(10*ans[i] + m);
    if(m < 9) ans.push_back(10*ans[i] + m + 1);
  }
  cout << ans[k-1] << endl;
}


Measured memory_bytes: 3828
#include<stdio.h>
#include<stdlib.h>
int main(){
  int a,b,c;
  scanf("%d %d",&a,&b);
  if(a<0||a>1000000000 && b<0||b>1000000000){
    printf("error");
    return 0;
  }
  //swap
  if(a<b){
    c=a;
    a=b;
    b=c;
  }
  while(b>0){
    c=a%b;
    a=b;
    b=c;
  }
  printf("%d\n",a);
  return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << __LINE__ << ' ' << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


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

	ll n, k;
	cin >> n >> k;
	vector<P> p(n);
	rep(i, n) {
		cin >> p[i].first >> p[i].second;
		p[i].first--;
	}
	sort(all(p), [](P a, P b) {return a.second > b.second; });
	priority_queue<P, vector<P>, greater<P>> que;
	ll sum = 0; ll v = 0;
	vector<ll> cnt(n);
	rep(i, k) {
		int x = p[i].first;
		sum += p[i].second;
		if (cnt[x] > 0) {
			que.push({ p[i].second,x });
		}
		else v++;
		cnt[x]++;
	}
	ll ans = sum + v * v;
	for (int i = k; i < n; i++) {
		int x = p[i].first;
		if (cnt[x] == 0 && !que.empty()) {
			P q = que.top(); que.pop();
			sum -= q.first; sum += p[i].second;
			v++;
			cnt[q.second]--;
			cnt[x]++;
			chmax(ans, sum + v * v);
		}
	}
	cout << ans << '\n';
}

Measured memory_bytes: 6616
a,b,c=map(int,input().split())
d=0
if a==b==c and a%2==0:
    print(-1)
else:
    while a%2==0 and b%2==0 and c%2==0:
        a,b,c=(b+c)//2,(a+c)//2,(a+b)//2
        d+=1
    print(d)

Measured memory_bytes: 8916
use proconio::{input, fastout};
static MODC: i64 = 998244353;

#[fastout]
fn main() {
    input! {
        a: usize, b: usize, c: usize, d: usize,
    }
    let mut dp: Vec<Vec<i64>> = vec![vec![0; d-b+1]; c-a+1];
    dp[0][0] = 1;
    for v in 0..(c-a+1) {
        for h in 0..(d-b+1) {
            if h != 0 { dp[v][h] = dp[v][h-1]*(a+v)as i64 % MODC }
            if v != 0 { dp[v][h] += dp[v-1][h]*(b+h)as i64 % MODC }
            if h != 0 && v != 0 { dp[v][h] -= dp[v-1][h-1]*((a+v-1)*(b+h-1))as i64 % MODC - MODC }
            dp[v][h] %= MODC
        }
    }
    println!("{}", dp[c-a][d-b]);
}


Measured memory_bytes: 72440
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
using namespace std;
typedef long long s64;

const int ONE = 2005;
const int MOD = 1e9 + 7;

int get()
{
		int res = 1, Q = 1; char c;
		while( (c = getchar()) < 48 || c > 57)
			if(c == '-') Q = -1;
		if(Q) res = c - 48;
		while( (c = getchar()) >= 48 && c <= 57)
			res = res * 10 + c - 48;
		return res * Q;
}

int Qucikpow(int a, int b)
{
		int res = 1;
		while(b)
		{
			if(b & 1) res = (s64)res * a % MOD;
			a = (s64)a * a % MOD;
			b >>= 1;
		}
		return res;
}

int n, k;
int fac[ONE * ONE], inv[ONE * ONE];

void Deal_first()
{
		fac[0] = 1;
		for(int i = 1; i <= n * k; i++)
			fac[i] = (s64)fac[i - 1] * i % MOD;

		inv[n * k] = Qucikpow(fac[n * k], MOD - 2);
		for(int i = n * k; i >= 1; i--)
			inv[i - 1] = (s64)inv[i] * i % MOD;
}

int C(int n, int m)
{
		return (s64)fac[n] * inv[m] % MOD * inv[n - m] % MOD;
}

int f[ONE][ONE];

int main()
{
		//freopen(".in","r",stdin);
		//freopen(".out","w",stdout);
		n = get(), k = get();
		if(k == 1) {printf("1\n"); return 0;}
		Deal_first();

		f[1][1] = f[1][0] = 1;
		for(int i = 2; i <= n; i++)
			for(int j = 0; j <= i; j++)
			{
				if(j) (f[i][j] += f[i][j - 1]) %= MOD;
				(f[i][j] += (s64)f[i - 1][j] * C(i * (k - 1) + j - 1, k - 2) % MOD) %= MOD;
			}

		printf("%d", (s64)f[n][n] * fac[n] % MOD);
}

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

int main() {
    string s, t;
    cin >> s >> t;
    if(t.find(s) == 0 && s.size() + 1 == t.size()) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

using type = double;
using Vec = vector<type>;
using Mat = vector<Vec>;

const double EPS=1e-4;
bool isZero(type x){
    return abs(x)<=EPS;
}
// sweep mat[i][j] 0<=i<m && 0<=j<c(default c=n)
// return Vec{j| i,j s.t. minj mat[i][j]!=0}
vector<int> sweep(Mat& mat,int c=-1){
    if(c==-1) c=mat[0].size();
    int m = mat.size(),n=mat[0].size();
    int row = 0;
    vector<int> res;
    for(int j=0;j<c;j++){
        if(row==m) break;
        int tar = -1;
        type v = 0;
        for(int i=row;i<m;i++){
            if(!isZero(mat[i][j]) && abs(v)<abs(mat[i][j])){
                tar = i;
                v = mat[i][j];
            }
        }
        if(tar==-1) continue;
        if(row!=tar) swap(mat[row],mat[tar]);
        for(int i=0;i<m;i++){
            if(i==row) continue;
            if(!isZero(mat[i][j])){
                type r = mat[i][j]/mat[row][j];
                for(int k=j;k<n;k++){
                    mat[i][k]-=r*mat[row][k];
                }
            }
        }
        res.push_back(j);
        row++;
    }
    return res;
}

int rank(Mat mat){
    int m = mat.size(), n = mat[0].size();
    return sweep(mat).size();
}

// return an answer of [mat*x=vec]
Vec linearEq(Mat mat,Vec vec){
    int m =mat.size(),n=mat[0].size();
    for(int i=0;i<mat.size();i++) mat[i].push_back(vec[i]);
    auto ids=sweep(mat);
    if(ids.back()==n) return {};
    Vec res(n);
    for(int i=0;i<ids.size();i++) res[ids[i]]=mat[i][n]/mat[i][ids[i]];
    return res;
}

// return kernel of mat i.e. basis of {vec|mat*vec==0}
vector<Vec> kernel(Mat mat){
    int h=mat.size(),w=mat[0].size();
    Mat tmp(w,Vec(h+w));
    for(int i=0;i<h;i++) for(int j=0;j<w;j++) tmp[j][i]=mat[i][j];
    for(int i=0;i<w;i++) tmp[i][h+i]=1;
    int r = sweep(tmp,h).size();
    vector<Vec> res;
    for(int i=r;i<w;i++) res.emplace_back(tmp[i].begin()+h,tmp[i].end());
    return res;
}

void AOJ_1328(){
    int d;
    while(cin>>d,d){
        Vec v(d+3);
        for(int i=0;i<=d+2;i++) cin>>v[i];
        Mat mat(d+3,Vec(d+1));
        for(int i=0;i<=d+2;i++) mat[i][0]=1;
        for(int i=1;i<=d+2;i++) for(int j=1;j<=d;j++) mat[i][j]=pow(i,j);

        auto check=[](Mat mat,Vec vec){
            auto tmp=linearEq(mat,vec);
            return tmp.size();
        };
        for(int i=0;i<=d+2;i++){
            auto tmpMat=mat;
            auto tmpVec=v;
            tmpMat.erase(tmpMat.begin()+i);        
            tmpVec.erase(tmpVec.begin()+i);
            if(check(tmpMat,tmpVec)){
                cout<<i<<endl;
                break;
            }
        }
    }
    return;
}

void test_linearEq(){
    AOJ_1328();    
}

int main(){
    test_linearEq();
    return 0;
}




Measured memory_bytes: 3336
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
#include <string>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

int main() {
    int n;
    cin>>n;
    int a[n];
    long long int sum[n+1];
    sum[0]=0;
    for(int i=0;i<n;i++){
      cin>>a[i];
      sum[i+1]=sum[i]+a[i];
    }
    if(sum[n]%2==0){
      long long int tmp=sum[n]/2;
      for(int i=0;i<n;++i){
        if(labs(sum[n]/2-sum[i])<tmp) tmp=labs(sum[n]/2-sum[i]);
      }
      cout<<2*tmp<<endl;
    }
    else{
      long long int tmp=sum[n]/2;
      for(int i=0;i<n;++i){
        if(labs(sum[n]/2-sum[i]+0.5)<tmp) tmp=labs(sum[n]/2-sum[i]+0.5);
      }
      cout<<2*tmp+1<<endl;
    }
   return 0;
 }


Measured memory_bytes: 2560
import java.util.Arrays;
import java.util.Scanner;
class Main{
public static void main(String[] args) {
Scanner entrada=new Scanner(System.in);
  int A[] = new int[3];
  int n1,n2,n3,caso;
caso=entrada.nextInt();
for(int i=0;i<caso;i++){
n1=entrada.nextInt();
n2=entrada.nextInt();
n3=entrada.nextInt();
A[0]=n1; A[1]=n2;  A[2]=n3;
    Arrays.sort(A);
if (((A[0]*A[0])+(A[1]*A[1]))==A[2]*A[2])
System.out.println("YES");else
System.out.println("NO");
}
}
}

Measured memory_bytes: 12000