akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://atcoder.jp/contests/abc122/tasks/abc122_b

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

    int max = 0;
    for (int i = 0; i < S.length(); i++) {
        int s = 0;
        for (int j = i; j < S.length(); j++) {
            if (S[j]!='A' && S[j] != 'C' && S[j] != 'G' && S[j] != 'T') break;
            s++;
        }
        max = std::max(max, s);
    }

    cout << max << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long     ll;
#define fast          ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define last          freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fr            first
#define sc            second
#define lcm(a,b)      (a*b)/__gcd(a,b)
#define com(i,n)      for(int i=0;i<n;i++)
#define dom(i,n)      for(int i=1;i<=n;i++)
#define mom(i,n)      for(int i=n;i>=0;i--)
#define sortI(a,n)    sort(a,a+n)
#define sortD(a,n)    sort(a,a+n,greater<int>())
#define sortvi(a)     sort(a.begin(),a.end())
#define sortvd(a)     sort(a.begin(),a.end(),greater<int>())
#define sumall(a,x)   accumulate(a.begin(),a.end(),x)
#define pi            3.14159265358979323846264338327950
#define endl          '\n'
using namespace std;
int main()
{
    ll n,sum=0;
    cin>>n;
    if(n==360)
        cout << 2 << endl;
    else
    {
        dom(i,100000)
        {
             sum+=n;
             if(sum%360==0)
             {
                  cout << i << endl;
                  break;
             }
        }
    }
}


Measured memory_bytes: 3500
//#pragma GCC optimize ("-O3","unroll-loops")
#include<bits/stdc++.h>
 
using namespace std;
 
#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
#define move(x) ans.push_back(x),c[x]--,now=x;
 
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9+7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 2e18;

vector<int> calc(int A,int B,int N){
	vector<int>ret;
	if(N==1){
		ret.push_back(A);ret.push_back(B);
		return ret;
	}
	int s=0,t=B^A;
	if(t<(1<<(N-1))){
		ret=calc(s,t,N-1);
		vector<int>ret2=calc(s^(1<<(N-1)),ret[1]^(1<<(N-1)),N-1);
		REP(i,ret2.size()){
			ret.insert(ret.begin()+1+i,ret2[i]);
		}
		REP(i,ret.size()){
			ret[i]^=A;
		}
	}
	else{
		vector<int>ret1=calc(0,1,N-1);
		vector<int>ret2=calc(1^(1<<(N-1)),t,N-1);
		REP(i,ret1.size())ret.push_back(ret1[i]);
		REP(i,ret2.size())ret.push_back(ret2[i]);
		REP(i,ret.size())ret[i]^=A;
	}
	return ret;
}
void solve() {
	int N,A,B;
	cin>>N>>A>>B;
	if(__builtin_popcount(A)%2==__builtin_popcount(B)%2){
		print("NO");return;
	}
	else{
		print("YES");
		vector<int>ans=calc(A,B,N);
		REP(i,ans.size()){
			pe(ans[i]);
		}cout<<endl;
	}
}

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

	solve();
}

Measured memory_bytes: 2740
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int n,a,b;
  cin>>n>>a>>b;
  int cnt=0;
  for(int i=1;i<n+1;i++){
    int g=i;
    int s=0;
    for(int j=5;j>=0;j--){
      s+=g/int(pow(10,j));
      g-=g/int(pow(10,j))*int(pow(10,j));
    }
    if(a<=s&&s<=b) cnt+=i;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 3948
import java.util.Scanner;

public class Main {
    private static int debit=100000;
    private static final double rate=1.05;

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n=scan.nextInt();
        for(int i=0;i<n;i++){
            debit*=rate;
            if(debit%1000>0){
                debit/=1000;
                debit=(debit+1)*1000;
            }
        }
        System.out.println(debit);
    }
}

Measured memory_bytes: 17296
n = int(input())
dat_a = list(map(int, input().split()))
dat_b = list(map(int, input().split()))
dat_c = list(map(int, input().split()))
dat_a.sort()
dat_b.sort()
dat_c.sort()

import bisect
res = 0
for i in range(n):
    x = bisect.bisect_left(dat_a, dat_b[i])
    y = bisect.bisect_right(dat_c, dat_b[i])
    res += x * (n - y)
print(res)

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

using namespace std;

int N, Left[100009], Right[100009], sz[100009];
multiset < long long > L, R;
long long leftDeflection, rightDeflection, ans = 0;

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=1; i<=N; i++)
    scanf ("%d %d", &Left[i], &Right[i]), sz[i] = Right[i] - Left[i];
L.insert (Left[1]), leftDeflection = 0;
R.insert (Left[1]), rightDeflection = 0;
for (int i=2; i<=N; i++)
{
    int A = sz[i - 1], B = sz[i];
    ///f(x) = min (f(x - A), ..., f(x + B)
    leftDeflection += B, rightDeflection += A;
    long long x = Left[i], st = (*L.rbegin ()) - leftDeflection, dr = (*R.begin ()) + rightDeflection;
    if (st <= x && x <= dr)
    {
        L.insert (x + leftDeflection);
        R.insert (x - rightDeflection);
        continue;
    }
    if (x < st)
    {
        ans += st - x;
        auto it = L.end (); it --;
        L.erase (it);

        L.insert (x + leftDeflection);
        L.insert (x + leftDeflection);
        R.insert (st - rightDeflection);
        continue;
    }
    ans += x - dr;
    R.erase (R.begin ());

    L.insert (dr + leftDeflection);
    R.insert (x - rightDeflection);
    R.insert (x - rightDeflection);
}
printf ("%lld\n", ans);
return 0;
}


