akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999

ll fact(int n){
    ll ret=1;
    for(int i=1;i<=n;i++) ret*=i;
    return ret;
}

int main(){
    int al[30]={};
    
    string s;
    cin>>s;
    rep(i,s.size()){
        al[s[i]-'a']++;
    }
    
    int even=0,odd=0;
    ll div=1;
    rep(i,28){
        if(al[i]==0)continue;
        if(al[i]%2==0){
            even+=al[i]/2;
            div*=fact(al[i]/2);
        }
        else{
            odd++;
            even+=(al[i]-1)/2;
            if(al[i]>1)div*=(al[i]-1)/2;
        }
    }
    
    if(odd>1){
        cout<<0<<endl;
    }
    else{
        cout<<fact(even)/div<<endl;
    }
    
}

Measured memory_bytes: 3204
#include<stdio.h>
int main(void)
{
  int price,num,amari;
  char str[16];
  
  fgets(str,sizeof(str),stdin);
  sscanf(str,"%d",&price);
  
//百で割った商numだけ購入する
  num = price / 100;
/*その際、十の位以下はmin 0 max 5*num
  この区間にある数は全て表現できる*/
  amari = price % 100;
  if(amari <= 5*num)
  {
    puts("1");
  }else
  {
    puts("0");
  }
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c,k;
    cin>>a>>b>>c;
    cin>>k;
    while(k--){
        if(b<=a){
            b*=2;
        }else{
            c*=2;
        }
    }
    if(c>b&&b>a){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }



return 0;

}

//      *   *  *****  *   *  *   *   ****  ****    ****     **  ***
//     *   *  *      **  *  *   *  *      *   *  *        * *  *  *
//    *****  *****  * * *  *   *  *      ****   *       *  *    *
//   *   *      *  *  **  *   *  *      *  *   *       *****  *
//  *   *  *****  *   *   ***    ****  *   *    ****     *   ****

//     ****  *   *  *   *   ***   *   *  *****  *   *
//    *     *   *  *   *  *   *  *   *  *      *   *
//    ***  *****  *   *  *****  * * *  ****   *   *
//      *   *    *   *  *   *  * * *  *      *   *
//  ****   *     ***   *   *   * *   *****   ***


Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef pair<ll, ll> pll;

#define all(x) (x).begin(), (x).end()
#define size(x) (ll)x.size()
#define x first
#define y second
#define chkmax(x, y) x = max(x, y)
#define chkmin(x, y) x = min(x, y)
#define pb emplace_back
mt19937_64 gen;

void run() {
	string s;
	cin >> s;
	vector<ll> ans(size(s) + 1);
	ll cur = 0;
	for(int i = 0; i < size(s); i++) {
		if (s[i] == '<') cur++;
		else cur = 0;
		ans[i + 1] = cur;
	}
	cur = 0;
	for(int i = size(s) - 1; i >= 0; i--) {
		if (s[i] == '>') cur++;
		else cur = 0;
		chkmax(ans[i], cur);
	}
	cout << accumulate(all(ans), 0LL);
}
 
signed main() {
#ifdef kek
  gen(12 * 21);
#else
  gen.seed(time(0));
#endif // kek
  ios::sync_with_stdio(0);
  cin.tie(0);
  run();
}

Measured memory_bytes: 4764
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
#define fs first
#define sc second

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

int INF = 100000000;

typedef pair<int, int> P;

int main(){
    int h, w;
    cin >> h >> w;
    string s[h];
    for(int i = 0; i < h; i++) cin >> s[i];

    int ans = 0;

    for(int si = 0; si < h; si++){
        for(int sj = 0; sj < w; sj++){
            for(int gi = 0; gi < h; gi++){
                for(int gj = 0; gj < w; gj++){
                    if(s[si][sj] == '#' || s[gi][gj] == '#') continue;
                    //start si,sj goal gi gj

                    queue<P> que;
                    vector<vector<int>> d(h, vector<int>(w, INF));
                    que.push(P(si, sj));
                    d[si][sj] = 0;

                    while(que.size()){
                        P p = que.front();
                        que.pop();
                        if(p.first == gi && p.second == gj) break;

                        for(int k = 0; k < 4; k++){
                            int nx = p.fs + dx[k];
                            int ny = p.sc + dy[k];
                            if(0 <= nx && nx < h && 0 <= ny && ny < w){
                                if(d[nx][ny] == INF && s[nx][ny] == '.'){
                                    que.push(P(nx, ny));
                                    d[nx][ny] = d[p.fs][p.sc] + 1;
                                }
                            }
                        }
                    }

                    ans = max(ans, d[gi][gj]);
                }
            }
        }
    }

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

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

int main()
{
    auto h = int(0);
    auto w = int(0);

    std::cin >> h >> w;

    auto white = int(0);
    auto s =
        std::vector<std::vector<char>>(h, std::vector<char>(w, 0));
    auto visited = std::vector<std::vector<bool>>(h, std::vector<bool>(w, false));
    for (std::size_t i = 0; i < static_cast<std::size_t>(h); ++i)
        for (std::size_t j = 0; j < static_cast<std::size_t>(w); ++j)
        {
            std::cin >> s[i][j];
            if (s[i][j] == '.') white++;
        }

    auto comp = [](auto a, auto b) { return std::get<2>(a) > std::get<2>(b); };
    auto q =
        std::priority_queue<std::tuple<int, int, int>, std::vector<std::tuple<int, int, int>>, decltype(comp)>(comp);

    auto sx = int(0);
    auto sy = int(0);
    auto gx = int(w - 1);
    auto gy = int(h - 1);

    auto dx = std::vector<int>({0, 1, 0, -1});
    auto dy = std::vector<int>({1, 0, -1, 0});

    q.emplace(sx, sy, 1);
    visited[static_cast<std::size_t>(sy)][static_cast<std::size_t>(sx)] = true;
    auto steps = std::vector<int>();
    while (!q.empty())
    {
        auto px = std::get<0>(q.top());
        auto py = std::get<1>(q.top());
        auto round = std::get<2>(q.top());

        q.pop();
        auto tx = int(0);
        auto ty = int(0);

        for (std::size_t i = 0; i < 4; ++i)
        {
            tx = px + dx[i];
            ty = py + dy[i];

            if (tx < 0 || w <= tx || ty < 0 || h <= ty) continue;

            if ((!visited[static_cast<std::size_t>(ty)][static_cast<std::size_t>(tx)]) &&
                s[static_cast<std::size_t>(ty)][static_cast<std::size_t>(tx)] == '.')
            {
                if (tx == gx && ty == gy)
                {
                    steps.emplace_back(round + 1);
                    continue;
                }

                visited[static_cast<std::size_t>(ty)][static_cast<std::size_t>(tx)] = true;
                q.emplace(tx, ty, round + 1);
            }
        }
    }

    if (steps.empty())
        std::cout << -1 << std::endl;
    else
        std::cout << white - *std::min_element(steps.begin(), steps.end()) << std::endl;
  
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define M 1000000007 
#define MM 998244353
#define PI 3.14159265 
using namespace std;

int main()
{
	int n;
	cin >> n;

	int h[n];
	
	for (int i = 0; i < n; i++)
	{
		cin >> h[i];
	}

	int dp[n];

	dp[0] = 0;

	dp[1] = abs(h[1] - h[0]);

	for (int i = 2; i < n; i++)
	{
		dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i-2] - h[i]));
	}

	cout << dp[n-1];

  	return 0;
}

