akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		for(int i=0; i<N; i++){
			A[i] = sc.nextInt();
		}
		sort(A);
		long answer = 0;
		int l = N/2;
		for(int i=N-1; i>=l; i--){
			answer += A[i]*2;
		}
		for(int i=0; i<l; i++){
			answer -= A[i]*2;
		}
		if(N%2==0){
			answer += A[l-1];
			answer -= A[l];
		}else{
			if(A[l-1]+A[l+1] > A[l]*2){
				answer += A[l-1];
				answer -= A[l]*3;
			}else{
				answer -= A[l]+A[l+1];
			}
		}
		System.out.println(answer);
		System.out.flush();
		return;
	}

	public static void sort(int[] a){
		quickSort(a, 0, a.length-1);
	}

	private static void quickSort(int[] a, int left, int right){
		if(left >= right){return;}
		int pivot = med3(a[left], a[left+(right-left)/2], a[right]);
		int l=left, r=right;
		while(true){
			while (a[l] < pivot){l++;}
			while (pivot < a[r]){r--;}
			if(l>=r){break;}
			int t=a[l]; a[l]=a[r]; a[r]=t;
			l++; r--;
		}
		quickSort(a, left, l-1);
		quickSort(a, r+1, right);
	}

	private static int med3(int x, int y, int z){
	    if(x < y){
	        if (y < z){return y;}else if(z < x){return x;}else{return z;}
	    } else {
	        if (z < y){return y;}else if(x < z){return x;}else{return z;}
	    }
	}
}


Measured memory_bytes: 51788
# 2019/09/30

from fractions import gcd

a,b=map(int,input().split())

g=gcd(a,b)


def trial_div(n):
    from collections import Counter
    
    prime=Counter()

    for i in range(2,int(pow(n,0.5)+2)):
        while n%i==0:
            n//=i
            prime[i]+=1
    if n>1:prime[n]+=1
    
    return prime


res=trial_div(g)
print(1+len(res))

Measured memory_bytes: 5476
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
using namespace std;
const int INF = 0x3f3f3f3f;
int n, a[3], l[10], type[10], s[3][10], cnt[3];
bool chosen[10];
int dfs1(int x, int y)
{
    if (y == cnt[x])
    {
        int sum = 0, cnt_chosen = 0;
        for (int i = 0; i < cnt[x]; i++)
            sum += (chosen[i] ? s[x][i] : 0), cnt_chosen += chosen[i];
        if (!cnt_chosen) return INF;
        //printf("%d\n", sum);
        return (cnt_chosen - 1) * 10 + abs(sum - a[x]);
    }
    int re = INF;
    chosen[y] = 0;
    re = min(re, dfs1(x, y + 1));
    chosen[y] = 1;
    re = min(re, dfs1(x, y + 1));
    return re;
}
int get_ans()
{
    cnt[0] = cnt[1] = cnt[2] = 0;
    for (int i = 0; i < n; i++)
        s[type[i]][cnt[type[i]]++] = l[i];
    if (!cnt[0] || !cnt[1] || !cnt[2]) return INF;
    /*
    for (int i = 0; i < 3; i++)
        for (int j = 0; j < cnt[i]; j++)
            printf("!%d%c", s[i][j], j == cnt[i] - 1 ? '\n' : ' ');
    printf("%d\n", dfs1(0, 0) + dfs1(1, 0) + dfs1(2, 0));
    puts("");
    */
    return dfs1(0, 0) + dfs1(1, 0) + dfs1(2, 0);
}
int dfs(int x)
{
    if(x == n)
        return get_ans();
    int re = INF;
    for (int i = 0; i < 3; i++)
        type[x] = i, re = min(re, dfs(x + 1));
    return re;
}
int main()
{
    scanf("%d%d%d%d", &n, &a[0], &a[1], &a[2]);
    for (int i = 0; i < n; i++)
        scanf("%d", &l[i]);
    printf("%d\n", dfs(0));
    return 0;
}


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

int main() {
	string s;
	cin >> s;
	int i,n=s.size();
	for(i=0; i<n-1; i++){
		if(s[i]=='A' && s[i+1]=='C'){
			cout << "Yes"; return 0;
		}
	}
	cout << "No"; 
	return 0;
}

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

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

const int INF = 1e9 + 7;

using namespace std;

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

	int n, k;
	cin >> n >> k;

	vector<ll> h(n);
	rep (i, 0, n)
		cin >> h[i];

	sort(h.begin(), h.end(), greater<ll>());

	ll res = LLONG_MAX;
	rep (i, 0, n - (k - 1))
		res = min(res, h[i] - h[i + (k - 1)]);

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 1024
S = input()
N = len(S)
ans = 1
tmp = S[0]
csr = 1
while csr < N:
    if S[csr] == tmp:
        if csr == N - 1:
            ans -= 1
        tmp = S[csr:csr+2]
        csr += 2
        
    else:
        tmp = S[csr]
        csr += 1
    ans += 1

print(ans)

Measured memory_bytes: 3500
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
using vi  = vector<int>;
 
const double EPS = 1e-8;
using P = valarray<double>;
const int dim = 3;
using L = vector<P>;
struct C{
  P p; double r;
};
 
