akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int mn[4*200005];
ll ans;
int ar[200005];
int pos[200005];
int N;

void build(int lo,int hi,int at)
{
    if(lo==hi)
    {
        mn[at]=ar[lo];
        return;
    }
    int mid=(lo+hi)/2;

    build(lo,mid,2*at);
    build(mid+1,hi,2*at+1);
    mn[at]=min(mn[2*at],mn[2*at+1]);
}

int q(int lo,int hi,int at,int from,int to)
{
    if(lo==from && hi==to)
    {
        return mn[at];
    }

    int mid=(lo+hi)/2;

    if(mid>=to) return q(lo,mid,2*at,from,to);
    else
    {
        if(mid<from) return q(mid+1,hi,2*at+1,from,to);
        else
        {
            int c=q(lo,mid,2*at,from,mid);
            c=min(c, q(mid+1,hi,2*at+1,mid+1,to));
            return c;
        }
    }

}

void recur(int lo,int hi)
{
    if(lo>hi) return;

    ll len=hi-lo+1;
    int m=q(1,N,1,lo,hi);
    ans = ans + len*m + 1ll*(pos[m]-lo)*(hi-pos[m])*m;

    if(lo==hi) return;

    recur(lo, pos[m]-1);
    recur(pos[m]+1, hi);
}

