akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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


double facctorialMethod(ll k){
    double sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

void solve(long long N, std::vector<long long> x, std::vector<long long> y){
    ll a[N];
    double d=0;
    rep(i,N)a[i]=i;
    do
    {
        rep(i,N-1){
            d+=hypot(x[a[i]]-x[a[i+1]],y[a[i]]-y[a[i+1]]);
        }
    } while (next_permutation(a,a+N));

    cout<<(d/facctorialMethod(N))<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
      cout << fixed << setprecision(10);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> x(N);
    std::vector<long long> y(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&x[i]);
        scanf("%lld",&y[i]);
    }
    solve(N, std::move(x), std::move(y));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
//TODO add string to vector of integers macro or function
vector<int> str_to_vect(string s)
{
	vector<int> v;
	for(int i=0;i<s.size();++i)
	{
		v.push_back((int)s[i]-48);
	}
	return v;
}
int main()
{
	int n,m;
	cin>>n>>m;
	double ar[n]; 
	double sum=0;
	for(int i=0;i<n;i++)
	{
		cin>>ar[i];
		sum+=ar[i];
	}
	sort(ar,ar+n);
	int f=0;
	for (int i = n-1; i >= 0 ; i--)
	{
		if(ar[i]/sum>=1.0/(4*m))
			f++;
	}
	if(f>=m)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
LI = lambda: list(map(int, input().split()))

N = int(input())
D = [LI() for _ in range(N)]


def main():
    m = 0
    x = 0
    for a, b in D:
        if a == b:
            x += 1
            m = max(m, x)
        else:
            x = 0
    ans = "Yes" if m >= 3 else "No"
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9180
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
	int k, s;
	int cnt = 0;

	cin >> k >> s;
	rep(x,k+1) {
		rep(y,k+1) {
			int z = s - x - y;
			if (0 <= z && z <= k) cnt++;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
import itertools

s = input()
a, b, c, d = int(s[0]), int(s[1]), int(s[2]), int(s[3])

for bb, cc, dd in itertools.product([1, -1], repeat=3):
    if a + bb*b + cc*c + dd*d == 7:
        ans = ''
        ans += str(a)
        if bb == 1:
            ans += '+'
        else:
            ans += '-'
        ans += str(b)
        if cc == 1:
            ans += '+'
        else:
            ans += '-'
        ans += str(c)
        if dd == 1:
            ans += '+'
        else:
            ans += '-'
        ans += str(d)
        ans += '=7'
        print(ans)
        exit()

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

int main() {
  long sum=0;
  string n;
  cin >> n;
  for(long i=0;i<n.size();i++) sum+=n[i]-'0';
  if(sum%9==0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
#define itn int
#define nibu(K,x) binary_search(K.begin(),K.end(),x)
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define out(x) cout<<x<<endl
#define put(x) out(x)
#define in(x) cin>>x
#define maxx(a,b,c) max(a,max(b,c))
#define minn(a,b,c) min(a,min(b,c))
using ll = long long;
using vl = vector<ll>;
using vs = vector<string>;
const double pi = 3.14159265358979;
const ll mod = 1000000007;

int main() {
ll N,M;
  in(N);
  vs S(N);
  rep(i,N) in(S[i]);
  in(M);
  vs T(M);
  rep(i,M) in(T[i]);
  ll ans =0;
  rep(i,N){
   ll k=1; 
    rep(j,N){
     if(i!=j&&S[i]==S[j]) k++;
    }
    rep(j,M){
     if(S[i]==T[j]) k--; 
    }
    ans = max(k,ans);
  }
  out(ans);
}

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

#ifdef LOCAL
	#define D(a) cerr << #a << " = " << a << endl
#else
	#define D(a)
	#define cerr false && cerr
#endif
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define dforn(i,n) dforsn(i,0,n)
#define forn(i,n) forsn(i,0,n)
#define all(a) a.begin(),a.end()
#define si(a) int((a).size())
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first
#define endl '\n'
using pii = pair<int,int>;
using vi = vector<int>;
using ll = long long;

int main() {
	fastio;
	
    int n; cin >> n;
    ll res = 0, neg = 0, m = 1e9;
    forn(i,n){
        ll x; cin >> x;
        if(x < 0) neg++, x = -x;
        m = min(m,x);
        res += x;
    }
    if(neg & 1) res -= 2*m;
    cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>

int main(void)
{
    int N, K, X, Y;
    std::cin >> N >> K >> X >> Y;
    if (N <= K)
    {
        std::cout << (N * X) << std::endl;
    }
    else
    {
        std::cout << (K * X + (N - K) * Y) << std::endl;
    }
    return 0;
}

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

int main()
{
    int A,B;
    cin >> A >> B;

    int count = 0;
    for (int i=A; i<=B; i++) {
        int t = (i%100)/10;
        int s = i%10;
        if (i/1000 == s*10 + t) {
            count++;
        }
    }

    cout << count << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <time.h>
#include <chrono>
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a,b) for(ll i=a;i>b;i--)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,l,r) for(int i=(1);i<(r);i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = (1LL << 31) - 1;
const ll mod = 1e9 + 7;


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


	ll N; cin >> N;
	ll ans = 0;
	FOR(i, 0, N) {
		ans += (i + 1)*(N - i);
	}

	FOR(i, 0, N - 1) {
		ll u, v; cin >> u >> v;
		if (u > v)swap(u, v);
		ans -= u * (N - v + 1);
	}

	cout << ans << endl;


}


Measured memory_bytes: 3536
#include<iostream>
#include<vector>
#define N 1025
using namespace std;

void disp(vector<char> tmp);

int main(){
    bool firflg = true;
    char inp[N];
    vector<char> tmp;
    cin.getline(inp, sizeof(inp));
    for(int i = 0; inp[i] != '\0'; i++){
        if(inp[i] != ' ' && inp[i] != ',' && inp[i] != '.'){
            tmp.push_back(inp[i]);
        } else{
            if(tmp.size() >= 3 && tmp.size() <= 6){
                if(!firflg){
                    cout <<" ";
                }
                firflg = false;
                disp(tmp);
            }
            tmp.clear();
        }
    }
    cout <<endl;
    return 0;
}

void disp(vector<char> tmp){
    for(int i = 0; i < tmp.size(); i++){
        cout <<tmp[i];
    }
}
//00:24:05

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

using namespace std;

// 別解
int main() {
    int64_t A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    // 考え方メモ
    // 10^5なので、forは1重まで
    // Cを何個買うか決めれば、残りは決まるので、Cの全てのパターンを洗い出す -> O(N) -> 10^5
    // Cを基準に選んだ理由は、条件がAとBで対称になり実装が楽なため

    int64_t minTotal = 10000000000000;

    for (int i = 0; i <= 100000; i++)
    {
        minTotal = min(minTotal, 2 * C * i + max((int64_t)0, A * (X - i)) + max((int64_t)0, B * (Y - i)));
    }

    cout << minTotal << endl;

    return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
   
    string s; cin >> s;
    if(s[0] == s[1] and s[0] == s[2]) cout << "No\n";
    else cout << "Yes\n";


    return 0;
}

Measured memory_bytes: 256
import numpy as np

H, W = map(int, input().split())
h, w = map(int, input().split())

ones_h = np.ones((h, W, ))
zero_h = np.zeros((H-h, W, ))
sum_h = np.vstack([ones_h, zero_h])

ones_w = np.ones((H, w, ))
zero_w = np.zeros((H, W-w, ))
sum_w = np.hstack([ones_w, zero_w])


sum_result = sum_h + sum_w

print(np.sum(sum_result==0))

Measured memory_bytes: 12504
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

type TrieNode struct {
  depth int
  children map[rune]*TrieNode
}
func InitTrieNode(d int) *TrieNode {
  c := make(map[rune]*TrieNode)
  t := TrieNode{d, c}
  return &t
}

func Solve() {
  var N, L int
  var t *TrieNode
  var ok bool
  NextInt(&N, &L)
  T := make([]*TrieNode, 0)
  T = append(T, InitTrieNode(0))
  for i := 0; i < N; i++ {
    t = T[0]
    for i, s := range NextLine() {
      if _, ok = (*t).children[s]; !ok {
        T = append(T, InitTrieNode(i + 1))
        (*t).children[s] = T[len(T) - 1]
      }
      t = (*t).children[s]
    }
  }
  cnt := 0
  for _, t := range T {
    if len((*t).children) == 1 { cnt ^= (L - (*t).depth) & ((*t).depth - L) }
  }
  if cnt > 0 {
    Write("Alice")
  } else {
    Write("Bob")
  }
}

func main() {
  Solve()
  Output()
}

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}

Measured memory_bytes: 22272
#include "bits/stdc++.h"
using namespace std;
int main(){
	string S;
	cin >> S;
	sort(S.begin(), S.end());
	if(S[0]==S[1] && S[2]==S[3] && S[0] != S[2]){
		cout << "Yes";
	}else{
		cout  << "No";
	}
}



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

using namespace std;

int main(){
  string s;
  string str;
  vector<int> a;
  cin>>str;
  int n=str.size();
  for(int i=0;i<n;i++){
    s=str.at(i);
    if(s=="0"){
      a.push_back(0);
    }else if(s=="1"){
      a.push_back(1);
    }else if(s=="B"){
      if(!a.empty()){
        a.pop_back();
      }

    }

  }
  for(int i=0;i<a.size();i++)cout<<a.at(i);
  cout<<endl;
  return 0;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
#define pb(n,m) n.push_back(m)
#define pi(n,m) n.insert(n.begin(),m);
#define ee(n) n.erase(n.end()-1)
#define eb(n) n.erase(n.begin())
#define check(n) reverse(all(n));rep(z,0,n.size())cout<<n[z];co("");reverse(all(n));
using namespace std;
namespace mp=boost::multiprecision;
typedef long long ll;
typedef unsigned long long ull;
using bint=mp::cpp_int;

int main(){
  int n,a,b;
  cin>>n>>a>>b;
  rep(i,a,b+1){
    if(i%n==0){co("OK"); return 0;}
  }
  co("NG");
  
  return 0;
}


Measured memory_bytes: 3624
module.exports=function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(r,i,function(e){return t[e]}.bind(null,i));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";var r=n(1);n(2)(r.readFileSync("/dev/stdin","utf8"))},function(t,e){t.exports=require("fs")},function(t,e,n){"use strict";var r=n(3),i=n(5);t.exports=function(t){var e=new r(t);i(e)}},function(t,e,n){"use strict";var r=n(4);t.exports=class{constructor(t){var e=t.trim().split(/\s+/g);this.inp=new r(e)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(t,e,n){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=t.length,this.items=t,this.ind=0}enq(t){this.size+=1,this.items.push(t)}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}clear(){this.items=[],this.size=0,this.ind=0}}},function(t,e,n){"use strict";t.exports=function(t){for(var e=t.in(),n=t.in(),r=t.in(),i=[],s=1;s<=100;s++)e%s==0&&n%s==0&&i.push(s);i.sort(function(t,e){return e-t});var o=i[r-1];console.log(o)}}]);

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

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
   template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (a == 0) return 0; else if (b % 2 == 0) return (pow((a * a) % m, b / 2, m) % m); else return (pow((a * a) % m, b / 2, m) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

   ll dx[4]={1,0,-1,0};
   ll dy[4]={0,1,0,-1};

ll n;
ll a[3];
ll L[8];
int main(){
   cin >> n;
   cin >> a[0] >> a[1] >> a[2];
   REP(i, n) cin >> L[i];

   ll ans = INF;
   REP(i, pow(4, n)){
      ll cost = 0;
      ll x[4] = {};
      REP(j, n){
         ll type = (i / pow(4ll, j)) % 4ll;
         x[type] += L[j];
         if(type) cost += 10;
      }
      REP(k, 3){
         cost += ((x[k+1] == 0) ? INF : abs(x[k+1] - a[k]));
      }
      cost -= 30;
      chmin(ans, cost);
   }
   cout << ans << endl;
}


Measured memory_bytes: 256
sa=list(input())+['a']
sb=list(input())+['b']
sc=list(input())+['c']
dis=''
turn='a'
winner=''
while all(i>0 for i in [len(sa),len(sb),len(sc)]):
    if any(i==0 for i in [len(sa),len(sb),len(sc)]):
        break
    else:
        if turn=='a':
            dis=sa[0]
            del sa[0]
        elif turn=='b':
            dis=sb[0]
            del sb[0]
        else:
            dis=sc[0]
            del sc[0]
        turn=dis
print(turn.upper())


Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
int main() {
    int N, K, X, Y, kotae;
    cin >> N  >> K >> X >> Y;
    if(K >= N){
        kotae = N * X;
    }
    else if(K < N){
        kotae = K * X + (N - K) * Y;
    }
    cout << kotae << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>

int main(){
    int r,c;
    scanf("%d %d",&r,&c);
    int a[r + 1][c + 1];
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            scanf("%d",&a[i][j]);
        }
    }
    int s;
    for(int i = 0; i < r; i++){
        s = 0;
        for(int j = 0; j < c; j++){
            printf("%d ",a[i][j]);
            s += a[i][j];
        }
        printf("%d\n",s);
    }
    int t;
    int sum = 0;
    for(int i = 0; i < c; i++){
        t = 0;
        for(int j = 0; j < r; j++){
            t += a[j][i];
        }
        printf("%d ",t);
        sum += t;
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 2796
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  // ここにプログラムを追記
	int a,b;
  	cin >> a >> b;
  	if((a + b) % 2 == 0)
  		cout << (a + b) / 2 << endl;
  	else
      	cout << (a + b) / 2 + 1<< endl;
  

}

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

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

typedef pair<int,int> pii;
typedef long long int ll;

void gen_sosuu(int sosuu[]){
  REP(i,100010){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(100000)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<=100000;j++){
      //printf("%d %d %d\n",i*j,i,j);
      sosuu[i*j] =false;
    }
  }
}
// lhs < rhs true
bool comp(pii lhs, pii rhs){
  return lhs.second > rhs.second;
}


int n;
vector<pii> r,b;
int dp[210][210] = {{0}};
/*
rx<bx && ry<by
*/
int ans = 0;

bool ok(pii r,pii b){
  return r.first<b.first && r.second < b.second;
}
int main(){
  cin >>n;
  REP(i,n){
    int m,l;
    cin >> m>>l;
    r.push_back(pii(m,l));
  }
  REP(i,n){
    int m,l;
    cin >> m>>l;
    b.push_back(pii(m,l));
  }
  sort(r.begin(),r.end(),comp);
  sort(b.begin(),b.end());
  while(true){
    bool flag = false;
    REP(i,r.size()){
      REP(j,b.size()){
        if(ok(r[i],b[j])){
          ans++;
          r.erase(r.begin()+i);
          b.erase(b.begin()+j);
          flag = true;
          break;
        }
      }
      if(flag) break;
    }
    if(!flag) break;
  }
  cout << ans<<endl;
}


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

int main(){
    int K, N;
    cin >> K >> N;
    vector<int> A(N);
    for(int i = 0; i < N; ++i) cin >> A[i];
    sort(A.begin(), A.end());
    int max_distance = 0, buf = 0;
    for(int i = 0; i < N; ++i){
        if(i == 0) max_distance = K-A[N-1] + A[i];
        else max_distance = max(max_distance, A[i]-A[i-1]);
    }
    cout << K-max_distance << endl;
    return 0;
}

Measured memory_bytes: 4024
package main

import (
	"fmt"
)

func main() {
	var h int
	fmt.Scan(&h)

	heap := make([]int, h+1)
	heap[0] = -1
	for i := 1; i <= h; i++ {
		fmt.Scan(&heap[i])
	}
	for i := 1; i <= h; i++ {
		fmt.Printf("node %d: key = %d, ", i, heap[i])
		if i > 1 {
			fmt.Printf("parent key = %d, ", heap[i/2])
		}
		if 2*i <= h {
			fmt.Printf("left key = %d, ", heap[2*i])
		}
		if 2*i+1 <= h {
			fmt.Printf("right key = %d, ", heap[2*i+1])
		}
		fmt.Println()
	}
}



Measured memory_bytes: 1120
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;cin>>s;
  vector<int> a(26,0);
  for(int i=0;i<s.size();i++){
    a[s[i]-'a']++;
  }
  for(int i=0;i<26;i++){
  	if(a[i]==0){
      cout<<char(i+'a')<<endl;
      return 0;
    }
  }
  cout<<"None"<<endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <cstring>
using namespace std;
char a[101][101];
bool flag [101];
bool flag2[101];
int main() {
    memset(flag, false, 101);
    memset(flag2,false, 101);
    int H, W;
    cin >> H >> W;
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 1; i <= W; i++) {
        if (a[1][i] == '.') {
            int k ;
            for (k = 1; k <= H; k++) {
                if (a[k][i] != '.') { 
                    break;
                }
            }
            if (k > H) {
                flag[i] = true;
            }
        }
    } 
    for (int i = 1; i <= H; i++) {
        if (a[i][1] == '.') {
            int k ;
            for (k = 1; k <= W; k++) {
                if (a[i][k] != '.') { 
                    break;
                }
            }
            if (k > W) {
                flag2[i] = true;
            }
        }
    } 
    for (int i = 1; i <= H; i++) {
        if (flag2[i] == false) {
            for (int j = 1; j <= W; j++) {
                if (flag[j] == false) {
                    cout << a[i][j];
                }
            }
            cout << endl;
        }
    }     

    return 0;
}


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

int times(int a){
  int rlt = 0;
  while(a>0){
    if(a%2==0){
      rlt++;
      a /= 2;
    }else{
      break;
    }
  }
  return rlt;
}

int main(){
  int n;
  cin >>n;
  int sum=0;
  int* a = (int*)calloc(sizeof(int),n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    //cout << a[i]<<endl;
    sum += times(a[i]);
  }

  cout<< sum<<endl;

  return 0;
}

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

typedef long long ll;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;


//===

const ll mod = ll(1e9 + 7);



int main() {
	int N;
	cin >> N;
	vector<Pll> AB(N);
	for (int i = 0; i < N; ++i) {
		cin >> AB[i].first >> AB[i].second;
	}
	sort(AB.begin(), AB.end(),
		[](Pll lhs, Pll rhs) -> bool {
			return lhs.second < rhs.second;
		}
	);

	ll A_sum = 0;
	bool OK = true;
	for (int i = 0; i < N; ++i) {
		A_sum += AB[i].first;
		if (A_sum > AB[i].second) {
			OK = false;
			break;
		}
	}

	cout << (OK ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3328
#include <stdio.h>
int main()
{
	int N,K,X,Y,sum=0;
	scanf("%d%d%d%d",&N,&K,&X,&Y);
	if(N>=K)
	{
		sum=K*X+(N-K)*Y;
		printf("%d",sum);	
	}
	else
	{
		sum=N*X;
		printf("%d",sum);
	}
	return 0;
} 

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 998244353
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

using namespace std;


int main(){

    int h,w,k;
    cin >> h >> w >> k;

    vector<string> s;
    vector<int> strawberry_l;

    rep(i,h){
        string tmp;
        cin >> tmp;
        s.pback(tmp);
    }

    rep(i,h){
        int count = 0;
        rep(j,w){
            if(s[i][j] == '#') count++;
        }
        strawberry_l.pback(count);
    }

    int area = 1;

    vector<vector<int>> ans(h, vector<int>(w));

    rep(i,h){
        if(strawberry_l[i] == 1){
            rep(j,w){
                ans[i][j] = area;
            }
            area++;
        }else if(strawberry_l[i] != 0){
            int maxc = strawberry_l[i] - 1;
            rep(j,w){
                ans[i][j] = area;
                if(s[i][j] == '#' && maxc > 0){
                    area++;
                    maxc--;
                }
            }
            area++;
        }
    }

    function<void(int,int)> paint = [&](int y, int x) -> void{

        bool find = false;
        int tmparea;
        for(int i = y + 1; i < h; i++){
            if(ans[i][x] != 0){
                find = true;
                tmparea = ans[i][x];

                for(int j = i - 1; j >= y; j--){
                    ans[j][x] = tmparea;
                }
                break;
            }
        }

        if(!find){
            for(int i = y - 1; i >= 0; i--){
                if(ans[i][x] != 0){
                    tmparea = ans[i][x];

                    for(int j = i; j <= y; j++){
                        ans[j][x] = tmparea;
                    }
                    break;
                }
            }
        }

    };

    rep(i,h){
        rep(j,w){
            if(ans[i][j] == 0){
                paint(i,j);
            }
        }
    }

    rep(i,h){
        rep(j,w){
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }



    return 0;
}

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

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


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

int main(){
    int n;cin>>n;
    int ans=0;
    vector<int> s(n);
    int t;
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    int q;cin>>q;
    for(int i=0;i<q;i++){
        cin>>t;
        for(int i=0;i<n;i++){
            if(t==s[i]){
                ans++;
                break;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3108
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String s = in.next();
            int ans = 0;
            int left = 0, right = s.length() - 1;

            while (left < right) {
                if (s.charAt(left) == s.charAt(right)) {
                    left++;
                    right--;
                } else if (s.charAt(left) == 'x') {
                    ans++;
                    left++;
                } else if (s.charAt(right) == 'x') {
                    ans++;
                    right--;
                } else {
                    out.println(-1);
                    return;
                }
            }
            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}



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


public class Main {
	
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final long a = sc.nextLong();
			final long b = sc.nextLong();
			
			if(a == 0 && b == 0){
				break;
			}
			
			System.out.println(Math.min(a, b) + " " + Math.max(a, b));
		}
		
		
	}
	
}

Measured memory_bytes: 27340
#include <stdio.h>
inline void pll(int a, int b){
    char c[14];
    c[13]=' ';
    int i=12;
    do{ c[i]=b%10+48; b/=10; i--; }while(b>0);
    c[i]=' '; i--;
    do{ c[i]=a%10+48; a/=10; i--; }while(a>0);
    if(__builtin_expect(stdout->_IO_write_ptr+14 >= stdout->_IO_write_end,0)){
        fflush_unlocked(stdout);
    }
    for(i++;i<14;i++){
        *stdout->_IO_write_ptr++ = c[i];
    }
}

static void solve(const int n, const int a, const int b, int mask, const int common){
    const int t = a^b;
    const int d = t&(-t);
    mask ^= d;
    const int aa = a & mask, ab = aa ^ (mask&(-mask));
    if(n==2){
        pll(common|a, common|ab|(a&d));
        pll(common|ab|(b&d), common|b);
    }else{
        solve(n-1, aa, ab, mask, common|(a&d));
        solve(n-1, ab, b&mask, mask, common|(b&d));
    }
}

int main(void){
    int n, a, b;
    scanf("%d %d %d", &n, &a, &b);
    if(__builtin_parity(a)==__builtin_parity(b)){
        puts("NO");
    }else{
        puts("YES");
        if(n==1){
            pll(a, b);
        }else{
            solve(n, a, b, -1, 0);
        }
    }
    return 0;
}

Measured memory_bytes: 896
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <map>
using namespace std;
const int N = 1000500;
typedef long long llong;
int A[N];

int X[N];
int Y[N];

int main() {
    int n;
    scanf("%d", &n);
    int ans = 0;
    map<int, int> M;
    for (int i = 0; i < n; i++) {
        scanf("%d", &A[i]);
        M[A[i]];
    }

    int pt = 0;
    for (map<int, int>::iterator it = M.begin(); it != M.end(); it++)
        it->second = pt++;
    for (int i = 0; i < n; i++) {
        A[i] = M[A[i]];
        X[i] = A[i] % 2;
        Y[i] = i % 2;
        ans += X[i] != Y[i];
    }
    assert(ans % 2 == 0);
    printf("%d\n", ans / 2);
}


Measured memory_bytes: 6144
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

public class Main {
	int V,E,r;
	List<ArrayList<P>> graph;
	long[] ans;

	private class P{
		int n,c;
		public P(int n,int c){
			this.n = n;
			this.c = c;
		}
	}

	private class D implements Comparable<D>{
		int n;
		long c;
		public D(int n,long c){
			this.n = n;
			this.c = c;
		}

		public int compareTo(D d){
			if(this.c - d.c < 0){
				return -1;
			}else if(this.c - d.c > 0){
				return 1;
			}else{
				return 0;
			}
		}
	}

	public void dijkstra(int s){
		boolean[] used = new boolean[V];

		PriorityQueue<D> pq = new PriorityQueue<D>();
		pq.add(new D(r,0));
		while(pq.size() > 0){
			D d = pq.poll();

			used[d.n] = true;
			ans[d.n] = Math.min(ans[d.n],d.c);

			for(P i : graph.get(d.n)){
				if(used[i.n])continue;
				pq.add(new D(i.n,d.c + i.c));
			}
		}
	}

	public void solve() {
		V = nextInt();
		E = nextInt();
		r = nextInt();

		graph = new ArrayList<ArrayList<P>>();
		ans = new long[V];

		for(int i = 0;i < V;i++){
			graph.add(new ArrayList<P>());
		}

		for(int i = 0;i < V;i++){
			ans[i] = Long.MAX_VALUE;
		}

		for(int i = 0;i < E;i++){
			int s = nextInt();
			int t = nextInt();
			int d = nextInt();

			graph.get(s).add(new P(t,d));
		}

		dijkstra(r);

		for(int i = 0;i < V;i++){
			if(ans[i] == Long.MAX_VALUE)out.println("INF");
			else out.println(ans[i]);
		}
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

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

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

Measured memory_bytes: 132104
N = int(input())
A = [int(x) for x in input().split()]
B = [int(y) for y in input().split()]

B.append(0)
k = 0
answer = 0

for i in range(N+1):
    if A[i] <= B[i] + k:
        answer += A[i]
        if A[i] <= k:
            k = B[i]
        else:
            k = B[i] + k - A[i]
    else:
        answer += B[i] + k
        k = 0
        
print(answer)

Measured memory_bytes: 18624
import fractions

a,b,c,d=map(int,input().split())
cnt=0

cc=b//c-(a-1)//c
dd=b//d-(a-1)//d
ee=b//(c * d // fractions.gcd(c, d))-(a-1)//(c * d // fractions.gcd(c, d))
    
print((b-a+1)-(cc+dd-ee))

Measured memory_bytes: 5048
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;

int vec[4];
int main(){
    int n;
    cin >> n;
    for(int i=3; i>=0; i--){
        vec[i] = n%10;
        n/=10;
    }
    vector<char> ops(4);
    ops[3] = '=';
    int ans=vec[0];
    for (int i=0; i<8; i++){
        for (int j=0; j<3; j++){
            if (i&(1<<j)) {
                ans+=vec[j+1];
                ops[j] = '+';

            }

            else {
                ans-=vec[j+1];
                ops[j] = '-';
            }
        }
        if (ans == 7){
            break;
        }
        ans = vec[0];
    }
    
    for(int i=0; i<4; i++){
        cout << vec[i] << ops[i];
    }
    cout << 7 << endl;
    return 0;


}

Measured memory_bytes: 256
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353



A, B, K = list(map(int, sys.stdin.buffer.readline().split()))

ok = []
for i in range(1, max(A, B) + 1):
    if A% i == 0 and B % i == 0:
        ok .append(i)
ans = ok[-K]
print(ans)


Measured memory_bytes: 13584
K=int(input())
if K==1:
    print(1)
    print(1)
    exit()
m=-((-K)//4)
n=2*m
a=[[0 for i in range(n)] for i in range(n)]
for r in range(n):
    for c in range(n):
        p=-1
        if r%2==0:
            p=(r+c)%n
        else:
            p=n+(r+c)%n
        if p>=K:
            p-=n
        a[r][c]=p
s=[[str(a[i][j]+1) for i in range(n)] for j in range(n)]
print(n)
for line in s:
    print(" ".join(line))


Measured memory_bytes: 27948
#include <stdio.h>

int main(void)
{
	char target, from, to;
	
	target = 'A';
	
	while (scanf("%c%*c%c", &from, &to) != EOF){
		getchar();
		if (target == from){
			target = to;
		}
		else if (target == to){
			target = from;
		}
	}
	
	printf("%c\n", target);
	
	return (0);
}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define range(i,a,b) for(int i=a; i<(int)(b); i++)
#define rep(i,b) range(i,0,b)

typedef int Capacity;
struct Edge {
    int src, dst;
    Capacity cap;
    Edge(int src_, int dst_, int cap_) :
        src(src_), dst(dst_), cap(cap_) { }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<int> Array;
typedef vector<Array> Matrix;

int const inf = 1e9;

typedef int Capacity;
struct FordFulkerson {
    typedef vector<vector<Capacity>> Matrix;
    int n, t;
    vector<bool> vis;
    Matrix cap, flow;
    vector<vector<int>> g;
    FordFulkerson(int n){ *this = FordFulkerson(Graph(n)); }
    FordFulkerson(const Graph &graph)
        : n(graph.size()),
          cap(n, Array(n)), flow(n, Array(n)), g(n, vector<int>()){
        rep(i,n) for(const Edge &e : graph[i]) add_edge(e.src, e.dst, e.cap);
    }
    void add_edge(int u, int v, Capacity c){
        cap[u][v] += c; cap[v][u] += c; flow[v][u] += c;
        g[u].push_back(v); g[v].push_back(u);
    }
    Capacity solve(int s, int t){
        this->t = t;
        Capacity res = 0, f = -1;
        while(f) vis.assign(n,false), res += (f = augment(s,inf));
        return res;
    }
    Capacity augment(int v, Capacity lim){
        vis[v] = true;
        if(v == t) return lim;
        for(const int &i : g[v]){
            if(vis[i] || flow[v][i] == cap[v][i]) continue;
            Capacity f = augment(i, min(lim, cap[v][i] - flow[v][i]));
            flow[v][i] += f; flow[i][v] -= f;
            if(f) return f;
        }
        return 0;
    }
};

int main(){
    int N,M;
    cin >> N >> M;
    FordFulkerson g(N);
    rep(i,M){
        int a,b,c;
        cin >> a >> b >> c;
        g.add_edge(a,b,c);
    }
    cout << FordFulkerson(g).solve(0,N-1) << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector <int> h(N);
  for (int i = 0; i < N; i++) {
    cin >> h.at(i);
  }
  vector <int> total(N);
  total.at(0) = 0;
  total.at(1) = abs(h.at(1) - h.at(0));
  for (int i = 2; i < N; i++) {
    int i1 = total.at(i - 1) + abs(h.at(i) - h.at(i - 1));
    int i2 = total.at(i - 2) + abs(h.at(i) - h.at(i - 2));
    total.at(i) = min(i1, i2);
  }

  cout << total.at(N - 1) << endl;
  return 0;
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
const int maxn=100000+5;
int a[maxn];
int n;
bool hav4[maxn],hav2[maxn],non[maxn];
int has4=0,has2=0,no=0;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=1;i<=n;i++){
        if(a[i]%4==0){
            hav4[i]=true;
            has4++;
            continue;
        }else if(a[i]%2==0){
            hav2[i]=true;
            has2++;
            continue;
        }else{
            non[i]=true;
            no++;
        }
    }
    if(has4<no-1) printf("No\n");
    else if(has4==no-1){
        if(has2==0) printf("Yes\n");
        else printf("No\n");
    }else{
        printf("Yes\n");
    }
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

template <typename T>
T powi(T a, ll n) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) ret *= a; 
        a *= a;
        n >>= 1;
    }
    return ret;
}

template <ll mod>
class ModInt {
private:
    ll num;
public:
    ModInt() {};
    ModInt(ll n) { num = n % mod; }
    ModInt inv() const { return powi(*this, mod-2); }
    explicit operator ll() const { return num; }

    ModInt& operator+=(const ModInt& a) {
        num += a.num; 
        if (num >= mod) num -= mod; 
        return *this;
    }
    ModInt& operator-=(const ModInt& a) {
        if (num < a.num) num += mod;
        num -= a.num;
        return *this;
    }
    ModInt& operator*=(const ModInt& a) {
        num = num * a.num % mod;
        return *this;
    }
    ModInt& operator/=(const ModInt& a) { return *this *= a.inv(); }
    friend ModInt operator+(const ModInt& a, const ModInt& b) { return ModInt(a) += b; }
    friend ModInt operator-(const ModInt& a, const ModInt& b) { return ModInt(a) -= b; }
    friend ModInt operator*(const ModInt& a, const ModInt& b) { return ModInt(a) *= b; }
    friend ModInt operator/(const ModInt& a, const ModInt& b) { return ModInt(a) /= b; }

    friend ostream& operator<<(ostream& os, const ModInt& a) { return os << a.num; }
    friend istream& operator>>(istream& is, ModInt& a) {
        ll tmp;
        is >> tmp;
        a.num = tmp % mod;
        return is;
    }
};
using mint = ModInt<1000000007>;

template <typename T>
struct BIT {
private:
    vector<T> v;
public:
    BIT(int n) : v(n, 0) {}
    T sum(int i) const {
        T s = 0;
        while (i > 0) {
            s += v[i];
            i = (i & (i + 1)) - 1;
        }
        return s;
    }
    void add(int i, T x) {
        while (i < (int)v.size()) {
            v[i] += x;
            i |= i + 1;
        }
    }
    int size() const { return v.size(); }
};

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (auto &e: a) cin >> e;

    BIT<ll> all(2001), part(2001);
    for (int i = 0; i < n; ++i) {
        all.add(a[i], 1);
    }

    mint ans = 0;
    mint m = ((mint)0 + (k-1)) * k / 2;
    for (int i = 0; i < n; ++i) {
        mint cnt = i - part.sum(a[i]);
        ans += m * (n - all.sum(a[i])) + cnt * k;
        part.add(a[i], 1);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  cout<<max<int>(0,c-(a-b))<<endl;
}

Measured memory_bytes: 256
a,b=map(int,input().split())
g=1
while 1:
  if a==b:
    g=a
    break
  if a<b:
    k=a
    a=b
    b=k
  a-=b
ans=1
i=2
while i*i<=g:
  if g%i==0:
    ans+=1
    while g%i==0:
      g//=i
  i+=1
if g!=1:
  ans+=1
print(ans)

Measured memory_bytes: 9200
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"

int main()
{
	int n,c=1;
	cin>>n;
	string s;
	cin>>s;
	for0(i,n-1){
		if(s[i]!=s[i+1]) c++;
		}
	cout<<c<<nw;
	
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <unordered_map>

using namespace std;

int main()	{
  int n, m;
  cin >> n >> m;
  unordered_map<int, int> cities;
  int a, b;
  for (int i = 0; i < m; i++)	{
    cin >> a >> b;
    cities[a]++;
    cities[b]++;
  }
  for (int i = 1; i <= n; i++)	{
    cout << cities[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#define N 100000
using namespace std;


int C[N];
queue<int> k;
vector<int> v[N];
void color(int);
bool search(int,int);

int main(){
	int n,m,a,b,q;
	cin >> n >>m;
	for(int i=0;i<m;i++){
		cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	cin >> q;
	for(int i=0;i<n;i++){
		C[i]=-1; //?????????
	}
	for(int i=0;i<n;i++){
		if(C[i]==-1)color(i); //i????§??????¨????????±???
	}
	for(int i=0;i<q;i++){
		cin>>a>>b;
		if(search(a,b)) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
	return 0;
}

bool search(int a,int b){
	if(C[a]==C[b]) return true;
	else return false;
}

void color(int a){
	static int c=0;
	c++;
	C[a]=c;
	k.push(a);
	while(!k.empty()){
		int m = k.front();
		k.pop();
		for(int i=0;i<v[m].size();i++){
			int Z= v[m].at(i);
			if(C[Z]==-1){
				C[Z]=c;
				k.push(Z);
			}
		}
	}
}

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

using namespace std;
const int MAXN = 2e5 + 10;

int main(){
    //freopen("in", "r", stdin);
    ios::sync_with_stdio(false);
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    swap(a[0], a[1]);
    swap(a[0], a[2]);
    cout << a[0] << ' ' << a[1] << ' ' << a[2];
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
main(){
  int n, A[1000];
 
  while(1){
     cin >> n;
     if ( n == 0 ) break;

     for ( int i = 0; i < n; i++ )
       cin >> A[i];
       int sum = 0;
     for ( int i = 0; i < n; i++ )
       sum += A[i];
     double avg = 1.0*sum/n;
     double dist = 0.0;
     for ( int i = 0; i < n; i++ ){
       dist += (avg - A[i])*(avg-A[i]);
}

    printf("%lf\n", sqrt(dist/n));
}

}


Measured memory_bytes: 3224
fun main(args: Array<String>) = yorukatsu19a()

fun yorukatsu19a() {
    val n = readLine()!!.toInt()
    val list = readLine()!!.split(' ').map { it.toInt() }.sorted()

    val answer = if (list.last() < list.dropLast(1).sum()) "Yes" else "No"

    println(answer)
}


Measured memory_bytes: 36328
n=int(input())
keta=[26]
t=2
while keta[-1]<10**15+1:
    keta.append(keta[-1]+26**t)
    t+=1
#print(keta)

import bisect,sys
nagasa=bisect.bisect_left(keta,n)+1
#print(nagasa)

alpha='abcdefghijklmnopqrstuvwxyza'
if nagasa==1:
    print(alpha[n-1])
    sys.exit()

n-=keta[nagasa-2]
n-=1

ans=''
L=[]
while n>0:
    L.append(n%26)
    n//=26
while len(L)<nagasa:
    L.append(0)
for i in L:
    ans+=alpha[i]
print(ans[::-1])

Measured memory_bytes: 9144
from collections import deque
N = int(input())
memo = {i:1 for i in [357, 375, 537, 573, 735, 753]}
ans = 0
queue = deque()
mod = [10**i for i in range(10)]
for key in memo.keys():
  if key <= N:
    ans += 1
    queue.append(key)
while queue:
    key = queue.popleft()
    len_key = len(str(key))
    for i in range(len_key):
        for j in [3,5,7]:
            tmp = (key // mod[i]) * mod[i+1] + j * mod[i] + key % mod[i]
            if tmp not in memo and tmp <= N:
                ans += 1
                memo[tmp] = 1
                queue.append(tmp)
print(ans)


Measured memory_bytes: 6452