akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			char[] s = in.nextString().toCharArray();
			int n = s.length;
			int ans = INF;
			for (int i = 0; i+2 < n; i++) {
				int tmp = Character.getNumericValue(s[i]) * 100 + Character.getNumericValue(s[i+1]) * 10 + Character.getNumericValue(s[i+2]);
				ans = Math.min(ans, Math.abs(tmp - 753));
			}

			out.println(ans);

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public int[] nextIntArray1Index(int n) {
			int[] res = new int[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public long[] nextLongArray1Index(int n) {
			long[] res = new long[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextLong();
			}
			return res;
		}

		public double[] nextDoubleArray(int n) {
			double[] res = new double[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextDouble();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 21332
#include <stdio.h>

int
main(void)
{
	char line[80];
	int a[5000];
	int n;

	while (fgets(line, sizeof line, stdin)) {
		if (sscanf(line, "%d", &n) == 1) {
			if (n == 0) {
				break;
			}
			
			for (int i = 0; i < n; i++) {
				if (fgets(line, sizeof line, stdin) == NULL) {
					return 1;
				}
				if (sscanf(line, "%d", &(a[i])) != 1) {
					return 1;
				}
			}
			
			int m1 = -100001;
			for (int i = 0; i < n; i++) {
				int s = 0;
				int m0 = -100001;
				for (int j = i; j < n; j++) {
					s += a[j];
					if (m0 < s) {
						m0 = s;
					}
				}
				if (m1 < m0) {
					m1 = m0;
				}
			}
			printf("%d\n", m1);
		}
	}

	return 0;
}

Measured memory_bytes: 1056
#include <iostream>
#include <string>

using namespace std;

char data[5][5] = { {'.', '.', '.', '.', '.'},
					{'.', 'A', 'B', 'C', '.'},
					{'.', 'D', 'E', 'F', '.'},
					{'.', 'G', 'H', 'I', '.'},
					{'.', '.', '.', '.', '.'}
};
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};

bool is_ok(string str)
{
	int y, x;
	for (int i = 0; i < 5; i++){
		for (int j = 0; j < 5; j++){
			if (str[0] == data[i][j]){
				y = i, x = j;
			}
		}
	}
	for (int cnt = 1; cnt < str.length(); cnt++){
		bool f = false;
		for (int i = 0; i < 4; i++){
			int ny = y + dy[i], nx = x + dx[i];
			if (data[ny][nx] == str[cnt]){
				y = ny, x = nx;
				f = true;
				break;
			}
		}
		if (!f) return false;
	}
	
	return true;
}

int main(void)
{
	string s;
	for (int i = 0; i < 1000; i++){
		cin >> s;
		if (is_ok(s)) cout << s << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1180
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int n;
	cin >> n;
	int N = n;
	int cnt = 0;
	while (N != 0) {
		cnt += N % 10;
		N /= 10;
	}
	if (n % cnt == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

int main() {
  int a, b; cin >> a >> b;
  if (a >= 13){
    cout << b << endl;
  }else if (a < 13 && a >= 6) {
    cout << b/2 << endl;
  }else {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;
vector<int> seen;
void dfs(const Graph &G,int v,int c){
    seen[v]=c;
    for(auto nv:G[v]){
        if(seen[nv]!=-1)continue;
        dfs(G,nv,c);
    }
}





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

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

    int A[M],B[M];
    int C[K],D[K];
    Graph G(N);
    seen.assign(N,-1);
    vector<vector<int>> v(N);
    rep(i,M){
        cin>>A[i]>>B[i];
        A[i]--;
        B[i]--;
        G[A[i]].push_back(B[i]);
        G[B[i]].push_back(A[i]);
    }
    rep(i,K){
        cin>>C[i]>>D[i];
        C[i]--;
        D[i]--;
        v[C[i]].push_back(D[i]);
        v[D[i]].push_back(C[i]);
    }
    
    int co=0;
    for(int i=0;i<N;i++){
        if(seen[i]!=-1) continue;
        dfs(G,i,co);
        co++;
    }
    int q[co]{};
    rep(i,N){
        q[seen[i]]++;
    }
    rep(i,N){
        int ans=q[seen[i]];
        for(auto nv:v[i]){
            if(seen[i]==seen[nv]) ans--;
        }
        ans-=G[i].size();
        ans--;
        cout << ans << " ";
    }
    cout << endl;



}


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

int n, m;
int p[1010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  while (cin >> n >> m, n) {
    for (int i = 0; i < n; i++) {
      cin >> p[i];
    }
    sort(p, p + n, greater<int>());
    int ans = 0;
    for (int i = 0; i < n; i++) {
      if ((i + 1) % m == 0) continue;
      ans += p[i];
    }
    cout << ans << endl;
  }  

  return 0;
}


Measured memory_bytes: 3136
#include<stdio.h>

int main(void){
  int n,a[100],i,j,count=0,min,temp,flag;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&a[i]);

  for(i=0;i<n;i++){
    min=i;
    flag=0;
    for(j=i;j<n;j++){
      if(a[j]<a[min]) {
	min=j;
	flag=1;
      }
    }
    if(flag==1){
    temp=a[min];
    a[min]=a[i];
    a[i]=temp;
    count++;
    }
  }
  for(i=0;i<n;i++){
    if(i==n-1) printf("%d\n",a[i]);
    else printf("%d ",a[i]);
  }
  printf("%d\n",count);

  return 0;
}

Measured memory_bytes: 600
object Main extends App {
  val n = scala.io.StdIn.readInt()
  val a = scala.io.StdIn.readLine()
  var result = 1L
  val max = 1000000000000000000L
  a.split(" ").map(_.toLong).sorted.foreach { n =>
    if (result != 0L && result != -1L) {
      if (Math.log10(n.toDouble) + Math.log10(result.toDouble) > 18.1d) {
        result = -1
      } else {
        result = result * n
        // println(result)
        if (result > max) {
          result = -1L
        } else if (result < 0L) {
          result = -1L
        }
      }
    }
  }
  println(result)
}

Measured memory_bytes: 70252
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define int ll
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 13
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;

    ll power(ll a, ll b)    //a is base, b is exponent
    {
        if(b==0)
            return 1;
        if(b==1)
            return a;
        if(b%2 == 1)
            return (power(a,b-1)*a)%mod;
        ll q = power(a,b/2);
        return (q*q)%mod;
    }

    ll dp[200001][13];
    string s;

    ll func(int i,int rem)
    {
        //assert(rem>=0 && rem<=12);
        if(i==s.length())
        {
            if(rem==0)
                return 1;
            return 0;
        }
        if(dp[i][rem]!=-1)
            return dp[i][rem];

        ll x=power(10,i),z;
        //cout<<x<<" "<<i<<endl;
        ll ans=0;
        if(s[i]=='?')
        {
            for(int j=0;j<10;++j)
            {
                z=(j*x)%13;
                for(int k=0;k<13;++k)
                {
                    if((z+k)%13==rem)
                        ans=(ans+func(i+1,k))%1000000007;
                }
            }
            return dp[i][rem]=ans;
        }
        else
        {
            z=(ll)(s[i]-'0');
            assert(z>=0 && z<=9);
            z=(z*x)%13;
            for(int k=0;k<13;++k)
            {
                if((z+k)%13==rem)
                ans=(func(i+1,k))%1000000007;
            }
            return dp[i][rem]=ans;
        }
    }

    signed main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            cin>>s;
            reverse(s.begin(),s.end());
            int n=s.length(),i,j;
            for(i=0;i<=n+10;++i)
                for(j=0;j<13;++j)
                    dp[i][j]=-1;
            ll ans=0;
            cout<<func(0,5)<<endl;
        }
        return 0;
    }


Measured memory_bytes: 20048
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

long long solve(vector<int> A, vector<int> B){
    const int N = A.size();
    long long res = 0;
    priority_queue<pair<int,int>> qu;
    for(int i=0;i<N;i++){
        if(A[i] > B[i]) return -1;
        if(A[i] == B[i]) continue;
        qu.emplace(B[i], i);
    }
    while(!qu.empty()){
        int idx = qu.top().second; qu.pop();
        int sub = B[(idx+1)%N] + B[(idx+N-1)%N];
        int target = max(A[idx], max(B[(idx+1)%N], B[(idx+N-1)%N]));
        int num = max(1, (B[idx]-target)/sub);
        B[idx] -= num * sub;
        res += num;
        if(B[idx] < A[idx]) return -1;
        if(B[idx] > A[idx]) qu.emplace(B[idx], idx);
    }
    return res;
}

int main(){
    int N;
    while(cin >> N){
        vector<int> A(N), B(N);
        for(auto& t : A) cin >> t;
        for(auto& t : B) cin >> t;
        cout << solve(A, B) << endl;
    }
}

Measured memory_bytes: 5620
n = int(input())
aa = list(map(int, input().split()))

mx_v = 0
mn_v = 0

for i in range(n):
    if aa[i] > mx_v:
        mx_v = aa[i]
        mx_i = i + 1
    if aa[i] < mn_v:
        mn_v = aa[i]
        mn_i = i + 1

ans = []

if abs(mx_v) >= abs(mn_v) and mx_v != 0:
    for i in range(n):
        if aa[i] < 0:
            ans.append((mx_i, i + 1))
    for i in range(1, n):
        ans.append((i, i + 1))

if abs(mx_v) < abs(mn_v):
    for i in range(n):
        if aa[i] > 0:
            ans.append((mn_i, i + 1))
    for i in range(n, 1, -1):
        ans.append((i, i - 1))

print(len(ans))
for x, y in ans:
    print(x, y)

Measured memory_bytes: 3064
#include<stdio.h>
int a,b;
int sum(int f)
{
    int m,n,g=0;
    while(f>0)
    {
        g=g+f%10;
        f/=10;
    }
    return g;
}
int main()
{
    int c,d,i,j=0,m,n;
    scanf("%d%d%d",&c,&m,&n);
    for(i=1;i<=c;i++)
    {
        d=sum(i);
        if(d>=m&&d<=n)j+=i;
    }
    printf("%d\n",j);
    return 0;

}


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


int main (){
    string s;
    cin >> s;
    int n = s.size();

    rep(i,n){
        cout << 'x';

    }
    cout << endl;
    return 0;
}

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

using namespace std;

int main() {
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;
  if (x >= r && x <= (W-r) && y >= r && y <= (H-r)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 1156
#include <cstdio>
#include <cstdint>
#include <cstddef>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
#include <tuple>

int main() {
  size_t N;
  intmax_t F;
  scanf("%zu %jd", &N, &F);

  std::map<std::pair<std::string, std::string>, intmax_t> map;
  for (size_t i = 0; i < N; ++i) {
    size_t M;
    scanf("%zu", &M);

    std::vector<std::string> v(M);
    for (auto& vi: v) {
      char buf[32];
      scanf("%s", buf);
      vi = buf;
    }
    for (size_t j = 0; j < M; ++j) {
      for (size_t k = 0; k < j; ++k) {
        std::pair<std::string, std::string> p(v[j], v[k]);
        if (p.first > p.second) std::swap(p.first, p.second);
        ++map[p];
      }
    }
  }

  std::vector<std::pair<std::string, std::string>> res;
  for (auto const& p: map) {
    if (p.second < F) continue;
    res.push_back(p.first);
  }

  std::sort(res.begin(), res.end());

  printf("%zu\n", res.size());
  for (auto const& ri: res)
    printf("%s %s\n", ri.first.c_str(), ri.second.c_str());
}



Measured memory_bytes: 3364
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair < ll, ll > PLL;
#define rep(i,n) for (int i = 0; i < (n); ++i)
int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i, n) cin >> d[i];
    sort(d.begin(), d.end());
    d.erase(unique(d.begin(), d.end()), d.end());
    cout << d.size() << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

#define MAX 100
#define INFTY 1<<21
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[MAX][MAX];

void dij(){
  int minv;
  int i;
  int v,u;
  int d[MAX], color[MAX];

  for(i = 0; i < n; i++){
    d[i] = INFTY;
    color[i] = WHITE;
  }

  d[0] = 0;
  color[0] = GRAY;
  
  while(1){
    minv = INFTY;          
    for(i = 0; i < n; i++){
      if(minv > d[i] && color[i] != BLACK){
	u = i;
	minv = d[i];
      }
    }
      
    if( minv == INFTY ) break;
    color[u] = BLACK;
    for(v = 0; v < n; v++){
      if( color[v] != BLACK && M[u][v] != INFTY){
	if(d[v] > d[u] + M[u][v]){
	  d[v] = d[u] + M[u][v];
	  color[v] = GRAY;
	}
      }
    }
  }

  for(i = 0; i < n; i++){
    printf("%d %d\n", i, d[i]);
  }
}


int main(){
  int i, j;
  int k,c;
  int u,v;
  
  scanf("%d", &n);

  for(i = 0; i < n; i++){
      for(j = 0; j < n; j++){
	  M[i][j] = INFTY;
	}
    }
  
  for(i = 0; i < n; i++){
      scanf("%d%d", &u, &k);

      for(j = 0; j < k; j++){
	  scanf("%d%d", &v, &c);
	  M[u][v] = c;
	}
    }

  dij();

  return 0;
}
      




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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    int n,r;
    cin>>n>>r;
    if(n>=10)cout<<r<<endl;
    else{cout<<r+100*(10-n);}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define SZ(x) ((int)(x.size()))
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))

const double pi = 4 * atan(1);
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;
const int MAXN = 200005;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	vector<ll> nums(n,0);
	FOR(i,0,n) {
		cin >> nums[i];
	}
	int ans = 0;
	for(int i = 0; i < n-2; i++){
		for (int j = i+1; j < n-1; j++){
			for (int k = j+1; k < n; k++) {
				if (nums[i]==nums[j]||nums[j]==nums[k]||nums[i]==nums[k]) {
					continue;
				}
				if (nums[i] < nums[j]+nums[k] && nums[j] < nums[i]+nums[k] && nums[k] < nums[j]+nums[i]) {
					ans++;
				}
			}
		}
	}
	cout << ans << "\n";

}


Measured memory_bytes: 3644
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;

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

    cout << n * n * n << endl;
}

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

//#include "triangle_point.h"
//#include "linear_search.h"
//#include "binary_search.h"
//#include "algo_lowerbound.h"
//#include "point_radian.h"





int main(){
    string S;
    cin >> S;

    char current = S[0];
    int count = 1;
    for (auto itr = S.begin()+1; itr!=S.end(); ++itr){
        if (current != *itr){
            count += 1;
            current = *itr;
        }else{
            current = *itr;
        }
    }
    cout << count -1 << endl;
}


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

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

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

    int ans = 1;
    int d = 0;

    for(int i = 0;i < n;i++){
        d += l[i];
        if(d <= x){
            ans++;
        }
    }

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



Measured memory_bytes: 256
N, M = map(int, input().split())
l = input().split()
n = list()
H = list()
for i in range(N):
  H.append(int(l[i]))
  n.append(int(l[i]))
for i in range(M):
  Ai, Bi = map(int,input().split())
  if H[Ai-1] > H[Bi-1]:
    n[Bi-1] = 0
  elif H[Ai-1] < H[Bi-1]:
    n[Ai-1] = 0
  else:
    n[Bi-1] = 0
    n[Ai-1] = 0
r = 0
for i in range(N):
  if n[i] != 0:
    r += 1
print(r)

Measured memory_bytes: 25792
#include<iostream>

using namespace std;

int main()
{
    int n;

    cin >> n;

    int house[5][4][11];

    for(int i = 1; i < 5; i++)
        for(int j = 1; j < 4; j++)
            for(int k = 1; k < 11; k++)
                house[i][j][k] = 0;

    int b, f, r, v;

    for(int l = 0; l < n; l++)
    {
        cin >> b >> f >> r >> v;
        house[b][f][r] += v;
    }

    for(int m = 1; m < 5; m++)
    {
        for(int n = 1; n < 4; n++)
        {
            for(int o = 1; o < 11; o++)
            {
                cout << " " << house[m][n][o];
            }
            cout << endl;
        }
        if(!(m == 4))
            cout << "####################" << endl;
    }

    return 0;
} 

Measured memory_bytes: 1160
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int A, B;
	cin >> A >> B;

	if ((A + B) % 2 == 1)
	{
		cout << "IMPOSSIBLE" << endl;
	}
	else
	{
		cout << (A + B) / 2 << endl;
	}

	return 0;
}

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

