akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int l, r, d;
  cin >> l >> r >> d;
  
  int ans = 0;
  for (int i = l; i <= r; i++) {
    if (i%d == 0) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3520
#include<cstdio>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;

ll n, m, t, ans;
vector<ll> v[300000];
priority_queue<ll> que;

int main() {
  scanf("%lld", &n);
  for (ll i = 0; i < n; i++) {
    scanf("%lld", &m);
    for (ll j = 0; j < m; j++) scanf("%lld", &t), v[i].push_back(t);
  }
  for (ll i = n-1; i >= 0; i--) {
    for (ll j = 0; j < v[i].size(); j++) que.push(v[i][j]);
    ans += que.top();
    que.pop();
  }
  printf("%lld\n", ans);
}



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

bool compare(const pair<int, int> &a, const pair<int, int> &b){
	int at = a.first * a.first + a.second * a.second;
	int bt = b.first * b.first + b.second * b.second;
	if(at == bt) return a.first < b.first;
	else return at < bt;
}

int main(void){
	int H, W;
	while(cin >> H >> W && H != 0 && W != 0){
		int t1 = H * H + W * W;
		vector< pair<int, int> > cand;
		for(int h = 1; h <= 150; h++){
			for(int w = h + 1; w <= 150; w++){
				int t2 = h * h + w * w;
				if(t2 > t1) cand.push_back(pair<int, int>(h, w));
				else if(t2 == t1 && h > H) cand.push_back(pair<int, int>(h, w));
			}
		}
		sort(cand.begin(), cand.end(), compare);
		cout << cand[0].first << " " << cand[0].second << endl;
	}
	return 0;
}

Measured memory_bytes: 1328
#include<algorithm>
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

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

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

    vll A(N);
    rep(i, N) cin >> A[i];

    vll B(M);
    rep(i, M) cin >> B[i];

    vll X(N + 1);
    rep(i, N) X[i + 1] = X[i] + A[i];

    vll Y(M + 1); 
    rep(i, M) Y[i + 1] = Y[i] + B[i];

    int ans = 0;

    rep(i, N + 1)
    {
        int lb = -1;
        int ub = M + 1;

        while (ub - lb > 1)
        {
            int mid = (lb + ub) / 2;

            if (X[i] + Y[mid] <= K)
            {
                lb = mid;
            }
            else
            {
                ub = mid;
            }
        }

        if (lb >= 0 && lb <= M && X[i] + Y[lb] <= K) chmax(ans, lb + i);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9532
#include<bits/stdc++.h>
using namespace std;
long long miti[100000]={0};
int main(){
  int n,m;
  long long ans=0; 
  cin>>n>>m;
  miti[1]=0;
  n--;
  for(int i=2;i<=n+1;i++){
    int s;
    cin>>s;
    miti[i]=miti[i-1]+s;
    // cout<<miti[i]<<" ";
  }
  //cout<<endl;
  int mae=1,now=1;
  for(int i=0;i<m;i++){
    int a;
    cin>>a;
    now+=a;
    //cout<<mae<<" "<<now<<endl;
    ans+=abs(miti[now]-miti[mae]);
    mae=now;
  }
  cout<<ans%100000<<endl;
  return 0;
}
  

Measured memory_bytes: 1936
#include <bits/stdc++.h>
#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define numa(x,a) for(auto x: a)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define pf push_front
#define sec second
#define sz(x) ((int)(x).size())
#define ALL( c ) (c).begin(), (c).end()
#define gcd(a,b) __gcd(a,b)
#define mem(x,n) memset(x,n,sizeof(x))
#define endl "\n"
using namespace std;
template <int POS, class TUPLE> void deploy(std::ostream &os, const TUPLE &tuple){}
template <int POS, class TUPLE, class H, class ...Ts> void deploy(std::ostream &os, const TUPLE &t){ os << (POS == 0 ? "" : ", ") << get<POS>(t); deploy<POS + 1, TUPLE, Ts...>(os, t); }
template <class T,class U> std::ostream& operator<<(std::ostream &os, std::pair<T,U> &p){ os << "(" << p.first <<", " << p.second <<")";return os; }
template <class T> std::ostream& operator<<(std::ostream &os, std::vector<T> &v){ int remain = v.size(); os << "{"; for(auto e: v) os << e << (--remain == 0 ? "}" : ", "); return os; }
template <class T> std::ostream& operator<<(std::ostream &os, std::set<T> &v){ int remain = v.size(); os << "{"; for(auto e: v) os << e << (--remain == 0 ? "}" : ", "); return os; }
template <class T, class K> std::ostream& operator<<(std::ostream &os, std::map<T, K> &mp){ int remain = mp.size(); os << "{"; for(auto e: mp) os << "(" << e.first << " -> " << e.second << ")" << (--remain == 0 ? "}" : ", "); return os; }
#define DEBUG1(var0) { std::cerr << (#var0) << "=" << (var0) << endl; }
#define DEBUG2(var0, var1) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG1(var1); }
#define DEBUG3(var0, var1, var2) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG2(var1,var2); }
#define DEBUG4(var0, var1, var2, var3) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG3(var1,var2,var3); }
using ll = long long;
ll ans[20];
#define XY2Z(x_,y_) (x_ * W + y_)
int main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  mem(ans, 0);
  ll H,W;
  int N;
  cin >> H >> W >> N;
  vector <pair <int,int> > blacks(N);
  rep(i,N){
    cin >> blacks[i].fir >> blacks[i].sec;
    blacks[i].fir--;
    blacks[i].sec--;
  }
  //set <pair <int,int> > counted;
  set <ll> counted;
  sort(ALL(blacks));
  int dx[] = {0,-1,-2,0,-1,-2,0,-1,-2};
  int dy[] = {0,0,0,-1,-1,-1,-2,-2,-2};
  rep(i,N){
    int x = blacks[i].fir, y = blacks[i].sec;
    rep(k,9){
      //lu
      int cx = x + dx[k], cy = y + dy[k];
      if (0 <= cx && cx + 2 < H && 0 <= cy && cy + 2 < W && counted.find(XY2Z(cx,cy)) == counted.end()) {
        ;
      }else{
        continue;
      }
      int cnt = 0;
      counted.insert(XY2Z(cx,cy));
      rep(i,3){
        rep(j,3){
          cnt += binary_search(ALL(blacks), mp(cx+i, cy + j));
        }
      }
      ans[cnt] += 1;
    }
  }
  //DEBUG1(counted);
  ll z = (H - 2) * (W - 2) - sz(counted);
  cout << z << endl;
  rep2(i,1,10){
    cout << ans[i] << endl;
  }

  return 0;
}



Measured memory_bytes: 43264
using System;

namespace AOJ
{
    class LinearSearch
    {
        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            var input = Console.ReadLine().Trim().Split(' ');
            var data = new int[n];
            for (int i = 0; i < n; i++) { data[i] = int.Parse(input[i]); }

            int q = int.Parse(Console.ReadLine());
            input = Console.ReadLine().Trim().Split(' ');
            var search = new int[q];
            for (int i = 0; i < q; i++) { search[i] = int.Parse(input[i]); }

            int counter = 0;
            for (int i = 0; i < q; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (data[j] == search[i])
                    {
                        counter++;
                        break;
                    }
                }
            }

            Console.WriteLine(counter);
        }
    }
}

