akhauriyash/Code-Regression huggingface dataset:
n = int(input())
r = [int(input()) for _ in range(n)]

min_x = r[0]
profit = -(10 ** 9)
for i in range(1, n):
  min_x = min(min_x, r[i-1])
  profit = max(profit, r[i] - min_x)
print(profit)


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

int main(){
    int N;
    cin >> N;
    int res = 0;
    res += min(9,N);
    res += max(min(999, N) - 99,0);
    res += max(min(99999, N) -9999,0);
    cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e2+7;
const ll mod = 1e9 + 9;
const int sz = 25;
#define afdafafafdafaf y1;
int n,m;
int ar[maxn];
char ch[maxn][maxn];
vector<int> v[maxn];
int vis[maxn], dis[maxn];
int main()
{
    scanf("%d", &n);
    for(int i=1;i<=n;i++)scanf("%s", ch[i] + 1);
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(ch[i][j] == '1'){
                v[i].push_back(j);
                v[j].push_back(i);
            }
        }
    }
    int ans = -1;
    for(int i=1;i<=n;i++){
        queue<int> qu;
        memset(dis, -1, sizeof(dis));
        qu.push(i);
        dis[i] = 1;
        int ans_mid = 0, flag = 1;
        while(qu.size()){
            int x = qu.front();
            ans_mid = max(ans_mid, dis[x]);
            qu.pop();
            for(int y : v[x]){
                if(dis[y] == dis[x] + 1 || dis[y] == dis[x] - 1);
                else if(dis[y] == -1){
                    dis[y] = dis[x] + 1;
                    qu.push(y);
                }
                else{
                    flag=0;
                    break;
                }
            }
            if(!flag)break;
        }
        if(flag){
            ans = max(ans, ans_mid);
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 512
// input: HW
// output: chessboard, left-top is #
// # and .

#include <iostream>

using namespace std;

int main(void){
  int H, W;
  while(1){
    cin >> H >> W;
    if(H == 0 && W == 0) break;
    for(int h=0; h<H; h++){
      for(int w=0; w<W; w++){
        if((w%2 == 1 && h%2 == 1) || (w%2 == 0 && h%2 == 0)) cout << "#";
        else cout << ".";
      }
      cout << endl;
    }
    cout << "\n";
  }
  return 0;
}


Measured memory_bytes: 3108
#include <stdio.h>
#include <stdbool.h>
#define true 1
#define false 0
#define MAX 1000
#define VMAX 10000

int n , A[MAX] , s;
int B[MAX] , T[VMAX+1];

void sort(int C[])
{
	int flag = 1;
	int tmp;
	while(flag == 1)
	{
		flag = 0;
		for( int j = n-1; j >= 1; j--)
		{
			if(C[j] < C[j-1])
			{
				tmp = C[j];
				C[j] = C[j-1];
				C[j-1] = tmp;
				flag = 1;
			}
		}
	}
}

int min(int a , int b)
{
	if(a < b) return a;
	else return b;
}

int solve()
{
	int ans = 0;
	
	bool V[MAX];
	for( int i = 0; i < n; i++)
	{
		B[i] = A[i];
		V[i] = false;
	}
	sort(B);
	for( int i = 0; i < n; i++) T[B[i]] = i;
	for( int i = 0; i < n; i++) {
		if(V[i])continue;
		int cur = i;
		int S = 0;
		int m = VMAX;
		int an = 0;
		while(1){
			V[cur] = true;
			an++;
			int v = A[cur];
			m = min(m,v);
			S += v;
			cur = T[v];
			if(V[cur])break;
		}
		ans += min(S+(an-2)*m,m+S+(an+1)*s);
	}
	return ans;
}

int main(void)
{
	scanf("%d",&n);
	s = VMAX;
	for( int i = 0; i < n; i++)
	{
		scanf("%d",&A[i]);
		s = min(s,A[i]);
	}
	int ans = solve();
	printf("%d\n",ans);
}


Measured memory_bytes: 2108
#include <iostream>

using namespace std;

int pow(int n, int r) {
    if (r == 0) return 1;
    if (r % 2) return n * pow(n, --r);
    int t = pow(n, r / 2);
    return t * t;
}

int main() {
    int n, m;
    cin >> n >> m;
    cout << (1800 * m + 100 * n) * pow(2, m) << endl;
    return 0;
}


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

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

int min(int a,int b){
    if(a-b>0) return b;
    return a;
}

int max(int a,int b){
    if(a-b>0) return a;
    return b;
}

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

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

using namespace std;
long long mod(long long x)
{
    return ((x%(1000000007)+1000000007)%(1000000007));
}
int main()
{
    long long n;
    cin>>n;
    long long pow10 = 1;
    long long pow9 = 1;
    long long pow8 = 1;
    long long ans;
    for(int i = 0;i<n;i++)
    {
        pow10 = mod(pow10*10);
        pow9 = mod(pow9*9);
        pow8 = mod(pow8*8);
    }
    ans = mod(pow10 + pow8 - 2*pow9);
    /*if(ans<0)
    {
        ans+=1000000007;
    }*/
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

ll mod=1e9+7;

int main()
{
    fast();
    ll n,cap;
    cin>>n>>cap;

    ll w[n+1],val[n+1];

    for(ll i=1;i<=n;i++)
        cin>>w[i]>>val[i];

    ll dp[n+1][cap+1];
    for(ll i=0;i<=n;i++)
        for(ll j=0;j<=cap;j++)
            dp[i][j]=0;

    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=cap;j++)
        {
            dp[i][j]=dp[i-1][j];

            if(j-w[i]>=0)
            {
                dp[i][j] = max(dp[i][j] , dp[i-1][j-w[i]] + val[i] );
            }
        }
    }
    cout<<dp[n][cap];
}



Measured memory_bytes: 79232
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace cShaprTest
{
    class Program
    {
        public static int N { get; private set; }
        public static int A { get; private set; }
        public static int B { get; private set; }
        public static int C { get; private set; }

        private static int max;
        private static int[] l;

        static void Main(string[] args)
        {
            var NABC = Console.ReadLine().Split().Select(int.Parse).ToArray();
            N = NABC[0];

            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var res = input[0];
            for (var i = 0; i < N; i++)
            {
                res = Gcd(res, input[i]);
            }
            Console.WriteLine(res);
        }
        
        public static int Gcd(int a, int b)
        {
            if (b == 0) return a;
           return Gcd(b, a % b);
        }
    }
}

Measured memory_bytes: 21728
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define reg register
#define maxn 200005
inline ll read()
{
	reg ll x=0,w=0;reg char ch=getchar();
	while(!isdigit(ch))w|=ch=='-',ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return w?-x:x;
}
int n;
ll a[maxn],k;
inline ll tran(ll x,ll y)
{
	if(x<0)
	{
		x=-x,y=-y;
		return (x-1)/y+1;
	}
	return x/y;
}
inline ll calc(ll x)
{
	reg int i;reg ll res=0,tmp;
	for(i=1;i<n;++i)
	{
		if(a[i]<0)
		{
			tmp=a+1+n-lower_bound(a+i+1,a+1+n,tran(x,a[i]));
			res+=tmp;
		}
		else if(a[i]>0)
		{
			tmp=upper_bound(a+i+1,a+1+n,x/a[i])-a-i-1;
			res+=tmp;
		}
		else 
		{
			if(x>=0)res+=n-i;
		}
	}
	return res;
}
int main()
{
	n=read();k=read();reg int i;
	for(i=1;i<=n;++i)a[i]=read();
	sort(a+1,a+1+n);
	reg ll mid,l=-1e18,r=1e18;--l; 
	while(l<r-1)
	{
		mid=(l+r)>>1;
		if(calc(mid)>=k)r=mid;
		else l=mid;
	}
	printf("%lld\n",r);
	return 0;
}

Measured memory_bytes: 1792
S = input()
N = len(S)
for i in range(N):
    if i%2==0:
        if not(S[i]=="R" or S[i]=="U" or S[i]=="D"):
            print("No")
            break

    else:
        if not (S[i]=="L" or S[i]=="U" or S[i]=="D"):
            print("No")
            break
else:
    print("Yes")

Measured memory_bytes: 61804
#include <iostream>
using namespace std;
void ABC70(void);
void ABC71(void);
void ABC72(void);
void ABC73(void);
void ABC75(void);
void ABC77(void);
void ABC78(void);
void ABC79(void);

int main(void){
    ABC78();
}

void ABC78(void){
    char x,y;
    cin>>x>>y;
    if(x<y)cout<<'<'<<endl;
    else if(x>y)cout<<'>'<<endl;
    else cout<<'='<<endl;
}

Measured memory_bytes: 256
N = int(input())
a =list(map(int,input().split()))

cnt = 0
num = 1
for i in range(N):
  if a[i] == num:
    num += 1
  elif a[i] != num:
    cnt += 1

if N - cnt == num-1 and 1 in a:
  print(cnt)
else:
  print(-1)

Measured memory_bytes: 26268
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int main() {
  ll n;cin >> n;
  if(n%2==1) {
    cout << 0 << endl;
    return 0;
  }
  n /= 2;

  ll ans = 0;
  ll five = 5;
  rep(i,25) {
    ans+=n/five;
    five*=5;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3616
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<ll,ll>
#define vi(x) vector<x>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;

signed main()
{
    fast;
   
    ll n;
    cin>>n;
    cout<<n + n*n + n*n*n;
}

Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {

    	Scanner sc=new Scanner(System.in);

    	int N=sc.nextInt();
    	int W=sc.nextInt();

    	int[] w=new int[N];
    	int[] v=new int[N];

    	int[][] dp=new int[N+1][W+1];

    	for(int i=0;i<N;i++) {
    		v[i]=sc.nextInt();
    		w[i]=sc.nextInt();
    	}

    	//dp[i+1][j] i番目までのアイテムで容量jのリュックに詰めれる価値の最大値

    	//dp[0][j]=0;

    	for(int i=0;i<=W;i++) {
    		dp[0][i]=0;
    	}


    	for(int i=0;i<N;i++) {
    		for(int j=0;j<=W;j++) {
    			if(j-w[i]<0) {
    				dp[i+1][j]=dp[i][j];
    			}else {
    				dp[i+1][j]=Math.max(dp[i][j],dp[i][j-w[i]]+v[i]);
    			}
    		}
    	}

    	System.out.println(dp[N][W]);

    }
}



Measured memory_bytes: 31156
#include <iostream>
#include <vector>

using namespace std;

const int INF = 1 << 30;

struct FordFulKerson {
    struct edge {
        int to;
        int cap;
        int rev;
    };

    int V;
    vector<vector<edge>> table;
    vector<bool> visited;

    int dfs(int s, int t, int mn) {
        if (s == t) return mn;
        visited[s] = true;

        for (int i = 0; i < table[s].size(); i++) {
            edge &e = table[s][i];
            if (visited[e.to] || e.cap == 0) continue;
            int diff = dfs(e.to, t, min(mn, e.cap));
            if (diff > 0) {
                e.cap -= diff;
                table[e.to][e.rev].cap += diff;
                return diff;
            }
        }

        return 0;
    }

public:
    FordFulKerson(int v) {
        V = v;
        table.resize(V);
        visited.resize(V);
    }

    void add_edge(int from, int to, int cap) {
        table[from].emplace_back((edge) {to, cap, (int) table[to].size()});
        table[to].emplace_back((edge) {from, 0, (int) table[from].size() - 1});
    }

    int calc(int from, int to) {
        int flow = 0;

        while (true) {
            fill(visited.begin(), visited.end(), false);
            int f = dfs(from, to, INF);
            if (f == 0) break;
            flow += f;
        }

        return flow;
    }
};

signed main() {
    int V, E;
    cin >> V >> E;

    FordFulKerson ff = FordFulKerson(V);
    for (int i = 0; i < E; i++) {
        int s, t, cap;
        cin >> s >> t >> cap;
        ff.add_edge(s, t, cap);
    }

    cout << ff.calc(0, V - 1) << endl;
}


Measured memory_bytes: 3232
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<map>
#include<list>
#include<vector>
#include<string>
#include<unordered_map>
#define int long long
using namespace std;

signed main() {
	string a; cin >> a;
	for (int i = a.length() / 2 - 1; i >= 0;i--) {
		if (a.substr(0, i) == a.substr(i, i)) { cout << i*2 << endl; break; }
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i, v.size()){ cout << v[i] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;}
#define pb push_back
#define int long long
#define INF 1000000000000000000

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

template<typename T> void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

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

int mod = 1000000007;
//int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod
#define AddMult(x, y, z) x = (x + (y) * (z)) % mod

int num(int n, int d){
    int a = 0;
    int t = 1;
    IREP(i, 60){
        if(d == i){
            if(((n >> i) & 1) == 0) t = 0;
        }else{
            if((n >> i) & 1) a = 2 * a + t;
            else a = 2 * a;
        }
    }
    return a;
}

signed main(){

    int A, B; cin >> A >> B;
    B++;
    int ans = 0;
    REP(i, 60){
        if((num(B, i) - num(A, i)) % 2) ans += bit(i);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
s = gets.strip.split("").map(&:to_i)
if s.size==1
  puts s[0]
  exit
end
cnt = 0
#bit全探索
[0,1].repeated_permutation(s.size-1) do |bits|
  sum = 0
  k = 0
  for i in 0..s.size-2
    if bits[i]==1
      sum += s[k..i].join("").to_i
      k = i + 1
    end
  end
  sum += s[k..s.size-1].join("").to_i
  cnt += sum
end
puts cnt

Measured memory_bytes: 14368
#include<bits/stdc++.h>
using namespace std;
string s,k="keyence";
int main()
{
	cin>>s;
	if(s==k)
	{
		cout<<"YES"<<endl;
		return 0; 
	}
	int n=s.size();
	for(int i=0;i<n;i++)
	{
		for(int j=i;j<n;j++)
		{
			string t=""; 
			for(int k=0;k<n;k++)
			{
				if(k<i || k>j)
				{
			    	t+=s[k];
				}
			}
			if(t==k)
			{
				cout<<"YES"<<endl;
				return 0;
			}
		}
	}
	cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>
#define _USE_CMATH_DEFINES

long h, w;

int main(){
    scanf("%ld%ld", &h, &w);
    if(std::min(h, w) == 1){
        printf("%ld\n", 1);
        return 0;
    }
    if(h * w % 2 == 0){
        printf("%ld\n", h * w / 2);
    }else{
        printf("%ld\n", h * w / 2 + 1);
    }
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

final class Main {

    private Main() {
    }

    public static void main(final String[] argv) throws IOException {
        final BufferedReader inputReader =
                new BufferedReader(new InputStreamReader(System.in));
        String input = inputReader.readLine();
        int problemCount = Integer.parseInt(input);
        while (problemCount-- > 0) {
            input = inputReader.readLine();
            int B = Integer.MIN_VALUE;
            int C = Integer.MIN_VALUE;
            boolean success = true;
            for (String ball : input.split(" ")) {
                int value = Integer.parseInt(ball);
                if (B < value) {
                    B = value;
                } else if (C < value) {
                    C = value;
                } else {
                    success = false;
                    break;
                }
            }
            if (success) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        }
    }
}

Measured memory_bytes: 9192
import java.util.*;
public class Main{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
Map<Integer,Integer>map=new HashMap<>();
for(int i=0;i<n;i++){
    int a=sc.nextInt();
    if(map.containsKey(a))
        map.put(a,map.get(a)+1);
    else
        map.put(a,1);
}
int ans=0;
for(Integer key:map.keySet())
    if(key.compareTo(map.get(key))>0)ans+=map.get(key);
    else ans+=map.get(key)-key;
System.out.println(ans);
}
}

Measured memory_bytes: 63484
import java.io.PrintWriter;
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		//String S = sc.next();
		//int N = Integer.parseInt(sc.next());
		//out.println();
		// ArrayList<String> list = new ArrayList<String>();
		// list.stream().sorted().distinct();
		int N = Integer.parseInt(sc.next());
		int M = Integer.parseInt(sc.next());
		int O = Integer.parseInt(sc.next());
		if(O>=N && O<=M){
			out.println("Yes");
		}else{
			out.println("No");
		}
		out.flush();	
	}
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
#define double long double
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

lint c = 1;

lint diff(string &s, string &t){
    lint a = stoll(s), b = stoll(t);
    return min(abs(a-b), c - abs(a-b));
}

int main(){
    string s;
    cin >> s;
    rep(_, s.size()) c *= 10;
    string p;
    rep(i, 10) p += '0'+i;
    string ans = p.substr(0, s.size());
    do{
        string q = p.substr(0, s.size());
        if(diff(ans, s) < diff(q, s)) ans = q;
    }while(next_permutation(p.begin(), p.end()));
    cout << ans << "\n";
}


Measured memory_bytes: 3204
#include <stdio.h>

int main(){
    int numeros[3][3],n;
    int x;
    for(int i=0;i<3;++i)
        for(int j=0;j<3;++j)
            scanf("%d",&numeros[i][j]);

    scanf("%d",&n);
    for(int k=0;k<n;++k){
        scanf("%d",&x);

        for(int i=0;i<3;++i ){
            for(int j=0;j<3;++j){
                if(numeros[i][j]==x)
                    numeros[i][j]=-1;
            }


        }
    }

    if((numeros[0][0]==-1) && (numeros[0][1]==-1) &&(numeros[0][2]==-1))
        printf("Yes\n");
    else if((numeros[1][0]==-1) && (numeros[1][1]==-1) && (numeros[1][2]==-1))
        printf("Yes\n");
    else if((numeros[2][0]==-1) && (numeros[2][1]==-1) && (numeros[2][2]==-1))
        printf("Yes\n");
    else if((numeros[0][0]==-1) && (numeros[1][0]==-1) && (numeros[2][0]==-1))
        printf("Yes\n");
    else if((numeros[0][1]==-1) && (numeros[1][1]==-1) && (numeros[2][1]==-1))
        printf("Yes\n");
    else if((numeros[0][2]==-1) && (numeros[1][2]==-1) && (numeros[2][2]==-1))
        printf("Yes\n");
    else if((numeros[0][0]==-1) && (numeros[1][1]==-1) && (numeros[2][2]==-1))
        printf("Yes\n");
    else if((numeros[2][0]==-1) && (numeros[1][1]==-1) && (numeros[0][2]==-1))
        printf("Yes\n");

    else
        printf("No\n");





    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

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

    ll n;
    cin>>n;

    ll k=0;
    ll t;
    for(int i=0;i*(i-1)/2<=n;i++){
        if(i*(i-1)/2==n) k=i;
    }
    if(k==0){
        Yes(false);
        return 0;
    }
    Yes(true);
    cout<<k<<endl;

    VVi s(k+1);
    ll cnt = 1;

    REP(j,2,k+1)REP(i,1,j){
        s[i-1].pb(cnt);
        s[j-1].pb(cnt);
        cnt++;
    }
    rep(i,k){
        cout<<s[i].size()<<" ";
        rep(j,s[i].size()){
            cout<<s[i][j]<<" ";
        }
        cout<<endl;
    }
    return  0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) for(auto&& x : v){cout << x << " ";} cout << endl
#define printVV(vv) for(auto&& v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto&& p : vp) printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
// typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
// const int inf = 1e9;
const int mod = 1e9 + 7;

typedef tuple<double, int, int, int> TUPLE;
const double inf = 1e12;

struct edge {
    int to, d, c;
    edge(){}
    edge(int _to, int _d, int _c) : to(_to), d(_d), c(_c) {}
};
typedef vector<vector<edge>> Graph;
double dijkstra(const Graph& G, int s, int g) {
    int n = G.size();
    priority_queue<TUPLE, vector<TUPLE>, greater<TUPLE>> pq;   // cost, i, j, pre
    vector<vector<vector<double>>> d(n, vector<vector<double>>(31, vector<double>(n + 1, inf)));
    d[s][0][n] = 0;
    pq.push(make_tuple(0, s, 0, n));

    while (!pq.empty()) {
        double cost;
        int i, j, pre;
        tie(cost, i, j, pre) = pq.top(); pq.pop();
        if (d[i][j][pre] < cost) continue;
        for (const auto& e : G[i]) {
            for (int k = -1; k <= 1; k++) {
                if (e.to == pre) continue;
                if (1 <= j + k && j + k <= e.c && d[e.to][j + k][i] > d[i][j][pre] + 1. * e.d / (j + k)) {
                    d[e.to][j + k][i] = d[i][j][pre] + 1. * e.d / (j + k);
                    pq.push(make_tuple(d[e.to][j + k][i], e.to, j + k, i));
                }
            }
        }
    }

    return *min_element(all(d[g][1]));;
}

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

    int n, m;
    int t = 0;
    while (cin >> n >> m, n) {
        int s, g;
        cin >> s >> g;
        s--, g--;
        Graph G(n);
        rep(i, m) {
            int x, y, d, c;
            cin >> x >> y >> d >> c;
            x--, y--;
            G[x].emplace_back(y, d, c);
            G[y].emplace_back(x, d, c);
        }

        double ans = dijkstra(G, s, g);
        if (ans < inf) {
            cout << fixed << setprecision(10) << ans << endl;
        } else {
            cout << "unreachable" << endl;
        }
    }

}

Measured memory_bytes: 4072
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int k;

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

int solve() {
    int res = 0;
    for (int a = 1; a <= k; a++) {
        for (int b = 1; b <= k; b++) {
            for (int c = 1; c <= k; c++) {
                res += gcd(gcd(a, b), c);
            }
        }
    }
    return res;
}

void input() {
    cin >> k;
}

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

    input();
    cout << solve() << endl;
}


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

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

    bool ten=true;

    for (int i = 0; i < n; i++){
      if(pts.at(i)%10!=0){
          ten=false;
      }
    }

    if(ten){
        cout << 0 << endl;
        exit(0);
    }
    
    sort(pts.begin(),pts.end());
    int ptssum=accumulate(pts.begin(),pts.end(),0);

    int scr=ptssum;
    if(scr%10==0){
        for (int i = 0; i < n; i++){
            scr=ptssum-pts.at(i);
            if(scr%10!=0){
                break;
            }
        }
    }
    

    cout << scr << endl;
    
}

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

#define int long long
#define ll long long
#define f1(i,a,b) for(int i=a;i<b;i++)
#define f2(i,a,b) for(int i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod=1000000007;
ll temp;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int l;
    cin>>l;
    double ans = l/3.0;
    
    cout<<setprecision(13)<<fixed<<(ans*ans)*ans;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include<math.h>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;

int main() {

    int N;
    cin >> N;

    vector<long long> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }

    long long min = *std::min_element(A.begin(), A.end());
    long long max = *std::max_element(A.begin(), A.end());

    cout << max - min << endl;
}

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


int main(){
int a,b,c;
  cin >> a >> b >> c;
bool flag = false;
for(int i=1;i<=b;i++){
if((i*a)%b==c){
flag=true;
break;  
}
}
if(flag==true) cout << "YES" << endl;
  else cout << "NO" << endl;
  
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  string s;
  ll n, a, b;
  in2(n, s);
  vector<vector<ll>> c(500, vector<ll> (26, 0));
  vector<vector<ll>> d(500, vector<ll> (26, 0));
  char f;
  rep2(i, 1, n + 1){
    f = 'a';
    rep(j, 26){
      rep(k, n){
        if(s[k] == f){
          if(k < i)
            c[i][j]++;
          else
            d[i][j]++;
        }
      }
      f++;
    }
  }
  a = 0;
  rep(i, 500){
    b = 0;
    rep(j, 26){
      if(c[i][j] != 0 && d[i][j] != 0)
        b++;
    }
    a = max(a, b);
  }
  out(a);
  memi;
}


Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

/**
 * Usage:
 * 
 * G[from].push_back(Edge(to, weight));
 * using Graph = vector<vector<Edge>>;
 * 
 */ 
struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

template<typename T>
void printv(vector<T>& v) {
  if (v.size() == 0) {
    cout << "\n";
    return;
  }

  Rep(i, v.size()) {
    cout << v[i] << ((i + 1 < v.size()) ? ' ' : '\n');
  }
}



int N;
int a[60];

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

  int tmp = -1;
  int tmp_i = 0;

  rep(i, N) {
    if (abs(a[i]) > tmp) {
      tmp = abs(a[i]);
      tmp_i = i;
    }
  }

  cout << 2 * (N - 1) << "\n";

  rep(i, N) {
    if (i == tmp_i) {
      continue;
    }

    cout << tmp_i << " " << i << "\n";
  }

  if (a[tmp_i] >= 0) {
    for (int i=1;i<=N-1;++i) {
      cout << i << " " << i+1 << "\n";
    }
  } else {
    for (int i=N;i>=2;--i) {
      cout << i << " " << i-1 << "\n";
    }
  }
}