int main() {
  string s;
  cin >> s;
  map<char,int> mp;
  for (char c : s) mp[c] += 1;
  for (auto m : mp) {
    if (m.second % 2 != 0) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
from itertools import product
N, M = map(int, input().split())
cake = [list(map(int, input().split())) for i in range(N)]

ans = 0
for x, y, z in product([1, -1], repeat=3):
    tmp = []
    for a, b, c in cake:
        tmp.append(a*x + b*y + c*z)
    tmp.sort(reverse=True)
    ans = max(ans, sum(tmp[:M]))

print(ans)


Measured memory_bytes: 3384
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <string.h>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
 
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;
const ll M = 998244353;

ll long_long_max(ll a, ll b) {
   if(a > b) return a;
   else return b;
}

int main(void) {
    ll k, n, ma=0, pos=-1, sum=0;
    cin >> k >> n;
    ll a[n];
    ll diff[n];
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<n-1;i++) { 
    	diff[i] = a[i+1] - a[i];
    	sum += diff[i];
    	if(diff[i] > ma) {
          ma = diff[i];
          pos = i;
        }
    }
    diff[n-1] = a[0] + (k-a[n-1]);
    sum += diff[n-1];
    if(diff[n-1] > ma) {
        ma = diff[n-1];
        pos = n-1;
    }

    cout << sum - ma << endl;
    
}


Measured memory_bytes: 3328
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
from queue import PriorityQueue
from fractions import gcd
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

N = _I()
X = LI()

# 距離の2乗の体力を消費
# 100ループすれば求まる

min_x = min(X)
max_x = max(X)

min_XP = 10**9
for p in range(min_x, max_x+1):
    XP = 0
    for x in X:
        XP += (x-p)**2
    if min_XP > XP:
        min_XP = XP
print(min_XP)


Measured memory_bytes: 64876
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N = I()

d = defaultdict(int)
for i in range(2,10**5):
    if i*(i-1)//2 > 10**5:
        break
    d[i*(i-1)//2] = i

if d[N]==0:
    print('No')
    exit()

k = d[N]
group = [[] for _ in range(k)]
val = 1
now = 0
while val<=N:
    for i in range(val,N+1):
        if len(group[now])==k-1:
            break
        else:
            group[now].append(i)
    for i in range(now+1,k):
        group[i].append(val)
        val += 1
    now += 1

print('Yes')
print(k)
for i in range(k):
    print(k-1,*group[i])

Measured memory_bytes: 47836
N, K = map(int,input().split())
h = [int(input()) for _ in range(N)]
h.sort()
m = 10**9
for i in range(N-K+1):
    if h[i+K-1] - h[i] < m:
        m = h[i+K-1] - h[i]
for i in range(N-K+1):
    if h[i+K-1] - h[i] == m:
        print(int(m))
        break


Measured memory_bytes: 7384
#include<bits/stdc++.h>
//using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++)
#define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb emplace_back
#define mp std::make_pair
//
#define endl "\n"
//using std::endl;
using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=std::pair<ll,ll>;
//
constexpr ll MOD=1e9+7;
//constexpr ll MOD=998244353;
//constexpr ll MOD=10000000;
//constexpr ll MOD=1e5;
constexpr ll MAX=1e7;
constexpr ll INF=(1ll<<62);
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
const ll N=26;
ll solve(ll D,vii &A,vi &C,vi &S){
    vi last(N,-1);
    ll a=0;
    rep(i,0,D){
        ll memo; memo=S[i];
        last[memo]=i;
        a+=A[i][memo];
        rep(j,0,N) a-=(i-last[j])*C[j];
    }
    return a;
}
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    srand((unsigned)time(NULL));
    ll D; cin>>D;
    vi C(N);
    rep(i,0,N) cin>>C[i];
    vii A(D,vi(N));
    rep(i,0,D){
        rep(j,0,N) cin>>A[i][j];
    }
    vi last(N,-1);
    vi ans(D);
    rep(i,0,D){
        ll max=0,memo=0;
        rep(j,0,N){
            if(max<A[i][j]+(i-last[j])*C[j]){
                max=A[i][j]+(i-last[j])*C[j];
                memo=j;
            }
        }
        last[memo]=i;
        ans[i]=memo;
    }
    ll max=solve(D,A,C,ans);
    rep(_,0,45){
        rep(i,0,D){
            rep(j,0,N){
                vi S=ans;
                S[i]=j;
                ll X=solve(D,A,C,S);
                if(max<X){
                    max=X;
                    ans[i]=j;
                }
            }
        }
    }
    rep(i,0,D) cout<<ans[i]+1<<endl;
}


Measured memory_bytes: 3756
#include "bits/stdc++.h"
#define REP(i,n,N) for(ll i=(n);i<(N);i++)
#define RREP(i,n,N) for(ll i=(N-1);i>=(n);i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(), (v).end()
#define MCP(a,b) memcpy(b,a, sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a,b) cout<<(a)<<" "<<(b)<<endl
typedef long long ll;
using namespace std;
const ll mod = 1e9+7;
const ll inf =1e18;

ll r, n;
ll height[50];
int main(){
    while(cin>>r>>n && r!=0 || n!=0){
        REP(i,0,50) height[i] = 0;
        REP(i, 0, n){
            ll xl, xr, y;
            cin>>xl>>xr>>y;
            REP(j, xl, xr){
                height[j+20]=max(height[j+20], y);
            }
        }

        bool ok=false;
        for(double t=0; t<=21; t+=0.0001){
            REP(i, -r+1, r){
                double h=sqrt(r*r-i*i);
                if(h+t>=min(height[20+i], height[20+i-1])+r){
                    printf("%.4lf\n", t);
                    ok=true;
                    break;
                }
            }
            if(ok) break;
        }
    }
    return 0;
}


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

const int MAXN=2e5;
int a,b,c;
string s;
int main(){
    cin>>s;
    int ok1=0,ok2=0;
    for(int i=0;i<s.length();i++){
        if(s[i]=='A')ok1=1;
        if(s[i]=='B')ok2=1;
    }
    if(ok1==1&&ok2==1){
        cout<<"Yes";
        return 0;
    }
    cout<<"No";
    return 0;
}



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

int main()
{
  int H, W;
  cin >> H >> W;

  int c[10][10];
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> c[i][j];
      // cout << c[i][j] << ' ';
    } // cout << endl;
  }

  int A[H][W];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> A[i][j];
      // cout << A[i][j] << ' ';
    } // cout << endl;
  }

  for (int k = 0; k < 10; k++) {   // ワーシャルフロイド
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
      }
    }
  }

  int sum = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (A[i][j] != -1) {
        sum += c[A[i][j]][1];
        // cout << sum << endl;
      }
    }
  }

  cout << sum << endl;

  return 0;
}


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

