akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	cin>>n;
	vector<int>arr(n);
	for(int i=1; i<n; i++)
	 cin>>arr[i];
	for(int i=2; i<n-1; i++)
	{
		if(arr[i]>arr[i-1] && arr[i]>arr[i+1])
		 arr[i]=max(arr[i-1],arr[i+1]);
	}
	vector<int>ans(n+1);
    ans[1]=arr[1];
    int sum=arr[1];
	for(int i=2; i<n; i++){
		ans[i]=min(arr[i-1],arr[i]);
		sum+=ans[i];
	}
	ans[n]=arr[n-1];
	sum+=ans[n];
	cout<<sum;
	return 0;
	
}

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

int isPrime(int x){
    int i;
    if (x<2)return false;
    else if(x ==2)return true;
    if (x %2 ==0)return false;
    for(i = 3; i*i<=x; i+=2){
        if(x%i == 0)return false;
    }
    return true;
}

int main(){
    int n, a, count;
    count = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a;
        if(isPrime(a)) count++;
        
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3036
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define fst first
#define sc second
#define snd second
#define sz(fst) (int)(fst).size()
#define forn(i, N) for (ll i = 0; i < ll(N); i++)
#define fornr(i, N) for (int i = int(N) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define all(fst) fst.begin(), fst.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;

const int N = 1e6;

vector<bool> p(N);
vector<int> primes;

void pr() {
    for (int i = 2; i <= N; ++i) {
        if (!p[i]) {
            primes.pb(i);
            if (i * 1ll * i > N) continue;
            for (int j = i * i; j <= N; j += i) p[j] = true;
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    pr();
    int x;
    cin >> x;
    for (int y : primes) {
        if (y >= x) {
            cout << y << "\n";
            return 0;
        }
    }
}

Measured memory_bytes: 1020
import queue

n,m=list(map(int,input().split()))
graph = [[] for i in range(n)]
    
for i in range(m):
  x,y = list(map(int,input().split()))
  graph[x-1].append(y-1)
  graph[y-1].append(x-1)
    
v = [-1 for i in range(n)]
v[0] = [0]

q = queue.Queue()
q.put(0)
    
while not q.empty():
  x = q.get()
  
  for y in graph[x]:
    if v[y]!=(-1):
      continue
    q.put(y)
    v[y] = x
    
print("Yes")
for i in range(1,n):
  print(v[i]+1)

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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}

int mx[8001], my[8001];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    string s;
    int x, y; cin >> s >> x >> y;

    int parity = 0, cx = 0, cy = 0, a = 0, b = 0;

    for(auto i : s){
        if(i == 'F'){
            parity ? ++my[b] : ++mx[a];
        } else {
            parity ? ++b : ++a;
            parity ^= 1;
        }
    }

    parity ? ++b : ++a;

    cx = mx[0];

    sort(mx + 1, mx + a);
    sort(my, my + b);

    for(int i = a; i > 0; --i){
        //cout << mx[i] << " ";
        cx += mx[i] * (cx < x ? 1 : -1);
    }
    for(int i = b; i >= 0; --i)
        cy += my[i] * (cy < y ? 1 : -1);

    cout << (cx == x && cy == y ? "Yes\n" : "No\n");

    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq  priority_queue<double, std::vector<double>, std::greater<double>>

int lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}

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







int main(){
    int S;
    cin >> S;
    vector<int> A(10000000);
    int i = 0;
    A[0] = S;
    map<int, int> M;
    M[A[0]]++;
    if(A[0] < 3){
        cout << 4 << endl;
        return 0;
    }
    while (true)
    {
        i++;
        if(A[i-1] % 2== 0){
            A[i] = A[i - 1] / 2;
            M[A[i]]++;
            if(M[A[i]] >= 2){
                cout << i << endl;
                return 0;
            }
        }
        else{
            A[i] = A[i - 1] * 3 + 1;
        }
    }
}


Measured memory_bytes: 39296
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#include <queue>
#include <cstdio>
using namespace std;

template <class T> using V = vector<T>;
template <class S, class T> using P = pair<S, T>;
template <class... T> using TP = tuple<T...>;

using ll = long long;
using db = double;
using ldb = long db;
using str = string;
using ch = char;
using vll = V<ll>;
using vvll = V<V<ll>>;
using vvvll = V<V<V<ll>>>;
using pll = P<ll,ll>;
using tpll = TP<ll,ll,ll>;
using vpll =V<pll>;
using vvpll = V<vpll>;
using vtpll = V<tpll>;
using vst = V<str>;
using vch = V<ch>;
using vvch = V<vch>;
using qll = queue<ll>;
using vqll = V<qll>;

#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin() 
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl
#define pb(a) push_back(a)
#define pob pop_back()
#define mp make_pair
#define mt make_tuple
#define pbmp(a,b) push_back(mp(a,b))
#define subs(a,b) substr(a,b)
#define cfs(a) cout<<fixed<<setprecision(a) //
/*vvll v(n,vll(m)) n行m列  continue
A.erase(A.begin()+i); 配列Aのi番目を消せる
std::binary_search(v.bgn,v.en,a); 二分探索
abs(a,b)   pow(a,n)  to_string  stoll
auto Iter=lower_bound(v.bgn,v.en,a); v[i]>=aとなる初のv[i]
v.insert(lower_bound(v.bgn,v.en,a),b); bを入れられる
lower upper  co(*Iter) co(Iter-v.bgn) v[i]>=aとなる初のi
vvll v(100001,vll(0)); v[a].pb(b); v[b].pb(a);
priority_queue<ll> pque; pque.push(ai); pque.top()→max(ai) 
vqll q(3);  q[0].push(0); q[0].push(2); q[0].push(1);
q[0].front()→0 q[0].back()→1 q[0].pop(); q[0].front()→2
que.pop() que.sz while(!que.empty())
*/

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
#define comuse Comuse()
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll pow_mod(ll a,ll n,ll mod){
  ll res=1;
  for(;n>0;n/=2){
    if(n%2==1)res=(res*a)%mod;
    a=(a*a)%mod;
  }
  return res;
}
ll digit_sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0)break;
  }
  return m;
}
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}