Measured memory_bytes: 10752
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr,0,sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9+7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t  main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int n, m;
        cin >> n >> m;
        string s;
        for(int i = 0; i < n; i++){
            s += '#';
        }
        int flag = 0;
        for(int i = 0; i < m; i++){
            int pos;
            char d;
            cin >> pos >> d;
            pos--;
            if(s[pos] != '#' and s[pos] != d){
                flag = 1;
            }else{
                s[pos] = d;
            }
        }
        if(n != 1 and s[0] == '0'){
            flag = 1;
        }
        if(flag){
            cout << "-1\n";
            return 0;
        }
        if(n != 1 and s[0] == '#'){
            s[0] = '1';
        }
        for(int i = 0; i < n; i++){
            if(s[i] == '#'){
                s[i] = '0';
            }
        }
        cout << s << '\n';
    } 
}

Measured memory_bytes: 31488
#include <bits/stdc++.h>
#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 all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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;}
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;}
int const INF = 1001001001;


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

string s;
cin >> s;
s = 'a' + s;
s = s + 'a';
int cnt = 0;
vi v;
string t = "a";
rep(i,SZ(s)) {
    if(i == 0) continue;
    if(s[i] == 'x') cnt++;
    else {
        t.push_back(s[i]);
        v.push_back(cnt);
        cnt = 0;
    }
}
int n = SZ(v);
int ans = 0;
for(int l = 0, r = n-1; l < r; ++l, --r) {
    if(v[l] == v[r]) continue;
    int m = max(v[l],v[r]);
    ans += m - v[l];
    ans += m - v[r];
    v[l] = m, v[r] = m;
}

bool ok = true;
for(int l = 0, r = SZ(t)-1; l < r; ++l,--r) {
    if(t[l] != t[r]) ok = false;
}

if(ok) cout << ans << endl;
else cout << -1 << endl;
return 0;
}