Measured memory_bytes: 256
<?php
$s=trim(fgets(STDIN));
for($i=0;$i<strlen($s);$i++){
	$tiles[]=intval($s[$i]);
}
$tempTiles=$tiles;
$changeStart=0;
$fixStart=0;
for($i=0;$i<count($tempTiles)-1;$i++){
	if($tempTiles[$i]===$tempTiles[$i+1]){
    	$tempTiles[$i+1]=($tempTiles[$i+1]+1)%2;
      	$fixStart+=1;
    }else{
    	continue;
    }
}
$tempTiles=$tiles;
$tempTiles[0]=($tempTiles[0]+1)%2;
$changeStart+=1;
if(isset($tempTiles[1])){
	for($i=0;$i<count($tempTiles)-1;$i++){
		if($tempTiles[$i]===$tempTiles[$i+1]){
    		$tempTiles[$i+1]=($tempTiles[$i+1]+1)%2;
      		$changeStart+=1;
    	}else{
    		continue;
    	}
	}
}

//echo $changeStart;
//echo $fixStart;
if($changeStart>=$fixStart){
	echo $fixStart;
}else{
	echo $changeStart;
}

Measured memory_bytes: 32268
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int one = Integer.parseInt(sc.next());
		int zero = Integer.parseInt(sc.next());
		int min = Integer.parseInt(sc.next());
		int count = Integer.parseInt(sc.next());
		int time = 0;
		if(count==0) {
			System.out.println(0);
		}
		else if(one+zero>=count) {
			if(one>=count) {
			System.out.println(count);}else {
				System.out.println(one);
			}
		}else {
			int mins = count -one-zero;
			System.out.println(one-mins);
		}
}
}