int main(){
  ll n;
  cin>>n;
  vll v(n);
  FOR(i,0,n){
    cin>>v[i];
    v[i]-=(i+1);
  }
  SORT(v);
  ll sub=0;
  if(n==1){
    sub==v[0];
  }
  if(n%2==1){
    sub=v[n/2];
  }
  else{
    sub=(v[n/2-1]+v[n/2])/2;
  }
  ll ans=0;
  FOR(i,0,n){
    ans+=abs(v[i]-sub);
  }
  co(ans);
}
  

Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>
 
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
 
#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;
 
template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

inline void write_bool(bool b, const string &tval, const string &fval) {
  cout << (b ? tval : fval) << endl;
} 
inline void YESNO(bool b) { return write_bool(b, "YES", "NO"); }
inline void YesNo(bool b) { return write_bool(b, "Yes", "No"); }
inline void yesno(bool b) { return write_bool(b, "yes", "no"); }


int main() {
  int n;
  while (cin >> n) {
    ++n;
    int result = 0;
    REP(i,n) {
      if (i == 0) continue;
      result += (to_s(i).length()) % 2;
    }
    cout << result << endl;
  }

  
}


Measured memory_bytes: 888
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <fstream>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <tuple>
#include <climits>
#include <unordered_map>

using namespace std;

int main() {
    int N;
    long long K;
    cin>>N>>K;
    vector<int> v(N);
    for (int i=0; i<N; i++) {
        cin>>v[i];
    }
    int len = 0, next = 0;
    vector<int> t(N, -1);
    while (t[next] == -1) {
        t[next] = len++;
        next = v[next] - 1;
        if (--K == 0) {
            cout<<next + 1 <<endl;
            return 0;   
        }
    }
    len -= t[next];
    K %= len;
    for (int i=0; i<N; i++) {
        if (t[i] == K + t[next]) {
            cout<<i + 1<<endl;
            break;
        }
    }
    return 0;
}


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

int main() {
  while(1) {
    int n;
    cin >> n;
    if(n == 0) break;

    int i;
    for(i = 0; n != 1; i++) {
      if(n % 2 == 0) {
	n /= 2;
      } else {
	n = n * 3 + 1;
      }
    }
    cout << i << endl;
  }
  return 0;
}

Measured memory_bytes: 0
import java.util.*;

public class Main {
    public static void main(String[] args) {
	Scanner s = new Scanner(System.in);
	int[] dat = new int[10];
	for(int tc = 0; tc < 10; ++tc) {
	    dat[tc] = s.nextInt();
	}
	Arrays.sort(dat);
	for(int i = 0; i < 3; ++i) {
	    System.out.println(dat[9-i]);
	}
    }
}

Measured memory_bytes: 11000
#include <cstdio>
#include <vector>
#include <map>

using namespace std;

typedef long long ll;

vector<ll> cd;
vector< map<int, ll> > d;

void cost(int v, int prev) {
    cd.at(v) = cd.at(prev) + d.at(prev).at(v);
    for (auto i = d.at(v).begin(); i != d.at(v).end(); ++i) if ((*i).first != prev) cost((*i).first, v);
}

int main() {
    int n, a, b, q, k, x, y;
    ll c;
    scanf("%d", &n);
    cd.resize(n + 1);
    d.resize(n + 1);
    for (int i = 1; i < n; ++i) {
        scanf("%d%d%lld", &a, &b, &c);
        d.at(a)[b] = c;
        d.at(b)[a] = c;
    }
    scanf("%d%d", &q, &k);
    d.at(0)[k] = 0;
    cost(k, 0);
    for (int i = 0; i < q; ++i) {
        scanf("%d%d", &x, &y);
        printf("%lld\n", cd.at(x) + cd.at(y));
    }
    return 0;
}


Measured memory_bytes: 27520
#include<cstdio>
#include<cctype>
using namespace std;

int main(){
    char ch;
    while(1){
        scanf("%c", &ch);
        
        if(isalpha(ch)){
            if(islower(ch)){
                printf("%c", toupper(ch));
            }
            else printf("%c", tolower(ch));
        }
        else printf("%c", ch);
        if(ch == '\n') break;
    }
    return 0;
}



Measured memory_bytes: 2620
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;


int main(){
    string n;
    int count = 0;
    cin >> n;
    for(int i = 0; i < 4; i++){
        if(n[i] == '2'){
            count++;
        }
    }
    
    cout << count << endl;
}


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

if a > 0:
    if a > k:
        a -= k
        k = 0
    else:
        k -= a
        a = 0

if b > 0:
    if b > k:
        b -= k
    else:
        b = 0

print(str(a) + " " + str(b))

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

int main(){
    int a, b;
    cin >> a >> b;
    int diff = b - a;
    int sum = 0;
    for(int i = 1; i <= diff; i++){
        sum += i;
    }
    cout << sum - b << endl;
}