Measured memory_bytes: 4400
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();
		int count = 0;
		
		for(int i = A; i <= B; i++) {

			String I = Integer.toString(i);
			if(I.substring(0, 1).equals(I.substring(4,5)) && I.substring(1, 2).equals(I.substring(3,4))) {
				count++;
			}
		}
		
		System.out.println(count);
		
		
	}

}


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

int main() {
  string s, t, u;
  cin>>s>>t;
  int a, b;
  cin>>a>>b;
  cin>>u;
  if (s == u) {
    cout<<a - 1<<" "<<b<<endl;
  } else {
    cout<<a<<" "<<b - 1<<endl;
  }
}

Measured memory_bytes: 764
#include <stdio.h>

int	main(void)
{
  	int	N;
  	int A[101];
  	int	i;
  	double	B[101];
  	double	sum;
  
  	scanf("%d\n", &N);
  	for(i=1; i<=N; i++)
    {
      	scanf("%d", &A[i]);
      	B[i] = (double)1.0 / A[i];
    }
  
  	sum = 0.0;
  	for(i=1; i<=N; i++)
    {
      	sum += B[i];
    }
  
  	printf("%f", 1.0 / sum);
  	return (0);
}
  
  	

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう

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

int main() {
  string s;
  int q;
  cin>>s>>q;
  int cnt=0;
  int temp=0;
  int a=0;
  char x;
  string fr;
  rep(i,q){
    cin>>a;
    if(a==1){
      cnt++;
      continue;
    }
    else{
      if(cnt%2){a+=2;}
      cin>>temp>>x;
      a+=temp;
      temp=0;
      if(a==3||a==6)fr=fr+x;
      else s=s+x;
    }
  }
  reverse(fr.begin(),fr.end());
  s=fr+s;
  if(cnt%2){reverse(s.begin(),s.end());cnt=0;}
  cout<<s<<endl;   
}



Measured memory_bytes: 1708
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        private static Tuple<int, int> Solve(int A, int B, int C, int D, int E, int F)
        {
            var set = new HashSet<Tuple<int, int>>();
            var queue = new Queue<Tuple<int, int>>();
            var zero = new Tuple<int, int>(0, 0);
            set.Add(zero);
            queue.Enqueue(zero);
            while (queue.Count > 0)
            {
                var t1 = queue.Dequeue();
                int w1 = t1.Item1;
                int s1 = t1.Item2;
                foreach (var t2 in new[] { new Tuple<int, int>(w1 + 100 * A, s1),
                                           new Tuple<int, int>(w1 + 100 * B, s1),
                                           new Tuple<int, int>(w1, s1 + C),
                                           new Tuple<int, int>(w1, s1 + D) })
                {
                    int w2 = t2.Item1;
                    int s2 = t2.Item2;
                    if (!set.Contains(t2) && w2 * E >= s2 * 100 && w2 + s2 <= F)
                    {
                        set.Add(t2);
                        queue.Enqueue(t2);
                    }
                }
            }
            return set.OrderByDescending(t => (double)t.Item2 / (t.Item1 + t.Item2)).ElementAt(0);
        }
        static void Main(string[] args)
        {
            int[] values = ReadInts();
            var tuple = Solve(values[0],
                              values[1],
                              values[2],
                              values[3],
                              values[4],
                              values[5]);
            Console.WriteLine("{0} {1}", tuple.Item1 + tuple.Item2, tuple.Item2);
        }
    }
}


Measured memory_bytes: 16860
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i=0;i<(n);++i)
#define RANGE(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(n)-1;i>= 0;--i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define dcout cout<<fixed<<setprecision(20)
#define Accepted_MAGIC cin.tie(0);ios::sync_with_stdio(false);cerr << "compiled" << endl

// typedef long long ll;
using Real = long double;
#define int long long

const long long dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;
constexpr Real eps = 1e-9, pi = acos(-1);

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
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;}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

signed main(void){
  Accepted_MAGIC;
  
  string S; cin >> S;
  if((S!="AAA") and (S!="BBB")) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

//AtCoder Beginner Contest 135
//A	Harmony
public class Main {

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

		if ((A + B) % 2 == 0) {
			System.out.println((A + B) / 2);
		} else {
			System.out.println("IMPOSSIBLE");
		}
	}
}