Measured memory_bytes: 6176
square = input()
 
down = []
edge = []
pool = []
 
for i, strings in enumerate(square):
    if strings == "\\":
        down.append(i)
    elif down and strings == "/":
        left = down.pop()
        area = i - left
 
        while edge:
            if edge[-1] < left:
                break
            edge.pop()
            area += pool.pop()
 
        edge.append(left)
        pool.append(area)
 
print(sum(pool))
print(len(pool), *pool)

Measured memory_bytes: 8200
#include <bits/stdc++.h>
using namespace std;
 
int main() {
string S;
string T;
cin>>S;
cin>>T;
int ans=0;
for(int i=1;i<(S.length()+1);i++)
{char s=S[i-1];
char t=T[i-1];
  if(s==t);
else ans++;}
cout<<ans<<endl;
}

Measured memory_bytes: 3808
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define iREP(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

bool hurui[1000010];
int dp[1000010];

bool isPrime(int n){
    if(n==1)return false;
    if(n==2)return true;
    for(int i=2;i<sqrt(n)+1;i++){
        if((n%i)==0)return false;
    }
    return true;
}

int main(){
    
    REP(i,1000010)hurui[i]=true;
    hurui[0]=hurui[1]=false;
    for(int i=2;i<=1000005;i++){
        if(hurui[i]){
            if(isPrime(i)){
                for(int j=i+i;j<=1000005;j+=i)hurui[j]=false;
            }
        }
    }
    
    REP(i,1000005)dp[i+1]=dp[i]+(hurui[i+1]?1:0);
    
    int t;
    while(cin>>t){
        cout<<dp[t]<<endl;
    }
    
    return 0;
}

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

using namespace std;

using ll = long long;

using vll = vector<ll>;
using vvll = vector<vll>;

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

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

  ll n, k;
  cin >> n >> k;
  vll a(n);
  rep(i, n) {
    cin >> a[i];
  }

  vll s(n + 1);
  rep(i, n) {
    s[i + 1] = s[i] + a[i];
  }

  ll ans = 0;

  map<ll, vll> m;
  rep(i, n + 1) {
    ll mod = (s[i] - i) % k;

    auto it = upper_bound(all(m[mod]), i - k);
    ll idx = distance(m[mod].begin(), it);
    ans += m[mod].size() - idx;

    m[mod].push_back(i);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 25216
using System;

namespace question1
{
    class Program
    {
        static void Main(string[] args)
        {
            var p = new Program();
            p.Run();
        }

        void Run()
        {
            var line = Console.ReadLine();
            var a = int.Parse(line.Split(' ')[0]);
            var b = int.Parse(line.Split(' ')[1]);

            if (a == b)
            {
                Console.WriteLine(a + b);
            }
            else
            {
                Console.WriteLine(Math.Max(a, b) * 2 - 1);
            }
        }
    }
}


Measured memory_bytes: 13140
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in = new Scanner(System.in);
        long a = in.nextLong(), b = in.nextLong();
        if (a >= b) {
            a = a % b;
        }
        if (a > b - a)
            System.out.println(b - a);
        else {
            System.out.println(a);
        }
    }
}


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