Measured memory_bytes: 3648
#include<cstdio>
char c;
int a[10];
int main()
{
	for(int i=0;i<3;i++)
	{
		scanf("%c",&c);
		a[c-'a']++;
	}
	if(a[0]==1&&a[1]==1&&a[2]==1)printf("Yes");
	else
		printf("No");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define reg register
using namespace std;
int n, r, ans;
int main() {
  cin >> n >> r;
  if(n >= 10) {
    printf("%d\n", r);
  }
  else {
    ans = 100 * (10 - n);
    printf("%d\n", ans + r);
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<cstring>
#include<set>
#include<map>
#include<vector>
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstdlib>
#define reep(n1,n2,n3) for(int n1=n3;n1<n2;n1++)
#define rep(n1,n2) reep(n1,n2,0)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define INF 1e9
using namespace std;
typedef long long int lint;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<pair<int,int> > vp;
typedef pair<int,int> pi;
typedef pair<int,pair<int,int> > pii;
typedef vector<string> vs;
const double PI  = acos(-1.0);
bool flg[30];
int main(){
    rep(i,28){
        int a;
        cin>>a;
        flg[a-1]=true;
    }
    rep(i,30){
        if(!flg[i])cout<<i+1<<endl;
    }
}

Measured memory_bytes: 1160
import math
import collections
import heapq
from collections import defaultdict
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    n = int(input())
    maxv = n*(n-1)//2
    a = [list(map(int, input().split())) for i in range(n)]
    for i in range(n):
        for j in range(n-1):
            a[i][j] -= 1
    v = 0
    Id = [[0 for i in range(n)] for j in range(n)]
    for i in range(n):
        for j in range(n):
            if i < j:
                Id[i][j] = v
                v += 1

    def toId(i, j):
        if i > j:
            i, j = j, i
        return Id[i][j]

    to = [[] for i in range(maxv)]
    for i in range(n):
        for j in range(n - 1):
            a[i][j] = toId(i, a[i][j])
        for j in range(n - 2):
            to[a[i][j+1]].append(a[i][j])

    visited = [False for i in range(maxv)]
    calculated = [False for i in range(maxv)]
    dp = [0 for i in range(maxv)]

    def dfs(v):
        if visited[v]:
            if not calculated[v]:
                return -1
            return dp[v]
        visited[v] = True
        dp[v] = 1
        for u in to[v]:
            ret = dfs(u)
            if ret == -1:
                return -1
            dp[v] = max(dp[v], ret + 1)
        calculated[v] = True
        return dp[v]

    ans = 0
    for i in range(v):
        ret = dfs(i)
        if ret == -1:  # detected cycle
            print(-1)
            exit()
        ans = max(ans, ret)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 211952
function Main(input) {
	var lines = input.split("\n");
	var words1 = lines[0].split(" ");
	var words2 = lines[1].split(" ");
	var words3 = lines[2].split(" ");
	var n = Number(words1[0]);
	var k = Number(words1[1]);
	var r = Number(words2[0]);
	var s = Number(words2[1]);
	var p = Number(words2[2]);
	var t = words3[0]
	
	// console.log(n, k)
	// console.log(r, s, p)
	// console.log(t)

	// 全て勝利するパターンを作る
	// 例：prpsr
	var myBestHand = t.split("").map((h) => {
		return beater(h)
	}).join("")

	// k個の間隔で同じ手が出ている場合、修正候補を作る
	for(var i = 0; i <= n - k + 1; i++) {
		if(myBestHand[i] === myBestHand[i + k]){
			// k間隔で2連続で同じ手なら、2回目に負ける
			if(myBestHand.length > i+k+k) {
				myBestHand = replaceAt(myBestHand, i + k, not2(myBestHand[i+k], myBestHand[i+k+k])) 
			} else {
				myBestHand = replaceAt(myBestHand, i + k, not(myBestHand[i+k])) 
			}
			
		} 
	}
	//  
	console.log(calculateWin(myBestHand, t))


	// 修正候補の期待得点をそれぞれ計算する

	function replaceAt(string, index, char) {
		return string.substr(0, index) + char + string.substr(index + 1);
	}

	function not(hand) {
		var hands = ['r', 's', 'p']
		if(hand === hands[0]) return hands[1]
		if(hand === hands[1]) return hands[2]
		if(hand === hands[2]) return hands[0]
	}

	// ここで次の手の邪魔にならない手を選ぶ必要がある
	function not2(hand, hand2) {
		var hands = 'rsp'
		return hands.replace(hand, '').replace(hand2, '')[0]
	}

	function beater(hand) {
		switch (hand) {
			case 'r': 
				return 'p'
			case 's':
				return 'r'
			case 'p':
				return 's'
		}
	}
	function calculateWin(myHand, enemyHand) {
		var win = 0
		for(var i =0;i < myHand.length; i++) {
			if(myHand[i] === 'r' && enemyHand[i] === 's') {
				win += r
			} else if(myHand[i] === 's' && enemyHand[i] === 'p') {
				win += s
			} else if(myHand[i] === 'p' && enemyHand[i] === 'r') {
				win += p
			}
		}
		return win
	}
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int main()
{
	double r;
	cin>>r;
	printf("%.5lf",r*2*3.14159);
	return 0;
}

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

int main(){
  int n,m;
  long long int a,b,c;
  long long int ans;

  int p[100000];
  int count[100000] ={0};

  cin >> n >> m;

  for(int i = 0; i < m; i++){
    cin >> p[i];
    p[i]--;
  }

  for(int i = 0; i < m - 1; i++){
    if(p[i] < p[i + 1]){
      count[p[i]] += 1;
      count[p[i + 1]] -= 1;
    }
    else{
      count[p[i + 1]] += 1;
      count[p[i]] -= 1;
    }
  }

  for(int i = 1; i < n; i++){
    count[i] += count[i - 1];
  }
  
  for(int i = 0; i < n - 1; i++){
    cin >> a >> b >> c;
    
    ans += min(a * count[i],b * count[i] + c);
  }

  cout << ans << endl;
}

Measured memory_bytes: 3872
t=[int(input())for i in range(3)]
x=int(input())
c=0
for i in range(min(x//500,t[0])+1):
    a=t[:]
    d=x-500*i
    if d<=100*a[1]+50*a[2]:
        for j in range(a[1]+1):
            if d>=100*j:
                r=d-100*j
                if r<=50*a[2]:
                    c+=1
            else:
                break
print(c)

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

int main() {
 int a = 0;
 string b;
 cin >> b;
 if(b=="SSS") cout << "0" << endl;
 else if(b=="RRS"||b=="SRR") cout << "2" <<endl;
 else if(b=="RRR") cout << "3" << endl;
  else cout << "1" <<endl;
   }


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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);

int main(int argc, char* argv[]) {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);

  ll ans = 0;
  rep(i, K + 1, N + 1) {
    ans += (N / i) * (i - K);
    ans += max((N % i) - K + 1, 0LL);
    if (K == 0) ans--;

    // if (N != 10) continue;
    // debug(i);
    // cerr << (N / i) * (i - K) << endl;
    // cerr << max((N % i) - K + 1, 0LL) << endl;
  }

  put(ans);
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

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

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); }

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}

template <class T> T mod(T a, T m) { return (a % m + m) % m; }


Measured memory_bytes: 256
fun main(arr:Array<String>) {
    val wd = listOf("SUN","MON","TUE","WED","THU","FRI","SAT").toMutableList()
    wd.addAll(wd)
    val s = readLine()!!
    val idx = wd.indexOf(s)
    val ans = wd.subList(idx+1, wd.lastIndex).indexOf("SUN") + 1
    println(ans)
}

Measured memory_bytes: 35776
#include"bits/stdc++.h"
 
 
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(int x = (l);x<=(u);x++)
#define RREP(x,l,u) for(int x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()
 
typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
 
const int maxn = 310;
const int mod = 1e9+7;
const int MAX = 1000000010;
const double eps = 1e-6;
const double PI = acos(-1);
 
template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}
 
template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}
 