Measured memory_bytes: 1132
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        int remain = int.Parse(Reader.ReadLine());
        int ans = GetAns(remain);
        Console.WriteLine(ans);
    }


    private Dictionary<int, int> dic = new Dictionary<int, int>();
    private int GetAns(int remain) {
        if(remain < 6) {
            return remain;
        }

        if(dic.ContainsKey(remain)) {
            return dic[remain];
        }

        int mul = 9;

        int ans = remain;
        for (int i = 1; i <= remain; i++) {
            if(mul > remain) {
                break;
            }
            ans = Math.Min(ans, GetAns(remain - mul) + 1);
            mul = mul * 9;
        }

        mul = 6;

        for (int i = 1; i <= remain; i++) {
            if (mul > remain)
            {
                break;
            }
            ans = Math.Min(ans, GetAns(remain - mul) + 1);
            mul = mul * 6;
        }

        dic[remain] = ans;
        return ans;
    }

    public class Reader
    {
        static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"




44852


";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}

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

int main(){
  int N;
  cin>>N;
  int a[N];
  for (int i=0;i<N;i++) cin>>a[i];
  int minsum=4000000;
  for(int i=-100;i<=100;i++){
    int sum=0;
    for(int j=0;j<N;j++){
      sum=sum+pow((a[j]-i),2);
    }
    minsum=min(minsum,sum);
  }
  cout<<minsum<<endl;
  return 0;
}

  

Measured memory_bytes: 256
// Problem : B - One Clue
// Contest : AtCoder Beginner Contest 137
// URL : https://atcoder.jp/contests/abc137/tasks/abc137_b
// Memory Limit : 1024,000000 MB 
// Time Limit : 2000,000000 milisec 
// Powered by CP Editor (https://github.com/coder3101/cp-editor2)

#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  cout.precision(16);
  cout << fixed;
  
  int k;
  int x;
  cin >> k >> x;
  
  for (int i = x - k + 1; i <= x; ++i)
    cout << i << ' ';
    
  for (int i = x + 1; i < x + k; ++i)
    cout << i << ' ';
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <vector>
#include <numeric>
#include <string>
#include <bitset>
#include <queue>
#include <tuple>
#include <regex>
#include <cmath>
#include <map>
#include <cstring>


using namespace std;
int main() {
	int n, k, q, sum = 1;
	cin >> n >> k >> q;
	deque<int>d(q);
	deque<int>b(n);
	for (int i = 0; i < q; i++)
		cin >> d[i];
	sort(d.begin(), d.end());

	for (int i = 1; i < q; i++) {
		if (d[i] == d[i - 1]) {
			sum++;
			if (i == q - 1) {
				b[d[i] - 1] = sum;
				break;
			}
		}

		else {
			b[d[i - 1] - 1] = sum;
			sum = 1;
		}
	}

	for (int i = 0; i < n; i++) {
		if (b[i] > q - k)
			cout << "Yes" << endl;
		else cout << "No" << endl;
	}


	return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>

int main()
{
  int n;
  int m = 1;
  int power = 0;
  
  scanf("%d", &n);

  while (n / 2) {
    n /= 2;
    power++;
  }

  while (power--) {
    m *= 2;
  }
  
  printf("%d\n", m);

  return 0;
}



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

#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define MAX (int)1e9 + 99
#define vi vector<int>
#define vb vector<bool>
#define ll long long
#define ull unsigned long long
#define vll vector<ll>
#define pa pair<int, int>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define MOD 998244353
#define bitcnt(x) __builtin_popcount(x)
#define gcd(a,b) __gcd(a,b)
#define all(x) (x).begin(),(x).end()
#define ts(x) to_string(x)
#define set0(x) memset(x, 0, sizeof(x))
ll fastPowMod(ll a, ll p,ll mod){ if(p==0) return 1; ll z = fastPowMod(a,p/2,mod); z = (z*z)%mod; if(p%2) z = (z*a)%mod; return z; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is;}
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) {if (!v.empty()) {os << v.front();for (int i = 1; i < v.size(); ++i) os << ' ' << v[i];} return os;}

string s,t;
void print(int a, int b, int dp[][3001], string &ans)
{
    if(a==0 || b==0) return;
    if(s[a-1]==t[b-1])
    {
        print(a-1,b-1,dp,ans);
        cout<<s[a-1];
    }
    else if(dp[a-1][b]>dp[a][b-1])
    print(a-1,b,dp,ans);
    else print(a,b-1,dp,ans);
}

void solve()
{
    
    cin>>s;
    cin>>t;
    int sLen = s.length(), tLen = t.length();
    string ans="";
    int dp[sLen+1][3001];
    set0(dp);
    srep(i,1,sLen)
    {
        srep(j,1,tLen)
        {
            if(s[i-1]==t[j-1])
            {
                dp[i][j] = 1 + dp[i-1][j-1];
            }
            else
            {
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            } 
        }
    }
    print(sLen,tLen,dp, ans);
    
   
}

int main()
{
    fastio;
    
    solve();
    cout<<"\n";
    
    return 0;
}

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

//少数点表示
//cout <<std::fixed << std::setprecision(14)

int main(){
    //cin.tie( 0 ); ios::sync_with_stdio( false );
    int n;
    cin>>n;
    vector<int>p(n);
    vector<int>q(n);
    vector<int>r(n);
    rep(i,n)cin >> p[i];
    rep(i,n)cin >> q[i];
    rep(i,n)r[i]=i+1;    
    map<vector<int>,int> mp;
    int count=1;
    do{
        mp[r]=count;
        count++; 
    }while(next_permutation(r.begin(),r.end()));
    int ans=abs(mp[p]-mp[q]);
    cout << ans;

}

Measured memory_bytes: 5248
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            if b not in fct:
                fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

A, B = map(int, input().split())
g = gcd(A,B)
print(len(factorize(g))+1)

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

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

using ll = long long;
using P = pair<int,int>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

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

int main(){
    ll N;
    cin>>N;
    ll ans = 0LL;
    for(ll i = 1; i <= N; i++){
        ans += i*(N/i+1)*(N/i)/2LL;
    }
    cout<<ans<<endl;
}
    

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 998244353
#define int long long
#define ll long long
#define EPS 0.000000001
#define ld long double
#define inf 5e18
#define N 3005
#define K 17

int dp[N][N];

int fact[N],ifact[N];

ll fastexpom(ll a,ll b,ll m)
{
    ll res=1;
    a = a % m;
    while(b>0)
    {
        if(b % 2 == 1)
            res = (res * a) % m;
        a = (a * a) % m;
        b/=2;
    }
    return res;
}
ll modinv(ll a, ll m=1000000007)
{
  return fastexpom(a,m-2,m);
}
void preprocess()
{
    fact[0] = 1;
    ifact[0] = 1;
    for(int i = 1;i < N;i++)
    {
        fact[i] = (fact[i-1] * i)%mod;
        
    }
    ifact[N - 1] = modinv(fact[N - 1], mod);
    for(int i  = N - 2;i >= 1;i--)
    {
        ifact[i] = (ifact[i + 1] * (i + 1)) % mod;
        // assert(ifact[i] == modinv(fact[i], mod));
    }
}

int nCr(int n,int r)
{
    if(n == 0 and r == 0)
        return 1;
    if(r > n or r < 0 or n == 0)
        return 0;
    int ans = (fact[n] * ifact[n-r])%mod;
    ans = (ans * ifact[r])%mod;
    return ans;
}
int a, b, c, d;
int rec(int x,int y)
{
    if(x > c or y > d)
        return 0;
    
    if(x == c and y == d)
        return 1;
    
    if(dp[x][y] == -1)
    {   
        int& ans = dp[x][y];
        ans = 0;
        ans = (y * rec(x + 1,y)) % mod;;
        ans = (ans + (x * rec(x , y + 1))%mod) % mod;
        ans = ((ans - ((x * y) % mod * rec(x + 1,y + 1)) % mod)%mod + mod)%mod;
        // cerr << x << " " << y << " " << ans << endl;
        return ans;
    }
    else
        return dp[x][y];
}

int32_t main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("int.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    // preprocess();
    memset(dp,-1,sizeof(dp));
    cin >> a >> b >> c >> d;
    cout << rec(a,b);
    
    return 0;
    
}   

Measured memory_bytes: 74504
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.parents=[-1]*n

    def find(self,x): #根を見つける、繋ぎ直す
        if self.parents[x]<0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]
    
    def unite(self,x,y): #x,yの含むグループを併合する
        x=self.find(x)
        y=self.find(y)

        if x==y:
            return
        
        if self.parents[x]>self.parents[y]:
            x,y=y,x

        self.parents[x]+=self.parents[y]
        self.parents[y]=x
    
    def same(self,x,y):#xとyが同じグループにいるか判定
        return self.find(x)==self.find(y)
    
    def members(self,x):#xと同じグループのメンバーを列挙
        root=self.find(x)
        return [i for i in range(self.n) if self.find(i)==root]
    
    def size(self,x):#xが属するグループのメンバーの数
        return -self.parents[self.find(x)]
    
    def roots(self):#ufの根を列挙
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):#グループの数を数える
        return len(self.roots())

    def all_group_members(self):#根:メンバの辞書を返す
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):#print()での表示用
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
    n,m,k=map(int,input().split())
    F=[tuple(map(int,input().split())) for _ in range(m)]
    B=[tuple(map(int,input().split())) for _ in range(k)]
   

    uf=UnionFind(n)
    for a,b in F:
        a-=1
        b-=1
        uf.unite(a,b)
      
    cnt=[0]*n
    for i in range(n):
        cnt[i]=uf.size(i)-1
    
    for a,b in F:
        a-=1
        b-=1
        if uf.same(a,b):
            cnt[a]-=1
            cnt[b]-=1
    
    for c,d in B:
        c-=1
        d-=1
        if uf.same(c,d):
            cnt[c]-=1
            cnt[d]-=1
    print(*cnt)
   