Measured memory_bytes: 21844
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <string.h>

int main()
{
    int max = 0;
    int min = INT_MAX;
    int array[5];
    int count = 0;
    int idxmax,idxmin;
    char str[124]={'\0'};
    for (int i=0; i<5; i++)
    {
        scanf("%d",&array[i]);
        sprintf(str, "%d", array[i]);
        int a = str[strlen(str)-1]-'0';
        if (max<=a)
        {
            max=a;
            idxmax=i;
        }
        if (min>=a && a!=0)
        {
            min=a;
            idxmin=i;
        }
    }
    if (min==max)idxmin--;
    int j = 0;
    int res = 0;
    int sum = array[idxmax];
    while (j<=4)
   {


        res = array[j];
       if (sum%10==0 && j!=idxmin && j!=idxmax)sum+=res;
       else if (sum%10!=0 && j!=idxmin && j!=idxmax)
       {

          while (sum%10!=0)
           sum++;
         sum+=res;
       }
     while (sum%10!=0)
           sum++;
     j++;
    }

    while (sum%10!=0)sum++;
    sum+=array[idxmin];

    printf("%d",sum);


    return 0;

}



Measured memory_bytes: 128
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}


signed main(){
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	rep(i,h){
		cin >> s[i];
	}

	auto v = vectors(4, h, w, 0);
	rep(i,h){
		int a = 0, b= 0;
		rep(j,w){
			if(s[i][j] == '.') a++;
			else a = 0;
			v[0][i][j] = a;
		}
		for(int j = w - 1; j >= 0; j--){
			if(s[i][j] == '.') b++;
			else b = 0;
			v[1][i][j] = b;
		}
	}
	rep(i,w){
		int a = 0, b= 0;
		rep(j,h){
			if(s[j][i] == '.') a++;
			else a = 0;
			v[2][j][i] = a;
		}
		for(int j = h - 1; j >= 0; j--){
			if(s[j][i] == '.') b++;
			else b = 0;
			v[3][j][i] = b;
		}
	}

	int ans = 0;
	rep(i,h){
		rep(j,w){
			int sum = 0;
			rep(k,4){
				sum += v[k][i][j];
			}
			ans = max(ans, sum - 3);
		}
	}
	cout << ans << endl;
}


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

#define MIN(a, b) (a > b ? b : a)

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

using namespace std;

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

  long long k;
  cin >> k;

  int n = max(2, (int) MIN(k, 50));
  long long ans[n];
  REP(i, n) {
    ans[i] = i;
  }

  long long div = k / n;
  REP(i, n) {
    ans[i] += div;
  }

  int mod = (int) (k % n);
  REP(i, mod) {
    ++ans[n - i - 1];
  }

  cout << n << endl;

  REP(i, n) {
    if (i != 0) {
      cout << ' ';
    }
    cout << ans[i];
  }

  cout << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main{

    int[] par, rank;
    int V, E;
    P[] es;

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

    int find(int x){
        if(par[x]==x) return x;
        else return par[x] = find(par[x]);
    }

    void unit(int x, int y){
        x = find(x); y = find(y);
        if(x==y) return;
        if(rank[x]<rank[y]) par[x] = y;
        else {
            par[y] = x;
            if(rank[x]==rank[y]) rank[x]++;
        }
    }

    boolean same(int x, int y){
        return find(x)==find(y);
    }

    class P{
        int u, v, cost;
        P(int u, int v, int cost){
            this.u = u;
            this.v = v;
            this.cost = cost;
        }
    }

    void solve(){
        Scanner sc = new Scanner(System.in);
        int INF = Integer.MAX_VALUE/2;

        while(true){
            V = sc.nextInt(); E = sc.nextInt();
            if(V==0 && E==0) break;

            es = new P[E];
            for(int i=0; i<E; i++){
                int a = sc.nextInt()-1, b = sc.nextInt()-1, w = sc.nextInt();
                es[i] = new P(a, b, w);
            }

            Arrays.sort(es, new Comparator<P>(){
                    public int compare(P p1, P p2){
                        return p1.cost - p2.cost;
                    }
                });

            int ans = INF;
            for(int i=0; i<E; i++){
                init(V);
                int max = 0, min = INF;
                int cnt = 0;
                for(int j=i; j<E; j++){
                    P e = es[j];
                    if(!same(e.u, e.v)){
                        unit(e.u, e.v);
                        max = Math.max(max, e.cost);
                        min = Math.min(min, e.cost);
                        cnt++;
                    }
                }
                if(cnt!=V-1) continue;
                ans = Math.min(ans, max - min);
            }
            if(ans==INF) ans = -1;
            System.out.println(ans);
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 76552
#include <stdio.h>
int main(void)
{
 int n, k, x, i;
 scanf("%d %d", &n, &k);

 int ans = 0;

 for (i = 0; i < n; i++ ) {
  scanf("%d", &x);
  if(k / 2 < x) ans += (k-x)*2;
  else ans += x * 2;
 }

 printf("%d", ans);
 return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();
		int X = sc.nextInt();
		int costL = 0;
		int costR = 0;

		for(int i = 0; i < M; i++) {
			int tmp = sc.nextInt();
			if(tmp < X) {
				costL++;
			} else {
				costR++;
			}
		}

		System.out.println(Math.min(costL,costR));

	}

}


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

typedef long long ll;

#define int ll
 
struct node{
	ll w;
	int y;
}a[100050];
 
struct node2{
	int t, nxt;
}edge[200050];
 
struct node3{int fr, f;};
 
int head[100050], cnt, n, siz[100050], anss;
 
void add(int u, int v){
	edge[++cnt] = (node2){v, head[u]};
	head[u] = cnt;
}
 
bool cmp(node a, node b){return a.w<b.w;}
 
int find(int u){
	for(int i = u-1; i >= 1; i--)if(a[i].w - a[u].w == 2*siz[a[u].y] - n) return a[i].y;
	return -1;
}
 
void print(int u, int fa){
	queue<node3> q;
	q.push((node3){u, fa});
	while(!q.empty()){
		u = q.front().fr;
		int ff = q.front().f;
		q.pop();
		for(int i = head[u]; i; i = edge[i].nxt){
			int v = edge[i].t;
			printf("%d %d\n", u, v);
			q.push((node3){v, u});
		}
	}
}

void test(int u, int fa, int dep){
	anss+=dep;
	for(int i = head[u]; i; i = edge[i].nxt){
		int v = edge[i].t;
		if(v == fa) continue;
		test(v, u, dep+1);
	}
}

main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		scanf("%lld", &a[i].w);
		a[i].y = i;
	}
	sort(a+1, a+n+1, cmp);
	int rt = a[1].y;
	for(int i = n; i >= 2; i--) {
		siz[a[i].y]++;
		int p = find(i);
		if(p == -1){
			printf("-1");
			return 0;
		}
		siz[p]+=siz[a[i].y];
		add(p, a[i].y);
	}
	test(rt, 0, 0);
	if(anss != a[1].w){
		printf("-1");
		return 0;
	}
	print(rt, 0);
}