int n;
 
char s[maxn][maxn];
 
int main(){
	read(n);
	REP(i,0,n-1)scanf("%s",s[i]);
	int ans=0;
	REP(x,0,n-1){
		bool ok=1;
		REP(i,0,n-1)REP(j,0,n-1)if(s[(i+x)%n][j]!=s[(j+x)%n][i])ok=0;
		if(ok)ans+=n;
	}
	iout(ans);
	return 0;
}

Measured memory_bytes: 512
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  [a, b, h, m] <- getIntList

  let m' = (fromIntegral m) / 60.0
      h' = (fromIntegral h + m') / 12.0

      theta_a :: Double
      theta_a = 2.0 * pi * h'

      theta_b :: Double
      theta_b = 2.0 * pi * m'

      xa = (fromIntegral a) * cos theta_a
      ya = (fromIntegral a) * sin theta_a

      xb = (fromIntegral b) * cos theta_b
      yb = (fromIntegral b) * sin theta_b

      dx = abs (xa - xb)
      dy = abs (ya - yb)

      d = sqrt (dx^2 + dy^2)

  print d


Measured memory_bytes: 4360
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pli pair<ll,int>
const int N=100;
 
struct Edge{
  int to,nxt,val;
}edge[3000000];
int head[N*N],tot;
void add(int u,int v,int w){
  edge[++tot]={v,head[u],w};
  head[u]=tot;
}
 
char s[N][25];
int l[N][25],r[N][25],c[N],id=0;
int len[N],n,st,ed;
 
bool check(int i,int l,int r){
  while(l<r){
    if(s[i][l]!=s[i][r])return 0;
    l++,r--;
  }
  return 1;
}
 