if __name__=='__main__':
    main()

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

int main(){
  // 入力
  string S; // 数字の文字列
  long long tmp = 0; // 一時的な計算値を保持する変数
  long long sum = 0; // 合計

  cin >> S; 

  int digit = S.size() - 1; // 入力文字列の桁数 - 1

  // ビット全探索 ビットパターン 2^(digit)
  for (int i = 0; i < (1 << digit); ++i) {
    tmp = S[0] - '0'; // 文字列から数値に変換して保持
    // ビットパターンと'+'が入る位置を関連付け
    // "1":'+'が入る "0":'+'が入らない
    // '+'が入るか一桁ずつ確認
    for (int j = 0; j < digit; ++j) {
      // '+'が入ったら保持値を合計に足し、0を代入
      if (i & (1 << j)) {
        sum += tmp;
        tmp = 0;
      }
      // '+'が入らなかったら保持値を10倍して次の桁を加算
      tmp = tmp * 10 + S[j + 1] - '0';
    }
    sum += tmp;
  }
  // 出力
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pi 3.14159265358979323846264338327950L
int main(){
  long double a,b,h,m;
  cin >> a >> b >> h >> m;
  //単針が何度か
  long double x = 30 * (h + ((long double)m/60));
  //長針が何度か
  long double y = m * 6;
  long double arg;
  if(x > y){
    arg = x - y;
  }
  else{
    arg = y - x;
  }
  if(arg > 180){
    arg = 360 - arg;
  }
  if(arg == 180) {
      cout << a+b;
      return 0;
  } else if(arg == 0) {
      cout << abs(a-b);
      return 0;   
  }
  arg *= ((long double)pi/180);
  
  long double ans = a*a + b*b - 2*a*b*cos(arg);
  cout << fixed << setprecision(20) << sqrt(ans) << endl;
                
}

Measured memory_bytes: 4036
package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &slice[i])
	}

	min := 1000000
	for i := 0; i <= 100; i++ {
		total := 0
		for j := 0; j < n; j++ {
			total += (slice[j] - i) * (slice[j] - i)

		}
		if min > total {
			min = total
		}
	}

	fmt.Println(min)
}



Measured memory_bytes: 1836
#include <iostream>
#include <vector>

int main() {
	int t, n, s, f;
	std::cin >> t;
	while (t != 0) {
		std::cin >> n;
		for (auto i = 0; i < n; ++i) {
			std::cin >> s >> f;
			t -= f - s;
		}
		if (t > 0) {
			std::cout << t << std::endl;
		}
		else {
			std::cout << "OK" << std::endl;
		}
		std::cin >> t;
	}
}


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