int main(int a, int b) {
    cin >> a >> b;
    int d = a / b;
    int r = a % b;
    double f = ((double)a) / b;
    cout << std::fixed;
    cout << d << " " << r << " " << std::setprecision(5) << f << endl;
    return 0;
}


Measured memory_bytes: 3272
#include<stdio.h>
int main(void)
{
    int N,S[100];
    int i,j,tmp,S2=0;
  
    scanf("%d",&N);
  
    for(i=0;i<N;i++)
      scanf("%d",&S[i]);
  
    for(i=0;i<N;i++){
      for(j=i+1;j<N;j++){
        if(S[i]<S[j]){
          tmp=S[i];
          S[i]=S[j];
          S[j]=tmp;
        }
      }
    }
  
    for(i=0;i<N;i++)
       S2+=S[i];
  
    if(S2%10!=0) { printf("%d\n",S2); return 0; }
    else {
      for(i=N-1;i>=0;i--){
        S2=S2-S[i];
       if(S2%10!=0){
         printf("%d\n",S2);
         return 0;
       }
       else S2=S2+S[i];
     }
    }
  
      printf("0\n");
      return 0;
}

Measured memory_bytes: 1692
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
int main()
{
	ll A,B,N;
	cin >> A >> B >> N;
	ll x = B-1;

	if(N<x)
		x = N;
		
	
	ll a = A*x/B;
	ll b = x/B;
	ll y = a - A*b;
	cout << y;

	cin >> A;
	
	return 0;	
}

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

int main() {
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  if(A+B>C+D){
    cout<<"Left"<<endl;
  }
  if(A+B==C+D){
    cout<<"Balanced"<<endl;
  }
  if(A+B<C+D){
    cout<<"Right"<<endl;
  }
}

Measured memory_bytes: 256
import Data.Char

transpose ([]:_) = []
transpose matrix =
  let row  = map (head) matrix
      rows = transpose $ map (drop 1) matrix
  in
    row:rows

concat' :: [String] -> String
concat' (x:[]) = x
concat' (x0:x1:xs) = concat' ((x0++"\n"++x1):xs)

line :: Int -> String
line n = 
  let n5 = n `div` 5
      n1 = n `mod` 5
      c5 = if n5 == 1 then " *=" else "* ="
      c1 = (replicate n1 '*') ++ " " ++ (replicate (4-n1) '*')
  in
    c5++c1

ans d =
  let n = map digitToInt d :: [Int]
      l = length(n)
      n'= (replicate (5-l) 0) ++ n
      c = map line n'
  in
    transpose c

main = do
  c <- getContents
  let i = lines c
      o = map ans i
  putStr $ concat' $ map unlines o

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

using namespace std;
typedef long long int lli;
typedef long long ll;

int main(){
  int n,m; cin >> n >> m;
  vector<int> p(m), y(m);
  vector<vector<int>> yd(100001,vector<int>());
  rep(i,m){
    cin >> p[i] >> y[i];
    yd[p[i]].push_back(y[i]);
  }

  rep(i,n) sort(all(yd[i+1]));
  rep(i,m) printf("%012lld\n", ll(p[i])*1000000+int(lower_bound(yd[p[i]].begin(), yd[p[i]].end(), y[i]) - yd[p[i]].begin())+1);
}


Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
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 long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

string s;

void input(){
    cin >> s;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    map<char, int> cnt;
    for(int i=0;i<s.size();i++) cnt[s[i]]++;
    bool flg = false;
    if((cnt['N'] > 0 && cnt['S'] > 0) && (cnt['E'] > 0 && cnt['W'] > 0)) flg = true;
    if((cnt['N'] > 0 && cnt['S'] > 0) && (cnt['E'] == 0 && cnt['W'] == 0)) flg = true;
    if((cnt['E'] > 0 && cnt['W'] > 0) && (cnt['N'] == 0 && cnt['S'] == 0)) flg = true; 
    if(flg) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int		main(void)
{
	int n;

	cin >> n;
	if (n == 1)
		cout << "Hello World" << endl;
	else
	{
		int a, b;

		cin >> a >> b;
		cout << a + b << endl;
	}
}


Measured memory_bytes: 256
l=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(l[int(input())-1])

Measured memory_bytes: 8956
/*input
3000
*/
#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define rd() abs((int)rng())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int maxn = 2e5 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0);
	int N;
	cin >> N;
	cout << (1000 - N % 1000) % 1000 << "\n";
	return 0;
}

Measured memory_bytes: 3608
#include<stdio.h>
int main(void)
{
	float a,b;
	int ar,al,br,bl,cr,cl,dr,dl;
	ar=0;
		al=0;
		br=0;
		bl=0;
		cr=0;
		cl=0;
		dr=0;
		dl=0;
	while(scanf("%f %f",&a,&b)!=EOF){
		
		if(a>=1.1){
			al++;
		}
		else if(a>=0.6){
			bl++;
		}
		else if(a>=0.2){
			cl++;
		}
		else if(a<0.2){
			dl++;
		}
		if(b>=1.1){
			ar++;
		}
		else if(b>=0.6){
			br++;
		}
		else if(b>=0.2){
			cr++;
		}
		else if(b<0.2){
			dr++;
		}
	}
	printf("%d %d\n%d %d\n%d %d\n%d %d\n",al,ar,bl,br,cl,cr,dl,dr);
	return 0;
}