Measured memory_bytes: 9984
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;



#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

ll debugFlag = false;
template<typename T> void debug(T&);
template<typename T> void debug(T&, bool);
template<typename T> void debug(vector<T>&);
template<typename T> void debug(vector<T>&, bool);
template<typename T, typename U> void debug(pair<T, U>&);
template<typename T, typename U> void debug(pair<T, U>&, bool);

template<typename T>
void debug(T& obj) {
	debug(obj, true);
}

template<typename T>
void debug(T& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << obj;
	if (lnFlag) cout << endl;
}

template<typename T>
void debug(vector<T>& obj) {
	debug(obj, true);
}

template<typename T>
void debug(vector<T>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "[";
	rep(i, obj.size()) {
		if (i != 0) cout << ",";
		debug(obj[i], false);
	}
	cout << "]";
	if (lnFlag) cout << endl;
}

template<typename T, typename U>
void debug(pair<T, U>& obj) {
	debug(obj, true);
}

template<typename T, typename U>
void debug(pair<T, U>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "(";
	debug(obj.first, false);
	cout << ",";
	debug(obj.second, false);
	cout << ")";
	if (lnFlag) cout << endl;
}

void solve() {

	ll N, K;
	cin >> N >> K;

	vector<pair<ll, ll>> sushi(N);

	rep(i, N) {
		cin >> sushi[i].second >> sushi[i].first;
	}

	sort(sushi.begin(), sushi.end(), [](const pair<ll, ll>& x, const pair<ll, ll>& y) {
		return x.first > y.first;
	});

	//debug(sushi);

	map<ll, ll> MP;

	priority_queue <
		pair<ll, ll>,
		vector<pair<ll, ll>>,
		greater<pair<ll,ll>>
	> ok;

	priority_queue <
		pair<ll, ll>
	> ng;

	ll sum = 0;

	rep(i, N) {
		if (i < K) {
			sum += sushi[i].first;
			MP[sushi[i].second]++;
			ok.push(sushi[i]);
		}
		else {
			ng.push(sushi[i]);
		}
	}

	ll cnt = MP.size();
	ll ans = sum + cnt * cnt;

	while (1) {

		pair<ll, ll> minpop, maxpop;
		bool end = false;

		while (1) {

			if (ok.size() == 0) {
				end = true;
				break;
			}

			minpop = ok.top();
			ok.pop();

			if (MP[minpop.second] > 1) {
				MP[minpop.second]--;
				break;
			}

		}
		if (end) break;

		while (1) {

			if (ng.size() == 0) {
				end = true;
				break;
			}

			maxpop = ng.top();
			ng.pop();

			if (MP[maxpop.second] == 0) {
				MP[maxpop.second] = 1;
				break;
			}


		}
		if (end) break;

		cnt++;
		sum = sum - minpop.first + maxpop.first;

		ans = max(ans, sum + cnt * cnt);
	}

	cout << ans;

}