int main(){
    int n,x;
    cin >> n >> x;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    std::sort(a.begin(), a.end());
    int num = 0;
    for(int i = 0; i < n; i++){
        x -= a[i];
        if(x < 0) break;
        num++;
    }
    if(x > 0) num--;
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;

/*
  最小全域木

  重み付きグラフの最小全域木の辺の重みの総和を計算する．
  最小全域木とは？：グラフで，すべての頂点に到達できるものの中で，　辺の重みが最小のもの
  プリムのアルゴリズム

*/

static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY= 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

int prim(){
  int u, minv;
  int d[MAX], p[MAX], color[MAX];
  //d: MSTに属する頂点とそれ以外の頂点の中で，重みが最小の辺の重み
  //p: p[v]  MSTにおける頂点vの親
  //color 訪問状態

  //初期化
  for(int i = 0; i < n; i++){
    d[i] = INFTY;
    p[i] = -1;
    color[i] = WHITE;
  }

  d[0] = 0;

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


int main(){
  cin >> n;

  //入力
  REP(i,n)REP(j,n){
    int e;
    cin >> e;
    if(e == -1) M[i][j] = INFTY;
    else M[i][j] = e;
  }

  cout << prim() << endl;

  return 0;
}



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

int l[9];
int A,B,C;

int dfs(int depth,int a, int b, int c,int n){
  int i,ans=3000;
  int ret0,ret1,ret2,ret3;
  if(depth==n) {
    if(min(min(a,b),c)==0) return 3000;
    return abs(A-a)+abs(B-b)+abs(C-c)-30;
  }

  ret0=dfs(depth+1,a,b,c,n);
  ret1=dfs(depth+1,a+l[depth],b,c,n)+10;
  ret2=dfs(depth+1,a,b+l[depth],c,n)+10;
  ret3=dfs(depth+1,a,b,c+l[depth],n)+10;

  return min(min(ret0,ret1),min(ret2,ret3));
}

int main(){
  int n; cin>>n>>A>>B>>C;
  int i,j;
  for(i=0;i<n;i++) cin>>l[i];
  int ans;
  ans = dfs(0,0,0,0,n);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int x, n;
    cin >> x >> n;
    int ans = 0;
    vector<int> A(n);
    for(auto &a : A) cin >> a;
    for(int i = 1; i <= 101 ; i++) {
        bool flag = 0;
        rep(j, n) if (i == A[j]) {
            flag = 1;
        }
        if(flag) continue;
        if (abs(i - x) < abs(ans - x)) ans = i;
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 3628
#23
N = int(input())
d,x = map(int,input().split())
an = []
num = 0
for i in range(N):
    a = int(input())
    #an.append(a)
    for i in range(101):
        if i*a+1 <=d:
            num += 1
        else:
            break

    
print(num+x)
    

Measured memory_bytes: 9032
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;

const int N=200005;
const int mod=1000000007;

struct E{
	int to,next;
}mem[N<<1];
int h,t,num,n,x,y,m,ans,res,sum,ns,siz,ssr;
int dp[N],sz[N],head[N],tp[N],q[N],fac[N],inv[N],d[N];
bool vis[N];

void addedge(int x,int y){
	num++;
	mem[num].to=y; mem[num].next=head[x];
	head[x]=num; d[x]++;
}

int quickpow(int x,int y){
	int s=1;
	for (;y;y>>=1,x=1ll*x*x%mod)
		if (y&1) s=1ll*s*x%mod;
	return s;
}

void init(int n){
	int i; fac[0]=fac[1]=inv[0]=inv[1]=1;
	for (i=1;i<=n;i++) fac[i]=1ll*fac[i-1]*i%mod;
	inv[n]=quickpow(fac[n],mod-2);
	for (i=n-1;i>=1;i--) inv[i]=1ll*inv[i+1]*(i+1)%mod;
}

int C(int x,int y){
	if (x<y) return 0;
	return 1ll*fac[x]*inv[y]%mod*inv[x-y]%mod;
}

void add(int &x,int y){
	x+=y;
	(x>=mod)?x-=mod:0;
}

void bfs(int st){
	int k,u,j;
	h=t=0; q[++t]=st;
	while (h<t){
		k=q[++h]; vis[k]=1;
		for (j=head[k];j;j=mem[j].next){
			u=mem[j].to;
			if (!vis[u]){
				q[++t]=u; vis[u]=1;
			}
		}
	}
}

void topsort(){
	int k,u,j;
	while (h<t){
		k=tp[++h];
		for (j=head[k];j;j=mem[j].next){
			u=mem[j].to; d[u]--;
			if (d[u]==1) tp[++t]=u;
		}
	}
}

void dfs(int k,int pre,int rt){
	int u,j; bool tag=0;
	for (j=head[k];j;j=mem[j].next){
		u=mem[j].to;
		if (u==pre||u==rt) continue;
		dfs(u,k,rt); tag=1;
	}
	if (!tag){
		sz[k]=dp[k]=1;
		return;
	}
	sz[k]=0; dp[k]=1;
	for (j=head[k];j;j=mem[j].next){
		u=mem[j].to;
		if (u==pre||u==rt) continue;
		if (u<pre){
			dp[k]=1ll*dp[k]*C(sz[k]+sz[u],sz[u])%mod*dp[u]%mod;
			sz[k]+=sz[u];
		}
		else{
			ssr=1ll*ssr*C(siz+sz[u],sz[u])%mod*dp[u]%mod;
			siz+=sz[u];
		}
	}
	sz[k]++;
}

void solve(int x,int &res,int &ns){
	int i,j,k,st=0;
	ns=0; res=0;
	bfs(x);
	ns=t; m=0; h=t=0;
	for (i=1;i<=ns;i++){
		k=q[i];
		for (j=head[k];j;j=mem[j].next) m++;
		if (d[k]==1) tp[++t]=k;
	}
	if (m/2!=ns) return;
	topsort(); t=0;
	for (i=1;i<=ns;i++)
		if (d[q[i]]>1&&q[i]>st) st=q[i];
	for (j=head[st];j;j=mem[j].next)
		if (d[mem[j].to]>1) tp[++t]=mem[j].to;
	for (i=1;i<=t;i++){
		k=tp[i]; ssr=1; siz=0;
		dfs(st,k,st);
		ssr=1ll*ssr*C(siz+sz[st],sz[st])%mod*dp[st]%mod;
		add(res,ssr);
	}
}

int main(){
	int i;
	scanf("%d",&n);
	for (i=1;i<=2*n;i++){
		scanf("%d%d",&x,&y);
		addedge(x,y+n); addedge(y+n,x);
	}
	init(n*2);
	ans=1;
	for (i=1;i<=n;i++)
		if (!vis[i]){
			solve(i,res,ns);
			ans=1ll*ans*C(sum+ns,ns)%mod*res%mod;
			sum+=ns;
		}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 13184
#include <iostream>
#include <algorithm>
#define llint long long int

using namespace std;

llint N;
llint A[100005], B[100005], C[100005];
llint BC[100005], sumBC[100005];
int main(void)
{
	cin >> 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);
	
	for(int i = 0; i < N; i++){
		BC[i] = (C+N) - upper_bound(C, C+N, B[i]);
	}
	llint sum = 0;
	for(int i = N-1; i >= 0; i--){
		sum += BC[i];
		sumBC[i] = sum;
	}
	
	llint ans = 0;
	for(int i = 0; i < N; i++){
		ans += sumBC[upper_bound(B, B+N, A[i]) - B];
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4224
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

using namespace std;
using ll = long long;
using P = pair<int, int>;

constexpr ll mod = 998244353;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());


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

  int n, m; cin >> n >> m;
  map<int, int> mp;
  rep(i, n) {
    int a; cin >> a;
    mp[a]++;
  }

  vector<P> vec(m); // pair, count
  for(auto e: mp) {
    auto pos = e.first%m;
    auto pair = e.second/2*2;
    vec[pos].first += pair;
    vec[pos].second += e.second;
  }

  //rep(i, m) {debug(vec[i].first);debugln(vec[i].second);}

  int ans = vec[0].second/2;
  //debugln(ans);
  for(int i=1; i<=m/2; i++) {
    int j=m-i;
    if (i==j) {
      ans += vec[i].second/2;
    } else {
      auto mi = min(vec[i].second, vec[j].second);
      ans += mi;
      ans += min(vec[i].second-mi, vec[i].first)/2;
      ans += min(vec[j].second-mi, vec[j].first)/2;
    }
    //debug(i);debugln(ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
string a, b;
int n, m;
int dp[3005][3005];
string res = "";

void recon(int i, int j) {
    if(i <= 0 || j <= 0) return ;
    if(a[i-1]==b[j-1]) {
        res += a[i-1];
        recon(i-1, j-1);
       // cout << "here" << endl;
    }
    else if(dp[i-1][j] > dp[i][j-1]) recon(i-1, j);
    else recon(i, j-1);
}
int main() {
    cin >> a >> b;
    n = a.size(), m = b.size();
    if(a[0] == b[0]){dp[1][1] = 1;} //cout << "here; " << endl;}
    for(int i = 1; i <= n;  i++) {
        for(int j =1; j <= m; j++) {
            if(a[i-1] == b[j-1]) {
                dp[i][j] = dp[i-1][j-1] + 1;
            }
            else dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
        }
    }
    recon(n, m);
    for(int i = dp[n][m]-1; i >= 0; i--) {
        cout << res[i];
    }
    return 0;
}

Measured memory_bytes: 35456
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <map>
using namespace std;

bool flg=false;

int solve(vector<int> pre,vector<int> in){
    if(pre.size() == 0) return 0;
    if(pre.size() == 1){
        if(flg) cout << ' ';
        cout << pre.at(0);
        flg = true;
    }
    else{
        int root=pre.at(0);
        vector<int> left,right,Lin,Rin;
        for(int i=0;i<in.size();i++){
            if(in.at(i) == root){
                for(int j=0;j<i;j++) left.push_back(in.at(j));
                for(int j=i+1;j<in.size();j++) right.push_back(in.at(j));
                Lin=left,Rin=right;
                sort(left.begin(),left.end());
                sort(right.begin(),right.end());
            }
        }
        for(int i=0;i<pre.size();i++){
            vector<int> l,r,Lpre,Rpre;
            l.clear();
            r.clear();
            for(int j=1;j<i+1;j++) l.push_back(pre.at(j));
            for(int j=i+1;j<pre.size();j++) r.push_back(pre.at(j));
            Lpre=l,Rpre=r;
            sort(l.begin(),l.end());
            sort(r.begin(),r.end());
            bool match=true;
            if(l.size() != left.size()) match=false;
            else{
                for(int k=0;k<l.size();k++){
                    if(l.at(k) != left.at(k)) match=false;
                }
            }
            if(r.size() != right.size()) match=false;
            else{
                for(int k=0;k<r.size();k++){
                    if(r.at(k) != right.at(k)) match=false;
                }
            }
            if(match){
                solve(Lpre,Lin);
                solve(Rpre,Rin);
                cout << ' ' << root;
            }
        }
    }
    return 0;
}

int main(){
    int n;
    cin >> n;
    vector<int> pre(n),in(n);
    for(int i=0;i<n;i++) cin >> pre[i];
    for(int i=0;i<n;i++) cin >> in[i];
    solve(pre, in);
    cout << endl;
}


Measured memory_bytes: 3220
N = int(input())
A = [int(x) for x in input().split()]
cost = 0

cost = cost + abs(A[0])
for i in range(1,N):
    cost = cost + abs(A[i-1] - A[i])
cost = cost + abs(A[N-1])

# print(cost) #ぬけがない時の合計
sigma = cost   #fix

print(cost - abs(A[0]) - abs(A[0] - A[1]) + abs(A[1]))

for j in range(1,N-1):
    cost = sigma
    cost = cost - abs(A[j-1] - A[j]) - abs(A[j] - A[j+1]) + abs(A[j-1] - A[j+1])
    print(cost)

cost = sigma
print(cost - abs(A[N-2] - A[N-1])  -abs(A[N-1]) + abs(A[N-2]))


Measured memory_bytes: 14048
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int n = sc.nextInt();
            if (n == 0) {
                break;
            }
            
            int ans = 0;
            for (int i = 1; i < n; i++) {
                int tmp = 0;
                for (int j = i; tmp < n; j++) {
                    tmp += j;
                }
                if (tmp == n) {
                    ans++;
                }
            }
            System.out.println(ans);
        }
    }
}

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

namespace AGC001_B
{
    class Program
    { 
       

        static void Main(string[] args)
        {
            var a = getsplit();
            long n = long.Parse(a[0]);
            long x = long.Parse(a[1]);
            Console.WriteLine(3*(n-gcd(n,x)));
        }
        static long gcd(long x ,long y)
        {
            while (y >0)
            {
                long r = x % y;
                x = y;
                y = r;
            }
            return x;
        }
        public static string[] getsplit()
        {
            string[] x = Console.ReadLine().Split(' ');
            return x;
        }
        public static int getint()
        {
            int x = int.Parse(Console.ReadLine());
            return x;
        }
    }
}


Measured memory_bytes: 2648
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;

int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	int h, a;
	cin >> h >> a;
	int ans = h / a;
	if(h%a) ans++;
	cout << ans; 
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define ALL(a) a.begin(), a.end()
typedef long long ll;
using namespace std;

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

    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int ans = min(A, B) + min(C, D);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h1 = sc.nextInt();
		int m1 = sc.nextInt();
		int h2 = sc.nextInt();
		int m2 = sc.nextInt();
		int K = sc.nextInt();
		
		int total = 0;
		if (m1 <= m2) {
			total = (h2 - h1)*60 + (m2 - m1);
		} else {
			total = (h2 - h1 - 1)*60 + (m2 + (60 - m1));
		}
		
		System.out.println(total - K);




		sc.close();
	}
}


Measured memory_bytes: 35788
#include <bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(long long i=a; i<b; i+=1)
#define repr(i,a,b) for(long long i=a; i<=b; i+=1)
#define vec vector<ll>
#define map map<string,int>
#define repa(p,A) for(auto p:A)
#define pb push_back
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())