int main()
{
 
    int a,b,c,d,e,x,y,z,l;

    scanf("%d",&N);

    for(a=1;a<=N;a++)
    {
        scanf("%d",&ar[a]);
        pos[ ar[a] ]=a;
    }

    ans=0;

    build(1,N,1);

    recur(1,N);

    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 10112
# include <bits/stdc++.h>
# define rep(i, n) for(ll i = 0; i < (n); ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define ll long long
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define P pair<int, int>
# define mp make_pair
# define x first
# define y second
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  double w, h, x, y; cin >> w >> h >> x >> y;

  double ans = w / 2;
  ans *= h;
  int subans = 0;
  if(w / 2 == x && h / 2 == y) subans = 1;

  cout << ans << endl;
  cout << subans << endl;
}


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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  //2,6,10
  //16,12,8
  ll next[3] = {};
  ll player[3] = {};
  rep(i,3) cin >> player[i];

  ll cnt = 0;
  if(player[0] % 2 == 1 ||
     player[1] % 2 == 1 ||
     player[2] % 2 == 1   ){
       cout << 0 << endl;
       return 0;
  }
  if(player[0]  == player[1] &&
     player[1] ==  player[2]){
       cout << -1 << endl;
       return 0;
  }
  while(true){

    rep(i,3){
      next[(i+1) % 3] += player[i]/2;
      next[(i+2) % 3] += player[i]/2;
    }
    rep(i,3){
      player[i] = next[i];
      next[i] = 0;
      //cout << player[i] << " ";
    }
    //cout << endl;
    cnt++;
    if(player[0] % 2 == 1 ||
       player[1] % 2 == 1 ||
       player[2] % 2 == 1   ){
         break;
       }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() { cerr << "--------------" << endl; }
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   int n;
   cin >> n;
   vector<tuple<string, int, int>> res;
   rep(i, 0, n) {
      string s;
      int p;
      cin >> s >> p;
      res.emplace_back(s, -p, i + 1);
   }
   sort(res.begin(), res.end());
   rep(i, 0, n) { cout << get<2>(res[i]) << endl; }
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#define REP(i,a,b) for (int i = (a); i < (b); i++)
#define rep(i,a) REP(i,0,a)
using namespace std;

int H, W;
int dw[] = {1,1,0,-1,-1,-1,0,1};
int dh[] = {0,1,1,1,0,-1,-1,-1};

int main(void){
    while (cin >> H >> W && H) {
        vector<string> S(H,"");
        rep(i, H) cin >> S[i];
        string ans = "";
        set<string> appear;
        
        rep(h, H) rep(w, W) rep(i, 8) {
            string s = "";
            s += S[h][w];
            int iw = w, ih = h;
            w = (w+dw[i]+W)%W; h = (h+dh[i]+H)%H;
            while (!(w == iw && h == ih)) {
                s += S[h][w];
                if (appear.find(s) != appear.end()) {
                    if (s.length()  > ans.length()) ans = s;
                    if (s.length() == ans.length()) ans = min(ans, s);
                }
                appear.insert(s);
                w = (w+dw[i]+W)%W; h = (h+dh[i]+H)%H;
            }
        }
        cout << (ans.length() > 1 ? ans:"0") << endl;
    }
    return 0;
}

Measured memory_bytes: 33768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int cost = 0;
int main()
{
        int a, b, c;
        cin >> a >> b >> c;
        int x, y;
        cin >> x >> y;
        a = min(a, 2 * c);
        b = min(b, 2 * c);
        if (2 * c < a + b)
        {
                cost += min(x, y) * c * 2;
                //cout << cost << endl;
                int cur = min(x, y);
                x -= cur;
                y -= cur;
                cost += x * a + y * b;
                cout << cost << endl;
        }
        else
        {
                cost += x * a + y * b;
                cout << cost << endl;
        }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main()
{
	
	vector<int> v;
	vector<int> ::iterator it;
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	for(int i=0;i<n-1;i++)
	{
		for(int j=1+i;j<n;j++)
		{
			v.push_back(a[i]*a[j]);
		}
 }
	int sum=0;
	for(it=v.begin();it!=v.end();it++)
	sum=sum+*it;
	cout<<sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    int w, h, n,m;cin>>w>>h>>n;
    vvint b;
    initvv(b, w, h, 0);
    rep(i, n){
        int x, y, a;cin>>x>>y>>a;
        if(a==1){
            rep(i, x){
                rep(j, h){
                    b[i][j] = 1;
                }
            }
        }
        if(a==2){
            for(int i = x;i < w; i++){
                rep(j, h){
                    b[i][j] = 1;
                }
            }
        }
        if(a==3){
            rep(i, w){
                rep(j, y){
                    b[i][j] = 1;
                }
            }
        }
        if(a==4){
            rep(i, w){
                for(int j=y;j < h;j++){
                    b[i][j] = 1;
                }
            }
        }
    }
    int ans = 0;
    rep(i, w){
        rep(j, h){
            if(b[i][j]==1){
                ans ++;
            }
        }
    }
    cout << w*h-ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

bool PrimeNumber(long long x) {
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;
	else {
		for (int i = 3; i <= sqrt(x);) {
			if (x % i == 0) return false;
			i += 2;
		}
	}	
	return true;
	
}

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

	vector<bool>PN(n);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		PN.at(i) = PrimeNumber(x.at(i));
		if (PN.at(i) == true) ans++;
	}

	cout << ans << endl;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, n) for (int i = (n-1); i >= 0; i--)
#define rea(i, a, b) for (int i = (a); i < (b); i++)
#define reab(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(),(a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const int MOD = 1000000007;
/* END OF TEMPLATE */


ll N, M;

map<int, int> dp;


int atob(int a)
{
    int b[] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
    return b[a-1];
}

int MaxDigit(vi& A, int n)
{
    auto itr = dp.find(n);
    if(itr != dp.end() && !dp.empty())
    {
        return dp[n];
    }
    else
    {
        int d = INT_MIN;
        rep(i, A.size())
        {
            int e;
            if(n-atob(A[i]) >= 0)
            {  
                e = MaxDigit(A, n-atob(A[i])) + 1;
                if(d < e) d = e;
            }
        }
        dp[n] = d;
        dump2(n, d);
        return d;
    }
}

int main()
{
    cin >> N >> M;
    vi A(M);
    rep(i, M)
    {
        cin >> A[i];
    }
    dp[0] = 0;
    int md = MaxDigit(A, N);
    dp[N] = md;
    sort(ALL(A), greater<int>());
    vi ans;
    int m = N;
    rep(i, md)
    {
        rep(j, M)
        {
            if(m-atob(A[j]) >= 0)
            {
                dump2(m, atob(A[j]));
                if(dp[m-atob(A[j])] == dp[m] - 1)
                {
                    m -= atob(A[j]);
                    ans.push_back(A[j]);
                    break;
                }
            }
        }
    }
    rep(i, md)
    {
        cout << ans[i];
    }
    cout << endl;
}

Measured memory_bytes: 1280
import java.util.*;
import java.math.BigInteger;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int h = sc.nextInt();
    int w = sc.nextInt();
    char[][] masu = new char[h][w];

    Deque<XY> q = new ArrayDeque<>();
    for (int i = 0; i < h; i++) {
      masu[i] = sc.next().toCharArray();
      for (int j = 0; j < w; j++) {
        if ('#' == masu[i][j]) {
          q.add(new XY(i, j, 0));
        }
      }
    }

    int max_depth = 0;

    while (true) {
      if (q.size() < 1) {
        break;
      }
      XY xy = q.poll();
      int x = xy.x;
      int y = xy.y;
      int depth = xy.depth;
      max_depth = Math.max(max_depth, depth);

      if (x+1 < w && masu[y][x+1] == '.') {
        masu[y][x+1] = '#';
        q.add(new XY(y, x+1, depth+1));
      }
      if (x - 1 >= 0 && masu[y][x - 1] == '.') {
        masu[y][x - 1] = '#';
        q.add(new XY(y, x - 1, depth + 1));
      }
      if (y + 1 < h && masu[y + 1][x] == '.') {
        masu[y + 1][x] = '#';
        q.add(new XY(y + 1, x, depth + 1));
      }
      if (y - 1 >= 0 && masu[y - 1][x] == '.') {
        masu[y - 1][x] = '#';
        q.add(new XY(y - 1, x, depth + 1));
      }

    }
    System.out.println(max_depth);
  }
}