ll dis[N*N],inf=1e18;
void dijkstra(){
  for(int i=0;i<N*N;i++)dis[i]=inf;
  priority_queue<pli,vector<pli>,greater<pli>>pq;
  pq.push({0,st}),dis[st]=0;
  while(!pq.empty()){
    pli fir=pq.top();pq.pop();
    int u=fir.second;
    if(fir.first>dis[u])continue;
    for(register int i=head[u];i;i=edge[i].nxt){
      int v=edge[i].to;
      if(dis[v]>dis[u]+edge[i].val){
        dis[v]=dis[u]+edge[i].val;
        pq.push({dis[v],v});
      }
    }
  }
}
int main(){
  scanf("%d",&n);
  for(int i=1;i<=n;i++){
    scanf("%s%d",s[i]+1,&c[i]);
    len[i]=strlen(s[i]+1);
    for(int j=1;j<=len[i];j++)
      l[i][j]=++id,r[i][j]=++id;
  }
  st=++id,ed=++id;
  for(int i=1;i<=n;i++){
    add(st,l[i][1],c[i]);
    for(int j=1;j<=len[i];j++){
      if(check(i,j,len[i]))add(l[i][j],ed,0);
      for(int k=1;k<=n;k++){
        if(len[k]<=len[i]-j+1){
          bool flag=1;
          int a=j,b=len[k];
          for(;b>=1;a++,b--)
            if(s[i][a]!=s[k][b]){
              flag=0;break;
            } 
          if(flag){
            if(check(i,a,len[i]))add(l[i][j],ed,c[k]);
            else add(l[i][j],l[i][a],c[k]);
          }
        }else{
          bool flag=1;
          int a=j,b=len[k];
          for(;a<=len[i];a++,b--)
            if(s[i][a]!=s[k][b]){
              flag=0;break;
            }
          if(flag){
            if(check(k,1,b))add(l[i][j],ed,c[k]);
            else add(l[i][j],r[k][b],c[k]);
          }
        }
      }
    }
  }
  for(int i=1;i<=n;i++){
    add(st,r[i][len[i]],c[i]);
    for(int j=1;j<=len[i];j++){
      if(check(i,1,j))add(r[i][j],ed,0);
      for(int k=1;k<=n;k++){
        if(len[k]<=j){
          bool flag=1;
          int a=j,b=1;
          for(;b<=len[k];b++,a--)
            if(s[i][a]!=s[k][b]){
              flag=0;break;
            }
          if(flag){
            if(check(i,1,a))add(r[i][j],ed,c[k]);
            else add(r[i][j],r[i][a],c[k]);
          }
        }else{
          bool flag=1;
          int a=j,b=1;
          for(;a>=1;a--,b++)
            if(s[i][a]!=s[k][b]){
              flag=0;break;
            }
          if(flag){
            if(check(k,b,len[k]))add(r[i][j],ed,c[k]);
            else add(r[i][j],l[k][b],c[k]);
          }
        }
      }
    }
  }
  dijkstra();
  if(dis[ed]>=inf)puts("-1");
  else printf("%lld\n",dis[ed]);
  return 0;
}