Measured memory_bytes: 624
#include<iostream>
using namespace std;
int main() {
	int h, w;
	cin >> h >> w;
	char buf[55][55];
	int dx[8] = {-1,-1,-1,0,0,1,1,1, };
	int dy[8] = { -1,0,1,-1,1,-1,0,1 };
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> buf[i][j];
		}
	}
	int count = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (buf[i][j] == '.') {
				for (int k = 0; k < 8; k++) {
					int x = j + dx[k];
					int y = i + dy[k];
					if (x>=0&&x<w&&y>=0&&y<h&&buf[y][x] == '#') {
						count++;
					}
				}
				buf[i][j] = char(count + '0');
				count = 0;

			}
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (j % w == 0) {
				cout << endl;
			}
			cout << buf[i][j];
		}
	}
	return 0;
}

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

int64_t inf = 1e18;

int main(){

    int A, B, Q;
    cin >> A >> B >> Q;
    vector<int64_t> s(A + 2), t(B + 2), x(Q);
    s.front() = t.front() = -inf;
    s.back() = t.back() = inf;
    for(int i = 1; i <= A; i++) cin >> s[i];
    for(int i = 1; i <= B; i++) cin >> t[i];
    for(int i = 0; i < Q; i++) cin >> x[i];

    // using bin_search O(Qlog(A, B))
    for(int i = 0; i < Q; i++){
        int64_t ans = inf;
        int r = distance(s.begin(), lower_bound(s.begin(), s.end(), x[i]));
        int l = distance(t.begin(), lower_bound(t.begin(), t.end(), x[i]));

        ans = min(ans, abs(x[i] - s[r]) + abs(s[r] - t[l]));
        ans = min(ans, abs(x[i] - s[r - 1]) + abs(s[r - 1] - t[l]));
        ans = min(ans, abs(x[i] - s[r]) + abs(s[r] - t[l - 1]));
        ans = min(ans, abs(x[i] - s[r - 1]) + abs(s[r - 1] - t[l - 1]));
        ans = min(ans, abs(x[i] - t[l]) + abs(s[r] - t[l]));
        ans = min(ans, abs(x[i] - t[l]) + abs(s[r - 1] - t[l]));
        ans = min(ans, abs(x[i] - t[l - 1]) + abs(s[r] - t[l - 1]));
        ans = min(ans, abs(x[i] - t[l - 1]) + abs(s[r - 1] - t[l - 1]));
        
        cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
#define ull unsigned long long int
using namespace std;

ll n,m,ar[N],sum,t,tut[40];

void solve(int a,int b)
{
	// cout<<a<<sp<<b<<endl;
	if(a==b-1 || a*2<=b)
	{
		cout<<"Yes"<<endl;
		return;
	}
	cout<<"No"<<endl;

}

int main()
{
	fast;
	cin>>n;
	fs(ar,n);
	sort(ar+1,ar+n+1);
	if(ar[1]<ar[n]-1)
		return cout<<"No",0;
	if(ar[1]==ar[n])
	{
		solve(ar[1],n);
		return 0;
	}
	int a=0;
	fo(i,1,n-1)
	{
		a++;
		if(ar[i]!=ar[i+1])
			break;
	}
	if(a>ar[1])
		return cout<<"No",0;
	if((ar[n]-a)*2<=n-a)
		cout<<"Yes";
	else
		cout<<"No";

}



Measured memory_bytes: 4408
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#define LL long long
using namespace std;
int x, y;
int main()
{ 
	cin >> x >> y;
	if (x == y) cout << "0\n";
	else if (x < y) cout << min(y - x, abs(y + x) + 1) << '\n';
	else cout << min(abs(x + y) + 1, x - y + 2) << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Mx 1000000000005 
#define ll long long  
#define pi 3.141592653
#define vi vector<ll>
#define Mo 1000000007
#define mp make_pair
#define M map<ll,ll>
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define vii vector<pair<ll,ll> > 
#define fi first
#define se second
#define pb push_back
#define ld long double
#define fill(a,x) memset(a,x,sizeof(a))
using namespace std;
bool comp(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
  return a.second<b.second;
}
/*vi b=v;
   sort(b.begin(), b.end());
  b.resize(unique(b.begin(), b.end()) - b.begin());
  ll t; cin>>t; fr(f,0,t){ 
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 */
vector<vector<ll>> dp(3001,vector<ll>(30001,-1));
ll func(ll l,ll r,ll a[])
{
  if(l==r) return a[l];
  if(r-l==1) return max(a[l],a[r]);

  if(dp[l][r]!=-1) return dp[l][r];

  ll x=a[l]+min(func(l+1,r-1,a),func(l+2,r,a));
  ll y=a[r]+min(func(l,r-2,a),func(l+1,r-1,a));
  return dp[l][r]=max(x,y);
}
int main()
{
  ll n,sum=0; cin>>n;
  ll a[n];
  fr(i,0,n)
  {
    cin>>a[i];
    sum+=a[i];
  }

  cout<<2*func(0,n-1,a)-sum;
}


Measured memory_bytes: 711652
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Reader r = new Reader();        
        int N = r.i();
        HashSet<Integer> hs = new HashSet<>();
        for(int i = 0; i < N; i++)
            hs.add(r.i());
        println(hs.size());
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class Reader extends BufferedReader{
        Reader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long(ss[j]);            
            return ll;
        }
    }
}

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

using namespace std;


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

	if(k<=a+b){
		if(k<=a) cout<<k<<endl;
		else cout<<a<<endl;
	}
	if(k>a+b){
		cout<<a-(k-(a+b))<<endl;
	}
}

Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <stack>