string s;
int cunt,sum;
bool flag=true;

int main(){
    cin.tie(0);  ios::sync_with_stdio(false);
    cin >> s;
    for(int i=1;i<s.size();i++){
        if(s[i]!='9') flag = false;
    }
    if(flag) cout << 9*(s.size()-1)+ (s[0]-'0')<<"\n";
    else{
        cout << 9*(s.size()-1) + (s[0]-'0')-1 <<"\n";
    }
    
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		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();
		}
		sc.close();

		long sum = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				sum += d[i] * d[j];
			}
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

#define INPUT_FROM_FILE (0)
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
#endif
	std::string str0;
	std::string str1;

#if INPUT_FROM_FILE
	ifs >> str0 >> str1;
#else
	std::cin >> str0 >> str1;
#endif

	for(unsigned int i = 0; i < str0.size(); i++){
		if(str0.at(i) == str1.at(0)){
			bool is_matched = true;
			for(unsigned int j = 0; j < str1.size(); j++){
				//std::cout << str1.at(j) << str0.at( (i + j) % str0.size() ) << std::endl;
				if(str1.at(j) != str0.at( (i + j) % str0.size() )){
					is_matched = false;
					break;
				}
			}
			//std::cout << std::endl;
			if(is_matched){
				std::cout << "Yes" << std::endl;
				return 0;
			}
		}
	}
	std::cout << "No" << std::endl;
	return 0;
}

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

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

