akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#ifdef DEBUG
std::ostream& dout = cout;
#else
stringstream dout;
#endif
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}
int digit(int n,int k){
    int ret=1,cnt=1;
    while(1){
        if(n<=cnt*k-1){
            return ret;
        }
        ret++;
        cnt*=k;
    }
}
signed main(signed argc, char* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    const int MOD = 1000000007;
    int n,k;
    cin>>n>>k;
    cout<<digit(n,k)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long double aa,bb;
	cin>>aa>>bb;
	long double h,m;
	long double pi=3.14159265358979323846;
	cin>>h>>m;
	h=h+m/60;
	h=h*5;
	h=h/60;
	m=m/60;
	long double x1=cosl(2*pi*h)*aa,y1=sinl(2*pi*h)*aa,x2=cosl(2*pi*m)*bb,y2=sinl(2*pi*m)*bb;
	cout<<setprecision(10)<<fixed;
	cout<<sqrtl((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))<<'\n';
}

Measured memory_bytes: 4184
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int number = sc.nextInt();
		int[] integral=new int[number];
		int sum=0;
		int average=0;
		int ans=0;
		for(int i=0; i<number; i++){
			integral[i]=sc.nextInt();
			sum+=integral[i];
		}
		if(sum%number!=0){
			if(((10*(sum%number))/number)>=5){
				average=(sum/number)+1;
			}else{
				average=sum/number;
			}
		}else{
			average=sum/number;
		}
		for(int i = 0; i<number; i++){
			ans+=(integral[i]-average)*(integral[i]-average);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
# mod = 998244353
# mod = 10 ** 9 + 9
mod = 10 ** 9 + 7
PI = Math::PI
dx = [ 1,  0, -1,  0,  1,  1, -1, -1]
dy = [ 0,  1,  0, -1,  1, -1,  1, -1]
eight = [0, 1, 1, 0, -1, -1, 1, -1, 0]
def max(a,b);       a > b ? a : b                              end
def min(a,b);       a < b ?  a : b                             end
def swap(a,b);      a, b = b, a                                end
def gi;             gets.to_i                                  end
def gf;             gets.to_f                                  end
def gs;             gets.chomp                                 end
def gai(n=nil); n.nil? ? gets.split.map(&:to_i) : n.times.map{ gets.to_i } end
def gaf(n=nil); n.nil? ? gets.split.map(&:to_f) : n.times.map{ gets.to_f } end
def gas(n=nil); n.nil? ? gets.split : n.times.map{ gets.chomp } end
def ga2i(h);        h.times.map{ gets.split.map(&:to_i) }      end
def yn(f); puts f ? "Yes" : "No" end
def YN(f); puts f ? "YES" : "NO" end
def yes(f=nil); f.nil? ? (puts "Yes"; exit) : (puts f ? "Yes" : "No") end
def no(f=nil); f.nil? ? (puts "No"; exit) : (puts f ? "Yes" : "No") end
def yay(f=nil); f.nil? ? (puts "Yay!"; exit) : (puts f ? "Yay!" : ":(") end

x = gi

ans = 0

ans += x / 500 * 1000
x = x % 500

ans += x / 5 * 5

puts ans

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

int main(){
    string s, t;
    cin >> s >> t;
    char s_characters[s.size()];
    for(int i = 0; i < s.size(); i++){
        s_characters[i] = s[i];
    }
    sort(s_characters, s_characters + s.size());
    char t_characters[t.size()];
    for(int i = 0; i < t.size(); i++){
        t_characters[i] = t[i];
    }
    sort(t_characters, t_characters + t.size(), greater<int>());
    string s_sorted = "", t_sorted = "";
    for(int i = 0; i < s.size(); i++){
        s_sorted.push_back(s_characters[i]);
    }
    for(int i = 0; i < t.size(); i++){
        t_sorted.push_back(t_characters[i]);
    }
    if(s_sorted < t_sorted){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e9
#define PI acos(-1)
typedef long long ll;
typedef pair<int, int> p_ii;


int main() {
	int n; cin >> n;
	ll a, b; cin >> a >> b;
	vector<ll> x(n);
	for (int i = 0; i < n; i++)cin >> x[i];
	ll ans = 0;
	for (int i = 1; i < n; i++) ans += min(a*(x[i] - x[i - 1]), b);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
const int MAXN = 1e5+1;
int indeg[MAXN], outdeg[MAXN];
bool vis[MAXN];
int main()
{
	int M, x, y, cnt = 1;
	vis[1] = 1;
	scanf("%*d%d", &M);
	while (M--)
	{
		scanf("%d%d", &x, &y);
		++outdeg[x], ++indeg[y];
		if(vis[x])
		{
			cnt += !vis[y];
			vis[y] = 1;
			if(indeg[x]+1 == outdeg[x])
			{
				vis[x] = 0;
				--cnt;
			}
		}
	}
	printf("%d\n", cnt);
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long ll;
typedef pair<ll,ll> P;


int n;
pair<int,int> a[2][100010];

int main(){
	cin >> n;
	for(int i = 0; i < 100010; i++){
		a[0][i].first = 0; a[0][i].second = i;
		a[1][i].first = 0; a[1][i].second = i;
	}
	for(int i = 0; i < n/2; i++){
		int c,d;
		cin >> c >> d;
		a[0][c].first++;
		a[1][d].first++;
	}
	
	sort(a[0]+1, a[0]+100001);
	sort(a[1]+1, a[1]+100001);
	
	if(a[0][100000].second == a[1][100000].second) cout << n - max(a[0][100000].first+a[1][99999].first, a[1][100000].first+a[0][99999].first) << endl;
	else cout << n - a[0][100000].first - a[1][100000].first << endl;
	
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
const int maxn=1000+10;
char s[maxn];

signed main(){
  	int n;
  	scanf("%d",&n);
  	scanf("%s",s);
  	if(n%2){
      	 puts("No");
     	 return 0;
    }
  	string s1="",s2="";
  	for(int i=0;i<n/2;i++){
      s1+=s[i];
    }
  	for(int i=n/2;i<n;i++){
      s2+=s[i];
  	}
    string ans=s1==s2?"Yes":"No";
  	cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//#include <atcoder/all>
//using namespace atcoder;
using namespace std;
using ll = long long;
using p = pair<int,int>;
const long long INF = 1ll << 60;


int main() {
  int k; cin >> k;
  string  a = "ACL";
  rep(i,k){
    cout << "ACL";
  }
   cout <<endl;



	return 0;
}



Measured memory_bytes: 3628
#79 C - Reconciled?
N,M = map(int,input().split())
MOD = 10**9 + 7

if abs(N-M) >= 2:
    ans = 0
else:
    # M! * N!
    Mfact = 1
    for m in range(1,M+1):
        Mfact = (Mfact * m)%MOD
    Nfact = 1
    for n in range(1,N+1):
        Nfact = (Nfact * n)%MOD
    ans = (Nfact*Mfact)%MOD
    if abs(N-M) == 0:
        ans = (ans * 2)%MOD
print(ans)

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

int main(){
  int N,M,X;
  cin >> N >> M>> X;
  vector<int> A(M);
  for(int i=0;i<M;i++) cin >> A[i];
  auto itr=upper_bound(A.begin(),A.end(),X);
  int ans=min(A.end()-itr,itr-A.begin());
  cout << ans << endl;
}

Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
using namespace std;
int main(){
	int a, b;
	cin >> a >> b;
	a = a*b;
	cout << (a % 2 == 0 ? "Even" : "Odd") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define prints(x, y) cout<<(x)<<" "<<(y)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> l(N);

  rep(i, N){
   cin >> l[i];
  }
  sort(l.begin(), l.end());
  reverse(l.begin(), l.end()); 
  int ans = 0;
  rep(i, K){
    ans += l[i];
  }
  print(ans);
}


Measured memory_bytes: 888
using System;

namespace AtCorder
{
    class ABC164
    {

        static void Main(string[] args)
        {
            var result = A();
            if(result == "")
            {
                return;
            }
            Console.WriteLine(result);
        }
        /*
          羊が S匹、狼がW匹います。
          狼の数が羊の数以上のとき、羊は狼に襲われてしまいます。
          羊が狼に襲われるなら unsafe、襲われないなら safe を出力してください。
         */

        static string A()
        {
            var lines = Console.ReadLine().Split(new char[] {' '});

            var s = int.Parse(lines[0]);
            var w = int.Parse(lines[1]);
            if(s <1 || s >100)
            {
                return "";
            }

            if(w  < 1 || w > 100)
            {
                return "";
            }
            if(s > w)
            {
                return "safe"; 
            }
            else
            {
                return "unsafe";
            }
        }
    }
}


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

#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<typename T, typename U> inline bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> inline bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
struct Init {
    Init() {
        cout << fixed << setprecision(20);
    };
} init;

int A, B;
signed main() {
    cin >> A >> B;
    int kuti = 1, ans = 0;
    while (kuti < B) {
        kuti--;
        kuti += A;
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from itertools import accumulate
def solve(N: int, W: int, w: "List[int]", v: "List[int]"):
    value = {}
    value[w[0]] = []
    value[w[0]+1] = []
    value[w[0]+2] = []
    value[w[0]+3] = []
    accum = {}
    answer = 0

    for i in range(N):
        value[w[i]].append(v[i])

    len0 = len(value[w[0]])
    len1 = len(value[w[0]+1])
    len2 = len(value[w[0]+2])
    len3 = len(value[w[0]+3])

    for i in range(4):
        value[w[0]+i].sort(reverse = True)
        accum[w[0]+i] = [0]+list(accumulate(value[w[0]+i]))

    for i in range(len0+1):
        for j in range(len1+1):
            for k in range(len2+1):
                for l in range(len3+1):
                    if i*w[0]+j*(w[0]+1)+k*(w[0]+2)+l*(w[0]+3) <= W:
                        answer = max(accum[w[0]][i]+accum[w[0]+1][j]+accum[w[0]+2][k]+accum[w[0]+3][l],answer)
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    w = [int()] * (N)  # type: "List[int]"
    v = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        w[i] = int(next(tokens))
        v[i] = int(next(tokens))
    solve(N, W, w, v)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include<iostream>
#include<queue>

using namespace std;
typedef pair<int, int> P;

int main(){
    int n;
    cin >> n;
    priority_queue<P,vector<P>,greater<P>> pq;
    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        pq.push(make_pair(b, a));
    }
    int nowTime = 0;
    int finishedTime;
    while (!pq.empty())
    {
        int a = pq.top().second;
        int b = pq.top().first;
        pq.pop();
        finishedTime = nowTime + a;
        if (b < finishedTime)
        {
            cout << "No" << endl;
            return 0;
        }
        nowTime = finishedTime;
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 2548
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0

for a in range(0, A + 1):
    if a * 500 == X:
        ans += 1
        break

    if a * 500 > X:
        break

    x_a = X - a * 500
    for b in range(0, B + 1):
        if b * 100 == x_a:
            ans += 1
            break

        if b * 100 > x_a:
            break
        
        x_b = x_a - b * 100
        for c in range(0, C + 1):
            if c * 50 == x_b:
                ans += 1
                break

            if c * 50 > x_b:
                break

print(ans)

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }
template <class T1, class T2, class Pred = std::less<T2> >
struct sort_pair_second {
    bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) {
        Pred p;
        return p(left.second, right.second);
    }
};

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

    ll A, B, N;
    cin >> A >> B >> N;
    ll x = min(B - 1, N);
    ll ans = ((A * x) / B) - A * (x / B);
    cout << ans << endl;
    return 0;
}

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


int main() {
  int n, k, ans;
  ans = 0;
  cin >> n;
  k = n;
 
  while(k >= 100){
    k = k / 100;
    ans++;
  }
  
  if(ans == 0){
    cout << min(9,n);
  }
  else if(ans == 1){
    if(n >= 1000){
      cout << 909;
    }
    else{
      cout << 9 + n - 99;
    }
  }
  else{
    if(n >= 100000){
      cout << 90909;
    }
    else{
      cout << 909 + n - 9999;
    }
  }
 
  
  return 0;
}

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

int main() {
  string A, B, C;
  cin >> A >> B >> C;
  int ans;
  for(int i = 0; i < 1000000; i++){   
    if(A.size() == 0 && ans == 1){
      cout << 'A' << endl;
      break;
    }
    else if(B.size() == 0 && ans == 2){
      cout << 'B' << endl;
      break;
    }
    else if(C.size() == 0 && ans == 3){
      cout << 'C' << endl;
      break;
    }    
    if(ans == 1 || i == 0){
      if(A[0]=='a'){
        ans = 1;
      }
      else if(A[0]=='b'){
        ans = 2;
      }
      else if(A[0] == 'c'){
        ans = 3;
      }
      A.erase(A.begin());
      continue;
    }
    if(ans == 2){
      if(B[0]=='a'){
        ans = 1;
      }
      else if(B[0]=='b'){
        ans = 2;
      }
      else if(B[0] == 'c'){
        ans = 3;
      }
      B.erase(B.begin());
      continue;
    }
    if(ans == 3){
      if(C[0]=='a'){
        ans = 1;
      }
      else if(C[0]=='b'){
        ans = 2;
      }
      else if(C[0] == 'c'){
        ans = 3;
      }
      C.erase(C.begin());
      continue;
    }
  }
}

Measured memory_bytes: 256
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.14159265358979323846
ll fac[MAX], finv[MAX], inv[MAX];


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 COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


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


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}

ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


string Toupper(string s){
  string ans="";
  rep(i,s.size()){
    if('a'<=s[i] && s[i]<='z') ans+=(char)s[i]-32;
    else ans+=s[i];
  }
  return ans;
}
string Tolower(string s){
  string ans="";
  rep(i,s.size()){
    if('A'<=s[i] && s[i]<='Z') ans+=(char)s[i]+32;
    else ans+=s[i];
  }
  return ans;
}


const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*bool cmp(pint a, pint b) { return a.second < b.second; }*/

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n,x;
  cin>>n>>x;
  vector<ll> v(n);
  rep(i,n) cin>>v[i];
  vector<ll> sum(n+1,0);
  sum[0]=0;
  rep(i,n){
    sum[i+1]=sum[i]+v[i];
  }
  ll ans=0;
  rep(i,n+1){
    if(sum[i]<=x) ans++;
  }
  cout<<ans<<endl;
}

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

int main() {
	uint32_t N;
	cin >> N;
	
	vector<uint32_t>a(N);
	for(uint32_t i=0; i<N; i++) cin >> a[i];
	
	vector<vector<int64_t>> dp(2, vector<int64_t>(N));
	copy(a.begin(), a.end(), dp[0].begin());
	
	for(uint32_t i=1; i<N; i++) {
		bool ic = i & 1;
		bool ip = (i - 1) & 1;
		
		for(uint32_t j=0; i+j<N; j++) {
			
			if(ic) { // odd turn = Y - X;
				dp[ic][j] = min(dp[ip][j] - a[j+i], dp[ip][j+1] - a[j]);
			} else { // even turn = X - Y;
				dp[ic][j] = max(dp[ip][j] + a[j+i], dp[ip][j+1] + a[j]);	
			}
			//cout << dp[ic][j] << " ";
		}
		//cout << endl;
	}
	
	if(N & 1) {
		cout << dp[0][0];
	} else {
		cout << -dp[1][0];
	}
	
	return 0;
}

Measured memory_bytes: 384
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
ans = 0
for i in range(1, n + 1):
    ans += c[i] * (c[i] - 1) // 2
for i in range(n):
    print(ans - c[a[i]] + 1)

Measured memory_bytes: 26780
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)


Measured memory_bytes: 47536
import sys
def input():
	return sys.stdin.readline()[:-1]

A, B, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = min(a) + min(b)
for _ in range(m):
	x, y, c = map(int, input().split())
	ans = min(ans, a[x-1] + b[y-1] - c)
print(ans)

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

int pow10(int);

int main()
{
  int n, m;
  int d[3];
  cin >> n >> m;
  for (int i=0; i<3; i++) d[i] = -1;
  int s, c;
  for (int i=0; i<m; i++) {
    cin >> s >> c;
    if (d[(3-n)+s-1] == -1) d[(3-n)+s-1] = c;
    else {
      if (d[(3-n)+s-1] != c) {
        cout << -1;
        return 0;
      }
    } 
  }
  if (d[3-n] == -1) {
    if (n == 1) d[3-n] = 0;
    else d[3-n] = 1;
  }
  int min = 0;
  for (int i=0; i<3; i++) {
    if (d[i] == -1) d[i] = 0;
    min += pow10(2-i) * d[i];
  }
  if (min >= pow10(n-1)) cout << min;
  else if (n == 1 && min == 0) cout << 0;
  else cout << -1;
  return 0;
}

int pow10(int n)
{
  int sum = 1;
  for (int i=0; i<n; i++) sum *= 10;
  return sum;
}



Measured memory_bytes: 256
#include "stdio.h"
#include "math.h"

#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) cerr << #x << "=" << static_cast<bitset<16> >(x) << endl;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

const int INF = 10000000;
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};
using namespace std;
typedef long long  ll;
/** Problem1138 : Traveling by Stagecoach **/
int n, m, a, b, p;
int t[10];
int d[30][30];
double dp[1<<10][30];

void solve()
{
	rep(i, 1<<n)
		fill(dp[i], dp[i]+m, INF);
	
	dp[(1<<n)-1][a-1]=0;
	double res = INF;
	for (int S = (1<<n)-1; S>=0; S--) {
		res = min(res, dp[S][b-1]);
		rep(v, m) {
			rep(i, n) {
				if (S>>i&1) {
					rep(u, m) {
						if (d[v][u]>=0) {
							dp[S&~(1<<i)][u] = min(dp[S&~(1<<i)][u], dp[S][v]+(double)d[v][u]/t[i]);
						}
					}
				}
			}
		}
	}
	if (res==INF)
		printf("Impossible\n");
	else
		printf("%.3f\n", res);
}

int main()
{
	while (cin>>n>>m>>p>>a>>b, n||m||p||a||b) {
		fill(d[0], d[0]+30*30, -1);
		rep(i, n) cin >> t[i];
		rep(i, p) {
			int x, y, z; cin >> x >> y >> z;
			d[x-1][y-1]=z;
			d[y-1][x-1]=z;
		}
		solve();
	}
	return 0;
}

Measured memory_bytes: 1264
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
        int side[] = new int[n];
        int max = 0;
        int sum = 0;
        for(int i = 0; i < n; i++){
        	side[i] = sc.nextInt();
            if(max < side[i]){
            	max = side[i];
            }
            sum += side[i];
        }
        if(sum - max > max){
        	System.out.println("Yes");
        }else{
        	System.out.println("No");
        }
    }
}

Measured memory_bytes: 35844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
   	
int main() {
	long long int n, m, v1, v2;
    cin >> n >> m;

    long long int l[m], r[m];

    for (long long int i = 0; i < m; i++)
    {
    	cin >> l[i] >> r[i];
    }

    v1 = l[0];
    v2 = r[0];

    for (long long int i = 1; i < m; i++)
    {
    	v1 = max(v1, l[i]);
    	v2 = min(v2, r[i]);
    }

    if(v2 - v1 >= 0)
    {
    	cout << v2-v1+1;
    } 
    else
    {
    	cout << 0;
    }

	return 0;
}



Measured memory_bytes: 5140
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProconTemplate
{
    //https://atcoder.jp/contests/abc141/tasks/abc141_c
    class abc169_b
    {
        //private static int[] m_aiPrimes;
        //private static int m_iCurPrimeIdx;
        public static void Main(string[] args)
        {
            //string s = Console.ReadLine();

            //string[] asInput = Console.ReadLine().Split(' ');
            //long A = long.Parse(asInput[0]);
            //decimal B = decimal.Parse(asInput[1]);
            //Console.WriteLine(A * (long)(100 * B) / 100);

            int[] xi = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

            for (int i = 0; i < xi.Length; i++)
            {
                if (xi[i] == 0)
                {
                    Console.WriteLine(i + 1);
                    break;
                }
            }

            Console.ReadLine();

        }

    }
}


Measured memory_bytes: 27976
#include <algorithm>
#include <iostream>
#include <vector>
template<typename I>
using DifferenceType = typename std::iterator_traits<I>::difference_type;
template<typename I>
using IteratorCategory = typename std::iterator_traits<I>::iterator_category;
template<typename I>
using ValueType = typename std::iterator_traits<I>::value_type;
// distance
template<typename I>
DifferenceType<I> distance(I f, I l, std::input_iterator_tag) {
    // 事前条件: valid_range(f, l)
    DifferenceType<I> n(0);
    while (f != l) {
        ++f;
        ++n;
    }
    return n;
}
template<typename I>
DifferenceType<I> distance(I f, I l, std::random_access_iterator_tag) {
    // 事前条件: valid_range(f, l)
    return l - f;
}
template<typename I>
DifferenceType<I> mydistance(I f, I l) {
    return distance(f, l, IteratorCategory<I>());
}
// advance
template<typename I>
void advance(I& x, DifferenceType<I> n, std::input_iterator_tag) {
    while (n) {
        --n;
        ++x;
    }
}
template<typename I>
void advance(I& x, DifferenceType<I> n, std::random_access_iterator_tag) {
    x += n;
}
template<typename I>
void myadvance(I& x, DifferenceType<I> n) {
    advance(x, n, IteratorCategory<I>());
}
// // linear find
// template<InputIterator I, Predicate P>
// I find_if(I f, I l, P p) {
//     std::cout << "find_if(InputIterator) is called" << std::endl;
//     while (f != l && !p(*f)) {
//         ++f;
//     }
//     return f;
// }
//
// template<InputIterator I, Predicate P>
// std::pair<I, DifferenceType<I>> find_if_n(
//         I f, DifferenceType<I> n, P p) {
//     while (n && !p(*f)) { ++f; --n; }
//     return {f, n};
// }
// binary search
template<typename I, typename P>
I partition_point_n(I f, DifferenceType<I> n, P p) {
    while (n) {
        I middle(f);
        DifferenceType<I> half(n >> 1);
        advance(middle, half);
        if (!p(*middle)) {
            n = half;
        } else {
            f = ++middle;
            n = n - (half + 1);
        }
    }
    return f;
}
template<typename I, typename P>
I mypartition_point(I f, I l, P p) {
    return partition_point_n(f, distance(f, l), p);
}
// lower_bound
template<typename I>
I mylower_bound(I f, I l, ValueType<I> a) {
    return mypartition_point(f, l,
            [=](ValueType<I> x) { return x < a; });
}
// upper_bound
template<typename I>
I myupper_bound(I f, I l, ValueType<I> a) {
    return mypartition_point(f, l,
            [=](ValueType<I> x) { return x <= a; });
}
int main() {
    int n; std::cin >> n;
    std::vector<int> a(n), b(n), c(n);
    for (int i = 0; i < n; ++i) std::cin >> a[i];
    for (int i = 0; i < n; ++i) std::cin >> b[i];
    for (int i = 0; i < n; ++i) std::cin >> c[i];
    sort(a.begin(), a.end());
    sort(c.begin(), c.end());
    long long ans = 0;
    for (int i = 0; i < n; ++i) {
        auto lb = mylower_bound(a.begin(), a.end(), b[i]);
        auto ub = myupper_bound(c.begin(), c.end(), b[i]);
        ans += (long long)mydistance(a.begin(), lb) * mydistance(ub, c.end());
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    int ans=0;
    while(x!=0||y!=0){
        if(x!=0&&y!=0){
            int min1=min(a+b,c*2);
            ans+=min1;
            x--; y--;
        }
        else if(x==0&&y!=0){
            int min2=min(b,c*2);
            ans+=min2;
            y--;
        }
        else if(x!=0&&y==0){
            int min3=min(a,c*2);
            ans+=min3;
            x--;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
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; }


int main(){
    ll a, b, c, d; cin >> a >> b >> c >> d;
    ll res = a * c;
    chmax(res, a * d);
    chmax(res, b * c);
    chmax(res, b * d);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
int main(void)
{
	int t,n,s;
	int i;
	
	for(i=0;i<4;i++){
		scanf("%d %d",&t,&n);
		if(t==1){
			s=n*6000;
		}
		else if(t==2){
			s=n*4000;
		}
		else if(t==3){
			s=n*3000;
		}
		else if(t==4){
			s=n*2000;
		}
		printf("%d\n",s);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;

static long long INF = (1LL<<62);
const LL C = 998244353;

LL N, K;
//dp[i] はマスiに行ける個数(をCで割ったもの)
LL dp[200004] = {0};
LL sdp[200004] = {0}; //dpの累積和

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N >> K;
	vector<int> L, R;
	for(int i=0; i<K; i++){
		int l, r; cin >> l >> r;
		L.push_back(l);
		R.push_back(r);
	}
	sort(L.begin(), L.end());
	sort(R.begin(), R.end());

	dp[0] = 0; dp[1] = 1;
	sdp[0] = 0; sdp[1] = 1;

	for(int i=2; i<=N; i++){
		for(int j=0; j<K; j++){
			LL l = max(0, i - R[j] - 1);
			LL r = max(0, i - L[j]);
			dp[i] += (sdp[r] - sdp[l]);
			dp[i] %= C;
			if(dp[i] < 0) dp[i] += C;
		}
		sdp[i] = sdp[i-1] + dp[i];
		sdp[i] %= C;
	}
	printf("%lld\n", dp[N]);
	return 0;
}



Measured memory_bytes: 6872
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		boolean flg = false;
		Main main = new Main();
		for (int i = 0; i < T.length(); i++) {
			if (S.equals(T)) {
				flg = true;
				break;
			}else {
				S = main.rotateString(S, true);
			}
		}

		if (flg) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

	}
	//true=right false=left
	public String rotateString(String s,boolean direction) {
		if (s.length() == 0) {
			return s;
		}else {
			//右
			if (direction) {
				s = s.substring(s.length()-1, s.length()) + s.substring(0, s.length()-1);
			}else {
				s = s.substring(1) + s.substring(0, 1);
			}
			return s;
		}
	}

}



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

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

  vector<pair<int, int>> vec;
  int p[m], y[m];
  
  for(int i=0; i<m; i++){
    cin >> p[i] >> y[i];
    vec.push_back(make_pair(y[i],p[i]));
  }
  
  sort(vec.begin(), vec.end());
  
  map<int, int> mp;
  map<int, int> cnt;
  
  for(auto el: vec){
    mp[el.first] = cnt[el.second]++;
  }

  for(int i=0; i<m; i++){
    printf("%06d%06d", p[i], mp[y[i]]+1);
    cout << endl;
  }
}

Measured memory_bytes: 12404
#include <bits/stdc++.h>
#include <string.h>
#define rep(i, n) for(int i = 0; i<(n); i++)
using namespace std;
typedef long long ll;
static const int MAX = 200000; 
//pi = 3.14159265358979323846
//みながら

int main(){

  int n;
  cin >> n;
  int a[n + 1], b[n];
  rep(i, n + 1){
    cin >> a[i];
  }
  rep(i, n){
    cin >> b[i];
  }

  ll count = 0;
  rep(i, n){
    if(a[i] <= b[i]){
      b[i] -= a[i];
      count += a[i];
      if(a[i +1] <= b[i]){
        count += a[i + 1];
        a[i + 1] = 0;
      }else{
        a[i + 1] -= b[i];
        count += b[i];
      }
    }else{
      count += b[i];
    }
  }
  
  cout << count << endl;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
typedef long long ll;
int main() {
//input
int n;
int count = 0;
string s;
cin>>n>>s;

//compute
for(int i=0;i<n-2;i++){
	if('A'==s[i]){
		if(s[i+1]=='B'){
			if(s[i+2]=='C'){
				count++;
			}
		}
	}
}
cout<<count;

//output


	return 0;
}

Measured memory_bytes: 256
// 坊主めくりの結末.cpp : Defines the entry point for the console application.
//
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

void sort(int a[], int n) {
	for (int i = 1; i < n; i++) {
		int v = a[i];
		int j = i - 1;
		while (j >= 0 && a[j] > v) {
			a[j + 1] = a[j];
			j--;
		}
		a[j + 1] = v;
	}
}

int main(void)
{

	int number[101], people[100][10] = { 0 }, field[100] = { 0 }, suffix = 0;

	while (1) {
		int card[100];

		scanf("%d", &number[suffix]);
		if (number[suffix] == 0) {
			break;
		}
		char c;
		getchar();
		for (int i = 0; i < 100; i++) {
			c = getchar();
			if (c == 'M') {
				people[suffix][i % number[suffix]]++;
			}
			else if (c == 'S') {
				field[suffix] += (people[suffix][i % number[suffix]] + 1);
				people[suffix][i % number[suffix]] = 0;
			}
			else if (c == 'L'){
				people[suffix][i % number[suffix]] += (field[suffix] + 1);
				field[suffix] = 0;
			}
		}

		sort(people[suffix], number[suffix]);
		suffix++;
	}

	for (int i = 0; i < suffix; i++) {
		for (int j = 0; j < number[i]; j++) {
			printf("%d ", people[i][j]);
		}
		printf("%d\n", field[i]);
	}

	return 0;
}

Measured memory_bytes: 1036
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()
#define INF ((int)1e9 + 9)

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
struct segtree{
	int SIZE;
	vector<int> maximum, lazy;

	segtree(int n){

		SIZE = 1;
		while(SIZE < n) SIZE *= 2;
		
		maximum.clear();
		maximum.resize(SIZE * 2, 0);
		lazy.clear();
		lazy.resize(SIZE * 2, 0);
	};

	void lazy_evaluate(int k){
		maximum[k] += lazy[k];

		if (k < SIZE - 1){ // k isn't leaf of SegmentTree
			lazy[k * 2 + 1] += lazy[k];
			lazy[k * 2 + 2] += lazy[k];
		} // end if
		lazy[k] = 0;
	} // end function

	void update(int a, int b, int k, int l, int r, int x){
		if (r <= a || b <= l) return;

		if (a <= l && r <= b){
			lazy[k] += x;
			lazy_evaluate(k);
		}else{
			lazy_evaluate(k);
			update(a, b, k * 2 + 1, l, (l + r) / 2, x);
			update(a, b, k * 2 + 2, (l + r) / 2, r, x);
			maximum[k] = max(maximum[k * 2 + 1], maximum[k * 2 + 2]);
			return;
		} // end if
	} // end function 

	int query(int a, int b, int k, int l, int r){
		lazy_evaluate(k);
		if (r <= a || b <= l) return 0;
		if (a <= l && r <= b) return maximum[k];
		else{
			int lch = query(a, b, k * 2 + 1, l, (l + r) / 2);
			int rch = query(a, b, k * 2 + 2, (l + r) / 2, r);

			return max(lch, rch);
		} // end if
	} // end function
};

int main()
{
	int N, H;
	int di[(int)1e5 + 5] = {0};
	int hi[(int)1e5 + 5] = {0};

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> N >> H;
	rep (i, N - 1){
		cin >> di[i] >> hi[i];
	} // end rep

	int currLife = H;
	int ans = 0;

	auto cmp = [](P left, P right){ return left.first != right.first ? left.first < right.first : left.second < right.second; };
	priority_queue<P, vector<P>, decltype(cmp) > que(cmp);	// P(plus, pos) 

	segtree seg(N);

	for (int i = 0; i < N - 1; ++i){
		seg.update(i, i + 1, 0, 0, seg.SIZE, currLife); // update(a, b, k, l, r, x);
		currLife -= di[i];
		que.push(P(hi[i], i));

		while(currLife <= 0){
			P heal = que.top(); que.pop();
			int segMax = seg.query(heal.second, i + 1, 0, 0, seg.SIZE);

			if (heal.first + segMax > H){
				heal.first = H - segMax;
				que.push(P(heal.first, heal.second));
				continue;
			} // end if
		
			int cnt = min((-1 * currLife) / heal.first + 1, (H - segMax) / heal.first);
			ans += cnt;
			currLife += cnt * heal.first;			

			seg.update(heal.second, i + 1, 0, 0, seg.SIZE, cnt * heal.first);
			que.push(P(heal));
		} // end while
	} // end for

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

Measured memory_bytes: 6696
N,M = map(int, input().split())
table = []
ans = 1

for i in range(M):
  a,b = map(int,input().split())
  table.append((a,b))
  
table.sort()
r = N
for a,b in table:
  if r <= a:
    ans += 1
    r = N
  r = min(b,r)
print(ans)

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

typedef long long int   ll;
typedef long double     ld;
typedef pair<ll, ll>    pll;

#define all(x)          x.begin(), x.end()
#define kill(x)         return cout << x << endl, 0;
#define X               first
#define Y               second
#define sep             ' '
#define endl            '\n'
#define fastio          ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define file_io         freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);
#define ld_io           cout << setprecision(10) << fixed;

ll pw(ll a, ll b, ll mod) {
    if (!b)    return 1;
    if (b & 1) return a * pw(a * a % mod, b / 2, mod) % mod;
    return pw(a * a % mod, b / 2, mod) % mod;
}

const ll MAXN  = 1e6 + 10;
const ll INF   = 8e18;
const ll MOD   = 1e9 + 7; // 998244353;
const ll LOG   = 32;      // log2(1e9)
const ll BLOCK = 320;     // sqrt(1e5)

ll n, k, a[MAXN], ps[MAXN], ans;
map<ll , vector<ll>> v;

int main() {
    fastio
    ps[0] = 0;
    v[0].push_back(0);
    cin >> n >> k;
    for (ll i = 1; i <= n; i++) {
        cin >> a[i];
        a[i]--;
        ps[i] = ps[i - 1] + a[i];
        v[ps[i] % k].push_back(i);
    }
    for (auto &i : v) {
        for(ll j = 0 ; j < i.Y.size() ; j++){
            ans += lower_bound(all(i.Y) , i.Y[j] + k) - i.Y.begin() - j - 1;
        }
    }
    cout << ans << endl;
    return 0;
}



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

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

  vector<string> a(n),b(m);
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++)
  {
    cin >> b[i];
  }

  for (int i = 0; i <= n-m; i++)
  {
    for (int j = 0; j <= n-m; j++)
    {
      bool flg = true;
      for (int k = 0; k < m; k++)
      {
        for (int l = 0; l < m; l++)
        {
          if(a[i+k][j+l]!=b[k][l]) flg=false;
        }         
      }
      if(flg){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

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

double minkowski(int* x, int* y, int n, int p) {
    double d = 0.0;
    for (int i = 0; i < n; i++) d += pow(abs(x[i] - y[i]), p);
    return pow(d, 1.0 / p);
}

int minkowski_infinite(int* x, int* y, int n) {
    int max = -1;
    for (int i = 0; i < n; i++) max = fmax(max, abs(x[i] - y[i]));
    return max;
}

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

    int x[100], y[100];
    for (int i = 0; i < n; i++) cin >> x[i];
    for (int i = 0; i < n; i++) cin >> y[i];

    cout.setf(ios::fixed , ios::floatfield);
    cout << minkowski(x, y, n, 1) << endl;
    cout << minkowski(x, y, n, 2) << endl;
    cout << minkowski(x, y, n, 3) << endl;
    cout << minkowski_infinite(x, y, n) << endl;

    return 0;
}

Measured memory_bytes: 1296
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define REP1(i,n) for(int i=1; i<=(int)(n); i++)
#define SORT(v) sort(v.begin(), v.end())
#define REVERSE(v)  reverse(v.begin(), v.end())
using namespace std;

const int INF = 0x3f3f3f3f;

int main() {
  int N,K; cin>>N>>K;
  vector<long long> x(N); REP(i,N) cin>>x[i];
  long long ans = INF;

  int i = 0;
  while(i+K-1 < N) {
    if(x[i] < 0 && x[i+K-1] < 0)
        ans = min(ans, abs(x[i]));
    else if(x[i] >= 0 && x[i+K-1] >= 0)
        ans = min(ans, x[i+K-1]);
    else
        ans = min(ans, min(abs(x[i])*2 + x[i+K-1], abs(x[i]) + x[i+K-1]*2));
    i++;
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 1024
using System;

public class hello
{
    const int MOD = 1000000007;
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = int.Parse(line[0]);
        var b = int.Parse(line[1]);
        var ans = getAns(b,a);
        Console.WriteLine(ans);
    }
    public static long getAns(int a, int b)
    {
        var ans = 1L;
        for (int i = a; i >= a-b+1; i--)
        {
            ans *= i;
            ans %= MOD;
        }
        return ans;
    }
}




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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
using ll = long long;

int main() {
    FAST;

    int n;
    cin >> n;
    
    cout << ((n >= 30) ? "Yes" : "No");

    return 0;
}


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

// flag?????¨????????????????????????
int bubbleSort(int arr[], int n) {
	int count = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (arr[j] < arr[j -1]) {
				// ??£??\????´????????????????
				swap(arr[j], arr[j - 1]);
				flag = 1;
				count++;
			}
		}
	}
	return count;
}

int main() {
	int arr[100], n, count;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	count = bubbleSort(arr, n);

	for (int i = 0; i < n; i++) {
		if (i) {
			cout << " ";
		}
		cout << arr[i];
	}
	cout << endl;
	cout << count << endl;

	return 0;
}

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

int math(int x, int y, int z)
{
    return x * x + y * y + z * z + x * y + x * z + y * z;
}
int main()
{
    int N;
    cin >> N;
    int a[10050] = { 0 };
    int i, ii, iii;
    i = 1;
    int maxi = i;
    int maxii = 10000000;
    int maxiii = 100000000;
    for (i = 1; i < 100; i++)
    {
        for (ii = 1;ii<100; ii++)
        {
            for (iii = 1; iii < 100; iii++)
            {
                int temp = math(i, ii, iii);
                if (temp <= N)
                {
                    a[temp - 1]++;
                }
            }
               
        }
    }
    for (int i = 0; i < N; i++)
    {
        cout << a[i] << endl;
    }
}

Measured memory_bytes: 3632
n = int(input())
h_list = list(map(int, input().split()))
dp = [0 for _ in range(n)]
for i, h in enumerate(h_list):
    if i == 0:
        dp[i] = 0
    elif i == 1:
        dp[i] = abs(h - h_list[i-1])
    else:
        dp[i] = min(dp[i-1] + abs(h - h_list[i-1]), dp[i-2] + abs(h - h_list[i-2]))
print(dp[-1])

Measured memory_bytes: 13980
#ifdef LOCAL111
#else
	#define NDEBUG
#endif
#include <bits/stdc++.h>
const long long INF = 1e15;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
#define rangej(a,b,c) ((a) <= (c) and (c) < (b))
#define rrangej(b,c) rangej(0,b,c)
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;
typedef pair<LL,LL> LP;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

LL f(LL b, LL n){
	if(b == 1) return n;
	LL res = 0;
	while(n != 0){
		res += n%b;
		n /= b;
	}
	return res;
}

int main()
{
	ios_init();
	LL n,s;
	while(cin >> n >> s){
		LL ans = INF;
		if(s == 1 and n != 1){
			ans = n;
		}
		if(s == n){
			ans = n+1;
		}
		for(LL i = 2; i <= sqrt(n); ++i) {
			LL ret = f(i,n);
			if(ret == s){
				ans = min(ans,i);
				break;
			}
		}
		if(ans == INF){
			stack<LL> sta;
			for(LL i = 1; i*i <= n; ++i) {
				sta.push((n)/i+1);
			}
			while(SZ(sta) > 1){
				LL l,r;
				l = sta.top();
				sta.pop();
				r = sta.top();
				LL ret = f(l,n);
				LL u = n/l;
				// DEBUG(l);
				// DEBUG(u);
				// FOR(i,l,r){
				// 	DEBUG(f(i,n));
				// }
				if(ret >= s and (ret-s)%u == 0 and (ret-s)/u < r-l){
					ans = l+(ret-s)/u;
					break;
				}
			}
		}
		if(ans != INF) cout << ans << endl;
		else cout << -1 << endl;
	}
	return 0;
}


Measured memory_bytes: 2816
import java.util.*;

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

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int[] a = new int[3];
        a[0] = sc.nextInt();
        a[1] = sc.nextInt();
        a[2] = sc.nextInt();

        boolean[] e = new boolean[3];

        int ne = 0;
        for (int i = 0; i < 3; i++) {
            if (a[i] % 2 == 0) {
                ne++;
                e[i] = true;
            }
        }

        int ans = 0;
        if (ne == 0 || ne == 3) {
            // no change
        } else {
            if (ne % 2 == 0) {
                for (int i = 0; i < 3; i++) {
                    if (e[i]) {
                        a[i]++;
                    }
                }
            } else {
                for (int i = 0; i < 3; i++) {
                    if (!e[i]) {
                        a[i]++;
                    }
                }
            }
            ans++;
        }

        // find max
        int max = -1;
        int idx = -1;
        for (int i = 0; i < 3; i++) {
            if (max < a[i]) {
                idx = i;
                max = a[i];
            }
        }
        for (int i = 0; i < 3; i++) {
            if (i != max) {
                ans += Math.abs(a[idx] - a[i]) / 2;
            }
        }

        System.out.println(ans);
        return;
    }

}

Measured memory_bytes: 22996
X = int(input())

for a in range(-1000,1001):
  for b in range(-1000,1001):
    if a**5 - b**5 == X :#or (-a)**5 - b**5 ==X or a**5 - (-b)**5 == X or (-a)**5 - (-b)**5 == X:
      print("{} {}".format(a,b))
      exit()

Measured memory_bytes: 65792
#include<bits/stdc++.h>
#define LL long long
#define maxn 100005
using namespace std;
struct node{
    LL len;
    LL en;
}kt[2*maxn];
bool cmp(node A,node B){
    return A.en<B.en;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%lld%lld",&kt[i].len,&kt[i].en);
    sort(kt,kt+n,cmp);
    LL now=kt[0].len,en=kt[0].en;
    for(int i=1;i<n;i++){
        if(now>en){
            printf("No\n");
            return 0;
        }
        now+=kt[i].len;
        en=kt[i].en;
    }
    if(now>en){
        printf("No\n");
        return 0;
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std; 
#define int int64_t
#define itn int
#define fi first
#define se second 
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,b;
  int sum=0,w;
  vector<int> a;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>b;
    a.push_back(b);
  }
  sort(a.begin(),a.end());
  for(int i=0;i<n-1;i++){
    if(sum<(a[n-1]*(a[n-1]+1)/2)-(a[n-1]-(a[i])*((a[n-1]-a[i]+1))/2)){
      sum=a[n-1]*(a[n-1]+1)/2-(a[n-1]-(a[i])*((a[n-1]-a[i]+1))/2);
      w=a[i];
    }
  }
  cout<<a[n-1]<<" "<<w<<"\n";
}


Measured memory_bytes: 4288