using std::vector;
using std::printf;
using std::cout;
using std::endl;
using std::string;
using std::cin;

#define i64t long long int

template<typename T>
void dump(vector<T> vec) {
    for (auto x : vec) {
        std::cout << x << " ";
    }
    std::cout << std::endl;
}

// ---------------------------

const i64t MOD = 1000000007;

int main() {
    i64t N;
    cin >> N;

    string S; 
    cin >> S;

    // determine
    string LR(S);
    LR[0] = 'L';
    for (int i = 1; i < 2 * N; ++i) {
        if (S[i] == S[i-1]) {
            LR[i] = (LR[i-1] == 'L') ? 'R' : 'L';
        }
        else {
            LR[i] = LR[i-1];            
        }
    }

    i64t lc = 0, rc = 0;
    for (int i = 0; i < 2 * N; ++i) {
        if (LR[i] == 'L') { lc++; }
        else { rc++; }
    }

    // cout << S << endl;
    // cout << LR << endl;
    // printf("%lld %lld\n", lc, rc);
    
    i64t ret;
    if (LR[2*N-1] != 'R') {
        ret = 0;
    }
    else if (S[0] != 'B') {
        ret = 0;
    }
    else if (lc != rc) {
        ret = 0;
    }
    else {
        i64t ll = 0, tot = 1;
        for (int i = 0; i < 2 * N; ++i) {
            if (LR[i] == 'L') {
                ll++;
            }
            else {
                tot = (tot * ll) % MOD;
                ll--;
            }
            // printf("DEBUG: %d %lld %lld\n", i, ll, tot);
        }

        ret = tot;
        for (i64t i = 1; i < N+1; ++i) {
            ret = (ret * i) % MOD;
        }
    }

    printf("%d", (int)ret);
}

Measured memory_bytes: 772
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
#define clrg(i, l, r) for(int i=(int)(l);i<(int)(r);i++)vis[i]=0,v[i].clear();
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<"\n";
#define ln length()
#define sz size()
#define mod 1000000007
#define elif else if
int32_t main(){
   int n;
   cin>>n;
   vector<int> v,fr(100005);
   int sum=0;
   rep(i,0,n){
       int t;
       cin>>t;
       v.pub(t);sum+=t;
       fr[t]++;
    }
    int q;
    cin>>q;
    while(q--){
        int a,b;
        cin>>a>>b;
        fr[b]+=fr[a];
        sum+=(fr[a]*(b-a));
        fr[a]=0;
        cout<<sum<<"\n";
    }
   return 0;
}

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

using namespace std;

int main()
{
  int n;
  while(cin >> n, n){
    int col[101][101], row[101][101];
    for(int i = 0; i < n; i++)
      for(int j = 0; j < n; j++) cin >> row[i][j], col[j][i] = -row[i][j];
    for(int i = 0; i < n; i++) sort(row[i], row[i] + n), sort(col[i], col[i] + n);

    bool flag = false;
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
	if(row[i][0] == -col[j][0]){
	  cout << row[i][0] << endl;
	  flag = true;
	  break;
	}
      }
      if(flag) break;
    }
    if(!flag) cout << 0 << endl;
  }
  return 0;
}

Measured memory_bytes: 1188
#include <iostream>

using namespace std;

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

    int res = n;
    for (int i = 0, j = 1; i < n; i++) {
        int a;
        cin >> a;

        if (a == j) {
            res--;
            j++;
        }
    }

    cout << (res < n ? res : -1) << endl;
}


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

uint64_t remain = 0;
std::unordered_map<uint64_t, uint64_t> layerCache;
std::unordered_map<uint64_t, uint64_t> cache;

uint64_t levelNLayer(uint64_t n)
{
    if (1 == layerCache.count(n)) {
        return layerCache[n];
    }

    uint64_t cnt = 0;
    if (n == 0) {
        return 1;
    } else {
        cnt += 3;
        if (1 == layerCache.count(n-1)) {
            cnt += (2 * layerCache[n-1]);
        } else {
            uint64_t cnt1 = levelNLayer(n-1);
            cnt += (2 * cnt1);
            layerCache[n-1] = cnt1;
        }

        return cnt;
    }
}