using namespace std;

using ull = unsigned long long;
using P = pair<ull, ull>;

// Time Complexity: O(items.size() * capacity)
// Space Complexity: O(capacity)
ull knapsack(vector<P> &items, ull capacity) {
    vector<ull> dp(capacity + 1, 0);
    FOR(i, 1, capacity + 1) {
        for (P p: items) {
            ull weight = p.first;
            ull value = p.second;
            if (weight <= i) {
                dp[i] = max(dp[i], dp[i - weight] + value);
            }
        }
    }
    return dp[capacity];
}

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

    int N;
    ull W;
    cin >> N >> W;
    vector<P> items(N);
    REP(i, N) {
        ull weight, value;
        cin >> value >> weight;
        items[i] = P(weight, value);
    }
    cout << knapsack(items, W) << endl;
    return 0;
}



Measured memory_bytes: 3248
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define int long long
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
int INF = 1e9+7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
unsigned day;
if(dow < dow1) dow += 7;
day = dow - dow1;
day += 7 * n - 6;
return day;
}
unsigned DayToWeekNumber(unsigned day)
{
  return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
  return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main(){
  int a,b;
  cin>>a>>b;
  cout<<(a<9&&b<9? "Yay!":":(")<<endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S,T; cin >>S>>T;
  int A,B;cin>>A>>B;
  string U;cin>>U;
  if(S==U){
    A=A-1;
  }
  if(T==U){
    B=B-1;
  }
  cout<<A<<" "<<B<<endl;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n, m;
    cin >> n >> m;
    vl s(m), t(m);
    vvl edges(n);
    for (int i = 0; i < m; ++i) {
        cin >> s[i] >> t[i];
        s[i]--, t[i]--;
        edges[s[i]].push_back(t[i]);
    }
    vector<double> prob(n, 0);
    vector<double> ex(n, 0);
    prob[0] = 1.0;
    for (int i = 0; i < n; ++i) {
        double num = edges[i].size();
        for (auto &e : edges[i]) {
            prob[e] += prob[i] / num;
        }
    }
    for (int i = n - 2; i >= 0; --i) {
        double num = edges[i].size();
        for (auto &e : edges[i]) {
            ex[i] += (ex[e] + 1) / num;
        }
    }
    double ret = ex[0];
    for (int i = n - 2; i >= 0; --i) {
        double num = edges[i].size();
        if (num == 1.0)
            continue;
        double currexp = ex[i];
        double newexp  = 0.0;
        double maxi    = 0.0;
        for (auto &e : edges[i]) {
            newexp += ex[e] + 1;
            chmax(maxi, ex[e] + 1);
        }
        newexp = (newexp - maxi) / (num - 1.0);
        chmin(ret, ex[0] - prob[i] * (currexp - newexp));
    }
    cout << fixed << setprecision(10) << ret << "\n";
    return 0;
}

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

int main() {
    string a, b;
    cin >> a >> b;
    int ab = stoi(a + b);
    string ans;
    int route_ab = (int)sqrt((double)ab);
    if (route_ab * route_ab == ab) ans = "Yes";
    else ans = "No";
    cout << ans << endl;
}


Measured memory_bytes: 256
n=int(input())
s=input()
ans=0

for i in range(1, n):
    a=s[:i]
    b=s[i:]
    dic=[]
    dic2=[]
    for j in range(len(a)):
        if a[j] not in dic:
            dic.append(a[j])
    for k in range(len(b)):
        if b[k] not in dic2:
            dic2.append(b[k])

    l=min(len(dic), len(dic2))
    cnt=0
    if l==len(dic):
        for j in range(len(dic)):
            if dic[j] in dic2:
                cnt+=1
    else:
        for k in range(len(dic2)):
            if dic2[k] in dic:
                cnt+=1
    
    ans=max(ans, cnt)
    
print(ans)

Measured memory_bytes: 3064
N,A = map(int,input().split())
X = list(map(int,input().split()))
dp = [[[0 for _ in range(50*(N+2))] for _ in range(N+2)] for _ in range(N+2)]

dp[0][0][0] = 1
#kまでみた
for k in range(N):
    #used個使った
    for used in range(N):
        for i in range(50*N):
            #使う時
            if dp[used][k][i] == 0: 
                continue
            dp[used+1][k+1][i+X[k]] += dp[used][k][i]
            dp[used][k+1][i] += dp[used][k][i]
ans = 0
for used in range(1,N+1):
    ans += dp[used][N][used*A]
print(ans)




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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll n, m, q, l, r, ans;
  cin >> n >> m >> q;
  ll p[501][501];
  memset(p, 0, sizeof(p));

  rep(i, m) {
    cin >> l >> r;
    p[l][r]++;
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) p[i][j] += p[i][j - 1];
    for (int j = 1; j <= n; ++j) p[i][j] += p[i - 1][j];
  }

  rep(i, q) {
    cin >> l >> r;
    ans = p[r][r] + p[l - 1][l - 1] - p[l - 1][r] - p[r][l - 1];
    cout << ans << endl;
  }
}

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

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 2e5 + 5;
int n , D,a[maxn],lab[maxn];
int FindLab(int u){return lab[u] < 0 ? u : lab[u] = FindLab(lab[u]);}

