akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#include <stdio.h>
int main() {
  int a, b, c; cin >> a >> b >> c;
  if (a==b) cout << c << endl;
  else if (b==c) cout << a << endl;
  else if (a==c) cout << b << endl;
}



Measured memory_bytes: 256
MOD = 10 ** 9 + 7
fac = [1] * (3 * 10 ** 6)
for i in range(len(fac) - 1):
    fac[i + 1] = fac[i] * (i + 1) % MOD

n, a, b, c = map(int, input().split())
x = a * pow(100 - c, MOD - 2, MOD) % MOD
y = b * pow(100 - c, MOD - 2, MOD) % MOD
z = c * pow(100, MOD - 2, MOD) % MOD
ans = 0
fninv = pow(fac[n - 1], MOD - 2, MOD)
ta = pow(x, n, MOD)
for i in range(n):
    ans += (n + i) * ta * pow(y, i, MOD) % MOD * \
        fac[n - 1 + i] * fninv * pow(fac[i], MOD - 2, MOD) % MOD
    ans %= MOD
tb = pow(y, n, MOD)
for i in range(n):
    ans += (n + i) * tb * pow(x, i, MOD) % MOD * \
        fac[n - 1 + i] * fninv * pow(fac[i], MOD - 2, MOD) % MOD
    ans %= MOD
ans *= z * pow((1 - z) % MOD, MOD - 2, MOD) + 1
ans %= MOD
print(ans)


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

int main(){
  int n,a,v,max=0,maxn=999;

  cin >>n;
  for(int i=0;i<n;++i){
    cin >>a >>v;
    if(v>max){
      max=v;
      maxn=a;
    }
    else if(v==max)
      if(a<maxn) maxn=a;
  }
  cout <<maxn <<" " <<max <<'\n';
  return 0;
}

Measured memory_bytes: 3096
#include<iostream>
#include<string>
#include<sstream>
#include<cctype>
#include<vector>
#include<algorithm>
using namespace std;

typedef vector<int> vi;
int n;
string s;

int stoi(string x){
  stringstream ss(x);
  int res;
  ss >> res;
  return res;
}

int parse(int l,int r){
  bool f = true;
  for(int i=l;i<r;i++){
    if(!isdigit(s[i])){
      f = false;
      break;
    }
  }
  if(f)return stoi(s.substr(l,r-l))/2+1;

  int pos = l+1,k=1;
  vi v;

  for(int i=l+1;i<r;i++){
    if(s[i]=='[')k++;
    else if(s[i]==']')k--;
    if(!k){
      v.push_back(parse(pos,i));
      pos = i+2;
    }
  }

  sort(v.begin(),v.end());
  int res = 0;
  for(int i=0;i<v.size()/2+1;i++)res += v[i];
  return res;
}

int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> s;
    cout << parse(1,s.size()-1) << endl;
  }
}

Measured memory_bytes: 1296
import math
A, B = map(int, input().split())
ans = []
for i in range(1, 2000):
    if math.floor(i * 0.08) == A and math.floor(i * 0.1) == B:
        ans.append(i)
if len(ans) == 0:
    print(-1)
    exit()
print(min(ans))

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();
		
		
		int h = S/3600;
		int a = S%3600;
		int m = a/60;
		int s = a%60;
			System.out.println(h+(":")+m+(":")+s);
			
			sc.close();
		}
	}



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

int main() {
	string S;
	cin >> S;
	
	int sum = 700;
	
	//冗長
	if(S[0]=='o') sum+= 100;
	if(S[1]=='o') sum+=100;
	if(S[2]=='o') sum+=100;
	
	/*
	for(int i=0; i<3; i++){
		if(S[i]=='o') sum+=100;
	}
	*/
	
	cout << sum;
	
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int IgarasiHiromi(const void* TomatuHaruka, const void* IgutiYuka) {
	int HanazawaKana = *(const int*)TomatuHaruka;
	int TamuraYukari = *(const int*)IgutiYuka;
	if (HanazawaKana < TamuraYukari) return 1;
	if (HanazawaKana > TamuraYukari) return -1;
	return 0;
}

int N;
int a[1000];

int main(void) {
	int i;
	double answer = 0;
	int cidx, didx;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &a[i]) != 1) return 1;
	}
	qsort(a, N, sizeof(*a), IgarasiHiromi);
	for (cidx = 0; cidx < N; cidx++) {
		for (didx = cidx + 1; didx < N; didx++) {
			int aidx, bidx;
			double score;
			for (aidx = 0; aidx == cidx || aidx == didx; aidx++);
			for (bidx = aidx + 1; bidx == cidx || bidx == didx; bidx++);
			score = (double)(a[aidx] + a[bidx]) / (a[cidx] - a[didx]);
			if (score > answer) answer = score;
		}
	}
	printf("%.15f\n", answer);
	return 0;
}

Measured memory_bytes: 688
import java.util.Scanner;


public class Main {
    static Scanner scanner;
    static int getInt(){
        return Integer.parseInt(scanner.next());
    }
    public static void main(String[] args) {
        scanner = new Scanner(System.in);
        int a = getInt();
        int b = getInt();
        int c = getInt();
        if(a < b && b < c){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
    }
}



Measured memory_bytes: 26272
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb emplace
#define pi pair <int, int>
#define f first
#define s second

char s[100][100];
int h, w, dist[100][100];
int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};

queue <pi> q, source;