uint64_t levelN(uint64_t n)
{
    uint64_t cnt = 0;

    if (remain == 0) {
        return 0;
    }

    if (n == 0) {
        remain--;
        return 1;
    } else {
        remain--;
        if (1 == cache.count(n-1)) {
            uint64_t layerCnt = levelNLayer(n-1);
            if (layerCnt <= remain) {
                cnt+= cache[n-1];
                remain -= layerCnt;
            } else {
                cnt += levelN(n-1);
            }
        } else {
            uint64_t cnt1 = levelN(n-1);
            if (remain != 0) {
                cache[n-1] = cnt1;
            }
            cnt += cnt1;
        }

        if (remain == 0) {
            return cnt;
        }

        remain--;
        cnt++;

        if (levelNLayer(n-1) <= remain) {
            cnt += cache[n-1];
            remain -= levelNLayer(n-1);
        } else {
            cnt += levelN(n-1);
        }
        if (remain == 0) {
            return cnt;
        }

        remain--;
        return cnt;
    }
}

int main()
{
    uint64_t n;
    std::cin >> n >> remain;

    uint64_t cnt = levelN(n);
    std::cout << cnt << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include"stdio.h"
#include"cstdio"
#include"algorithm"
#include"string.h"
using namespace std;
const int max_n=1e5+10;
char A[max_n];
int main()
{
	while(scanf("%s",A)!=EOF)
	{
		int l=-2,r=-2,i,n=strlen(A);
		for(i=0;i<n-1;i++)
		{
			if(A[i]==A[i+1])
			{
				l=i;r=i+1;
				break;
			}
			else if(A[i]==A[i+2]&&i+2<n)
			{
				l=i;r=i+2;
				break;
			}
		}
		printf("%d %d\n",l+1,r+1);
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define BeatMeScanf ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define sz 5030


int main()
{
    BeatMeScanf;
    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Numerics;
using System.IO;
using System.Runtime.InteropServices;
using static System.Math;
using static io;
public class CompetitiveProgramming
{
  public void Solve()
  {
    var o = Longs;
    var x = o[0];
    var y = o[1];

    Console.WriteLine(GCD(x, y));
  }
  static long GCD(long x, long y)
  {
    while (y > 0)
    {
      var r = x % y;
      x = y;
      y = r;
    }
    return x;
  }
}



class Program
{
  static void Main(string[] args)
  {
    var CompetitiveProgramming = new CompetitiveProgramming();
    CompetitiveProgramming.Solve();
  }
}
public static class io
{
  public static string Str => Console.ReadLine();
  public static string[] Strs => Str.Split(' ');
  public static long[] Longs => Strs.Select(long.Parse).ToArray();
  public static int[] Ints => Strs.Select(int.Parse).ToArray();
  public static char[] Chars => Str.ToArray();
  public static double[] Doubles => Strs.Select(double.Parse).ToArray();
  public static long Long1 => Longs[0];
  public static int Int1 => Ints[0];
  public static char Char1 => Chars[0];
  public static double Double1 => Doubles[0];
  public static long[] VerticalRead(int N) { long[] A = new long[N]; for (int i = 0; i < N; ++i) A[i] = Long1; return A; }
  public static void Write(string a) => Console.WriteLine(a);
  public static void Write(params object[] i) => Write(string.Join(" ", i));
  public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a));
  public static void Verticalwrite<T>(IEnumerable<T> a) { foreach (var z in a) Write(z); }
  public static void YN(bool i) { if (i) Write("Yes"); else Write("No"); }
}



Measured memory_bytes: 18444
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args){
        int D = in.i();
        int G = in.i();
        int[] p = new int[D];
        int[] c = new int[D];
        for (int i = 0; i < D; i++) {
            p[i] = in.i();
            c[i] = in.i();
        }
        int ans = Integer.MAX_VALUE;
        for (int i = 0; i < 1 << D; i++) {
            int t = 0;
            int sum = 0;
            for (int j = 0; j < D; j++) {
                if ((i >> j & 1) == 1) {
                    sum += 100 * (j + 1) * p[j] + c[j];
                    t += p[j];
                }
            }
            for (int j = D - 1; j >= 0; j--) {
                if (G <= sum) {
                    break;
                } else if ((i >> j & 1) == 0){
                    int n = min(p[j] - 1, (G - sum - 1) / (100 * (j + 1)) + 1);
                    t += n;
                    sum += 100 * (j + 1) * n;
                }
            }
            if (G <= sum) {
                ans = min(ans, t);
            }

        }
        out.println(ans);
    }

    static int min(int a, int b) {
        return a < b ? a : b;
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = read(cbuf, 0, cbuf.length);
            } catch (IOException e) {}
            head = 0;
        }
        return cbuf[head++];
    }

    void back() {
        head--;
    }

    boolean minus() {
        boolean minus;
        while (true) {
            char c = next();
            if (c != ' ' && c != '\n' && c != '\r') {
                if (!(minus = c == '-')) back();
                return minus;
            }
        }
    }

    void skip() {
        while (true) {
            char c = next();
            if (c != ' ' && c != '\n' && c != '\r') {
                back();
                break;
            }
        }
    }

    char[] s(final int N) {
        skip();
        char[] s = new char[N];
        for (int i = 0; i < s.length; i++) {
            s[i] = next();
        }
        return s;
    }

    int i() {
        boolean minus = minus();
        int n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        boolean minus = minus();
        long n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }
}