double dot(const P& a, const P& b){
  return (a * b).sum();
}
double norm(const P& p){
  return dot(p, p);
}
double absP(const P& p){
  return sqrt(norm(p));
}
bool intersectSP(const L &s, const P &p) {
  return absP(s[0]-p)+absP(s[1]-p)-absP(s[1]-s[0]) < EPS;
}
P projection(const L &l, const P &p) {
  double t = dot(p-l[0], l[1]-l[0]) / norm(l[1]-l[0]);
  return l[0] + t*(l[1]-l[0]);
}
double distanceSP(const L &s, const P &p) {
  const P r(projection(s, p));
  if (intersectSP(s, r)) return absP(r - p);
  return min(absP(s[0] - p), absP(s[1] - p));
}

int main(){
  int n, q; cin >> n >> q;
  vector<C> cs(n);
  vector<long long> cost(n);
  rep(i,n){
    cs[i].p.resize(3);
    rep(j,3) cin >> cs[i].p[j];
    cin >> cs[i].r;
    cin >> cost[i];
  }
  vector<L> ls(q, L(2, P(3)));
  rep(i,q){
    rep(j,3) cin >> ls[i][0][j];
    rep(j,3) cin >> ls[i][1][j];
  }
   
  rep(i,q){
    long long res = 0;
    rep(j,n){
      if(distanceSP(ls[i],cs[j].p) - EPS < cs[j].r) res += cost[j];
    }
    cout << res << endl;
  }
}


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

string replace(string str, int begin, int end, string replacedContents) {
    str.replace(begin, (end - begin) + 1, replacedContents);
    return str;
}

string reverse(string str, int begin, int end) {
    for (int i = begin, j = end; i < j; i++, j--) {
        swap(str[i], str[j]);
    }
    return str;
}

string print(string str, int begin, int end) {
    cout << str.substr(begin, (end - begin) + 1) << endl;
    return str;
}

int main(void){
    string str, order, replacedContents;
    int orderNumber, begin, end;
    cin >> str >> orderNumber;
    for (int i = 0; i < orderNumber; i++) {
        cin >> order >> begin >> end;
        if (order == "replace") {
            cin >> replacedContents;
            str = replace(str, begin, end, replacedContents);
        } else if (order == "reverse") {
            str = reverse(str, begin, end);
        } else if (order == "print") {
            str = print(str, begin, end);
        }
    }
    return 0;
}

Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 7;
struct node{
	int l,r;
}rob[maxn];
int cmp(node a,node b){
	return a.r < b.r;
	if(a.r==b.r) return a.l < b.l;
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		int idx,len;
		scanf("%d %d",&idx,&len);
		rob[i].l = idx - len;
		rob[i].r = idx + len;
	}
	sort(rob+1,rob+1+n,cmp);
//	for(int i = 1;i <= n;i++){
//		cout << rob[i].l << " " << rob[i].r <<endl;
//	}
	int la = rob[1].l;
	int cnt = 0;
	for(int i = 1;i <= n;i++){
		if(rob[i].l >= la){
			cnt++;
			la = rob[i].r;
		}
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 1024
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::cmp;

fn main() {
    input!(n: usize, m: usize, a: [usize1; n]);
    let mut start = vec![vec![]; m];
    let mut end = vec![vec![]; m];
    for i in 0..(n - 1) {
        let from = a[i];
        let to = a[i + 1];
        start[from].push(to);
        end[to].push(from);
    }

    let mut total = 0;
    let mut count = 0;
    for from in 0..m {
        for &to in start[from].iter() {
            if from > to {
                count += 1;
                total += to + 1;
            } else {
                total += to - from;
            }
        }
    }
    // eprintln!("cur=0 {}", total);
    let mut ans = total;
    for cur in 1..m {
        for &from in end[cur - 1].iter() {
            count -= 1;
            let to = cur - 1;
            total += (to + m - from) % m;
            total -= 1;
        }
        total -= count;

        ans = cmp::min(ans, total);
        // eprintln!("cur={} {}", cur, total);
        count += start[cur - 1].len();
    }
    println!("{}", ans);
}


Measured memory_bytes: 18684
N = int(input())
A = list(map(int, input().split()))
B = [0]*(N+1)
x = []
for n in range(N):
  if (sum(B[::N-n]))%2!=A[N-n-1]:
    B[N-n]=1
    x.append(str(N-n))
print(len(x),'\n',' '.join(x))

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  for (char c : s) {
  	if (c == '1') {
    	cout << 9;
    } else if (c == '9') {
    	cout << 1;
    }
  }
  cout << '\n';
  return 0;
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
  gearup;
  int h,w,d;cin>>h>>w>>d;
  int a;
  vl x(100000),y(100000);
  rep(i,h)rep(j,w){
    cin>>a; 
    x[a] = i;
    y[a] = j;
  }
  vl s(100000+1);
  for(int i=d+1;i<=h*w;i++)s[i] = s[i-d] + abs(x[i]-x[i-d]) + abs(y[i]-y[i-d]);

  int q; cin >> q;
  rep(i,q){
    int l,r; cin >> l >> r;
    out(s[r] - s[l]);
  }
}

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

using namespace std;