struct node{
    pair<ll,int> a,b;
    node(){a =  b = mp(1e18,-1);};
    void reset(){a = b = mp(1e18,-1);}
    void add(pair<ll,int> x , ll y = 0){
        x.first += y;
        if(a.second == x.second)a = min(a,x);
        else if(b.second == x.second)b = min(b,x);
        else if(a > x)b = a , a = x;
        else if(b > x)b = x;
        if(b<a)swap(a,b);
        assert(b.second != a.second || a.second == -1);
    }
}dp[maxn];
pair<ll,int> bezt[maxn];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> n >> D;
    for(int i = 1 ; i <= n ; ++i)cin >> a[i];
    fill_n(lab,maxn,-1);
    int cnt = n - 1;
    ll res = 0;
    while(cnt > 0){
        dp[0].reset();dp[n + 1].reset();
        fill_n(bezt,maxn,mp(1e18,0));;
        for(int i = 1 ; i <= n ; ++i){
            dp[i].reset();
            dp[i].add(dp[i-1].a,D);
            dp[i].add(dp[i-1].b,D);
            int  tmp = FindLab(i);
            if(dp[i].a.second != tmp)bezt[tmp] = min(bezt[tmp],mp(dp[i].a.first + a[i],dp[i].a.second));
            if(dp[i].b.second != tmp)bezt[tmp] = min(bezt[tmp],mp(dp[i].b.first + a[i],dp[i].b.second));
            dp[i].add(mp(a[i],tmp));
        }
        for(int i = n ; i >= 1 ; --i){
            dp[i].reset();
            dp[i].add(dp[i+1].a,D);
            dp[i].add(dp[i+1].b,D);
            int  tmp = FindLab(i);
            if(dp[i].a.second != tmp)bezt[tmp] = min(bezt[tmp],mp(dp[i].a.first + a[i],dp[i].a.second));
            if(dp[i].b.second != tmp)bezt[tmp] = min(bezt[tmp],mp(dp[i].b.first + a[i],dp[i].b.second));
            dp[i].add(mp(a[i],tmp));
        }
        for(int i = 1 ; i <= n ; ++i){
            if(lab[i] < 0){
                if(bezt[i].first < 1e18){
                    int u = FindLab(i),v = FindLab(bezt[i].second);
                    if(u==v)continue;
                    res += bezt[i].first;if(lab[u]>lab[v])swap(u,v);lab[u]+=lab[v];lab[v]=u;
                    --cnt;
                }
            }
        }
    }
    cout << res;
}