int main(int argc, char* argv[]) {
	if (argc == 2 && string(argv[1]) == "debug") debugFlag = true;
	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 7408
#include <bits/stdc++.h>
using namespace std;
 
int main(){
 
long long int i,a,b,c,k,count=0,sum=0;
cin >> a >> b >> c >> k;
for(i=0;i<a;i++){
  if(count>=k)break;
  sum++;
  count++;
}
for(i=0;i<b;i++){
  if(count>=k)break;
  count++;
}
for(i=0;i<c;i++){
  if(count>=k)break;
  
  sum--;
  count++;
}
cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3628
def solve(k,x,y):
    if k%2==0 and (x+y)%2==1:
        print(-1)
        return
    x_sign=1; y_sign=1
    xy_inv=False
    if x<0:
        x*=-1
        x_sign=-1
    if y<0:
        y*=-1
        y_sign=-1
    if x<y:
        xy_inv=True
        x,y=y,x

    def print_xy(x,y):
        if xy_inv:
            print(y*x_sign,x*y_sign)
        else:
            print(x*x_sign,y*y_sign)
        return

    if x+y<k and (x+y)%2==1:
        print(3)
        now_y=x-k
        print_xy(x,now_y)
        now_x=x+(k+x-y)//2
        now_y+=k-(k+x-y)//2
        print_xy(now_x,now_y)
        print_xy(x,y)
        return
    c=(k-((x+y)%k))%k
    if x+y<k:
        n=2
    else:
        n=((x+y+k-1)//k)+(c%2)
    print(n)
    ans=0
    now_y=-k
    l=-(k*n-x-y)//2
    while now_y>=l:
        print_xy(0,now_y)
        now_y-=k
    now_x=l-now_y
    while now_x<=x:
        print_xy(now_x,l)
        now_x+=k
    now_y=l+now_x-x
    while now_y<=y:
        print_xy(x,now_y)
        now_y+=k
    return

k=int(input())
x,y=map(int,input().split())
solve(k,x,y)

Measured memory_bytes: 53976
#include <bits/stdc++.h>
#define N 200020
#define ll long long
using namespace std;
inline int read(){
  int x=0,f=1;char ch=getchar();
  while(ch>'9'||ch<'0')ch=='-'&&(f=0)||(ch=getchar());
  while(ch<='9'&&ch>='0')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
  return f?x:-x;
}

int to[N<<1], nxt[N<<1], head[N], cnt;
void insert(int x, int y) {
  to[++ cnt] = y; nxt[cnt] = head[x]; head[x] = cnt;
  to[++ cnt] = x; nxt[cnt] = head[y]; head[y] = cnt;
}

char str[N];
int chs[N], tot, R[N], L[N], d1[N], d2[N];
ll ans;

int fir_dfs(int x,int f) {
  for (int i = head[x]; i; i = nxt[i]) {
    if (to[i] != f) {
      chs[x] += fir_dfs(to[i], x);
      int w = d1[to[i]] + 1;
      if (w > d1[x]) d2[x] = d1[x], d1[x] = w;
      else if (w > d2[x]) d2[x] = w;
    }
  }
  return chs[x];
}
void sec_dfs(int x, int f, int v) {
  R[x] = v > d1[x] ? d1[x] : max(v, d2[x]);
  L[x] = str[x] == '1' ? 0 : (tot != chs[x] ? v : (1 << 30));
  if (f) {
    if (d1[x] == v - 1) ++ ans;
    else if (d1[x] < v - 1) ans += chs[x] > 0;
    else ans += chs[x] < tot;
  }
  for (int i = head[x]; i; i = nxt[i]) {
    if (to[i] != f) {
      if (chs[to[i]]) L[x] = min(L[x], d1[to[i]] + 1);
      if (d1[to[i]] + 1 == d1[x]) sec_dfs(to[i], x, max(v, d2[x]) + 1);
      else sec_dfs(to[i], x, max(v, d1[x]) + 1);
    }
  }
}
int main(int argc, char const *argv[]) {
  // freopen("../../temp/.in", "r", stdin);

  int n = read();
  for (int i = 1; i < n; ++ i) {
    insert(read(), read());
  }
  scanf("%s", str + 1);
  for (int i = 1; i <= n; ++ i) {
    tot += chs[i] = str[i] == '1';
  }

  fir_dfs(1, 0);
  sec_dfs(1, 0, 0);

  for (int i = 1; i <= n; ++ i) {
    if (L[i] <= R[i]) {
      ans += R[i] - L[i] + 1;
    }
  }

  printf("%lld\n", ans);

  return 0;
}
/*

我们考虑枚举你染黑的连通块的中心（也就是所有直径的中点）。 
有两种情况：
1）中心是一个点； 
2）中心是一条边的中点；

对于1），考虑将其置为根rt，则连通块的“半径”是一个区间（半径就是说这个联通块的直径的一半）。

首先考虑其上界R：答案就是来自不同子树的最长链的第二长链，这里是不严格次长，也就是可以相等。这是由于，考虑最长链是A来自x，次长是B来自y，且A>B，那么当你半径>B的时候，y会全被涂黑，然后从从B的链底走到rt再走到x中被涂黑色的最深的点，显然长度>=2B，此时这条链的中心显然不是rt，就gg了。

其次考虑其下界L：下界就是，考虑rt的所有满足子树中存在s[y]=1的 rt的儿子x，然后把所有x的最长链取个min即可（可能还要加个1之类的）。这是由于，所有这样的x中，最大深度最小的那颗子树一定会被全部涂黑，否则同理分析可以知道rt不会是中心。

接着看中心是一条边的情况；假设这条边是(u, v)，断开后得到两颗分别以u和v为根的树A和B，并且记maxdpt(A)表示A的最大深度；则maxdpt小的那一颗树一定会被涂黑，也就是这种情况的答案不会超过1种，这个时候只需要判断maxdpt较小的那个树里面是否存在s[y]=1的y即可。特殊的当maxdpt(A)=maxdpt(B)的时候ans直接++即可，因为题目保证了至少存在一个1。

*/

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

struct edge{
    int to,weight;
    edge(int to,int weight):to(to),weight(weight){}
};
using Graph = vector<vector<int>> ;
using GraphEdge = vector<vector<int>> ;

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}
int main(){
    int a,b,k;
    cin >> a >> b >> k;
    int count = 0;
    for(int i=100;i>0;i--){
        if(a%i==0 && b%i==0)count++;
        if(count==k){
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
#define max(a,b) a>b?a:b
#define min(a,b) a<b?a:b
#define pb push_back
//#define IM_N00B ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;


int main(){

int n,k;
cin >> n >> k;
int h[n];
for(int i=0;i<n;i++) cin >> h[i];
sort(h,h+n);
ll sum = 0;
for(int i=0;i<n-k;i++) sum += h[i];
cout << sum;
return 0;
}



Measured memory_bytes: 1024
#include<stdio.h>
int main(){
    int a, n, i, min=1000000, max=-1000000;
    long int sum=0;
    
    scanf("%d", &n);
    for(i=0;i<n;i++){
        scanf("%d", &a);
        sum+=a;
        if(min>a){
            min=a;
        }
        if(max<a){
            max=a;
        }
    }
    printf("%d %d %ld\n", min, max, sum);
    return 0;
}


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

int main() {
	int N; cin >> N;
	string s, t; cin >> s >> t;

	for (int i = 0; i < N; i++) {
		bool ok = true;
		for (int j = 0; j < N - i; j++) {
			if (s[i + j] != t[j]) { ok = false; break; }
		}
		if (ok) { cout << N + i << endl; return 0; }
	}
	cout << 2 * N << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int maxv=-1,n,k,ans=0,l[51],temp;
int main(){
  cin>>n>>k;
  for(int cnt=0;cnt<n;cnt++){
    cin>>l[cnt];
  }
  for(int cnt=0;cnt<n;cnt++){
    for(int i=0;i<n-1-cnt;i++){
      if(l[i]<l[i+1]){
	temp=l[i];
	l[i]=l[i+1];
	l[i+1]=temp;
      }
    }
  }
  for(int cnt=0;cnt<k;cnt++){
    ans+=l[cnt];
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define ull unsigned long long
#define size(v) int((v).size())
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < int(n); i++)
template<typename T>
inline void read(T &a) {
	register int b=1,c=getchar();a=0;
	for(;!isdigit(c);c=getchar())if(c==45)b*=-1;
	for(;isdigit(c);c=getchar())a=(a<<3)+(a<<1)+(c^48);
	a*=b;
}
// Template end

const int maxn = 4005;
char tmp[maxn];
int n, a[maxn], tp[maxn], pos[maxn][2], cnt[maxn][maxn][2], dp[maxn][maxn];
inline void chkmin(int &a, int b) { if (b < a) a = b; }

int main() {
	read(n);
	for (int i = 1; i <= 2 * n; i++) {
		scanf("%s", tmp);
		read(a[i]);
		tp[i] = tmp[0] == 'B';
		pos[a[i]][tp[i]] = i;
	}
	for (int i = 1; i <= 2 * n; i++) {
		for (int j = 1; j <= n; j++) cnt[i][j][0] = cnt[i - 1][j][0];
		for (int j = 1; j <= n; j++) cnt[i][j][1] = cnt[i - 1][j][1];
		for (int j = a[i]; j <= n; j++) cnt[i][j][tp[i]] ++;
	}
	for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) dp[i][j] = 1000000007;
	dp[0][0] = 0;
	rep(i, n + 1) {
		rep(j, n + 1) {
			if (i < n) chkmin(dp[i+1][j], dp[i][j]+pos[i+1][0]-1-cnt[pos[i+1][0]][i][0]-cnt[pos[i+1][0]][j][1]);
			if (j < n) chkmin(dp[i][j+1], dp[i][j]+pos[j+1][1]-1-cnt[pos[j+1][1]][i][0]-cnt[pos[j+1][1]][j][1]);
//			printf("%3d",dp[i][j]);
		}
//		printf("\n");
	}
	printf("%d\n",dp[n][n]);
	// Work start
#ifdef DEBUG
	printf("\nRunning Time : %ldms", clock());
#endif
	return 0;
}


Measured memory_bytes: 158464
#include<iostream>
using namespace std;
const int mod=1e9+7;
int n,tong[30],ans=1;
string s;
int main()
{
	cin>>n>>s;
	for(int i=1;i<=n;i++) tong[s[i-1]-'a']++;
	for(int i=1;i<=26;i++) ans=1ll*ans*(tong[i-1]+1)%mod;
	cout<<(ans+mod-1)%mod<<endl;
}


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

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define md (ll)(1e9+7)
#define all(X) X.begin(),X.end()

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   str.substr (x) : returns a substring str[x],... end of string
   str.find(qtr) : returns the first occurenece of qtr in str */

const int M=1e6+6;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

ll dp[M],tmp[M];

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

	ll n,w,i,j,mx = 0,u,v;

	cin >> n >> w;

	for(i=1;i<=n;++i)
	{
		cin >> v >> u;
		for(j=v;j<=w;++j)
			tmp[j] = max(dp[j],dp[j-v]+u);
		for(j=v;j<=w;++j)
		{
			dp[j] = tmp[j];
			mx = max(mx,dp[j]);
		}
	}

	cout << mx << endl;
	return 0;
}



	


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

int main() {
    ll A, B, C; cin >> A >> B >> C;
    ll ans = 0;
    if (A * C < B) ans = C;
    else ans = B/A;
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <string.h>
#include <math.h>

int main(void)
{
    int m, d, i, j, k, ans1=0;
    scanf("%d%d", &m, &d);

    for(i=4; i<=m; i++)
    {
        for(j=2; j<=9; j++)
        {
            if(i%j == 0)
            {
                k=i/j;
                if(10*j+k<=d && 2<=k && k<=9) ans1++;
            }
        }
    }
    printf("%d", ans1);
    
    return 0;
}


Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <climits>
using namespace std;
#define MOD int(1e9 + 7)
#define INF (long long)(1e18)

int main()
{
    cout.precision(18);

    string S;
    long long N;

    cin >> S;
    cin >> N;
    for (long long i = 0; i < S.size(); i++)
    {
        if (S[i] != 'a' && N >= 26 - (S[i] - 'a'))
        {
            N -= (26 - (S[i] - 'a'));
            S[i] = 'a';
        }
    }

    S[S.size() - 1] = (S[S.size() - 1] - 'a' + N) % 26 + 'a';

    cout << S << endl;
}

Measured memory_bytes: 512
import java.util.*;

public class Main {
	
	
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		n=n*n;
		System.out.println(n);
		
	}

}


Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin >> n;
	vector<int>v(10007, 0);
	for (ll j = 1; j * j <= n; j++) {
		for (ll k = 1; k * k <= n ; k++) {
			for (ll r = 1; r * r <= n ; r++) {
				if (j * j + k * k + r * r + j * k + k * r + r * j <= n) {
					v[j * j + k * k + r * r + j * k + k * r + r * j]++;

				}
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		cout << v[i] << endl;
	}
	cout << endl;
}

Measured memory_bytes: 3644
/*
String[]の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
 */
import java.util.*;
import java.awt.*;
import java.awt.geom.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int n=sc.nextInt();
        int[] a=new int[n];
        for (int i = 0; i < n; i++) {
            a[i]=sc.nextInt();
        }
        Arrays.sort(a);
        out.print(a[n-1]+" ");
        int index=0;
        if(a[n-1]%2==0){
            index=Arrays.binarySearch(a,a[n-1]/2);
            if(index>=0){
                out.println(a[n-1]/2);
            }else {
                index=~index;
                if(index==0)out.println(a[0]);
                else if(index==n)out.println(a[n-1]);
                else {
                    if(a[n-1]/2-a[index-1]>a[index]-a[n-1]/2){
                        out.println(a[index]);
                    }else {
                        out.println(a[index-1]);
                    }
                }
            }
        }else {
            index=Arrays.binarySearch(a,a[n-1]/2);
            int index0=Arrays.binarySearch(a,a[n-1]/2+1);
            if(index>=0){
                out.println(a[n-1]/2);
            }else if(index0>=0){
                out.println(a[n-1]/2+1);
            }else {
                index=~index;
                if(a[n-1]/2-a[index-1]>a[index]-a[n-1]/2){
                    out.println(a[index]);
                }else {
                    out.println(a[index-1]);
                }
            }
        }
    }
}

Measured memory_bytes: 50656
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define int long long
#define ld long double
#define sb __builtin_popcount
#define vi vector<int>
#define vc vector<char>
#define ii pair<int, int>
#define pq priority_queue<ii, vector<ii>, greater<ii>>
#define vii vector<ii>
#define sz(a) int((a).size())
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <=n; i++)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rloop(i,a,b) for(int i=a;i>=b;i--)
#define in(a, b) (b.find(a) != string::npos)
#define minin(a) *min_element(all(a))
#define maxin(a) *max_element(all(a))
#define X first
#define Y second
#define fill(a, x) memset(a, x, sizeof(a))
#define pb push_back
#define pf push_front
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) reverse(v.begin(), v.end())
#define el "\n"
#define mx3(a, b, c) max(max(a, b), c)
#define mn3(a, b, c) min(min(a, b), c)
#define S(v) accumulate(all(v), (ll)0)
#define SP(n) cout.precision(n)
#define PI = atan(1.0) * 4.0;
#define MOD = 1e9 + 7;
void start() {
    fio;
    SP(10);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int32_t main() {
    start();
    int x, n, y;

    cin >> x >> n;
    set<int>st;
    for (int i = -105; i <= 105; i++) {
        st.insert(i);
    }
    for (int i = 0; i < n; i++) {
        cin >> y;
        st.erase(y);
    }
    int ans, mn = INT_MAX;
    for (auto e : st) {
        if (abs(e - x) < mn) {
            ans = e;
            mn = abs(e - x);
        }
    }
    cout << ans;
    return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> R(N);
  REP(i, N) cin >> R[i];
  int maxp = -10000000000;
  int min = R[0];
  for(int i = 1; i < N; i++) {
    if(R[i] - min > maxp) {
      maxp = R[i] - min;
    }
    if(R[i] < min) {
      min = R[i];
    }
  }
  cout << maxp << endl;
  return 0;
}


Measured memory_bytes: 3612
#include <stdio.h>  /*入出力*/
#include <stdlib.h> /*標準ライブラリ*/
#include <string.h> /*文字列*/
#include <math.h>   /*計算*/
#include <assert.h> /*確認*/
#include <ctype.h>  /*文字操作*/
#include <stdbool.h>/*bool型*/
#include <limits.h>/*限界*/
//---------------------------------------------------
#define rep(i, n) for(int  i = 0; i < (n); i++)
//#define max(a,b) ((a>b)?a:b)
#define ABS(a) (((a)>(0))?a:-(a))
#define LL long long
#define MOD 1000000007//10^9+7(素数)
//---------------------------------------------------

LL max(LL a, LL b)//2数のうち最大値を返す関数
{
  if (a<b) a = b;
  return a;
}

int main(void)
{
  LL q = 0;                       //作業用変数
  int n = 0;                      //夏休みの日数
  LL ans = -1;                    //結果を格納する変数
  LL DP[100010][3] = {0};         //DP[i][j]      := i日に活動j(下と同じ)をしたときの最大幸福度
  LL happiness[100010][3] = {0};  //happines[i][j]:= ai(j=0), bi(j=1), ci=(j=2)

  //入力部
  scanf("%d", &n);
  for (LL i = 0; i < n; i++) {
    scanf("%lld %lld %lld", &happiness[i][0], &happiness[i][1], &happiness[i][2]);
  }

  //DPの初期化
  for (size_t i = 0; i < 3; i++) {
    DP[0][i] = happiness[0][i];
  }

  //処理部
  for (LL i = 1; i < n; i++) {

    for (size_t j = 0; j < 3; j++) {
      //作業用変数qを初期化
      q = -1;

      for (size_t k = 0; k < 3; k++) {
        //i-1日とi日に異なる活動をしたときのみを考える(i-1日に活動k、i日に活動j)
        if (j != k) {
          q = max(q, DP[i-1][k] + happiness[i][j]);
        }
      }

      //i日に活動jをしたときの最大幸福度
      DP[i][j] = q;
    }
  }

  //最大幸福度の決定
  ans = -1;
  for (size_t i = 0; i < 3; i++) {
    ans = max(ans, DP[n-1][i]);
  }

  //出力
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 4864
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int sum = A + B;
		if (sum >= C)
			System.out.println("Yes");
		else
			System.out.println("No");
		sc.close();
	}
}

Measured memory_bytes: 23636
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int const mxn=2e5+5;
int a[mxn],vis[mxn];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int n; 
	ll k;
	cin >> n >> k;
	for(int i=1; i<=n; i++){
		cin >> a[i];
		vis[i]=0;
	}
	vi path; int ptr=1; int cnt=1;
	while(!vis[ptr]){
		vis[ptr]=cnt;
		cnt++;
		path.pb(ptr);
		ptr = a[ptr];
	}
	int minus = vis[ptr]-1;
	int sz = path.size();
	if(k<minus){
		cout << path[k%sz] << endl;
	}else{
		k-=minus;
		path.erase(path.begin(),path.begin()+minus);
		sz = path.size();
		cout << path[k%sz] << endl;
	}
}	


Measured memory_bytes: 5828
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
signed main(){
    int x,a,b;
    cin>>x>>a>>b;
    int d = -a+b;
    if(d<=0)cout<<"delicious"<<endl;
    else if(d<=x)cout<<"safe"<<endl;
    else cout<<"dangerous"<<endl;

}

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

std::vector<int> getArrayToLine(void);
int getMinimumPrice(std::vector<int> v, int i);

int main(void){
	int n; //number of bought vegetables
	int m; //number of vegetables that can be packed

	while(std::cin >> n >> m){
		if(n == 0 && m == 0){ //end input
			break;
		}

		std::cout << getMinimumPrice(getArrayToLine(), m) << std::endl; //output result
	}

	return 0;
}

std::vector<int> getArrayToLine(void){
	std::vector<int> v;
	std::string buf;
	int tmp;

	std::cin.ignore();
	std::getline(std::cin, buf); //input line data
	std::istringstream is(buf);

	while(is >> tmp){ //input number
		v.push_back(tmp); //add number to array
	}

	return v;
}

int getMinimumPrice(std::vector<int> v, int i){
	int ans = 0;
	size_t cnt = 0; 

	//do process
	std::sort(v.begin(), v.end());

	while(!(v.empty())){
		++cnt;

		if(cnt % i == 0){
			v.pop_back();
		}else{
			ans = ans + v.back();
			v.pop_back();
		}
	}

	return ans;
}

Measured memory_bytes: 3156
'use strict';
(function(stdin) { 
  var inputs = stdin.toString().trim().split('\n');
  var sorted = inputs
      .map(Number)
      .sort(function(a,b){
      	return b - a;
      })
      .slice(0,3)
      .join('\n');

  console.log(sorted);

}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 7644
// in the name if Allah
// YA Ali!
#include <bits/stdc++.h>

using namespace std;

typedef long long ll ;

const ll INF = 1<<30 ;
const ll N= 1e6 ;

#define f first
#define s second

ll n , s ;

int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> s ;
ll sq = sqrt(s) ;
if(sq*sq != s)sq ++ ;
ll xx = sq*sq ;
ll y1 = xx - s ;
ll x2 = 1 ;
ll x1 = sq , y2 = sq ;
cout << 0 << " " << 0 << " " << x1 << " " << y1 << " " << x2 << " " << y2 ;
    return 0;
}
 /*
              _     _   __
        /_\  (_    (_)  __)
       /   \  _) . (_) (__
 */


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

bool G[10][10];

int main(){
    int N, M; cin >> N >> M;
    for(int i=0; i<M; i++){
        int a,b; cin >> a >> b; --a, --b;
        G[a][b] = G[b][a] = true;
    }

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

    int res = 0;
    do{
        if(ord[0] != 0) break;

        bool ok = true;
        for(int i=0; i+1 < N; i++){
            int from = ord[i];
            int to = ord[i+1];
            if(!G[from][to]) ok = false;
        }
        if(ok) ++res;
    }while(next_permutation(ord.begin(), ord.end()));

    cout << res << endl;
}

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

int main(){
  ll n;
  cin >> n;
  vector<ll> a(n+1);
  ll sum = 0;
  for(int i=1;i<=n;i++){
    cin >> a.at(i);
    sum += a.at(i);
  }
  vector<ll> x(n+1);
  ll s=0;
  for(int i=3;i<=n;i+=2) s += 2*a.at(i);
  x.at(1) = sum - s;
  for(int i=2;i<=n;i++){
    x.at(i) = 2*a.at(i) - x.at(i-1);
  }
  cout << x.at(n) << " ";
  for(int i=1;i<n;i++){
    cout << x.at(i);
    if( i != n-1 ) cout << " ";
    else cout << endl;
  }
  return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iomanip>

using namespace std;

int v[2001][2001];
int n,k;
int num(int x1,int y1,int x2,int y2){
    return v[x2][y2] - v[x2][y1] - v[x1][y2] + v[x1][y1];
}
int main() {
    int x,y,ans = 0,sum;
    char ch;
    scanf("%d%d",&n,&k);
    for(int i = 1;i <= n;i ++){
        scanf("%d%d %c",&x,&y,&ch);
        x %= 2 * k;
        y %= 2 * k;
        x += k * (ch == 'W');
        v[x % (2 * k) + 1][y % (2 * k) + 1] ++;
    }
    for(int i = 1;i <= 2 * k;i ++)
        for(int j = 1;j <= 2 * k;j ++)
            v[i][j] += v[i - 1][j] + v[i][j - 1] - v[i - 1][j - 1];
            for(int i = 1;i <= k;i++)
                for(int j = 1;j <= k;j++) {
                    sum = num(0,0,i,j) + num(i,j,k + i,k + j) + num(k + i,k + j,2 * k,2 * k) + num(k + i,0,2 * k,j) + num(0,k + j,i,2 * k);
                    ans = max(ans,max(sum,n - sum));
                }
    printf("%d\n",ans);
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

  int N;
  cin >> N;

  vector<pair<long long,long long>> vec(N);
  
  for(int i = 0;i < N;i++) {
    int A,B;
    cin >> A >> B;
    vec.at(i) = make_pair(B,A);
  }

  sort(vec.begin(),vec.end());

  long long time = 0;
  for(int i = 0;i < N;i++) {
    time += vec.at(i).second;
    if(time > vec.at(i).first) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

}




Measured memory_bytes: 3328