Measured memory_bytes: 32528
import sys
input = sys.stdin.readline
INF = 10**20
MOD = 10**9 + 7

def main():
    k = int(input())
    print(50)

    l = (k + 49) // 50
    mod = k % 50
    ans = [l] * 50

    for i in range(50):
        ans[i] += 50 - i - 1
    
    if mod != 0:
        for i in range(50 - mod):
            for j in range(50):
                if i == j:
                    ans[j] -= 50
                else:
                    ans[j] += 1
    print(*ans)

if __name__=='__main__':
    main()

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

int w, h;
int c[50][50], flag[50][50];

int f(int x, int y){
    if(x >= w || x < 0 || y >= h || y < 0) return 0;
    if(flag[x][y] == 1 || c[x][y] == 0) return 0;
    flag[x][y] = 1;
    f(x+1,y);
    f(x-1,y);
    f(x,y+1);
    f(x,y-1);
    f(x+1,y+1);
    f(x+1,y-1);
    f(x-1,y+1);
    f(x-1,y-1);
    return 1;
}

int main(){
    do{
        int sum = 0;
        cin >> w >> h;
        if(w == 0 && h == 0) return 0;
        for(int y = 0; y < h; y++){
            for(int x = 0; x < w; x++){
                cin >> c[x][y];
                flag[x][y] = 0;
            }
        }
        for(int y = 0; y < h; y++){
            for(int x = 0; x < w; x++){
                sum += f(x,y);
            }
        }
        cout << sum << endl;
    }while(true);

    return 0;
}


Measured memory_bytes: 3120
import math
a, b, x = (int(i) for i in input().split())
t = 2 * (b/a - x/(a*a*a))
z = math.atan(b/a)
rad = math.atan(t)

if(rad <= z):
    deg = math.degrees(rad)
else:
    rad = math.atan((a*b*b)/(2*x))
    deg = math.degrees(rad)
print(deg)


Measured memory_bytes: 3060
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	int n;
	cin>>n;
	int cnt = 0;
	vi arr(n);
	for(int &i:arr)cin>>i;
	for(int i=0;i<n;i++) {
		if(arr[i]==i+1){
			cnt++;
			swap(arr[i],arr[i+1]);
		}
	}
	cout<<cnt;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3712
import java.util.*;
public class Main{
    public static void main(String args[]) {
      Scanner in = new Scanner(System.in);
      int A = in.nextInt();
      String op = in.next();
      int B = in.nextInt();
      if (op.equals("+"))
        System.out.println(A+B);
      else if (op.equals("-"))
        System.out.println(A-B);
    }
}

Measured memory_bytes: 21972
a,b,c,x = map(int,open(0).read().split())

ans = 0 
counta = 0

for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      ans = ((i*500) + (j*100) + (k*50))
      if ans == x:
        counta += 1
      else:
        pass
      
print(counta)