Measured memory_bytes: 3880
from collections import Counter
def main():
    n = int(input())
    A = list(map(int, input().split()))
    A1 = A[::2]
    A2 = A[1::2]
    C1 = Counter(A1).most_common()
    C2 = Counter(A2).most_common()
    if len(set(A)) == 1:
        print(n // 2)
    elif C1[0][0] == C2[0][0]:
        print(n - max(C1[0][1] + C2[1][1], C1[1][1] + C2[0][1]))
    else:
        print(n - C1[0][1] - C2[0][1])

if __name__ == '__main__':
    main()


Measured memory_bytes: 25180
#include<iostream>
#include<vector>
#include <algorithm>

using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<n; i++)


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

	vector<int>p(n);
	rep(i, n) {
		cin >> p[i];
	}

	int ans = 0;
	repr(i, 1, n-1) {
		if ((p[i - 1] < p[i]) && (p[i] < p[i + 1])) {
			ans++;
		}
		else if ((p[i - 1] > p[i]) && (p[i] > p[i + 1])) {
			ans++;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
N, Z, W = map(int, input().split(' '))
a= list(map(int, input().split(' ')))
if N == 1:
    print(abs(a[-1]-W))
elif abs(Z-W) < min(abs(a[-1]-W), abs(a[-2]-a[-1])):
    print(max(abs(a[-1]-W), abs(a[-2]-a[-1])))
else:
    print(max(abs(a[-2]-a[-1]), abs(a[-1]-W)))

Measured memory_bytes: 3188
import java.lang.reflect.Array;
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    static class pair {
        int a, b;

        pair(int a, int b) {
            this.a = a;
            this.b = b;
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String[] args) throws Exception {
        FastReader in = new FastReader();
        long n=in.nextLong();
        long p=in.nextLong();
        TreeMap<Long,Long>map=new TreeMap<>();
        long c=0;
        if(p%2==0) {
            c = 0;
            while (p % 2 == 0) {
                p = p / 2;
                c++;
            }
            map.put(2L, c);
            c = 0;
        }
        for(long i=3;i*i<=p;i+=2){
            if(p%i==0){
                while(p%i==0){
                    c++;
                    p=p/i;
                }
                map.put(i,c);
                c=0;
            }
        }
        if(p>2){
            map.put(p,map.getOrDefault(p,0L)+1);
        }
        long gcd=1L;
        while(!map.isEmpty()){
            Map.Entry<Long,Long> e=map.pollLastEntry();
            long key=e.getKey();
            long val=e.getValue();
            if(val>=n){
                gcd=(gcd*powe(key,(val/n)));
            }
        }
        System.out.println(gcd);
    }

    private static long powe(long a, long b) {
        long res=1;
        while(b!=0){
            if(b%2!=0){
                res=res*a;
            }
            b>>=1;
            a=a*a;
        }
        return res;
    }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define pb push_back
using namespace std;

typedef long long int ll;
int main()
{
    ll a,b;
    cin>>a>>b;

    ll ans=1;
    ll now=a;
    ll mul=2;
    for(ll i=1;i<=100;i++)
    {
        now=now*2;
        if(now>b)break;
        ans++;
    }
    cout<<ans<<endl;
    //main();

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>

#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;

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

    if(s[0] == s[1] && s[2] == s[3] && s[0] != s[2]){
        cout << "Yes" << endl;
    }else if(s[0] == s[2] && s[1] == s[3] && s[0] != s[1]){
        cout << "Yes" << endl;
    }else if(s[0] == s[3] && s[1] == s[2] && s[0] != s[1]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}




Measured memory_bytes: 256
/*
 * 1st.cpp
 *
 *  Created on: Sep 6, 2017
 *      Author: Nirav
 */


#include <bits/stdc++.h>
using namespace std;

#define fill(a,val) memset(a, (val), sizeof a)
#define pb push_back
#define lli long long int
#define scantype int
#define endl "\n"
#define unique(x) x.erase(unique(x.begin(),x.end()), x.end())
#define sort_f(x)  sort(x.begin(),x.end());
#define sort_r(x)  sort(x.rbegin(),x.rend());

lli MOD  = 1000000007;
lli inf = 1e15;

void scan(scantype &x);
lli powermod(lli _a,lli _b,lli _m){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
lli string_to_number(string s){lli x=0; stringstream convert(s); convert>>x; return x;}
lli add(lli a,lli b){lli x = (a+b)%MOD; return x; }
lli mul(lli a,lli b){lli x = (a*b)%MOD; return x; }
lli sub(lli a,lli b){lli x = (a-b+MOD)%MOD; return x; }
lli divi(lli a,lli b){lli x = a;lli y = powermod(b,MOD-2,MOD);lli res = (x*y)%MOD;return res;}

#define N 200003



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
     string s;
    cin>>s;
    int n=s.length();
    string s1="";
    for(int i=0;i<n;i++)
    {
        char c=s[i];
     if(i%2==0)
     {
       s1+=c;
     }
    }
    cout<<s1;
                    
	return 0;
}

void scan(scantype &x)
{
    register int c = getchar(); //for negative/positive
    x = 0;
    int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = getchar());
    if(c=='-') {neg=1;c=getchar();}
    for(;c>47 && c<58;c = getchar()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}









Measured memory_bytes: 592
import * as fs from 'fs'

const input: string = fs.readFileSync('/dev/stdin', 'utf8');
const args: string[][] = input.split('\n').map(l => l.split(' '));

const n: number = parseInt(args[0][0]);
const s: string = args[1][0];

let r = 0;
let g = 0;
let b = 0;
s.split('')
  .forEach(x => {
    switch (x) {
      case 'R':
        r++;
        break
      case 'G':
        g++;
        break
      case 'B':
        b++;
        break
    }
  });

let cnt = r * g * b;
for (let i = 0; i < n - 2; i++) {
  for (let j = i + 1; j < n - 1; j++) {
    const k = j + (j - i);
    if (k < n && s[i] !== s[j] && s[j] !== s[k] && s[k] !== s[i]) cnt--;
  }
}

console.log(cnt);


Measured memory_bytes: 35588
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define dbg puts("It's Just Begining.Wait For The End!!!!!\n")
#define CHECK(x) cout << (#x) << " is " << (x) <<"\n";
#define endl printf("\n")
typedef pair<ll,ll> pii;
#define pb push_back
#define ms(a,b) memset(a, b, sizeof(a))
#define in(x) scanf("%lld",&x)
#define out(x) printf("%lld",x)
#define X first
#define Y second
#define sps printf(" ")
#define dou(x) cout<<fixed<<setprecision(6)<<x
#define all(v) v.begin(),v.end()
#define dis(it,it1) distance(it,it1)+1
#define MAX 200005
#define INF 1000000000
#define MOD 1000000007
#define print(cs) printf("Case %lld: ",cs)
#define Yesno(ok) if(ok)puts("YES");else puts("NO")
#define yesno(ok) if(ok)puts("Yes");else puts("No")
ll lcm(ll a,ll b){return ((a*b)/__gcd(a,b));}
vector<ll>vt;;
int main()
{
    ll i,j,k,l=1,n=10000000,m,r;
    in(m);
    for(i=0,k=1;i<=n;i++,k=10)
    {
        l=(l*(k%m))%m;
        vt.pb(l);
    }
    ll num=0;
    for(i=0,l=7;i<=n;i++)
    {
        num+=((l%m)*(vt[i]%m))%m;
        num%=m;
        if(num==0)
        {
            cout<<i+1;endl;
            exit(0);
        }
    }
    puts("-1");
}


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

int main() {
  int n,count=0,flag=0;
  int a[200];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  
  
  while(true){
    for(int i=0;i<n;i++){
    if(a[i]%2==1){
      flag++;
      break;
     
    }
    a[i]=a[i]/2;
  	}
    if(flag!=0)break;
    count++;
  }
  cout<<count<<endl;
}


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

#ifndef DEBUG
#define DEBUG false
#endif

#define REP(t,i,a,b) for(t i = a; i < b; ++i)

using namespace std;

typedef long long ll;

void create_data (
    ll p,
    vector<bool>& checked,
    vector<vector<ll>>& neighbors,
    vector<vector<ll>>& data
) {
    if (checked[p]) return;
    checked[p] = true;
    for (const ll n: neighbors[p]) {
        if (checked[n]) continue;
        data[p].push_back(n);
        create_data(n, checked, neighbors, data);
    }
}

void calc (ll p, vector<ll>& score, vector<vector<ll>>& data) {
    if (data[p].size() <= 0) return;
    for (const ll d: data[p]) {
        score[d] += score[p];
        calc(d, score, data);
    }
}

int main (void) {
    ll n, q;
    cin >> n >> q;

    vector<vector<ll>> neighbors(n+1);
    REP (ll, i, 0, n-1) {
        ll a, b;
        cin >> a >> b;
        neighbors[a].push_back(b);
        neighbors[b].push_back(a);
    }

    vector<bool> checked(n+1, false);
    vector<vector<ll>> data(n+1);
    create_data(1, checked, neighbors, data);

    if (DEBUG) REP(ll, i, 0, data.size()) {
        cout << i << ": ";
        for (const ll d: data[i]) {
            cout << d << ", ";
        }
        cout << endl;
    }

    vector<ll> score(n+1, 0);
    REP (ll, i, 0, q) {
        ll p, x;
        cin >> p >> x;
        score[p] += x;
    }
    calc (1, score, data);

    REP (ll, i, 1, n+1) {
        cout << score[i];
        if (i < n) cout << ' ';
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 41472
from sys import stdin
import numpy as np
def main():
    #入力
    readline=stdin.readline
    n,k=map(int,readline().split())
    A=np.array(list(map(int,readline().split())),dtype=np.int64)
    A=np.sort(A)[::-1]
    F=np.array(list(map(int,readline().split())),dtype=np.int64)
    F=np.sort(F)

    l=-1
    r=10**12
    while l<r-1:
        x=(l+r)//2
        A_after=np.minimum(x//F,A)
        cnt=(A-A_after).sum()
        if cnt<=k: r=x
        else: l=x

    print(r)

if __name__=="__main__":
    main()

Measured memory_bytes: 37184
n,m = map(int,input().split())
e = [[False]*n for _ in range(n)]
visited = [False]*n
for _ in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    e[a][b] = True
    e[b][a] = True

def traverse(t,d):
    #print(t,d)
    visited[t] = True

    ans = 0
    is_end = True

    for i in range(n):
        if e[t][i] and not visited[i]:
            is_end = False
            ans += traverse(i, d+1)


    visited[t] = False
    if is_end:
        if d != n-1:
            return 0
        else:
            return 1
    
    return ans

print(traverse(0, 0))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)

int main() {
    int N, Pcnt, Qcnt, cnt;
    cin>>N;
    cnt = Pcnt = Qcnt = 0;

    vector<int> P(N, 0), Q(N, 0), R(N, 0);
    REP(i, 0, N){
        cin>>P[i];
    }
    REP(i, 0, N){
        cin>>Q[i];
    }
    iota(R.begin(), R.end(), 1);

    do{
        cnt++;
        REP(i, 0, N){
            if(P[i] == R[i]){
                if(i == N-1){
                    Pcnt = cnt;
                }
            }else{
                break;
            }
        }
    }while(next_permutation(R.begin(), R.end()));

    cnt = 0;
    iota(R.begin(), R.end(), 1);

    do{
        cnt++;
        REP(i, 0, N){
            if(Q[i] == R[i]){
                if(i == N-1){
                    Qcnt = cnt;
                }
            }else{
                break;
            }
        }
    }while(next_permutation(R.begin(), R.end()));

    cout << abs(Pcnt - Qcnt) << endl;
    return 0;    
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(){
  int N,i,Num,countNum=0;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&Num);
      if(isPrime(Num)==1){
        countNum++;
      }else{
        continue;
      }
    }
    printf("%d\n",countNum);
  return 0;
}

int isPrime(int Num){
  int i;
  if(Num==1) return 0;
  for(i=2;i<=sqrt(Num);i++){
    if(Num % i == 0){
      return 0;
      }
    } 
    return 1;
}

Measured memory_bytes: 596
a = input()
b = [0 if i == "W" else 1 for i in list(a)]

b_sum = sum(b)
b_aggr = 0
b_len= len(b)
for i in range(b_len):
    if b[i] == 1:
        b_aggr += (b_len - i - 1)
b_cali = b_sum * (b_sum - 1) / 2
print(int(b_aggr-b_cali))

Measured memory_bytes: 6632
import java.util.*;
import java.util.stream.*;

public class Main {
  public static void main(String[]$) {
    Scanner s=new Scanner(System.in);
    long a[]=new long[s.nextInt()+1];
    System.out.println(IntStream.range(0,a.length).mapToObj(i->a[i]=(i==0?0:a[i-1]+s.nextInt())).collect(Collectors.groupingBy(i->i,Collectors.counting())).values().stream().mapToLong(i->i*(i-1)/2).sum());
  }
}

Measured memory_bytes: 111484
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		
		A = (A+11)%13;
		B = (B+11)%13;
		System.out.println(A==B ? "Draw" : (A>B ? "Alice" : "Bob"));
		
		sc.close();
	}
}


Measured memory_bytes: 9684
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    int N, M, A;

    cin >> N >> M;

    int Answer = 0;

    for (int i = 0; i < M; i++)
    {
        cin >> A;

        Answer = Answer + A;
    }

    int S = N - Answer;

    if (S < 0)
    {

        S = -1;
    }

    cout << S << endl;
}

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

int main() {
    int D, G;
    cin >> D >> G;
    vector<int> p(D), c(D);
    for (int i = 0; i < D; i++) {
        cin >> p.at(i) >> c.at(i);
    }
    int min_answer = 1000;
    for (int bit = 0; bit < (1 << p.size()); bit++) {
        int score = 0;
        int num_answer = 0;
        for (int i = 0; i < p.size(); i++) {
            if (bit & (1 << i)) {
                score += c.at(i) + p.at(i) * 100 * (i + 1);
                num_answer += p.at(i);
            }
        }
//得点がGに届いているかチェック
        if (score >= G) {
            if (num_answer < min_answer){
                min_answer = num_answer;
            }
        }
        else {
            int max_bit = p.size() - 1;
            while (bit & (1 << max_bit)){
                max_bit--;
            }

            if (max_bit >= 0 && score + (p.at(max_bit) - 1) * 100 * (max_bit + 1) >= G) {
                num_answer += ((G - score) + 100 * (max_bit + 1) - 1) / (100 * (max_bit + 1));
                if (num_answer < min_answer) {
                    min_answer = num_answer;
                }
            }
        }
    }

    cout << min_answer << endl; 
}

Measured memory_bytes: 256
fun longList() = readLine()?.split(" ")?.map(String::toLong) ?: TODO()
fun main() {
    val n = readLine()?.toInt() ?: return
    val a = longList()
    var t = 0L
    var l = a[0]
    1.until(n).forEach {
        val b = a[it]
        if (l > b) {
            t += l - b
        } else {
            l = b
        }
    }
    println(t.toString())
}


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

int main()
{
 long long n, k ; cin >> n >> k;
 long long p = n , r = n;
 long long sum = 0;
 while(p >= k){sum += p ; p--;}
 //cout << sum <<endl;
 long long q = n*sum+(n-k)+2;
 //cout << q <<endl;
 while( r >= k ){q -= (r*r-r); r--;}
 cout << q%(1000000000+7) << endl;
}



Measured memory_bytes: 3616
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
#include<set>
using namespace std;
#define N 206
int head[N],cnt=1,dis[N],n,m,v[N][N],as[N][N],as2[N][N],cur[N];
multiset<int> sb[N],vl[N][N];
struct edge{int t,next,v;}ed[N*N*3];
void adde(int f,int t,int v){ed[++cnt]=(edge){t,head[f],v};head[f]=cnt;ed[++cnt]=(edge){f,head[t],0};head[t]=cnt;}
bool bfs(int s,int t)
{
	queue<int> v;
	memset(dis,-1,sizeof(dis));
	memcpy(cur,head,sizeof(cur));
	v.push(s);dis[s]=1;
	while(!v.empty())
	{
		int r=v.front();v.pop();
		for(int i=head[r];i;i=ed[i].next)
		if(dis[ed[i].t]==-1&&ed[i].v)
		{dis[ed[i].t]=dis[r]+1,v.push(ed[i].t);if(ed[i].t==t)return 1;}
	}
	return 0;
}
int dfs(int u,int t,int f)
{
	if(!f||(u==t))return f;
	int as=0,tp;
	for(int &i=cur[u];i;i=ed[i].next)
	if(ed[i].v&&dis[ed[i].t]==dis[u]+1&&(tp=dfs(ed[i].t,t,min(ed[i].v,f))))
	{
		ed[i].v-=tp,ed[i^1].v+=tp,as+=tp,f-=tp;
		if(!f)return as;
	}
	return as;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	{
		scanf("%d",&v[i][j]);
		int v1=(v[i][j]-1)/m+1;
		sb[i].insert(v1),vl[i][v1].insert(v[i][j]);
	}
	for(int i=1;i<=m;i++)
	{
		for(int j=1;j<=n*2+2;j++)head[j]=0;
		cnt=1;
		for(int j=1;j<=n;j++)
		{
			adde(n*2+1,j,1);adde(j+n,n*2+2,1);
			for(int k=1;k<=n;k++)
			{
				multiset<int>::iterator it=sb[j].lower_bound(k);
				if(it==sb[j].end()||*it!=k)continue;
				adde(j,k+n,1);
			}
		}
		while(bfs(n*2+1,n*2+2))dfs(n*2+1,n*2+2,1e8);
		for(int j=1;j<=n;j++)
		for(int k=head[j];k;k=ed[k].next)
		if(!ed[k].v)
		{
			int l=j,r=ed[k].t-n;
			as[l][i]=as2[i][l]=*vl[l][r].begin();
			vl[l][r].erase(vl[l][r].begin());
			sb[l].erase(sb[l].find(r));
		}
	}
	for(int i=1;i<=n;i++,printf("\n"))
	for(int j=1;j<=m;j++)
	printf("%d ",as[i][j]);
	for(int i=1;i<=m;i++)sort(as2[i]+1,as2[i]+n+1);
	for(int i=1;i<=n;i++,printf("\n"))
	for(int j=1;j<=m;j++)
	printf("%d ",as2[j][i]);
}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;

int main() {
	int N, Z, W;
	cin >> N >> Z >> W;
	vector<int> a(N);
	for(int i=0; i<N; ++i) cin >> a[i];
	if(N==1){
	    cout << abs(a[0]-W) << endl;
	    return 0;
	}
	cout << max(abs(a[N-1]-W), abs(a[N-1]-a[N-2])) << endl;
	return 0;
}


Measured memory_bytes: 256
#ｘは持っている飴のこすう
n,x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
if(sum(a)<x):
    ans -=1


a.sort()

for i in range(n):
    if(x >= a[i]):
        x = x-a[i]
        ans +=1
    
    else:
        break

print(ans)
    

Measured memory_bytes: 3060
#include <stdio.h>
 
int cnt;

int main() {
    int n;
    int a[100001], b[100001];
    scanf("%d", &n);
    for(int i=1; i<=n; i++) {
        int r, c;
        scanf("%d%d", &r, &c);
        a[r] = c;
        b[c] = r;
    }
    for(int i=1; i<n; i++) {
        if (a[i] == 0) {
            puts("-1");
            return 0;
        }
        int j = b[i];
        if (i != j) {
            a[j] = a[i];
            b[a[j]] = j;
            cnt++;
        }
    }
    printf("%d\n", cnt);
}



Measured memory_bytes: 2556