Measured memory_bytes: 11264
import sys
input = sys.stdin.readline

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

N,K = map(int, input().split())
lst_A = list(map(int, input().split()))
lst_A.sort()

p = 10 ** 9 + 7
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)


fmax = 0
fmin = 0
for i in range(N):
	if(K-1<=N-1-i):
		fmin += lst_A[i] * cmb(N-i-1, K-1,p)
	if(i>=K-1):
		fmax += lst_A[i] * cmb(i,K-1,p)

print((fmax-fmin)% p)

Measured memory_bytes: 20420
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)	for(int i=a; i<n; i++)
#define loop(i,a,n)	for(int i=a; i>=n; i--)

int main() 
{	
	ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(0);
	
	string v;
	cin>>v;
	int a;
	cin>>a;
	vector<char> s;
	forr(i,0,v.size())
		s.push_back(v[i]);
		int ct=0;
	while(a--)
	{
		int b;
		cin>>b;
		if(b==1)	
		{
			ct++;
		}
		else if(ct%2==0)
		{
			int x; char y;
			cin>>x>>y;
			if(x==1)
			{
				s.insert(s.begin(),y);
			}
			else s.insert(s.end(),y);
		}
		else
		{
			int x; char y;
			cin>>x>>y;
			if(x==2)
			{
				s.insert(s.begin(),y);
			}
			else s.insert(s.end(),y);
		}
	}
	if(ct&1)reverse(s.begin(),s.end());
	for(auto const t: s)	cout<<t;
	return 0;	
}