Measured memory_bytes: 9180
#include<stdio.h>
int main(){
       int x,y,z,a,b,c,d,f;
	scanf("%d",&x);
	//if(x%500!=0){
		y=x%500;
		z=x-y;
		a=z/500;
		b=a*1000;
		c=y%5;
		d=y-c;
		f=b+d;
		printf("%d",f);
		return 0;

}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main()
{
    long long int a,b,c,f,t;
    cin>>t;
    while(t--)
    {
        f=0;
        cin>>a>>b>>c;
        if(a>b && a>c)
        {
            if((b*b)+(c*c)==(a*a))
                f=1;
        }
        else if(b>a && b>c)
        {
            if((a*a)+(c*c)==(b*b))
                f=1;
        }
        else if(c>b && c>a)
        {
            if((b*b)+(a*a)==(c*c))
                f=1;
        }
        if(f==1)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define ll long long
#define pr pair<ll,ll>
using namespace std;
bool vis[1000005];
int pri[1000005],cnt;
int n, num[2005];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> num[i];
	}
	sort(num, num + n);
	int ans = 0;
	for (int i = 0; i < n-2; i++) {
		for (int j = i + 1; j < n-1; j++) {
			int k = num[i] + num[j],p=num[j]-num[i];
			int s = lower_bound(num + j + 1, num + n,p+1) - num;
			int m = upper_bound(num + j + 1, num + n, k-1) - num;
			if (s <= m)ans += m - s;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3648
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

ans_list = []
for x,a in enumerate(A):
    for y,b in enumerate(B):
        if (x+1)*(y+1)>K:
                break
        for z,c in enumerate(C):
            if (x+1)*(y+1)*(z+1)>K:
                break
            ans_list.append(a+b+c)

ans_list.sort(reverse=True)

for ans in ans_list[:K]:
    print(ans)

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

int main() {
  int A,B,C; cin>>A>>B>>C;
  int K; cin>>K;
  int max = 0;
  if(K>A){
    max = A;
    K -= A;
    if(K>B){
      K -= B;
      max -= K;
    }
  }else{
    max = K;
  }
  cout<<max<<endl;
}

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

int main(){
	int n;
    int ans=0;
	cin>>n;
    int a[n+10];
	for(int i=1;i<=n;i++){
      cin>>a[i];
	}
	for(int i=1;i<=n;i++){
		if(i==a[a[i]]){
          ans++;
        }
	}
	cout<<ans/2<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
     
int main() {
  int N;
  cin >> N;
  vector<int> point_queue(N);
  for(int i = 0; i < N; i++){
    cin >> point_queue.at(i);
  }
  sort(point_queue.begin(),point_queue.end(),greater<int>());
  int A = 0;
  int B = 0;
  for(int j = 0; j < N; j++){
  	if(j % 2 == 0){
    A += point_queue.at(j);
    }else{
    B += point_queue.at(j);
    }
  }
  cout << A - B << endl;
}

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

typedef long long ll;

int main() {
    int N,M;
    cin >> N >> M;
    int L = -1, R = 1000000;
    int Li, Ri;
    for (int i=0;i<M;i++){
        cin >> Li >> Ri;
        if (Li > L) L = Li;
        if (Ri < R) R = Ri;
    }
    cout << max(R - L + 1,0) << endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll n;
	cin >> n;
	Vec a(n);
	rep(i, n) cin >> a[i];

	Vec ans(n);
	repr(i, n-1){
		repr(j, i){
			if(a[j] == j+1){
				a.erase(a.begin()+j);
				ans[i] = j+1;
				break;
			}
		}
		if(!ans[i]){
			co(-1);
			return 0;
		}
	}
	rep(i, n) co(ans[i]);

	return 0;
}


Measured memory_bytes: 256
N, maxW = map(int, input().split())
maxV = 10**3*100
dp = [[float('inf') for i in range(maxV+1)] for j in range(N+1)]
W = [0 for i in range(N+1)]
V = [0 for i in range(N+1)]
for i in range(1, N+1):
    W[i], V[i] = map(int, input().split())

nv = 0
nw = 0
dp[0][0] = 0
for i in range(1, N+1):
    for v in range(maxV+1):
        dp[i][v] = min(dp[i-1][v], dp[i][v])
        nv = v + V[i]
        if nv <= maxV:
            dp[i][nv] = dp[i-1][v] + W[i]
ans = 0
for v in range(maxV, -1, -1):
    if maxW >= dp[N][v]:
        ans = v
        break

print(ans)

Measured memory_bytes: 319172
import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author otsuhata
 */
public class Main {
    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    
    if(0 <= a && a <= 100 && 0 <= b && b <= 100 && 0 <= c && c <= 100) {
        if(a < b && b < c) {
            System.out.println("Yes");
        }else {
            System.out.println("No");
        }        
    }else {
        System.out.println("Please enter a number from 0 to 100.");
    }
  }    
}

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

int main() {
	int N,H,W,c=0;
	cin >> N >> H >> W;

	rep(i,N) {
		int A,B;
		cin >> A >> B;
		if(A>=H && B>=W)
			++c;
	}

	cout << c << endl;
}

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

const int MAXN = 1e5 + 10;
long long e, t, dp[MAXN], mn = 1e17;
int n, x[MAXN];

int main() {
	cin >> n >> e >> t;
	for (int i = 1; i <= n; i++)
		cin >> x[i];
	dp[1] = t;
	int j = 1;
	for (int i = 2; i <= n; i++) {
		while ((x[i] - x[j]) * 2 > t) {
			mn = min(mn, dp[j - 1] - 2 * x[j]);
			j++;
		}
		dp[i] = min(mn + 2 * x[i], dp[j - 1] + t);
	}
	cout << dp[n] + e;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  if (n % 2 == 1) {
    cout << b[n / 2] - a[n / 2] + 1 << '\n';
  } else {
    cout << b[n / 2 - 1] - a[n / 2 - 1] + b[n / 2] - a[n / 2] + 1 << '\n';
  }
  return 0;
}

Measured memory_bytes: 4776
/* Filename: A.java
 * Author: Mushiyo
 */

import java.util.Scanner;

public class Main {

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

		while (input.hasNext()) {
			StringBuilder sb = new StringBuilder(input.next());
			
			System.out.println(sb.insert(4, ' '));
		}
	}

}


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

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


void bubble_sort(char arr[], int N){
  for(int j=N-1;j>0;j--){
  for(int i=0;i<j;i++)
    if(arr[i]>arr[i+1]){
      swap(arr[i],arr[i+1]);
    }
  }
}
int main(){
  int N;
  cin >>N;
  map<string,int> m;
  long long int ans=0;
  rep(i,N){
    string s;
    cin >>s;
    sort(s.begin(),s.end());
    m[s]++;
  }
  for(auto& p :m){
    int a = p.second;
    ans+=(long long int)a*(a-1)/2;

  }

  
    cout <<ans<<endl;


  return 0;
}


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

int main(void) {
  int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K;
  cin >> K;
  
  cout << a[K-1] << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	char c;
	cin >> c;
	cout << (char)(c+1) << endl;

	return 0;
}


Measured memory_bytes: 256
n = int(input())
march = ['M','A','R','C','H']
counter = [0]*5
for i in range(n):
	s = input()
	if s[0] in march:
		counter[march.index(s[0])] += 1

ans = 0
for i in range(3):
	for j in range(1+i,4):
		for k in range(1+j,5):
			ans += counter[i]*counter[j]*counter[k]

print(ans)

Measured memory_bytes: 3064