using namespace std;
int main() {
  ll A,B;
  cin>>A>>B;
  ll count=0;
  ll C;
  C=max(A,B)-1;
  count+=max(A,B)+max(C,min(A,B));
  cout<<count<<endl;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
a=list(map(int,input().split()))
l=[0]*n
r=[0]*n
MOD=10**9+7
for i in range(n):
    for j in range(n):
        if a[i]<a[j] and i<j:
            r[i]+=1
            continue
        if i>j and a[i]<a[j]:
            l[i]+=1
            continue
s=sum(l)
count=0
count+=k*(k+1)//2*s%MOD
s2=sum(r)
count+=k*(k-1)//2*s2%MOD
print(count%MOD)


Measured memory_bytes: 42220
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 20) + 1;
	
	char buf[L], *S , *T, c;
	 
	char getchar() {
		if(__builtin_expect(S == T, 0)) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}
	
	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	unsigned inpu()
	{
		unsigned x = 0; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar());
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x;
	}
	
	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	char B[25], *outs=B+20, *outr=B+20;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;
		
		if(!a)*--outs = '0';
		else 
			while(a)
				*--outs = (a % 10) + 48, a /= 10;
		
		if(x)
			*--outs = x;
		
		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inpu;
using io :: inp_ll;

ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}

const int MAXN = 200010;
const int MOD = 1000000007;
const int INF = 1000000000;