Measured memory_bytes: 1224
import java.util.*;

public class Main {
    public static void solve(int X) {
        int x = 0;
        for (int i = 0; i <= X; i++) {
            x += i;
            if (x >= X) {
                System.out.println(i);
                return;
            }

        }

    }


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

        solve(x);
    }
}


Measured memory_bytes: 22996
#include<stdio.h>
#define SMAX 100000
#define TMAX 50000

main(){

  int i,j,n,q,count = 0;
  int S[SMAX],T[TMAX];
  int left,right,mid;
  
  scanf("%d",&n);
  for(i = 0;i < n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(j = 0; j < q;j++){
    scanf("%d",&T[j]);
    left = 0;
    right = n;
    while(left < right){
      mid = (left + right)/2;
      if(T[j] == S[mid]){
	count++;
	break;
      }
      if(T[j] > S[mid]) left = mid + 1;
      else if(T[j] < S[mid]) right = mid;
      }
  }
  
  printf("%d\n",count);

  return 0;
}

Measured memory_bytes: 1184
#include "bits/stdc++.h"
using namespace std;

long long n,ans;

int main()
{
	cin>>n;
	if(n<10 or (n&1)) return 0 * printf("0");

	for(long long i=10;i<=n;i*=5) ans+=n/i;
	cout<<ans;	
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
 
typedef long long ll;
 
 
int main(){
	int n;
	cin >> n;
	vector<int> data(n);
	for(int i=0;i<n;++i){
		cin >> data[i];
	}
	
	ll res = 0;
	for(int i=0;i<n;++i){
		for(int j=i+1;j<n;++j){
			res += data[i] * data[j];
		}
	}
	
	cout << res <<endl;
	
	return 0;
}



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

int main(void){
	int n, k, q;
	cin >> n >> k >> q;
	vector<int> p(n,0);
	for(int i = 0; i < q; ++i){
		int a;
		cin >> a;
		a--;
		p[a]++;
	}
	for(int i = 0; i < n; ++i){
		if(p[i]<=q-k){
			cout << "No" << endl;
		}else{
			cout << "Yes" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1024
# -*- coding UTF-8 -*-

N = int(input())
a = [int(input()) for i in range(N)]
a.sort()

sum1 = a[N-1] - a[0]
sum2 = sum1
i = 0
while True:
    if i+1 == N-i-1:
        break
    sum1 += a[N-i-1] - a[i+1]
    if i+1 == N-i-2:
        break
    sum1 += a[N-i-2] - a[i]
    i += 1

i = 0
while True:
    if i == N-i-2:
        break
    sum2 += a[N-i-2] - a[i]
    if i+1 == N-i-2:
        break
    sum2 += a[N-i-1] - a[i+1]
    i += 1

max = sum1 if sum1 >= sum2 else sum2
print(max)


Measured memory_bytes: 7396
use std::io::Read;
use std::cmp::min;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let w_limit: usize = iterator.next().unwrap().parse().unwrap();
    let mut w: Vec<usize> = Vec::new();
    let mut v: Vec<usize> = Vec::new();
    for _ in 0..n {
        w.push(iterator.next().unwrap().parse().unwrap());
        v.push(iterator.next().unwrap().parse().unwrap());
    }

    const INF: usize = 1_000_000_000_000;
    let mut dp: Vec<Vec<usize>> = vec![vec![INF; 100_001]; n + 1];
    dp[0][0] = 0;
    for i in 1..(n + 1) {
        for j in 0..100_001 {
            if j >= v[i - 1] {
                dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i - 1]] + w[i - 1]);
            } else {
                dp[i][j] = dp[i - 1][j];
            }
        }
    }

    let mut ans = 0;
    for i in 0..100_001 {
        if dp[n][i] <= w_limit {
            ans = i;
        }
    }
    return ans.to_string();
}


Measured memory_bytes: 106748