int main(void) {
	long long N;
	cin >> N;
	long long t = N;
	long long f = 0;
	while(t > 0) {
		f += t % 10;
		t /= 10;
	}
	if(N % f == 0) {
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<vector>
using namespace std;
int main()
{
    long long n,i,ma=INT_MIN,mi=INT_MIN,k,c=0;
    cin>>n;
    vector<long long>v;
    for(i=0;i<n;i++)
    {
        cin>>k;
        v.push_back(k);
    }
    ma=v[0];
    k=0;
    for(i=1;i<n;i++)
    {
        if(v[i]>ma)
        {
            ma=v[i];
            k=i;
        }
    }
    for(i=0;i<n;i++)
    {
        if(v[i]==ma)
        {
            c++;
        }
    }
    for(i=0;i<n;i++)
    {
        if(v[i]!=ma)
        {
            mi=max(mi,v[i]);
        }

    }
   if(c>1)
   {
       for(i=0;i<n;i++)
       {
           cout<<ma<<endl;
       }
   }
   else
   {
    for(i=0;i<n;i++)
    {
        if(v[i]==ma)
        {
            cout<<mi<<endl;
        }
        else
        {
            cout<<ma<<endl;
        }
    }
   }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 5228
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Map<String, Integer> countMap = new HashMap<>();
		for(int i = 0; i < n; i++) {
			String word = sc.next();
			countMap.put(word, countMap.containsKey(word) ? countMap.get(word) + 1 : 1);
		}
		int m = sc.nextInt();
		for(int i = 0; i < m; i++){
			String word = sc.next();
			countMap.put(word, countMap.containsKey(word) ? countMap.get(word) -1 : -1);
		}
		System.out.println(Math.max(countMap.entrySet().stream().max((e1, e2) -> e1.getValue() - e2.getValue()).get().getValue(), 0));
	}
}

Measured memory_bytes: 28116
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    int n; sc(n)
    ll ans = 0;
    vector<int> a(n), b(n), c(n);
    for (int i = 0; i < n; i++) sc(a[i])
    for (int i = 0; i < n; i++) sc(b[i])
    for (int i = 0; i < n; i++) sc(c[i])
    sort(a.begin(), a.end()); 
    sort(b.begin(), b.end()); 
    sort(c.begin(), c.end());
    for (int i = 0; i < n; i++){
        auto it1 = upper_bound(c.begin(), c.end(), b[i]);
        auto it2 = lower_bound(a.begin(), a.end(), b[i]);
        ans += (c.end() - it1) * (it2 - a.begin());
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
N = int(input())
H = list(map(int, input().split()))

dp = [float("inf")] * N
dp[0] = 0

for n in range(1,N):
  dp[n] = min(dp[n], dp[n-1]+abs(H[n]-H[n-1])) 
  if n >= 2:
    dp[n] = min(dp[n], dp[n-2]+abs(H[n]-H[n-2]))
  
print(dp[-1])

Measured memory_bytes: 13980
# C - Prison

N, M = map(int, input().split())
left = 0
right = 10 ** 5
for _ in range(M):
    l, r = map(int, input().split())
    left, right = max(left, l), min(right, r)

print(len([i for i in range(left, right + 1)]) if left <= right else 0)


Measured memory_bytes: 7088
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
using namespace std;

int main(){
	long long x;
	cin >> x;
	long long cnt=2*(x/11);
	if(1<=x%11 && x%11<=6){
		cnt++;
	}else if(x%11>=7){
		cnt+=2;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define SIZE 500005
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define mp make_pair
#define ll long long
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
ll n, m, k, top;
char s[SIZE];
int t[26][SIZE];
int lowbit(int x) { return x & (-x); }

void add(int pos, int x, int num) { //pos位置加上x
	for (; pos <= n; pos += lowbit(pos)) { //n为数组大小
		t[num][pos] += x;
	}
}

int query_presum(int pos, int num) { //查询pos位置的前缀和，即a1 + a2 + ... + apos
	int ans = 0;
	for (; pos > 0; pos -= lowbit(pos)) {
		ans += t[num][pos];
	}
	return ans;
}

int query_sum(int l, int r, int num) { //[l, r]区间查询
	return query_presum(r, num) - query_presum(l - 1, num);
}

int main() {
	io(); cin >> n >> (s + 1);
	rep(i, 1, n) add(i, 1, (s[i] - 'a'));
	cin >> m;
	rep(i, 1, m) {
		int op, x, y; char ch; cin >> op;
		if (op == 1) {
			cin >> x >> ch;
			add(x, -1, (s[x] - 'a'));
			add(x, 1, (ch - 'a'));
			s[x] = ch;
		}
		else {
			int ans = 0;
			cin >> x >> y;
			rep(i, 0, 25) {
				if (query_sum(x, y, i) > 0) {
					++ans;
				}
			}
			cout << ans << '\n';
		}
	}
}
/*
8
aaaaaaaa
100
1 1 b
2 1 8
1 1 a
2 1 8
*/

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

using namespace std;

typedef long long int ll;

const int mod = 1e9 + 7;

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

  int n;
  string s;
  cin >> n >> s;

  vector < char > d (2 * n);
  d[0] = 'L';
  int cnt = 1;
  for (int i = 1; i < 2 * n; i++) {
    if (s[i] == s[i - 1]) {
      if (d[i - 1] == 'L') {
        d[i] = 'R';
      } else {
        d[i] = 'L';
      }
    } else {
      d[i] = d[i - 1];
    }

    if (d[i] == 'L') cnt++;
    else cnt--;
  }

  if (cnt != 0 || s[0] != 'B' || s[2 * n - 1] != 'B') {
    cout << 0 << '\n';
    return 0;
  }

  ll ans = 1;
  for (int i = 0; i < 2 * n; i++) {
    if (d[i] == 'R') ans = (ans * cnt) % mod;
    if (d[i] == 'L') cnt++;
    else cnt--;
  }

  for (int i = 1; i <= n; i++) ans = (ans * i) % mod;

  cout << ans << '\n';
}


Measured memory_bytes: 3808
w = input()

# lenw = int(len(w))

# if lenw%2==0:
#     print("Yes")

# else:
#     print("No")

counter = {}
alphabets = "abcdefghijklmnopqrstuvwxyz"

for i in alphabets:
    counter[i] = 0

for i in w:
    counter[i] = counter[i]+1

allok = True
for i in counter:
    if counter[i] % 2 != 0:
        allok = False

if allok == True:
    print("Yes")

else:
    print("No")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
int main(void) {
    int a,b,x; scanf("%d%d%d",&a,&b,&x);
    double ans;
    if (a*a*b >= 2*x) {
        double l = 2*x/(double)(a*b);
//        printf("l = %f, b = %d\n",l,b);
        ans = atan(l/b);
    } else {
        double l = 2*x/(double)(a*a)-b;
        ans = atan(a/(b-l));
    }
    ans = ans*180/pi;
    printf("%.10f\n",90-ans);
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,cc,n) for(int i=cc;i<(n);++i)
#define dreps(i,cc,n) for(int i=cc;i>(n);--i)
#define llreps(i,cc,n) for(long long i=cc;i<(n);++i)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

int main()
{
	int x[5];
	rep(i, 5)
		cin >> x[i];
	rep(i,5)
		if (x[i] == 0)
		{
			cout << i+1 << endl;
			return 0;
		}
}

Measured memory_bytes: 3540
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<sstream>
#include<iomanip>
#define pb push_back
#define LL long long
#define ff first
#define ss second
#define in inline
#define RE register
using namespace std;
const int MAXN=0x3f3f3f3f;
const int MAXL=0x7ffff;
in void read(int &x){
   x=0;
   char c=getchar();
   while(c>'9'||c<'0')c=getchar();
   while(c<='9'&&c>='0'){
   x=x*10+c-'0';
   c=getchar();
   }
}
inline void write(int re)
 {     /*
     if (re<0)
     {
         putchar('-');
         re=-re;
     }
     */
     if (re>9) write(re/10);
     putchar(re%10+'0');
}
int a[100000];
int n,ans;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)read(a[i]);
	for(int i=1;i<n;i++){
		if(a[i]==i){
			swap(a[i],a[i+1]);
			ans++;
		}
	}
	if(a[n]==n)ans++;
	cout<<ans;
} 

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>



using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const double EPS = 1e-10;
long long const MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

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

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

const int MAXN = 100005;

long long fact[MAXN], inv[MAXN];

void initComb() {
    fact[0] = 1;
    for (int i=1; i<MAXN; i++) {
        fact[i] = (fact[i-1] * i) % MOD;
    }

    inv[MAXN - 1] = mod_pow(fact[MAXN - 1], MOD-2);
    for (int i=MAXN - 2; i>=0; i--) {
        inv[i] = (inv[i+1] * (i+1)) % MOD;
    }
}

vector<vector<int>> G;
vector<int> childCnt;
vector<int> v;

int dfs(int crt) {
    v[crt] = 1;
    int child = 0;
    for (int i = 0; i < G[crt].size(); i++) {
        int nextV = G[crt][i];
        if (v[nextV] == 0) {
            dfs(nextV);
            child++;
        }
    }
    childCnt[crt] = child;
    return 0;
}

int main(void) {
    int N, K; cin >> N >> K;
    initComb();
    childCnt = vector<int>(N);
    v = vector<int>(N);
    G = vector<vector<int>>(N);

    for (int i = 0; i < N-1; i++) {
        int a, b; cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    dfs(0);

    long long ans = K;
    if (K-1 - childCnt[0] < 0) {
        cout << 0 << endl;
        return 0;
    }
    ans *= (fact[K-1] * inv[(K-1) - childCnt[0]]) % MOD;
    ans %= MOD;
    for (int i = 1; i < N; i++) {
        if (K-2 - childCnt[i] < 0) {
            ans = 0;
            break;
        }
        ans *= (fact[K-2] * inv[(K-2) - childCnt[i]]) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}

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

using namespace std;
# define rep(i, a, b) for(int i = a; i < (b); ++i)
# define trav(a, x) for(auto& a : x)
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

struct Tree {
    typedef int T;
    static constexpr T unit = 0;

    T f(T a, T b) { return a + b; } // (any associative fn)
    vector<T> s;
    int n;

    Tree(int n = 0, T def = unit) : s(2 * n, def), n(n) {}

    void update(int pos, T val) {
        for (s[pos += n] = val; pos /= 2;)
            s[pos] = f(s[pos * 2], s[pos * 2 + 1]);
    }

    T query(int b, int e) { // query [b, e)
        T ra = unit, rb = unit;
        for (b += n, e += n; b < e; b /= 2, e /= 2) {
            if (b % 2) ra = f(ra, s[b++]);
            if (e % 2) rb = f(s[--e], rb);
        }
        return f(ra, rb);
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    int q;
    cin >> q;
    Tree vTree(n + 1);
    Tree hTree(n + 1);
    vector<int> qt;
    vector<int> qx;
    for (int i = 0; i < q; i++) {
        int t;
        int x;
        cin >> t >> x;
        qt.push_back(t);
        qx.push_back(--x);
    }
    for (int i = 0; i < q; i++) {
        if (qt[i] == 1) {
            vTree.update(qx[i], 1);
        } else {
            hTree.update(qx[i], 1);
        }
    }
    ll maxV = n - 1;
    ll maxH = n - 1;
    ll sum = 0;
    for (int i = 0; i < q; i++) {
        if (qt[i] == 1) {
            if (qx[i] < maxV) {
                sum += vTree.query(qx[i], maxV) * (maxH - 1);
                maxV = qx[i];
            }
        } else {
            if (qx[i] < maxH) {
                sum += hTree.query(qx[i], maxH) * (maxV - 1);
                maxH = qx[i];
            }
        }
    }
    cout << (n-2ll)*(n-2ll) - sum;
    return 0;
}

Measured memory_bytes: 8260
func main() {
    let n = Int(readLine()!)!
    if n < 3 {
        print(0)
        return
    }
    let lList = readLine()!.split(separator: " ").map{Int($0)!}.sorted()
    var count = 0
    for i in 1...n-2 {
        let a = lList[i-1]
        for j in i+1...n-1 {
            let b = lList[j-1]
            if a == b { continue }
            for k in j+1...n {
                let c = lList[k-1]
                if b == c { continue }
                if c < a + b {
                    count += 1
                }
            }
        }
    }
    print(count)
    return
}

main()


Measured memory_bytes: 8388
#include <stdio.h>
#include <string.h>

int main(void)
{
	char str[20];
	char in[20];
	char ring[50];
	int n;
	int cnt;
	int i;
	
	scanf("%s", str);

	scanf("%d", &n);
	
	cnt = 0;
	for (i = 0; i < n; i++){
		scanf("%s", in);
		strcpy(ring, in);
		strcat(ring, in);
		if (strstr(ring, str) != NULL){
			cnt++;
		}
	}
	printf("%d\n", cnt);
	
	return (0);
}

Measured memory_bytes: 624
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A = sorted(A)
    A_M = sorted(A)
    A_M[0] *= -1
    start = 0
    if N == 2:
        print(max(A) - min(A))
        print('{} {}'.format(max(A), min(A)))
        return
    for i in range(1, N-1):
        if A_M[i] < 0:
            A_M[i] *= -1
            start = i
    M = sum(A_M)
    print(M)
    if start == 0:
        for i in range(1, N):
            if i < N-1:
                if i == 1:
                    x = A[0]
                    y = A[1]
                else:
                    x = tmp
                    y = A[i]
            else:
                x = A[-1]
                y = tmp
            tmp = x - y
            print('{} {}'.format(x, y))
    elif start == N - 2:
        for i in range(1, N):
            if i == 1:
                x = A[-1]
                y = A[start]
            else:
                x = tmp
                y = A[start-i+1]
            tmp = x - y
            print('{} {}'.format(x, y))
    else:
        for i in range(1, N):
            if i == 1:
                x = A[start]
                y = A[start+1]
            elif 1 < i < N - 1 - start:
                x = tmp
                y = A[start+i]
            elif i == N - 1 - start:
                x = A[-1]
                y = tmp
            else:
                x = tmp
                y = A[start-(i-(N-1-start))]
            tmp = x - y
            print('{} {}'.format(x, y))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 14096
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

char c;
int main(){
	ll n;
	scanf("%lld",&n);
	ll ans=0;
	rep(i,0,n){
		char t;
		scanf(" %c",&t);
		if(c!=t)ans++;
		c=t;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
typedef long long ll;
using namespace std;

const ll MOD = 1000000007;

ll N, ans=0, tmp=0;
vector<ll> K(60, 0);

signed main(){
    cin >> N;
    for(int i=0;i<N;i++) {
        cin >> tmp;
        //cout << bitset<60>(tmp) << endl;
        ll k=0;
        while(tmp>=1) {
            K[k] += tmp%2;
            k++;
            tmp /= 2;
        }
    }
    ll d=1;
    for(int i=0;i<60;i++) {
        ans += (d*K[i]%MOD)*(N-K[i])%MOD;
        ans %=MOD;
        //cout << K[i] << " " << ans << endl;
        d*=2;
        d%=MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A, B = [int(x) for x in input().split()]
score = [0, 0, 0]
lst = [int(x) for x in input().split()]
for i in lst:
    if i <= A:
        score[0] += 1
    elif i <= B:
        score[1] += 1
    else:
        score[2] += 1
    
print(min(score))
    
    

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

#define rep(i, o) for (ll i = 0; i < (o);i++)
#define rep_s(i, o) for (int i = 1; i <= (o);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
#define NUM 1e5

typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }


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

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

const int MOD = 1000000007;
int main() {
    ll n; cin >> n;
    ll a[n]; rep(i, n) cin >> a[i];

    ll ans = 0; ll max_n = a[0];
    rep(i, n) {
        if (i == 0) continue;
        
        if (max_n < a[i]) max_n = a[i];
        ans += max_n - a[i];
    }
    cout << ans << endl;
    return 0;
}

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

int n;
int a[100010];

int main(){
scanf("%d", &n);
for(int i = 1; i <= n; i++) scanf("%d", a + i);
int ans = 0;
for(int i = 1; i <= n; i++) if(a[a[i]] == i) ans++;
printf("%d\n", ans / 2);
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
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 ALL(v) v.begin(), v.end()
typedef long long ll;

int main(){
    string s,t;
    cin >> s >> t;
    for(int i=0;i<s.length();i++){
        if(s[i]!=t[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
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: 3152
#include<iostream>
#include<sstream>
#include<fstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<cmath>
using namespace std;

int main(){
	int n,m;
	cin>>n>>m;
	stringstream buff;
	while(n!=0 && m!=0){
		map<string,int> table;
		vector<string> args;
		for(int x=0;x<n;++x){
			string line;
			cin>>line;
			args.push_back(line);
		}
		int x=0,y=0;
		bool flag = true;
		while(args[x][y]!='.' && flag){
			stringstream buf;
			buf<<x<<":"<<y;
			if(table[buf.str()]){
				flag = false;
			}else{
					table[buf.str()]=100;
				switch(args[x][y]){
					case '>':
						++y;
						break;
					case '<':
							--y;
						break;
					case 'v':
						++x;
						break;
					case '^':
						--x;
						break;
						
				}
			}
		}
		if(flag)buff<<y<<" "<<x<<"\n";
		else	buff<<"LOOP\n";
		cin>>n>>m;
	}
	cout<<buff.str();
	return 0;
}

Measured memory_bytes: 1312
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int n;
    string s;
    cin>>n>>s;
    int ans=0;
    for(int i=0;i<n;i++)
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
            ans++;
            i+=2;
        }   
    cout<<ans<<endl;
}

Measured memory_bytes: 3548
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M = map(int, readline().split())

    if N >= M // 2:
        ans = M // 2
    else:
        ans = N
        L = M - 2 * N
        ans += L // 4

    print(ans)
    return


if __name__ == '__main__':
    main()


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

using namespace std;

#define int long long
#define  IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int INF = 1e11;

signed main() {
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    swap(a[0],a[1]);
    swap(a[0],a[2]);
    for(int i=0;i<3;i++) {
        cout<<a[i]<<" ";
    }
    return 0;
}

Measured memory_bytes: 256
s = [list(map(int,input().split())) for i in range(3)]

def solve():
    if not (s[0][1] - s[0][0] == s[1][1] - s[1][0] == s[2][1] - s[2][0]): return False
    if not (s[0][2] - s[0][1] == s[1][2] - s[1][1] == s[2][2] - s[2][1]): return False
    if not (s[1][0] - s[0][0] == s[1][1] - s[0][1] == s[1][2] - s[0][2]): return False
    if not (s[2][0] - s[1][0] == s[2][1] - s[1][1] == s[2][2] - s[1][2]): return False
    return True

print('Yes' if solve() else 'No')


Measured memory_bytes: 3064
import java.util.*;

public class Main {

    static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
    static int mod = 1000000007;

    public static void main(String[] args)  {
        Scanner sc = new Scanner(System.in);
        int A= sc.nextInt();
        int B =sc.nextInt();
        int C =sc.nextInt();
        int D =sc.nextInt();
        boolean isfinished = false;

        while(!isfinished){
            C -= B;
            if(C<=0){
                System.out.println("Yes");
                isfinished = true;
            } else {
                A -=D;
                if(A<=0){
                    System.out.println("No");
                    isfinished = true;
                }
            }
        }



    }

}









Measured memory_bytes: 35744
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,int,int> tp;
//typedef vector<tp> vt;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	cin>>n;
	vi in(20);
	rep(i,n){
		int a;cin>>a;
		if(a>=3200)a=3200;
		in[a/400]++;
	}
	int co=0,co1;
	rep(i,8)if(in[i])co++;
	co1=co;
	if(in[8]){
		if(co1==0)co1++;
		co+=in[8];
	}
	cout<<co1<<" "<<co<<endl;
}










Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
void brute_force(vector<vector<int>>&a,vector<int>&p,int &ans,vector<bool> &sw,int now = 0){
    if(now == sw.size()){
        int n_on = 0;
        for (int i = 0; i < a.size(); i++) {
            int temp = 0;
            for (int j = 0; j < a[i].size(); j++) {
                if(sw[a[i][j] - 1] == 1)temp++;
            }
            if(p[i] == temp % 2)n_on++;
        }
        //for(auto now : sw)cout << now << ' ';
        //cout << '\n';
        if(n_on == p.size())ans++;
        return;
    }
    sw[now] = 0;
    brute_force(a,p,ans,sw,now+1);
    sw[now] = 1;
    brute_force(a,p,ans,sw,now+1);
}
int main() {
    int n,m,ans = 0;
    cin >> n >> m;
    vector<vector<int>>a;
    for (int i = 0; i < m; i++) {
        int ki;
        cin >> ki;
        vector<int>vi(ki);
        for(int j =0;j<ki;j++){
           cin >> vi[j];
        }
        a.push_back(vi);
    }
    vector<int>p(m);
    for(int i = 0;i<m;i++)cin >> p[i];
    vector<bool> sw(n);
    brute_force(a,p,ans,sw);
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f/3
using namespace std;
const int N=209;

int flag,ans;
int n,dis[N][N];

void floyd()
{
	for(int k=1;k<=n;k++){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				if(dis[i][j]<inf&&dis[i][k]<inf&&dis[k][j]<inf){
					if(dis[i][j]!=dis[i][k]+dis[k][j]){
						int tmp=dis[i][j]+dis[i][k]+dis[k][j];
						if(tmp%2)flag=1;
					}
				}
				dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(dis[i][j]!=inf)ans=max(ans,dis[i][j]);
		}
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(i!=j)dis[i][j]=inf;
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			char c;cin>>c;
			if(c=='1')dis[i][j]=1;
		}
	}
	floyd();
	if(flag==1){
		cout<<"-1"<<endl;
	} else {	
		cout<<ans+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 512
import sys
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
num, ans, val = 0, 0, 0
vals = []

for i in range(n):
    c = b[i]-a[i]
    if c > 0:
        num += c
        ans += 1
    elif c < 0:
        vals.append(-c)
vals.sort()

if len(vals) == 0:
    print(0)
elif sum(a) < sum(b):
    print(-1)
else:
    for i in vals[::-1]:
        if val >= num:
            break
        ans += 1
        val += i
    print(ans)


Measured memory_bytes: 24428
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.Scanner;

import javax.swing.plaf.synth.SynthSeparatorUI;

public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int A = sc.nextInt();
		int B = sc.nextInt();
		System.out.println(A*B-A-B+1);		
		
	}
}

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

using namespace std;

typedef long long LL;
LL x;

int main() {
    cin >> x;
    int cnt;
    if(x % 11 == 0) {
        cnt = 0;
    } else if(x % 11 <= 6)
        cnt = 1;
    else if(x % 11 > 6)
        cnt = 2;
    cout<<x / 11LL * 2 + cnt<<endl;
    return 0;
}


Measured memory_bytes: 384
// A - Beginning
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
int in(){int x;cin>>x;return x;}

int flag[10];

int main(){
	rp(i, 0, 4) flag[in()] = 1;
	int Y[] = {1,9,7,4};
	for(int y:Y) if(flag[y] != 1){ puts("NO"); return 0; }
	puts("YES");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;
#define ll long long
#define cpp mp::cpp_int
#define dequeue deque
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
#define drep(i, n) for(int i = n-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define vi vector<int>
#define P pair<ll, ll>
int mod = 1'000'000'000 + 7;
struct edge {
	int to;
	ll cost;
};

void COME_LET_THE_GAMES_BEGIN() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << setprecision(20);
}
void reverse(string* s) {
	reverse((*s).begin(), (*s).end());
}
ll N;
ll A[100000];
ll B[300000];
ll C[300000];
ll x() {
	int k = (N - 1) * 2 + 1;
	C[0] = 0;
	for (int i = 1; i <= k; i++) {
		C[i] = abs(B[i] - B[i - 1]);
		C[i] += C[i - 1];
	}
	ll res = 0;
	for (int i = N - 1; i <= k; i++) {
		res = max(res, C[i] - C[i - (N - 1)]);
	}
	return res;
}
void y() {
	for (int i = 0; i * 2 < N; i++) {
		B[i * 2] = A[i];
	}
	reverse(A, A + N);
	for (int i = 0; i * 2 + 1 < N; i++) {
		B[i * 2 + 1] = A[i];
	}
	reverse(A, A + N);
	for (int i = N; i < N + N; i++) {
		B[i] = B[i - N];
	}
}
int main() {
	COME_LET_THE_GAMES_BEGIN();
	cin >> N;
	rep(i, N)cin >> A[i];
	sort(A, A + N);
	y();
	ll ans = x();
	reverse(A, A + N);
	y();
	ans = max(ans, x());
	cout << ans << endl;
}

Measured memory_bytes: 4608
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
 
int main(){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
 if(a == b && a==c){
   printf("1");
 }
 else if((a==b && a!=c) || (a != b && a==c) || (a==b && b!=c) || (a!=b && b==c))
 {
   printf("2");
 }
 else{
   printf("3");
 }
return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline


def read():
    N = int(input().strip())
    s = input().strip()
    t = input().strip()
    return N, s, t


def solve(N, s, t):
    for i in range(N, 0, -1):
        sl = N - i
        tr = i
        if s[sl:] == t[:tr]:
            return 2 * N - i
    return 2 * N


if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))


Measured memory_bytes: 3060
#include <stdio.h>
int isPrime(int);
int main(){
int n,x,i,cou=0;

 scanf("%d",&n);
 for(i=0;i<n;i++){
 scanf("%d",&x);
 if(isPrime(x))cou++;

 }
 printf("%d\n",cou);

 return 0;

}

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

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <set>
#include <climits>
#include <map>

using namespace std;

int p[100000];
int main(){
  int N;
  cin >> N;

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

  int ans = 0;
  for(int i = 0; i < N - 1; i++){
    if(p[i] == i + 1){
      ans ++;
      p[i] = p[i + 1];
      p[i + 1] = i + 1;
    }
  }
  if(p[N - 1] == N){
    ans ++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define srep(i,s,t) for (ll i = s; i < t; ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    ll n, k;
    cin >> n >> k;
    ll MOD = 1e9+7;
    ll ans = 0;

    srep(i,k,n+2){
        ll l = (i-1)*i/2;
        ll r = l + (n-i+1) * i;
        ans += (r - l + 1);
        ans %= MOD;
    }

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


Measured memory_bytes: 3592
#include <stdio.h>

struct{
	int g;
	int p;
} list[6]={
	{200,380},   //190
	{300,550},   //183.3
	{500,850},   //170
	{1000,1520}, //152
	{1200,1870}, //155.8
	{1500,2244}  //149.6
};

static map[51]={0};

int main(){
	int i,j,n;
	map[2]=380;map[3]=550;map[5]=850;
	map[10]=1520;map[12]=1870;map[15]=2244;
	for(i=4;i<=50;i++){
		for(j=i-2;j>=i/2;j--)
			if(!map[i] || map[j] + map[i-j] < map[i]) map[i] = map[j] + map[i-j];
	//	if(map[i] < map[i-1]) map[i-1] = map[i];
	}
	while(scanf("%d ", &n), n) printf("%d\n", map[n/100]);
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;
#define ll long long 
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define frr(i,a,b) for(int i=a;i>=b;i--)
#define ms(a,b) memset(a,b,sizeof(a))
#define scfd(a) scanf("%d",a)
#define scflf(a) scanf("%lf",a)
#define scfs(a) scanf("%s",a)
#define ptfd(a) printf("%d\n",a)
#define ptfs(a) printf("%s\n",a)
#define showd(a,b) printf(a"=%d\n",b)
#define showlf(a,b) printf(a"=%lf\n",b)
#define shows(a,b) printf(a"=%s\n",b)
#define mmcp(a,b) memcpy(a,b,sizeof(b))
const int MAXN=1000005;
int s[7];
int f[7];
int tb[20][20];
bool isok[MAXN];
int cnt=0;
bool ok(){
	int t=0;
	for(int i=0;i<5;i++)
		t=tb[t][s[i]];
	if(!t)
		return true;
	else
		return false;
}
// void dfs(int cur){//已?枚?
// 	if(cur==5){
// 		int t=0;
// 		for(int i=0;i<5;i++){
// 			t*=10;
// 			t+=f[i];
// 			s[i]=f[i];
// 		}
// 		isok[t]=ok();
// 		return;
// 	}
// 	fr(i,0,9){
// 		f[cur]=i;
// 		dfs(cur+1);
// 	}
// }
void dfs2(int cur){
	if(cur==5){
		fr(i,0,4)
			s[i]=f[i];
		//printf("!!!!!!!!!now=%d\n",t);
		fr(i,0,4)
			fr(j,0,9)
				if(j!=s[i]){
					int tt=s[i];
					s[i]=j;
					if(ok()){
						cnt++;
						return;
					}
					s[i]=tt;
				}
		fr(i,0,3){
			if(s[i]!=s[i+1]){
				swap(s[i],s[i+1]);
				if(ok()){
					cnt++;
					return;
				}
				swap(s[i],s[i+1]);
			}
		}
	}
	else if(cur==4){
		int t=0;
		for(int i=0;i<4;i++){
			//printf("making..t=%d\n",t);
			t=tb[t][f[i]];
		}
		//printf("making..t=%d\n",t);
		f[cur]=t;
		dfs2(cur+1);
	}
	else{
		fr(i,0,9){
			f[cur]=i;
			dfs2(cur+1);
		}
	}
}
int main(){
	//ms(isok,false);
	fr(i,0,9)
		fr(j,0,9)
			scfd(&tb[i][j]);
	dfs2(0);
	ptfd(cnt);
	return 0;
}

Measured memory_bytes: 3236
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

fn main() {
    input! {
        s: chars,
        t: chars,
    }

    let mut ans = vec!['z'; s.len()];
    let mut found = false;

    for i in 0..s.len() - t.len() + 1 {
        let mut ok = true;
        let mut ss = vec![];
        for k in 0..s.len() {
            if i <= k && k < i + t.len() {
                if s[k] != '?' && s[k] != t[k - i] {
                    ok = false;
                    break;
                }
                ss.push(t[k - i]);
            } else {
                if s[k] == '?' {
                    ss.push('a');
                } else {
                    ss.push(s[k]);
                }
            }
        }
        if ok {
            ans = min(ans, ss);
            found = true;
        }
    }
    if found {
        println!("{}", ans.into_iter().collect::<String>());
    } else {
        println!("UNRESTORABLE");
    }
}


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

    int main() {
      int N; cin >> N;  // 入力値の数
      int R = 1000000000;        // 結果

      rep(i,N){
        int A; cin >> A; // 判定数値
//        cout << A << ":";
	    int j = 0; // 今回の操作回数
        for (j=0;j<1000000000;j++){
		  if ( A % 2 == 0 ) {
            A /= 2;
          } else {
            break;
          }
        }
//        cout << j << endl;
        if ( j < R ) { R = j; }
      }
      cout << R << endl;
    }

Measured memory_bytes: 256