int n;
int a[MAXN], b[MAXN];
int v[MAXN];

void add(int x, int p)
{
	for (; x <= 2*n+1; x += x&-x)
		v[x] += p;
}

int get(int x)
{
	int p = 0;
	for (; x; x -= x&-x)
		p += v[x];
	return p;
}

bool check(int m)
{
	for (int i = 1; i <= 2*n+1; ++ i)
		v[i] = 0;
	ll cnt = 0;
	add(0+n+1, 1);
	for (int i = 1; i <= n; ++ i)
	{
		b[i] = (a[i] >= m) ? 1 : -1;
		b[i] += b[i-1];
		cnt += get(b[i]+n+1);
		add(b[i]+n+1, 1);
	}
	return cnt >= ((ll)n*(n+1)/2+1)/2;
}

int main()
{
	
	n = inp();
	for (int i = 1; i <= n; ++ i)
		a[i] = inp();
	int L = 1, R = 1000000000;
	int ans = 0;
	while (L <= R)
	{
		int m = (L+R)/2;
		if (check(m))
		{
			ans = m;
			L = m+1;
		}
		else
			R = m-1;
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 2816
#include <stdio.h>
int main ( )
{
    int a , b ;
    scanf ("%d%d", &a , &b ) ;
    int r = 0 ;
    for (int i = a ; i <= b ; i++)
        {
            int s = i % 10 , t = i / 10000;
            int u = i / 10 % 10 , v = i / 1000 % 10;
            if ( s == t&&u == v ) r++;
        }
    printf ("%d\n" , r);
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vii = vector<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; }

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
int dx[4] = { 0,  0, 1, -1 };
int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────


int main() {
	string s; cin >> s;
	sort(ASC(s));
	Rep(i, s.size()) {
		if (s[i] == s[i - 1]) {
			ANS("no");
			return 0;
		}
	}
	ANS("yes");

}

Measured memory_bytes: 256
import java.util.*;

class Main {
	Scanner sc;
	int N;
	int[] p = new int[2];
	List<Integer>[] to;
	int[][] d;
	
	@SuppressWarnings("unchecked")
	private void calc() {
		sc = new Scanner(System.in);
		N = sc.nextInt();
		p[0] = sc.nextInt()-1;
		p[1] = sc.nextInt()-1;
		to = new List[N];
		for (int i = 0; i < N; i++) to[i] = new ArrayList<>();
		for (int i = 0; i < N-1; i++) {
			int a = sc.nextInt()-1;
			int b = sc.nextInt()-1;
			to[a].add(b);
			to[b].add(a);
		}
		d = new int[3][N];
		for (int i = 0; i < N; i++) d[0][i] = d[1][i] = d[2][i] = -1;
		Deque<Integer> stack = new ArrayDeque<>();
		for (int i = 0; i < 2; i++) {
			stack.push(p[i]);
			d[i][p[i]] = 0;
			while (!stack.isEmpty()) {
				int from = stack.pop();
				for (int vtx : to[from]) {
					if (d[i][vtx] > -1) continue;
					stack.push(vtx);
					d[i][vtx] = d[i][from] + 1;
				}
			}
		}
		
		stack.push(p[0]);
		d[2][p[0]] = 0;
		int max = d[1][p[0]];
		while (!stack.isEmpty()) {
			int from = stack.pop();
			for (int v : to[from]) {
				if (d[2][v] > -1 || d[0][v] >= d[1][v]) continue;
				stack.push(v);
				d[2][v] = 0;
				max = Math.max(max, d[1][v]);
			}
		}
		System.out.println(max-1);
	}

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


Measured memory_bytes: 105172
N = int(input())
ans = 0
keta = 0
count = 10**keta
for i in range(1, N+1):
  count = 0
  keta = 0
  while count <= i:
    keta +=1
    count = 10**keta
  keta -=1
  if keta %2==0:
    ans += 1

print(ans)
  

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

#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)

int main(){
  int n;
  /*long long x=pow(10,9)+7,ans=1;powでずれた*/
  long long x=1000000007,ans=1;
  cin>>n;
  for(int i=1;i<=n;i++){
    ans*=i;
    ans%=x;
  }
  //cout<<x<<endl;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0].split(" ")[0]);
  var K = parseInt(input[0].split(" ")[1]);
  h=new Array(N);
  for(i=0;i<N;i++){
    h[i]=parseInt(input[i+1]);
  }
  var ans=1000000000;
  h.sort(function(a, b) {return b-a});
  for(i=0;i<N-K+1;i++){
    ans=Math.min(ans,h[i]-h[i+K-1]);
  }

  console.log('%s', ans);
}
  
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(){
  var input = document.getElementById("input").value;
  Main(input);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 28968
use std::io::*;
use std::str::*;

fn scan_token<T: FromStr>() -> T {
    stdin().bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>()
        .parse::<T>().ok().unwrap()
}

fn scan_line<T: FromStr>() -> Vec<T> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace().map( |token| token.parse::<T>().ok().unwrap() ).collect()
}

fn main() {
    let a: i32 = scan_token();
    let b: i32 = scan_token();

    let ans = (a - 1) * (b - 1);

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

Measured memory_bytes: 4352