class XY {
  int y;
  int x;
  int depth;

  XY(int y, int x, int d) {
    this.x = x;
    this.y = y;
    this.depth = d;
  }
}


Measured memory_bytes: 79484
//Author rahuliitkgp

/*A thing of beauty is a joy forever,
Its loveliness increases,
it will never pass into nothingness.*/
//Men at Work :)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;

#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

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

void cpp(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int main(){
    cpp();
    ll n;
    cin>>n;
    vector<ll> v(n);
    for(ll i=0; i<n; i++){
        cin>>v[i];
    }
    vector<ll> num(1000020);
    sort(v.begin(), v.end());
    for(ll i=0; i<n-1; i++){
        if(v[i]==v[i+1]){
            num[v[i]]=1;
        }
    }
    ll ans = 0;
    for(ll i=0; i<n; i++){
        if(!num[v[i]]){
            ans++;
        }
        if(v[i]!=v[i-1]){
            for(ll j = 2*v[i]; j<=1000000; j+=v[i]){
                num[j] = 1;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 12656
#include <iostream>
#include <map>
using namespace std;
int main() { 
  int n, a, x, y, min=500000000; 
  multimap<int,int> P;
  multimap<int,int>::iterator it, next, q;
  cin >> n; 
  for(int i=0; i<n; i++) {   
    cin >> x >> y;  
    P.insert(make_pair(x,y));
  } 
  for(it=P.begin(); q!=P.end(); it++) {  
    q=it;  
    q++;  
    for(next=q; next!=P.end(); next++) { 
      if((it->first-next->first)*(it->first-next->first) > min) break; 
      a=(it->first-next->first)*(it->first-next->first)+(it->second-next->second)*(it->second-next->second);  
      if(min>a) min = a;  
    }  
  }   
  cout << min << endl;
  return 0;
}


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

int check_golem_pos(int mid, string str, char t[], char d[]);

int N,Q;

int main(void){
    // Your code here!
    cin >> N >> Q;
    
    string str;
    cin >> str;
    
    char t[Q],d[Q];
    for(int i = 0; i < Q; i++){
        cin >> t[i] >> d[i];
    }
    
    int left = -1;
    int right = str.length();
    
    while(right - left > 1) {
        int mid = left+(right-left)/2;
        int finally_position = check_golem_pos(mid,str,t,d);
        if (finally_position == -1) left = mid;
        else right = mid;
    }
    
    int answer_range_left = left;
    
    
    left = -1;
    right = str.length();
    
    while(right - left > 1) {
        int mid = left+(right-left)/2;
        int finally_position = check_golem_pos(mid,str,t,d);
        if (finally_position == N) right = mid;
        else left = mid;
    }
    
    int answer_range_right = left;
    
    cout << answer_range_right-answer_range_left;
}

int check_golem_pos(int mid, string str, char t[], char d[]){
    int golem_pos = mid;
    
    for(int i = 0; i < Q; i++){
        if(golem_pos == -1 || golem_pos == N) break;
        
        if(str[golem_pos] == t[i]){
            if(d[i] == 'R'){
                golem_pos++;
            }
            else{
                golem_pos--;
            }
        }
    }
    
    return golem_pos;
}

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

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

    for(int i = a; i <= b; i++)
    {
        if(i % k == 0)
        {
            cout << "OK";
            return 0;
        }
    }

    cout << "NG";

    return 0;
}

Measured memory_bytes: 3588
#include<stdio.h>
int main()
{
    char s[10];
    scanf("%s",&s);
    if(s[0]=='S')
        printf("Cloudy\n");
    else if(s[0]=='C')
        printf("Rainy\n");
    else if(s[0]=='R')
        printf("Sunny\n");
    return 0;
}


Measured memory_bytes: 128
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class CSpecialTrains {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int N;
        in>>N;
        vc<int> C(N-1), S(N-1), F(N-1);
        REP(i, N-1) in>>C[i]>>S[i]>>F[i];
        REP(i, N){
            int cur = 0;
            FOR(j, i, N-1){
                cur = max(S[j], (cur+F[j]-1)/F[j]*F[j]) + C[j];
            }
            out<<cur<<'\n';
        }
    }
};


int main() {
	CSpecialTrains solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3672
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  vector<string> n(2);
  int a, b;

  cin >> a >> b;
  string as = to_string(a);
  string bs = to_string(b);

  for(int i = 0; i < a; i++){
    n[1] += bs;
  }
  for(int i = 0; i < b; i++){
    n[0] += as;
  }

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

  cout << n[0] << endl;

}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * e.cc: E - Sequence Sum
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_M = 100000;

/* typedef */

typedef long long ll;

/* global variables */

int as[MAX_M + 1], rs[MAX_M];
ll ass[MAX_M + 2];

/* subroutines */

/* main */

int main() {
  ll n;
  int x, m;
  scanf("%lld%d%d", &n, &x, &m);
  x %= m;

  memset(rs, -1, sizeof(rs));
  rs[x] = 0;
  as[0] = x;
  int l1 = 0;
  for (;;) {
    l1++;
    as[l1] = (ll)as[l1 - 1] * as[l1 - 1] % m;
    if (rs[as[l1]] >= 0) break;
    rs[as[l1]] = l1;
  }
  int l0 = rs[as[l1]];
  //printf("l0=%d, l1=%d\n", l0,l1);
  //for (int i = 0; i <= l; i++) printf("%d ", as[i]); putchar('\n');

  for (int i = 0; i <= l1; i++) ass[i + 1] = ass[i] + as[i];

  ll ans;
  if (n <= l1)
    ans = ass[n];
  else {
    int l = l1 - l0;
    ll a = (n - l0) / l;
    int b = (n - l0) % l;
    ans = (ass[l1] - ass[l0]) * a + ass[l0 + b];
  }

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


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

int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(a*b>c)printf("%d\n",c);
	else printf("%d\n",a*b);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MOD 1000000007
#define MAX 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ub upper_bound
#define lb lower_bound
#define zoom ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define precise cout.precision(8); cout << fixed;
#define seed srand(chrono::steady_clock::now().time_since_epoch().count());
const double PI = acos(-1);
using namespace std;

void solve() {
    int N, i; cin >> N;
    vector<int> K(N + 1), L(N + 1), R(N + 1);
    set<pair<int, int> > positive, negative;
    vector<int> done(N + 1, -1);
    set<int> stock;
    ll ans = 0LL;
    for(i = 1; i <= N; i += 1) {
        cin >> K[i] >> L[i] >> R[i];
        stock.insert(i);
        if(L[i] - R[i] > 0) {
            positive.insert(make_pair(L[i] - R[i], i));
        }
        else if (L[i] - R[i] < 0) {
            negative.insert(make_pair(-(L[i] - R[i]), i));
        }
        else {
            ans += ((long long)L[i]);
        }
    }
    for(set<pair<int, int> >::reverse_iterator it = positive.rbegin(); it != positive.rend(); it++) {
        int pos = it -> second;
        set<int>::iterator it1 = stock.upper_bound(K[pos]);
        if(it1 == stock.begin()) {
            ans += ((long long)R[pos]);
            continue;
        }
        ans += ((long long)L[pos]);
        it1--;
        done[(*it1)] = pos;
        stock.erase(it1);
    }
    int strt = 1, en = 1;
    while(en != N) {
        if(done[en] == -1) {
            en += 1;
            continue;
        }
        done[strt] = done[en];
        strt += 1;
        en += 1;
    }
    stock.clear();
    for(i = strt; i <= N; i += 1) {
        stock.insert(i);
    }
    for(set<pair<int, int> >::reverse_iterator it = negative.rbegin(); it != negative.rend(); it++) {
        int pos = it -> second;
        set<int>::iterator it1 = stock.upper_bound(K[pos]);
        if(it1 == stock.end()) {
            ans += ((long long)L[pos]);
            continue;
        }
        ans += ((long long)R[pos]);
        done[(*it1)] = pos;
        stock.erase(it1);
    }
    cout << ans << endl;
}

int main() {
    int t = 1;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 25180
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<map>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(n);
    int sum=0;
    rep(i,n){
        cin >> a[i];
        sum += a[i];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());

    if(a[m-1]>=double(sum)/double(4*m)){
        cout << "Yes" << endl;
        return 0;
    }else{
        cout << "No" << endl;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //  repマクロ
#define leng(n) (int)(log10(n)+1)  //  桁数
using namespace std;

signed main() {
  int N, M, C;
  cin >> N >> M >> C;
  vector<int> B(M);
  rep(i, M){
    cin >> B[i];
  }
  vector<vector<int>> A(N, vector<int>(M));
  rep(i, N){
    rep(j, M){
      cin >> A[i][j];
    }
  }
  
  int ans = 0;
  rep(i, N){
    int sum = C;
    rep(j, M){
      sum += B[j] * A[i][j];
    }
    if (sum > 0) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100001,INF=1<<30;
struct edge{int to,dis,h;};
vector<edge> S[MAX];
int V;

int DFS(int cur,int from){
    
    int ans=0;
    
    for(int i=0;i<S[cur].size();i++){
        edge &e=S[cur][i];
        if(e.to==from) continue;
        if(e.h==-1) e.h=DFS(e.to,cur);
        ans=max(ans,e.dis+e.h);
    }
    
    return ans;
}

int main(){

    cin>>V;
    for(int i=0;i<V-1;i++){
        int a,b,c;cin>>a>>b>>c;
        S[a].push_back(edge{b,c,-1});
        S[b].push_back(edge{a,c,-1});
    }
    
    for(int i=0;i<V;i++){
        cout<<DFS(i,-1)<<endl;
    }
    
}




Measured memory_bytes: 6576
/*
　　　　　　 ＿＿
　　　　　／＞　　 フ
　　　　　| 　_　 _ l
　 　　　／` ミ＿xノ    見ちゃだめ！
　　 　 /　　　 　 |　
　　　 /　 ヽ　　 ﾉ　　
　 　 │　　|　|　|　　
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)__)
　＼二つ
*/

#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<vector<ll>> dp(1000000, vector<ll>(2));
  dp[0][0] = a[0];
  dp[0][1] = -a[0];
  rep(i, n - 1) {
    rep(j, 2) {
      if (j == 0) {
        dp[i + 1][0] = max(dp[i][0] + a[i + 1], dp[i][1] - a[i + 1]);
      } else {
        dp[i + 1][1] = max(dp[i][0] - a[i + 1], dp[i][1] + a[i + 1]);
      }
    }
  }
  cout << max(dp[n - 2][0] + a[n - 1], dp[n - 2][1] - a[n - 1]) << endl;
}

Measured memory_bytes: 55296
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a, i##_len = (b); i < i##_len; ++i)

const char day[7][4] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

int main()
{
    char S[4];
    scanf("%s", S);
    REP(i, 0, 7) if(strcmp(day[i], S)==0){
        cout << 7 - i << endl; return 0;
    } 
    return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args:Array<String>):Unit {
    val (n, t, q) = readLine()!!.trim().split(' ').map(String::toLong)
    val civils = List(n.toInt()){val (a, b) = readLine()!!.trim().split(' ').map(String::toLong)
        Pair(a, b)
    }.toTypedArray()
    val stack = Stack<Long>()
    for (i in 1 until civils.size){
        if (civils[i - 1].second == 1L && civils[i].second == 2L){
            stack.push((civils[i - 1].first + civils[i].first) / 2)
        }
    }
    val stopPos = stack.toLongArray()
    repeat(q.toInt()){
        val pos = civils[readLine()!!.trim().toInt() - 1]
        val idx = -stopPos.binarySearch(pos.first) - 1
        when(pos.second){
            1L -> if (idx == stopPos.size || pos.first + t < stopPos[idx] ){
                println(pos.first + t)
            }else{
                println(stopPos[idx])
            }
            else -> if (idx <= 0 || pos.first - t > stopPos[idx - 1]){
                println(pos.first - t)
            }else{
                println(stopPos[idx - 1])
            }
        }
    }
}


Measured memory_bytes: 83756
function Main(input) {
  input = input.split("\n");
  const N = parseInt(input[0],10);
  const hn = input[1].split(' ').map((n) => {
    return parseInt(n, 10);
  });
  const h_max = Math.pow(10,9);
  console.log(dp(N,hn,h_max));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

function dp(N,hn,h_max) {
  const dp = [];
  dp[0] = 0;
  for (var i = 1; i < N; i++) {
    dp.push(h_max);
    if (i === 1) {
      dp[i] = Math.min(dp[i],dp[i-1] + Math.abs(hn[i-1] - hn[i]))
    } else {
      dp[i] = Math.min(dp[i],dp[i-1] + Math.abs(hn[i-1] - hn[i]),dp[i-2] + Math.abs(hn[i-2] - hn[i]))
    }
  }
  return dp[N-1];
}


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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    int N;
    cin >> N;
    cout << (N-2)*180 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
    //Recieve the inputs
    int D, T, S;
    cin >> D >> T >> S;
 
    //Calculate the possible distance of Takahashi's travel
    int dist = S * T;
 
    //Output depending on the inequality between D and dist
    if (dist >= D) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3472
#include <stdio.h>

void trace(int A[], int N) {
	int i;
	for (i = 0; i < N; i++) {
		if (i > 0) printf(" ");
		printf("%d", A[i]);
	}
	printf("\n");
}

void InsertionSort(int A[], int N) {
	int i, j;
	int v;

	for (i = 1; i < N; i++) {
		v = A[i];
		j = i - 1;
		while (v < A[j] && j >= 0) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
		trace(A, N);
	}
}

int main() {
	int N, i;
	int A[100];

	scanf("%d", &N);

	for (i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}

	trace(A, N);
	InsertionSort(A, N);

	return 0;
}


Measured memory_bytes: 2092
n = int(input())
p = list(map(int, input().split()))

dif = []
for i in range(1,n+1):
  if p[i-1] != i:
    dif.append(i)

if len(dif) == 0 or len(dif) == 2:
  print('YES')
else:
  print('NO')
    

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1000000007;
const double PI = acos(-1);

int main()
{
	int x, y;
	cin >> x >> y;
	int ans = 0;
	for (int i = 0; i <= x; i++) {
		if (2 * i + 4 * (x - i) == y) ans++;
	}
	if (ans) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3616
a,b,c=map(int,input().split())
d,e,f=map(int,input().split())
g,h,i=map(int,input().split())
if a-b==d-e==g-h and b-c==e-f==h-i and a-c==d-f==g-i and a-d==b-e==c-f and d-g==e-h==f-i and a-g==b-h==c-i:print("Yes")
else:print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  string S;
  cin >> N >> S;
  if (N % 2 == 0) {
    if (S.substr(0,N/2) == S.substr(N/2,N/2)) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;

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

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

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

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

fn main() {
    input! {
        n: usize,
        mut s: chars,
    }
    s.dedup();

    println!("{}", s.len());
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;




int main()
{
    
    int N;
    cin >> N;
    vector<ll> A(N);
    ll Asum = 0;
    rep(i,N){
        cin >> A[i];
        Asum += A[i];
    }
    vector<ll> B(N);
    ll Bsum = 0;
    rep(i,N){
        cin >> B[i];
        Bsum += B[i];
    }
    if(Asum < Bsum){
        cout << -1 << endl;
        return 0;
    }
    
    int ans = 0;
    vector<ll> P;
    ll need = 0;
    rep(i,N){
        if(A[i] > B[i]) P.push_back(A[i] - B[i]);
        else if(A[i] < B[i]) need += (B[i] - A[i]), ans++;
    }
    
    sort(all(P));
    reverse(all(P));
    int i = 0;
    while (need > 0) {
        ans++;
        need -= P[i];
        i++;
    }
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 2428
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

template <typename T>
struct edge
{
    int src, to;
    T cost;

    edge(int to, T cost) : src(-1), to(to), cost(cost) {}

    edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

    edge &operator=(const int &x)
    {
        to = x;
        return *this;
    }

    operator int() const { return to; }
};

//Weighted edge set
template <typename T>
using Edges = vector<edge<T>>;

//Weighted graph
template <typename T>
using WeightedGraph = vector<Edges<T>>;

template <typename T>
T Prim(WeightedGraph<T> &g)
{
    T res = 0;
    vector<bool> used(g.size(), false);
    priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> que;
    que.emplace(0, 0);
    while (que.empty() != true)
    {
        auto p = que.top();
        que.pop();
        if (used[p.second] == true)
            continue;
        used[p.second] = true;
        res += p.first;
        for (auto &e : g[p.second])
        {
            que.emplace(e.cost, e.to);
        }
    }
    return res;
}

int N;

int main()
{
    cin >> N;
    vector<pair<pair<int, int>, int>> x, y;
    WeightedGraph<int> G(N);
    for (int i = 0; i < N; i++)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        x.emplace_back(make_pair(a, b), i);
        y.emplace_back(make_pair(b, a), i);
    }

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    for (int i = 0; i + 1 < N; i++)
    {
        int a = x[i].first.first, b = x[i].first.second, na = x[i + 1].first.first, nb = x[i + 1].first.second;
        int p1 = x[i].second, p2 = x[i + 1].second;
        G[p1].emplace_back(p2, min(abs(a - na), abs(b - nb)));
        G[p2].emplace_back(p1, min(abs(a - na), abs(b - nb)));
    }

    for (int i = 0; i + 1 < N; i++)
    {
        int a = y[i].first.first, b = y[i].first.second, na = y[i + 1].first.first, nb = y[i + 1].first.second;
        int p1 = y[i].second, p2 = y[i + 1].second;
        G[p1].emplace_back(p2, min(abs(a - na), abs(b - nb)));
        G[p2].emplace_back(p1, min(abs(a - na), abs(b - nb)));
    }

    cout << Prim(G) << endl;
}

Measured memory_bytes: 14636
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
	static void Main()
	{
		var nm = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }), number => int.Parse(number));
		var firsts = new List<int>();
		var routes = new bool[nm[0]];
		for (var i = 0; i < nm[1]; ++i) {
			var a = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }), number => int.Parse(number));
			if (a[0] == 1) {
				firsts.Add(a[1] - 1);
			} else if(a[1] == nm[0]) {
				routes[a[0] - 1] = true;
			}
		}

		if (nm[1] > 1) {
			var answer = false;
			foreach (var num in firsts) {
				if (routes[num]) {
					answer = true;
					break;
				}
			}

			Console.WriteLine(answer ? "POSSIBLE" : "IMPOSSIBLE");
		} else {
			Console.WriteLine("IMPOSSIBLE");
		}

		//デバッグ実行での確認用。そのまま提出しても問題なし
		Console.ReadKey();
	}
}


Measured memory_bytes: 18340
#include <iostream>
#include <vector>
#include <stack>
#include <math.h>

#define rep(i, n) for (int i=0; i< (n); ++i)
typedef long long ll;
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; }

using namespace std;

ll count_num2(ll h) {
/*
 * def a(n):
 *     return 0 if n==0 else 1 + 2*a(int(n/2))
 */
    if (h == 0) {
        return 0;
    }
    ll next = floor(h / 2);
    return 1 + 2 * count_num2(next);
}

int main() {
    ll d;
    cin >> d;
    //s.push(d);

    cout << count_num2(d) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n,k;
    cin >> n >> k;
    set<int> s;
    rep(i,k){
        int x;
        cin >> x;
        s.insert(x);
    }
    for(int i = n;i <= 1000000; i++){
        bool ok = 1;
        //cout << i << endl;
        int copy = i;
        while(copy > 0){
            if(s.count(copy%10)) ok = 0;
            copy /= 10;
        }
        if(ok){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define int long long int
using namespace std;
const int INF = 1e9 + 5;

int minCost(vector<int>& h){
    int n = h.size();
    vector<int> dp(n, INF);
    dp[0] = 0;
    for(int i=0; i<n-1; i++){
        if(i+1 < n)
            dp[i+1] = min(dp[i+1], dp[i]+abs(h[i+1]-h[i]));
        if(i+2 < n)
            dp[i+2] = min(dp[i+2], dp[i]+abs(h[i+2]-h[i]));
    }
    return dp[n-1];
}


int32_t main(){
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i=0; i<n; i++){
        cin >> h[i];
    }
    cout << minCost(h) << "\n";
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	private static final int MOD = (int)Math.pow(10, 9);
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		int[] cards = new int[n];
		for (int i = 0; i < n; i++) { cards[i] = sc.nextInt();}
		Arrays.sort(cards);
		
		int pos = n - 1;
		int alice = 0;
		while (pos >= 0) {
			alice += cards[pos];
			pos -= 2;
		}
		
		pos = n - 2;
		int bob = 0;
		while (pos >= 0) {
			bob += cards[pos];
			pos -= 2;
		}
		
		System.out.println(alice - bob);
	}
	
	static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}


Measured memory_bytes: 21204
#pragma region Header
#include <iostream>
#include <iomanip>
#include <cstdint>
#include <cmath>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#include <functional>
#include <algorithm>
#include <numeric>
#include <stdexcept>
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define repd(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define FORD(i, a, b) for (int i = static_cast<int>(b) - 1; i >= static_cast<int>(a); --i)
template <typename T>
int SZ(T const &x)
{
    return static_cast<int>(x.size());
}
#pragma endregion

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

    int n, x, t;
    cin >> n >> x >> t;
    cout << (n + x - 1) / x * t << endl;

    return 0;
}


Measured memory_bytes: 3664
#include <iostream>
#include <algorithm>
using namespace std;
using int64 = long long;
#define int int64

int solve(int p, int q) {
  int mx = max(p,q);
  int mn = min(p,q);
  if (mx%mn != 0) {
    return solve(mn, mx%mn) + (mx/mn)*2*mn; 
  } else {
    return (mx/mn)*2*mn - mn;
  }
}

signed main(){
  int n,x;cin>>n>>x;
  int ans = x + n-x + solve(x, n-x);
  cout<<ans<<endl;
}

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

int main() {
  int n;
  cin>>n;
  int A[300000];
  rep(i,n){
    cin>>A[i];
  }
  
  set<int> s;
  rep(i,n){
  s.insert(A[i]);
  }
  
 
  if(n==s.size())cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  
  
}

Measured memory_bytes: 10496
import java.util.*; 
import java.io.*;

public class Main {
	
	public static void solve(InputReader in) {
		int n = in.readInt(); 
		int a[][] = new int[11][11]; 
		int x = 1; 
		for(int i = 1; i<=n; i++) {
			a[i%10][i/x]++; 
			if(i >= x * 10)
				x *= 10; 
		}
		int ans = 0; 
		for(int i = 1; i<=9; i++) {
			for(int j = 1; j<=9; j++) {
				ans += a[i][j] * a[j][i]; 
			}
		}
		System.out.println(ans); 
	}

	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		int t = 1;
		while (t-- > 0)
			solve(in);
	}
}

class InputReader{
	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	 public InputReader(InputStream stream) {
		this.stream = stream;
	}

     public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

     public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

     public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

     public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}
	
     public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}
     
     public String next() {
		return readString();
	}
    
     public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


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

int main() {
    int A, B; cin >> A >> B;
    vector<vector<char>> m(100, vector<char>(100));

    for (int i = 0; i < 50; i++)
    {
        for (int j = 0; j < 100; j++)
        {
            if(j%2==0 && i%2==0 && B>1){
                m[i][j] = '#';
                B--;
            } else {
                m[i][j] = '.';
            }
        }
    }
    for (int i = 50; i < 100; i++)
    {
        for (int j = 0; j < 100; j++)
        {
            if(j%2==0 && i%2==1 && A>1){
                m[i][j] = '.';
                A--;
            } else {
                m[i][j] = '#';
            }
        }
    }
    cout << 100 << " " << 100 << endl;
    for(auto i : m){
        for(char c : i){
            cout << c;            
        }
        cout << endl;
    }
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;

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

    int ans = 0;
    sort(a, a + n + 1); // a[0] == 0 なので +1
    for (int i = 0; i <= n - k; ++i) {
        // ex1の入力をソートすると {0,0,0,1,2,2}
        // n-k で変換する番号の範囲を決める -> k種類以下にするためにはa[0]~a[3]までの合計を求める
        ans += a[i];
    }
    cout << ans;
}

Measured memory_bytes: 1024
// 2014/06/20 Tazoe

#include <iostream>
#include <string>
using namespace std;

int main()
{
	while(true){
		string r, a;
		cin >> r >> a;

		if(r=="0" && a=="0")
			break;

		int h = 0, b = 0;

		for(int i=0; i<4; i++){
			for(int j=0; j<4; j++){
				if(r[i]==a[j]){
					if(i==j){
						h++;
					}
					else{
						b++;
					}
				}
			}
		}

		cout << h << ' ' << b << '\n';
	}

	return 0;
}

Measured memory_bytes: 1184
#include<bits/stdc++.h>
using namespace std;
vector<int>v[100005];
bool vis[100005];
int dis[100005];
int dfs(int s)
{
    if(vis[s])return dis[s];
    vis[s]=true;

    for(auto it:v[s])
    {

        if(!vis[it])
            dis[s] = max(dis[s],dfs(it)+1);
        else dis[s] = max(dis[s],1+dis[it]);
    }

    return dis[s];
}
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
    }

    for(int i=1;i<=n;i++)
    {
        if(!vis[i])
            dfs(i);
    }

    int maxi=0;
    for(int i=1;i<=n;i++){
        //cout<<dis[i]<<" ";
        maxi = max(maxi,dis[i]);
    }
    cout<<maxi<<"\n";


}

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

int N;
int g1[5] = {2,4,5,7,9};
int g2[5] = {0,1,6,8};
int main () {
    cin >> N;
    for(int i=0;i<5;i++) if(N%10 == g1[i]) cout << "hon" << endl;
    for(int i=0;i<4;i++) if(N%10 == g2[i]) cout << "pon" << endl;
    if(N%10 == 3) cout << "bon" << endl;
    return 0;
}

Measured memory_bytes: 3576
#include<iostream>

using namespace std;

int main(){
    unsigned long long int n, m, ans=0;
    cin >>n >> m;
    if(m>=2*n){
        ans+=n;
        m-=2*n;
    }
    else{
        ans+=m/2;
        m=m%2;
    }
    ans += m/4;
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		//data nyuroku
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int d[] = new int[N];
		for (int i=0;i<N;i++) {
			d[i] = sc.nextInt();
		}
		//sort
		Arrays.sort(d);
		//mochimochi
		int n=N;
		for(int i=0;i<N-1;i++) {
			if (d[i]==d[i+1]) {
				n--;
			}
		}
		System.out.println(n);
	}
}

Measured memory_bytes: 23636