Measured memory_bytes: 35564
'use strict';
const main = input => {
    const n = parseInt(input[0], 10);
    let ans = 0;
    const sft = (val, num, n) => {
        
        // console.log(num);
        
        let Num = 10*num + val;
        let NumString = Num.toString();
        if(n>=Num) {
            if(NumString.indexOf('3')!= -1 && NumString.indexOf('5')!= -1 && NumString.indexOf('7')!= -1) ans++;
            sft(7, Num, n);
            sft(5, Num, n);
            sft(3, Num, n);
        }

    };
    sft(0, 0, n);
    console.log(ans);
    
}
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));

Measured memory_bytes: 12084
import java.util.Scanner;
public class Main {
public static void main(String[] args) {

Scanner sc = new Scanner(System.in);
// 2つの文字の固まりをそれぞれ整数値と想定して読み込む
int a = sc.nextInt();
int b = sc.nextInt();
int area = a*b;
int length = 2*a+2*b;
System.out.println(area + " " + length);
sc.close();
}
}



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

typedef long long ll;
const ll INF = (ll)1e12;

const int C = (int)1e6 + 3;
const int N = 200200;
int n, m;
ll a[N];
ll sum[N];
ll ans[C];

void solve()
{
	for (int i = 0; i < n - 1; i++)
		sum[i + 1] = sum[i] + a[i];
	for (int x = 0; x <= sum[2]; x++)
		ans[x] = -x;
	for (int i = 2; i < n - 1; i++)
		for (int x = sum[i] + 1; x <= sum[i + 1]; x++)
		{
			int y = 2 * sum[i] - x;
			if (y < 0)
				ans[x] = -y;
			else
				ans[x] = ans[y];
		}
	return;
}

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

	scanf("%d", &n);
	for (int i = 0; i < n - 1; i++)
		scanf("%lld", &a[i]);
	solve();
	scanf("%d", &m);
	while(m--)
	{
		ll x;
		scanf("%lld", &x);
		if (x >= sum[n - 1])
			printf("%lld\n", x - sum[n - 1] + 2 * a[0]);
		else
			printf("%lld\n", 2 * a[0] + ans[sum[n - 1] - x]);
	}

	return 0;
}