int32_t main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> h >> w;
	for(int i = 1; i <= h; ++i) {
		for(int j = 1; j <= w; ++j) {
			cin >> s[i][j];
			if ((s[i][j]) == '.') source.pb(i, j);
		}
	}
	int ans = 0;
	// bfs
	while (source.size()) {
		memset(dist, -1, sizeof(dist));
		dist[source.front().f][source.front().s] = 0;
		q.pb(source.front().f, source.front().s);
		source.pop();
		while (q.size()) {
			int y = q.front().f;
			int x = q.front().s;
			q.pop();
			for(int i = 0; i < 4; ++i) {
				int ny = y + dy[i];
				int nx = x + dx[i];
				if (nx < 1 || nx > w || ny < 1 || ny > h) continue;
				if (s[ny][nx] == '#') continue;
				if (dist[ny][nx] == -1) {
					// assert(0);
					q.emplace(ny, nx);
					dist[ny][nx] = dist[y][x] + 1;
				}
			}
		}
		for(int i = 1; i <= h; ++i) {
			for(int j = 1; j <= w; ++j) {
				ans = max(ans, dist[i][j]);
			}
		}
	}
	cout << ans;
}


Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
int main(void) {
    int n,sum=0;
    cin>>n;
    int tmp=n;
    for (int i=10000000;i>0;i=i/10) {
        if (n>=i) {
            sum=sum+n/i;
            n=n-i*(n/i);
        }
    }
    if (tmp%sum==0) {
        cout<<"Yes"<<endl;
    } else {
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PI 3.141592653589793238462
using namespace std;
typedef long long ll;
typedef long double db;
int c[200005],pre[200005];
pair<int,int> p[200005],a[200005];
int find(int x){
    return (x==pre[x])?x:(pre[x]=find(pre[x]));   
}
void merge(int x,int y){
    pre[find(x)]=find(y);
}
int main(){
    int n;cin>>n;
    for(int i=1;i<=n;i++){
        cin>>p[i].first>>p[i].second;pre[i]=i;
        a[i].first=p[i].first;a[i].second=p[i].second;
    }
    sort(p+1,p+1+n);
    stack<int> s;
    for(int i=1;i<=n;i++){
        if(s.size()==0||p[i].second<s.top()){
            s.push(p[i].second);
        }
        else{
            int v=s.top();
            while(s.size()&&s.top()<p[i].second){
                merge(p[i].second,s.top());s.pop();
            }
            s.push(v);
        }
    }
    for(int i=1;i<=n;i++){
        c[find(i)]++;
    }
    for(int i=1;i<=n;i++){
        cout<<c[find(a[i].second)]<<endl;
    }
}

Measured memory_bytes: 10556
#include<cstdio>

const int MAX_S = 100;

int N,s[MAX_S];
int point = 0;
int minno10 = 1000;

int main(){
	scanf("%d",&N);
	for(int i = 0;i < N;i++){
		scanf("%d",&s[i]);
		point += s[i];
		if(s[i] % 10 != 0 && s[i] < minno10) minno10 = s[i];
	}
	
	if(point % 10 == 0){
		if(minno10 == 1000) printf("0");
		else printf("%d",point - minno10);
	}else{
		printf("%d",point);
	}
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;
struct mint {
   ll x;
   mint(ll x = 0) { (this->x = (x + MOD)) %= MOD; }
   mint& operator+=(const mint a) {
      if ((this->x += a.x) >= MOD) x -= MOD;
      return *this;
   }
   mint& operator-=(const mint a) {
      if ((this->x += MOD - a.x) >= MOD) this->x -= MOD;
      return *this;
   }
   mint& operator*=(const mint a) {
      (this->x *= a.x) %= MOD;
      return *this;
   }
   mint operator+(const mint a) const {
      mint res(*this);
      return res += a;
   }
   mint operator-(const mint a) const {
      mint res(*this);
      return res -= a;
   }
   mint operator*(const mint a) const {
      mint res(*this);
      return res *= a;
   }
   mint pow(ll t) const {
      if (!t) return 1;
      mint a = pow(t >> 1);
      a *= a;
      if (t & 1) a *= *this;
      return a;
   }
   mint inv() const { return pow(MOD - 2); }
   mint& operator/=(const mint a) { return *this *= a.inv(); }
   mint operator/(const mint a) const {
      mint res(*this);
      return res /= a;
   }
};

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

   int n;
   cin >> n;
   vector<int> a(n);
   rep(i, 0, n) cin >> a[i];
   sort(a.begin(), a.end());
   mint ans;
   vector<mint> two(n + 1);
   two[0] = 1;
   rep(i, 0, n) two[i + 1] = two[i] * 2;
   rep(i, 0, n) {
      int l = i, r = n - 1 - i;
      mint now = two[r];
      if (r != 0) now += two[r - 1] * r;
      now *= two[l];
      now *= a[i];
      ans += now;
   }
   ans *= two[n];
   cout << ans.x << endl;
   return 0;
}

Measured memory_bytes: 2560
<?php
fscanf(STDIN, "%d%d%d", $N, $A, $B);
$c = 0;
for($i = 0; $i < $N; $i++){
  $t = intval(fgets(STDIN));
  $c+= $t < $A || $t >= $B;
}
echo $c,"\n";

Measured memory_bytes: 4728
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <unordered_map>
#include <map>
#include <climits>

using namespace std;

typedef long long ll;

int N;
unordered_map<string, int> umap[2];

void bfs(const string& start, const int idx) {

  umap[idx][start] = 0;
  queue<string> Q;
  Q.push(start);
  umap[idx][start] = 0;
  while(!Q.empty()) {
    
    const string now = Q.front(); Q.pop();
    const int ncost = umap[idx][now]+1;
    if(ncost >= 5) continue;
    
    for(int i=0; i<N; i++) {
      for(int j=i+1; j<=N; j++) {
        string next = now;
        reverse(next.begin()+i, next.begin()+j);
        unordered_map<string, int>::iterator it = umap[idx].find(next);
        if(it != umap[idx].end()) {
          if(it->second < ncost) {
            continue;
          }
        }
        umap[idx][next] = ncost;
        Q.push(next);
      }
    }
  }
}

int main() {
  
  cin >> N;
  string str; str.resize(N);
  for(int i=0; i<N; i++) {
    int in; cin >> in;
    str[i] = 'a'+in;
  }
  
  bfs(str, 0);

  sort(str.begin(), str.end());
  bfs(str, 1);
  
  int ans = N-1;
  for(auto i : umap[0]) {
    unordered_map<string, int>::iterator it = umap[1].find(i.first);
    if(it != umap[1].end()) {
      ans = min(ans, i.second+it->second);
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 196316
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define max3(x,y,z) max(x,max(y,z))
ll dp[100009]= {-1};
ll inf = -1*1e9;
ll n;
ll arr[100009];


int main()
{
  cin >> n;
  memset(dp,-1,sizeof dp);
  for(int i=0;i<n;i++)
  {
    cin>>arr[i];
  }  
 dp[0]=0;
 dp[1]=abs(arr[0]-arr[1]);
 for(int i=2;i<n;i++)
 {
   dp[i]=min(dp[i-1]+abs(arr[i-1]-arr[i]),dp[i-2]+abs(arr[i]-arr[i-2]));
 }

cout<<dp[n-1];

}

Measured memory_bytes: 1792
s = gets.chomp
t = gets.chomp

hash_s = {}
hash_t = {}
(0..s.length-1).each do |i|
  hash_s[s[i]] ||= [] 
  hash_s[s[i]] << i
  hash_t[t[i]] ||= [] 
  hash_t[t[i]] << i
end

hash_s.each do |k, v|
  if v.map {|i| t[i] }.uniq.length > 1
    puts "No"
    exit
  end
end

hash_t.each do |k, v|
  if v.map {|i| s[i] }.uniq.length > 1
    puts "No"
    exit
  end
end

puts "Yes"


Measured memory_bytes: 38636
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define repi(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) repi(i, 0, a)
#define repd(i, a, b) for(int i = (a); i >= (b); i--)
#define repit(i, a) for(__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)

#define all(u) (u).begin(), (u).end()
#define rall(u) (u).rbegin(), (u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)), (u).end())

#define pb push_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;

typedef complex<double> P;

double cross(const P& a, const P& b) {
    return imag(conj(a)*b);
}

double dot(const P& a, const P& b) {
    return real(conj(a)*b);
}

struct L {
    P a, b;
    L(const P &a, const P &b) : a(a), b(b){ }
};

/* 点の進行方向 (a->b->c) */
int ccw(P a, P b, P c) {
    b -= a; c -= a;
    if (cross(b, c) > 0)   return +1;       // +1 : 反時計回り
    if (cross(b, c) < -EPS)   return -1;       // -1 : 時計回り
    if (dot(b, c) < 0)     return +2;       // +2 : 線上(c--a--b)
    if (norm(b) < norm(c)) return -2;       // -2 : 線上(a--b--c)
    return 0;
}

bool intersectLL(const L &l, const L &m) {
    return abs(cross(l.b-l.a, m.b-m.a)) > EPS || // 平行でない
	abs(cross(l.b-l.a, m.a-l.a)) < EPS;   // 重なってない
}

P crosspointLL(const L &l, const L &m) {
    double A = cross(l.b - l.a, m.b - m.a);
    double B = cross(l.b - l.a, l.b - m.a);
    if (abs(A) < EPS && abs(B) < EPS) return m.a; // 重なっている
    if (abs(A) < EPS) return P(INF, INF); // 交差しない
    return m.a + B / A * (m.b - m.a);
}

int n;
vector<P> p;

bool attempt(P x)
{
    rep(i, n)
	if (ccw(p[i], p[(i + 1) % n], x) == -1)
	    return false;
    return true;
}

int main(){
    while (cin >> n && n) {
	p.clear();
	rep(i, n) {
	    double x, y; cin >> x >> y;
	    p.pb(P(x, y));
	}

	vector<P> cand;
	rep(i, n) {
	    rep(j, n) {
		if (i == j) continue;
		if (intersectLL(L(p[i], p[(i + 1) % n]), L(p[j], p[(j + 1) % n])))
		    cand.pb(crosspointLL(L(p[i], p[(i + 1) % n]), L(p[j], p[(j + 1) % n])));
	    }
	}

	int ans = 0;
	repit(it, cand) {
	    if (attempt(*it)) {
		ans = 1;
		break;
	    }
	}
	cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1356
#include<iostream>
using namespace std;
int main()
{
    long int a,b,c,k,sum=0;
    cin>>a>>b>>c>>k;
    while(k)
    {
        if(a>=k)
        {
            sum+=k;
            k=0;
            break;
        }
        if(k>a)
        {
            k-=a;
            sum+=a;
            //cout<<"K is"<<k<<endl;
            //cout<<"sum is"<<sum<<endl;
        }
        if(b>=k)
        {
            //sum+=0;
            k=0;
            break;
        }
        if(k>b)
        {
            k-=b;
           // cout<<"K is"<<k<<endl;
            //cout<<"sum is"<<sum<<endl;
            //sum+=0;
        }
        if(c>=k)
        {
            sum-=k;
            k=0;
            //cout<<"sum is"<<sum<<endl;
        }
    }
    cout<<sum;
}

Measured memory_bytes: 3536
def read():
    return int(input())

def readmap():
    return map(int, input().split())

def readlist():
    return list(map(int, input().split()))


if __name__ == "__main__":
    N = read()
    A = readlist()
    A = [0] + A

    Ainv = [0] * (N + 1)
    for i in range(1, N + 1):
        Ainv[A[i]] = i

    print(" ".join(list(map(str, Ainv[1:]))))

Measured memory_bytes: 18028
n=int(input())
#ne,[7,5,3,1,1,3,5,7]8
#no,[8,6,4,2,0,2,4,6,8]9
m=[0]*n
for i in map(int,input().split()):
  m[i]+=1
ans=1
for i in range(n-1,0,-2):
  if m[i]!=2:
    ans=0
if m[0]!=n%2:
  ans=0
if ans:
  print(2**(n//2)%1000000007)
else:
  print(0)
    

Measured memory_bytes: 10616
/*input
12345 678901
*/

#include <iostream>

using namespace std;

int main()
{

	long long N, M;
	cin >> N >> M;

	long long total = 0;

	if(M >= N*2){  // having many "c"
		// cout << "pattern 1" << endl;
		total += N;
		M -= N*2;
		total += M / 4;
	}else{ // having many "s"
		// cout << "pattern 2" << endl;
		total = M / 2;
	}

	cout << total << endl;

	return 0;
}


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

int main() {
ll n,m; cin>>n>>m;
  vector<pair<ll, ll>> vec;
  rep(i, n){
    ll a,b;
    cin>>a>>b;
		vec.push_back(make_pair(a,b));
  }
  
  sort(ALL(vec));
  
  ll money=0;
  ll count=0;
  for(int i=0;i<n;i++){
    bool fin=false;
    if(count+vec[i].second>=m){
      for(int j=0;j<vec[i].second;j++){
        money+=vec[i].first;
        count++;
        if(count==m){fin=true;
                     break;}
      }
    }
    if(fin) break;
    money+=vec[i].first*vec[i].second;
    count+=vec[i].second;
  }
    
  cout<<money<<endl;
  
}


Measured memory_bytes: 2420
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <complex>
#include <iomanip>
#include <iostream>
#include <limits>
#include <inttypes.h>
#include <map>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

[[maybe_unused]] constexpr ll LL_MAX = numeric_limits<ll>::max();
[[maybe_unused]] constexpr ll LL_MIN = numeric_limits<ll>::min();
[[maybe_unused]] constexpr ull ULL_MAX = numeric_limits<ull>::max();

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--)

template <typename T>
void chmin(T& x, T y) {
    x = min(x, y);
}

template <typename T>
void chmax(T& x, T y) {
    x = max(x, y);
}

ll csum(ll x, ll y) {
    if (x > 0 && y > 0 && x > LL_MAX - y) {
        return LL_MAX;
    }
    if (x < 0 && y < 0 && x < LL_MIN - y) {
        return LL_MIN;
    }
    return x + y;
}

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

ll readl() {
    ll ret;
    scanf("%" PRId64 "", &ret);
    return ret;
}

vector<ll> readvl(ll n) {
    vector<ll> ret(n);
    rep(i,0,n) {
        ret[i] = readl();
    }
    return ret;
}

void writel(ll x) {
    printf("%" PRId64 "\n", x);
}

int main() {
    ll N = readl();
    ll K = readl();
    K--;
    vector<ll> next = readvl(N);
    rep(i,0,N) {
        next[i]--;
    }
    vector<ll> scores = readvl(N);
    ll ans = LL_MIN;
    rep(start,0,N) {
        ll now = start;
        ll sum = 0;
        ll loop = 0;
        vector<ll> sum_max;
        sum_max.push_back(sum);
        vector<ll> sums;
        sums.push_back(0);
        do {
            now = next[now];
            sum += scores[now];
            loop++;
            sum_max.push_back(max(sum, sum_max.back()));
            sums.push_back(sum);
        } while (now != start);
        ll score = scores[start];
        ll score_sub = LL_MIN;
        rep(mod,0,loop) {
            if (mod > K) {
                break;
            }
            ll score_sub_loc = sums[mod];
            chmax(score_sub, score_sub_loc);
            score_sub_loc += (K - mod) / loop * sum;
            chmax(score_sub, score_sub_loc);
        }
        score += score_sub;
        chmax(ans, score);
    }
    writel(ans);
}

/*
 
 5 6
 2 4 1 5 3
 1 2 4 -1 -4
 
 */



Measured memory_bytes: 3444
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

ll dp[33][1000010];

int main(){
    ll N,C,s,t,c,ma=-1;
    cin >> N >> C;
    rep(i,N){
        cin >> s >> t >> c;
        dp[c][s-1]++;
        dp[c][t]--;
    }
    ll d=0;
    Rep(j,1,C+1){
        ll d=0;
        rep(i,100007){
            d+=dp[j][i];
            dp[j][i]=d;
            dp[j][i]=min(dp[j][i],1LL);
        }
    }
    rep(i,100007){
        ll k=0;
        Rep(j,1,C+1){
            k+=dp[j][i];
        }
        ma=max(k,ma);
    }
    cout << ma << endl;
}

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

int top, S, E, W, N, bot;

void what(char c)
{
		int tmp;
		switch (c) {
				case 'S':
						tmp = top;
						top = N;
						N = bot;
						bot = S;
						S = tmp;
						break;
				case 'E':
						tmp = top;
						top = W;
						W = bot;
						bot = E;
						E = tmp;
						break;
				case 'W':
						tmp = top;
						top = E;
						E = bot;
						bot = W;
						W = tmp;
						break;
				case 'N':
						tmp = top;
						top = S;
						S = bot;
						bot = N;
						N = tmp;
						break;
		}
}

int main()
{
		int i;
		string op;
		cin >> top >> S >> E >> W >> N >> bot;
		cin >> op;
		for (i=0; i<op.size(); i++) {
				what(op[i]);		}
		cout << top << "\n";
}

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

typedef long long ll;

int digit(ll n)
{
	int d=0;
	while(n)
	{
		n/=10;
		d++;
	}
	return d;
}

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

    int ans=100000;
    for(ll i=1;i*i<=n;i++) if(n%i==0) ans=min(digit(max(i,n/i)),ans); 

    cout<<ans;    
    return 0;

}

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

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

void Main(){
    ll S; cin >> S;

    ll dp[1001][S+1]; REP(i,1001)REP(j,S+1) dp[i][j] = 0;
    dp[0][0] = 1;

    REP(i,1000){
        VL sum(S+1,0); sum[0] = dp[i][0];
        REP(j,S) (sum[j+1] += sum[j] + dp[i][j+1]) %= MOD;
        FOR(j,3,S+1){
            (dp[i+1][j] += sum[j-3]) %= MOD;
        }
    }

    ll ans = 0;
    REP(i,1000) (ans += dp[i+1][S]) %= MOD;
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 19180
#include<bits/stdc++.h>
using namespace std;
const int INF = 111111;

int main(void){
    int N; cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    int ans = 0;
    int pos = 0;
    while(pos < N){
        int len1 = 0, len2 = 0;
        int pos1 = pos, pos2 = pos;
        // decrease
        while(1){
            if(pos1 >= N - 1) break;
            if(A[pos1] >= A[pos1+1]){
                len1++;
                pos1++;
            }else{
                break;
            }
        }
        // increase
        while(1){
            if(pos2 >= N - 1) break;
            if(A[pos2] <= A[pos2+1]){
                len2++;
                pos2++;
            }else{
                break;
            }
        }
        ans++;
        if(len1 >= len2){
            pos = pos1;
        }else{
            pos = pos2;
        }
        pos++;
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
	int N;
	int H[105];

	cin >> N;
	for ( int i = 0; i < N; i++ ) {
		cin >> H[i];
	}
	
	int ans = 0;

	for ( int cnt = 0; cnt < 100; cnt++ ) {
		for ( int i = 0; i < N; i++ ) {
			if ( H[i] > 0 ) {
				if ( i == 0 || H[i - 1] == 0 ) {
					ans++;
				}
			}
		}
		for ( int i = 0; i < N; i++ ) {
			if ( H[i] > 0 ) {
				H[i]--;
			}
		}
	}

	cout << ans << endl;

	return ( 0 );
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
	using namespace std;
	 
	int main ()
	{
		#ifdef LOCAL
			freopen("input.txt", "r", stdin);
		#endif

		int n, k;

		cin >> n >> k;
		int dp[n];
		int arr[n];
		for(int i = 0; i < n; i++)
			cin >> arr[i];
		dp[0] = 0;
		for(int i = 1; i < n; i++) {
			dp[i] = dp[i-1]+abs(arr[i-1]-arr[i]);
			for(int j = 2; j <= k && i-j >= 0; j++)
				dp[i] = min(dp[i], dp[i-j]+abs(arr[i-j]-arr[i]));
		}
		cout << dp[n-1] << endl;
		return 0;
	}

Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int N = sc.nextInt();
        int[] C = new int[N];
        int[] D = new int[N + 1];
        int[] F = new int[N + 1];
        for (int i = 0; i < N; i++) {
            int A = sc.nextInt() - 1;
            C[A]++;
        }
        for (int i = 0; i < N; i++) {
            D[C[i]]++;
        }
        int nowSum = N-D[0];
        int lSum = 0*D[0];
        F[1] = nowSum;
        for (int i = 2; i <= N; i++) {
            nowSum -= D[i-1];
            lSum += (i-1)*D[i-1];
            F[i] = lSum/i + nowSum ;
        }
        int x = N;
        for(int nowK=1;nowK<=N;nowK++) {
            while (x > 0 && F[x] < nowK) {
                x--;
            }
            System.out.println(x);
        }
    }
}

Measured memory_bytes: 102572
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	int n;
	cin >> n;
	cout << (1000 - n % 1000) % 1000 << endl;
	return 0;
}

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

typedef long long ll;
const ll MOD = 1e9 + 7;

#define each(i, mp) for(auto& i:mp)
// https://qiita.com/Seika139/items/8cacdb3cc8fa6655573c
// https://hiramekun.hatenablog.com/entry/2020/04/27/031032
int main() {
    string s;
    cin >> s;
    map<ll, ll> mp;
    mp[0] = 1;
    reverse(s.begin(), s.end());

    ll now = 0, ten = 1;
    for(auto& e : s) {
        now = (now + (e - '0') * ten) % 2019;
        ten *= 10;
        ten %= 2019;
        mp[now]++;
        // cout << now << endl;
    }
    ll ans = 0;
    for(auto& e : mp) {
        ans += e.second * (e.second - 1) / 2;
    }
    cout << ans << '\n';
    return 0;
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var set = new HashSet<char>();
            for (var i = 0; i < s.Length; i++) set.Add(s[i]);

            string ans = null;
            for (var alpha = 'a'; alpha < 'a' + 26; alpha++)
            {
                if (set.Contains(alpha)) continue;
                else
                {
                    ans = alpha.ToString();
                    break;
                }
            }

            Console.WriteLine(ans??"None");
        }
    }
}


Measured memory_bytes: 13664
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>

typedef struct BST {
    struct Node {
	int data;
	struct BST *left;
	struct BST *right;
    } *node;
} *BST;

typedef struct Node * Node;



BST
BSTNewTree(void)
{
    BST empty = (BST)malloc(sizeof(struct BST));
    empty->node = NULL;
    return empty;
}

void
BSTCreateLeaf(BST leaf, int item)
{
    leaf->node = (Node)malloc(sizeof(struct Node));
    leaf->node->data = item;
    leaf->node->left = BSTNewTree();
    leaf->node->right = BSTNewTree();
}

bool
BSTIsEmpty(BST tree)
{
    return tree->node == NULL;
}

void
BSTInsert(BST tree, int item)
{
    while (1)
    {
	if (BSTIsEmpty(tree))
	{
	    BSTCreateLeaf(tree, item);
	    break;
	}
	else if (item < tree->node->data)
	    tree = tree->node->left;
	else if (item > tree->node->data)
	    tree = tree->node->right;
    }
}

bool
BSTSearch(BST tree, int key)
{
    while (1)
    {
	if (BSTIsEmpty(tree))
	    return false;
	else if (key < tree->node->data)
	    tree = tree->node->left;
	else if (key > tree->node->data)
	    tree = tree->node->right;
	else
	    return true;
    }
}

void
BSTFree(BST tree)
{
    if (BSTIsEmpty(tree))
	free(tree);
    else
    {
	BSTFree(tree->node->left);
	BSTFree(tree->node->right);
	free(tree->node);
	free(tree);
    }
}

void
BSTPrintInorder(BST tree)
{
    if (BSTIsEmpty(tree))
	return;

    if (!BSTIsEmpty(tree->node->left))
	BSTPrintInorder(tree->node->left);	

    printf(" %d", tree->node->data);

    if (!BSTIsEmpty(tree->node->right))
	BSTPrintInorder(tree->node->right);	
}

void
BSTPrintPreorder(BST tree)
{
    if (BSTIsEmpty(tree))
	return;

    printf(" %d", tree->node->data);

    if (!BSTIsEmpty(tree->node->left))
	BSTPrintPreorder(tree->node->left);	

    if (!BSTIsEmpty(tree->node->right))
	BSTPrintPreorder(tree->node->right);	
}

int main(void)
{
    int i, n, key;
    char command[10], input[100];
    BST bst = BSTNewTree();

    scanf("%d\n", &n);
    for (i=0; i<n; i++)
    {
	fgets(input, 100, stdin);
	sscanf(input, "%s %d\n", command, &key);
	if (strcmp(command, "insert") == 0)
	    BSTInsert(bst, key);
	else
	{
	    BSTPrintInorder(bst);
	    puts("");
	    BSTPrintPreorder(bst);
	    puts("");
	}
    }

    BSTFree(bst);

    return 0;
}

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

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl

int sign_x[4] = {1, -1, +1, -1};
int sign_y[4] = {1, -1, -1, +1};

ll board[8][8];

ll queen[8]; // i行目のどこに置いたか

bool in_range(ll x, ll y){
    if(0<=x && x<8 && 0<=y && y<8){
        return true;
    }else{
        return false;
    }
}

// 盤面に置く or 取り除く
// 置く場合 add = 1
// 除く場合 add = -1
void put(ll x, ll y, ll add){
    // cout << "put " << x << " " << y << endl;
    if(add>0){
        queen[y] = x;
    }else{
        queen[y] = -1;
    }

    // row
    FOR(i, 0, 8){
        board[y][i] += add;
    }
    // column
    FOR(i, 0, 8){
        board[i][x] += add;
    }
    // 足しすぎを引く
    board[y][x] -= add;
    // diagonal
    FOR(i, 1, 8){ // 幅
        FOR(j, 0, 4){
            ll nx = x + i * sign_x[j];
            ll ny = y + i * sign_y[j];
            if(in_range(nx, ny)){
                board[ny][nx] += add;
            }
        }
    }
}

// 解答用：クイーンの位置をQで表示する
void printQueen(){
    FOR(y, 0, 8){
        FOR(x, 0, 8){
            if(queen[y]==x){
                cout << 'Q';
            }else{
                cout << '.';
            }
        }
        cout << endl;
    }
}

// ボードの状態を数字で表示する
void debugBoard(){
    FOR(y, 0, 8){
        FOR(x, 0, 8){
            cout << setw(2) << board[y][x] << ' ';
        }
        cout << endl;
    }
}

void setQueen(ll y){
    // pn(y);
    if(y==8){
        printQueen();
        exit(0);
    }

    // すでに置かれている
    if(queen[y]!=-1){
        setQueen(y+1);
    }

    // どこに置こうかな
    FOR(x, 0, 8){
        // 置いてみる
        if(board[y][x]==0){
            put(x, y, 1);
            setQueen(y+1);
            // キャンセル
            put(x, y, -1);
        }        
    }
}

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

    // input
    ll N;
    cin >> N;

    FOR(i, 0, 8){
        queen[i] = -1;
    }

    while(N--){
        ll y, x;
        cin >> y >> x;
        put(x, y, 1);
    }

    setQueen(0);
    return 0;
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b;
    char tmp[6];
    int count=0;
    cin>>a>>b;
    for(int i=a;i<=b;i++){
        sprintf(tmp,"%d",i);
        if((tmp[0]==tmp[4])&&(tmp[1]==tmp[3])){
            count++;
        }
    }
    cout<<count<<endl;
}


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

/*  using namespace  */
using namespace std;

/*  local var  */
int a,b,n;
vector<int> g[100005];
int dist_Fennec[100005];
int dist_Sunuke[100005];

/*  define  */
#define loop(i,j) for(int i = 0; i < j; i++)
#define scan1(d) scanf("%lld",&d);
#define scan2(a,b) scanf("%lld %lld",&a,&b);

/*  typedef  */
typedef long long ll;

/*  function  */
void dfs(int r,int f ,int d, int dist[])
{
	dist[r]=d;
	loop(x,g[r].size()){
		if(g[r][x]!=f) dfs(g[r][x],r,d+1,dist);
	}
}
/*  main program  */
int main()
{
	int ans=0;
	cin>>n;
	loop(i,n-1){
		cin>>a>>b;
		a--,b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(0,-1,0,dist_Fennec);
	dfs(n-1,-1,0,dist_Sunuke);
	loop(i,n) if(dist_Fennec[i]<=dist_Sunuke[i]) ans++;
	else ans--;
	printf("%s\n",(ans>0)?"Fennec":"Snuke");
}
	

Measured memory_bytes: 14336
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for (auto& a : A) {
        cin >> a;
    }
    rep(i, K, N) {
        if (A[i] > A[i - K]) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4780
n = int(input())
lst = [(0,0,0)]
for i in range(n):
    t,x,y = map(int, input().split())
    lst.append((t,x,y))

for i in range(n):
    T,X,Y = lst[i+1][0]-lst[i][0],abs(lst[i][1]-lst[i+1][1]),abs(lst[i][2]-lst[i+1][2])
    if X+Y>T or (X+Y-T)%2!=0:
        print("No")
        exit()

print("Yes")


Measured memory_bytes: 17376
// Problem : D - Sum of Divisors
// Contest : AtCoder - AtCoder Beginner Contest 172
// URL : https://atcoder.jp/contests/abc172/tasks/abc172_d
// Memory Limit : 1024 MB
// Time Limit : 3000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define debug(x) cerr << #x << " = " << x << '\n'
#define debug_arr(a , n) for(int i = 0 ; i < n ; i++)cerr << a[i] << " "
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define vll vector<ll> 
#define all(x) (x).begin() , (x).end()
#define inf 1000000000
#define mod 1000000007

const int max_n = 1e7 + 9;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a , ll b)
{
    ll prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return prod;
}
int n;
ll dp[max_n];
ll smallest_prime[max_n];
int main()
{
		speed;
    cin >> n;
    
    for(ll i = 2 ; i <= n ; i++){
    	smallest_prime[i] = i;
    }
    
    for(ll i = 2 ; i <= n ; i++){
    	if(smallest_prime[i] == i){
    		for(ll j = i * i ; j <= n ; j += i){
    			smallest_prime[j] = i;
    		}
    	}
    }
  
    dp[1] = 1;
    for(ll i = 2 ; i <= n ; i++){
    	ll cnt = 0 , temp = i;
    	while(temp % smallest_prime[i] == 0){
    		cnt++;
    		temp /= smallest_prime[i];
    	}
    	
    	dp[i] = dp[temp] * (cnt + 1);
    }
    
    ll sum = 0;
    for(ll i = 1 ; i <= n ; i++){
    	sum += i * dp[i];
    }
    
    cout << sum << "\n";
    return 0;
}

Measured memory_bytes: 159856
#include<bits/stdc++.h>
using namespace std;
 
int main () {
  int n;
  cin>>n;
  vector<tuple<string, int ,int>>a;

  for (int i=1;i<n+1;i++){
    string s;
    int p;
    cin >>s>>p;

    p = -p;
    a.push_back(tie(s,p,i));
  }

  sort (a.begin(),a.end());
  for(int i=0;i<n;i++){
    cout<<get<2>(a[i])<<endl;
    }

return 0;
}


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

refrigerator = list(map(int, input().split()))
microwave = list(map(int, input().split()))



min_price = min(refrigerator) + min(microwave)

for i in range(m):
    x, y, c = list(map(int, input().split()))
    min_price = min(min_price, refrigerator[x-1]+microwave[y-1]-c)
    
print(min_price)

Measured memory_bytes: 18612
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
  int n;
  cin >> n;
  int a[n], b[n], c[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    cin >> b[i];
  for (int i = 0; i < n; i++)
    cin >> c[i];

  sort(a, a + n);
  sort(b, b + n);
  sort(c, c + n);

  long long ans = 0;
  for (int j = 0; j < n; j++)
  {
    long long l = lower_bound(a, a + n, b[j]) - a;
    long long h = c + n - upper_bound(c, c + n, b[j]);
    ans += l * h;
  }

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

Measured memory_bytes: 1536
#include <stdio.h>
#include <stdlib.h>
#define n 500000
#define INFTY 1000000000

void merge(int *, int, int, int);
void mergeSort(int *, int, int);

int compare_count=0;

int main(){
  int A[n], A_len, i;

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

  mergeSort( A, 0, A_len);
  for(i = 0; i < A_len-1; i++) printf("%d ",A[i]);
  printf("%d\n%d\n", A[A_len-1], compare_count);
  
  return 0;
}

void merge(int *A, int left, int mid, int right){
  int n1, n2, *L, *R, i, j, k;

  n1 = mid - left;
  n2 = right - mid;
  L = (int *)malloc( (n1+1) * sizeof(int) );
  R = (int *)malloc( (n2+1) * sizeof(int) );
  for(i = 0; i < n1; i++) L[i] = A[left+i];
  for(i = 0; i < n2; i++) R[i] = A[mid+i];
  L[n1] = INFTY;
  R[n2] = INFTY;
  i = 0;
  j = 0;
  for(k = left; k < right; k++){
    if( L[i] <= R[j] ){
      A[k] = L[i];
      i++;
    }
    else{
      A[k] = R[j];
      j++;
    }
    compare_count++;
  }
}

void mergeSort(int *A, int left, int right){
  if( left+1 < right ){
    int mid;
    mid = (left + right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}



Measured memory_bytes: 64444
import itertools
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
data = list(range(1,n+1))
x = list(itertools.permutations(data, n))
c1 = 0
c2 = 0
for i in range(len(x)):
    if list(x[i]) == a:
        c1 = i
    if list(x[i]) == b:
        c2 = i
print(abs(c1-c2))

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

const ll mod = 1000000007;


int main() {
	ll n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		ll sum = 0;
		for (int x = 1; x <= i; x++) {
			if (x * x  + 2 * x > i) break;
			for (int y = x; y <= i; y++) {
				if (x * x +  x * y + y * y + 1 > i) break;
				for (int z = y; z <= i && x * x + y * y + z * z + x * y + y * z + z * x <= i; z++) {
					ll a = x * x + y * y + z * z + x * y + y * z + z * x;
					if (a == i) {
						if (x == y && y == z) {
							sum++;
						}
						else if (x == y) {
							sum += 3;
						}
						else if (y == z) {
							sum += 3;
						}
						else {
							sum += 6;
						}
					}
				}
			}
		}
		cout << sum << endl;
	}
	return 0;
}


Measured memory_bytes: 3524
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

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

  ll N;
  ull K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i, N) {
    cin >> A[i];
    --A[i];
  }

  vector<vector<int>> Table;
  for (ull i = 0, k = 1;k <= K;++i, k<<=1) {
    vector<int> B(N);
    if (i==0) B = A;
    else {
      rep(j, N) {
        B[j] = Table[i-1][Table[i-1][j]];
      }
    }
    Table.push_back(B);
  }
  ll K_tmp = K;
  int answer {};
  for (ll i = 0;K_tmp!=0;++i, K_tmp>>=1) {
    if (K_tmp&1) {
      answer = Table[i][answer];
    }
  }
  cout << answer + 1 << '\n';
}


Measured memory_bytes: 51652
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

class Hello {

        static void Main()
        {

                var abk = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                int a = abk[0];
                int b = abk[1];
                int k = abk[2];

                var total = b - a + 1;

                for (int i = 1, ii = a; ii <= b; ++i, ++ii) {

                        if (i <= k || i >= total - k + 1 ) {
                                Console.WriteLine(ii.ToString());
                        }
                }
        }

}


Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>
#include <set>

using namespace std;

vector<vector<int> > E;
vector<int> color;
int cntB, cntW;

bool dfs(int node, int c){
    if(c == -1){
        cntB++;
    }
    else{
        cntW++;
    }

    bool isOk = true;
    for(int next: E[node]){
        if(color[next] == 0){
            color[next] = -c;
            isOk = (isOk && dfs(next, -c));
        }
        else{
            if(c == color[next]){
                isOk = false;
            }
        }
    }

    return isOk;
}

void solve(int N, int M){
    E = vector<vector<int> >(N);

    int u, v;
    for(int i = 0; i < M; i++){
        cin >> u >> v;
        E[u - 1].push_back(v - 1);
        E[v - 1].push_back(u - 1);
    }

    cntB = 0;
    cntW = 0;
    color = vector<int>(N, 0);

    color[0] = -1;
    bool isOk = dfs(0, -1);

    if(!isOk){
        cout << 0 << endl;
    }
    else{
        set<int> ans;
        if(cntB % 2 == 0){
            ans.insert(cntB / 2);
        }
        if(cntW % 2 == 0){
            ans.insert(cntW / 2);
        }

        cout << (int)ans.size() << endl;

        for(int temp: ans){
            cout << temp << endl;
        }
    }
}

int main(){

    while(true){
        int N, M;
        cin >> N >> M;
        if(N == 0){
            break;
        }

        solve(N, M);
    }

    return 0;
}


Measured memory_bytes: 3228
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;

double expectation(int p);

int main() {
    int N, K, key, tmp = 0, MAX = 0;
    cin >> N >> K;
    vector<int>p(N);

    rep(i, N) {
        cin >> p[i];
        tmp += p[i];
        if (i + 1 > K) {
            tmp -= p[i - K];
        }
        if (MAX <= tmp) {
            key = i;
            MAX = max(MAX, tmp);
        }
    }

    double ans = 0;
    double sum = 0;
    for (int i = key - K + 1; i <= key; i++) {
        sum += expectation(p[i]);
    }
 
    cout << setprecision(15) << sum;

    return 0;
}

double expectation(int p) {
    double A = 0;
    for(int i = 1; i <= p; i++) {
        A += i;
    }
    A /= p;
    return A;
}

Measured memory_bytes: 4028