Measured memory_bytes: 13056
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;

signed main(){
    ll a,b;
    cin>>a>>b;
    if(a<=9 && b<=9) cout<<a*b<<endl;
    else cout<<"-1"<<endl;
}


Measured memory_bytes: 256
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

const int MAX_N = 1e5;
long long dp[MAX_N][2];

int main() {
    int N;
    cin >> N;
    vector<long long> A(N + 1);
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
    }

    dp[0][0] = 0;
    dp[0][1] = -1e6;
    for (int i = 1; i <= N; i++) {
        dp[i][0] = max(dp[i - 1][0] + A[i], dp[i - 1][1] - A[i]);
        dp[i][1] = max(dp[i - 1][0] - A[i], dp[i - 1][1] + A[i]);
    }
    cout << dp[N][0] << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ipair = pair<int, int>;
using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

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

const double PI=3.14159265358979323846;

const int mod = 1e9+7;

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 {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=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 {
    mint res(*this);
    return res/=a;
  }
};

// 使い方
// Nの取りうる最大値で初期化
// combination c(n+5);  
// c(n, k)
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main(){

  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  sort(A.begin(), A.end());

  combination c(N+1);

  mint ans = 0;
  rep(dir, 2){
    rep(i, N){
      mint now = c(i, K-1);
      if(dir == 1) now = -now;
      ans += now * A[i];
    }
    reverse(A.begin(), A.end());
  }

  cout << ans.x << endl;

  return 0;
}


Measured memory_bytes: 2304
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

//マクロ
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
//定数
#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100000
//略記
#define PB push_back
#define MP make_pair
#define F first
#define S second

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

    char a; cin >> a;

    if (isupper(a)) {
        cout << "A" << endl;
    }
    else {
        cout << "a" << endl;
    }
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N, K;
    cin >> N >> K;
    vector<int> d(N);
    for (int i = 0; i < N; i++) cin >> d[i];

    int ans = -INF;
    for (int i = 0; i <= min(K, N); i++) {
        for (int j = 0; j <= min(K, N); j++) {
            if (i + j > min(N, K)) continue;
            vector<int> v;
            copy(d.begin(), d.begin() + i, back_inserter(v));
            copy(d.rbegin(), d.rbegin() + j, back_inserter(v));
            sort(v.begin(), v.end());
            int tmp = accumulate(v.begin(), v.end(), 0);
            for (int k = 0; k < min((int)v.size(), K - (i+j)); k++) if (v[k] < 0) tmp -= v[k];
            ans = max(ans, tmp);
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include<math.h>

int main()
{
    long long int N,i,a,b,c,m,sum;
    scanf("%lld", &N);
    m=N+1;
    a=sqrt(N);
    for(i=a;i>=1;i--){
        if(N%i==0){
            b=N/i;
            c=b+i;
            if(c<=m){
                m=c;
                sum=m-2;
            }
        }
    }
    printf("%lld\n", sum);
    return 0;
}


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

#include <bits/stdc++.h>

template<typename T>
vector< T > divisor(T n) {
  vector< T > ret;
  for(T i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

template<typename T>
T gcd(T a, T b){
    if (b==0) return a;
    else return  gcd(b,a%b);
}

template<typename T>
T lcm(T a, T b){
    return a*b / gcd<T>(a,b);
}



template<typename T >
long long extGCD(T a, T b, T &x, T &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    T d = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return d;
}

using namespace std;

int main(){
    ll a,b;
    cin >>  a >> b;
    ll x,y;
    extGCD(a,b,x,y);
    ll d = lcm(a,b);
    ll cand1 = abs(x)+abs(y);
    ll cand2 = abs(x-d/a) + abs(y+d/b);
    ll cand3 = abs(x+d/a) + abs(y-d/b);
    vector<ll> cands{cand1,cand2,cand3};
    int ans_idx = min_element(cands.begin(),cands.end()) - cands.begin();
    if (ans_idx==0){
        printf("%lld %lld\n",x,y);
    }else if (ans_idx==1){
        printf("%lld %lld\n",x-d/a,y+d/b);
    }else{
        printf("%lld %lld\n",x+d/a,y-d/b);
    }



    
}


Measured memory_bytes: 3232
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int max = 0;
		int sum = 0;
		for(int i = 0; i < n; i++)
		{
			int p = sc.nextInt();
			sum += p;
			max = Math.max(max, p);
		}
		System.out.println(sum - max/2);
	}
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(W,n)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {REP(aaa,i){REP(bbb,j)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

//ａをbで割る
long long mod_div(long long a,long long b){
	long long tmp = MOD - 2,c = b,ret = 1;
	while(tmp > 0){
		if(tmp & 1){
			ret *= c;ret %= MOD;
		}
		c *= c;c %= MOD;tmp >>= 1;
	}
	return a*ret%MOD;
}

#define MAX_K 333333
vector<long long> kaijo(MAX_K);
long long combination(long long n, long long r){
    if(n < r || n < 0 || r < 0)
        return 0;
	if(kaijo[0] != 1){
		kaijo[0] = 1;
		for(long long i = 1;i < MAX_K;i++)kaijo[i] = (kaijo[i-1] * i) % MOD;
	}
    long long ret = kaijo[n];
	long long tmp = (kaijo[r] * kaijo[n-r]) % MOD;
    return mod_div(ret,tmp);
}

ll dp[3333][2];

void modadd(ll &a, ll b){
	a += b;
	a %= MOD;
}

int main(){

	int h,w,n;cin >> h >> w >> n;

	vector<P> v;
	REP(i,n){
		int a,b;cin >> a >> b;
		v.EB(a,b);
	}
	v.EB(1,1);
	v.EB(h,w);
	sort(ALL(v));
	dp[0][0] = 1;

	REP(i,v.size()){
		int y = v[i].FI;
		int x = v[i].SE;
		REP(j,2)if(dp[i][j]){
			for(int k = i+1;k < v.size();k++){
				int yy = v[k].FI;
				int xx = v[k].SE;
				if(y <= yy && x <= xx){
					modadd(dp[k][(j+1)%2],dp[i][j] * combination((yy-y)+(xx-x),(yy-y)) % MOD);
				}
			}
		}
	}

	cout << (dp[n+1][1] - dp[n+1][0] + MOD) % MOD << endl;

	return 0;
}


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

typedef long long int ll;

int main(){

    ll n,m,ans=0;
    cin >> n >> m;
    if(n>m){
        swap(n,m);
    }

    if(n == 1){

        if(m == 1){
            ans = 1;
        }else{
            ans = m-2;
        }
    }else{
        ans = (n-2)*(m-2);
    }

    cout << ans << endl;
   
    


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int NUM, add_num = 0;
 
  cin >> NUM >> add_num;
  // ここにプログラムを追記
  int total = 1;
  for (int iter = 0; iter < NUM; iter++) {
    if (total * 2 < total + add_num) {
      total *= 2;
    }
    else {
      total += add_num;
    }
  }
  cout << total << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define int long long

int N;
vector<vector<pair<int, int>>> graph;
vector<int> depth;

int dfs(int v, int p, int d) {
  depth[v] = d;
  for(auto e : graph[v]) {
    if(e.first == p) continue;
    dfs(e.first, v, d + e.second);
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  graph.resize(N);
  depth.resize(N);
  REP(i, N - 1) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    graph[a].emplace_back(b, c);
    graph[b].emplace_back(a, c);
  }

  int Q, K;
  cin >> Q >> K;
  K--;

  dfs(K, -1, 0);
  REP(i, Q) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    cout << depth[x] + depth[y] << endl;
  }
  return 0;
}

Measured memory_bytes: 14336