akhauriyash/Code-Regression huggingface dataset:
use std::cmp;

fn main(){
  loop {
    let nmhk: Vec<usize> = read_vec();
    let n = nmhk[0];
    let m = nmhk[1];
    let h = nmhk[2];
    let k = nmhk[3];

    if n == 0 && m == 0 && h == 0 && k == 0 { break; }

    let mut sv: Vec<u32> = Vec::new();

    for _ in 0 .. n {
      sv.push(read());
    }

    let mut vb: Vec<Vec<usize>> = vec![Vec::new();h];
    
    for _ in 0 .. m {
      let ab: Vec<usize> = read_vec();
      let a = ab[0];
      let b = ab[1];
      
      vb[b].push(a);
    }

    let mut akd: Vec<Vec<usize>> = vec![Vec::new(); h];
    akd[0] = (0 .. n).collect();
    
    for i in 1 .. h {
      for j in 0 .. n {
        let t = akd[i-1][j];
        akd[i].push(t);
      }

      for &j in &vb[i] {
        let t = akd[i][j];
        akd[i][j] = akd[i][j-1];
        akd[i][j-1] = t;
      }
    }

    let mut aku: Vec<Vec<usize>> = vec![Vec::new(); h];
    aku[h-1] = (0 .. n).collect();
    
    for i in (0 .. h-1).rev() {
      for j in 0 .. n {
        let t = aku[i+1][j];
        aku[i].push(t);
      }

      for &j in &vb[i+1] {
        let t = aku[i][j];
        aku[i][j] = aku[i][j-1];
        aku[i][j-1] = t;
      }
    }
    
    let mut ans: u32 = 0;

    for i in 0 .. k {
      ans += sv[aku[0][i]];
    }

    for i in 1 .. h {
      for &j in &vb[i] {
        let mut t: u32 = 0;
        
        for l in 0 .. n {
          if l == j - 1 || l == j {
            if akd[i-1][l] < k {
              t += sv[aku[i][l]];
            }
          } else {
            if akd[i][l] < k {
              t += sv[aku[i][l]];
            }
          }
        }

        ans = cmp::min(ans, t);
      }
    }
    
    println!("{}", ans);
  }
}

fn read<T>() -> T
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.trim().parse().unwrap()
}

fn read_vec<T>() -> Vec<T>
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.split_whitespace().map(|e| e.parse().unwrap()).collect()
}



Measured memory_bytes: 21420
from operator import itemgetter

N,M=map(int,input().split())

a=[]
for i in range(M):
    
    p,y=map(int,input().split())
    a.append([i+1,p,y])

a=sorted(a,key=itemgetter(2))
a=sorted(a,key=itemgetter(1))

ans=[]
p_id=a[0][1]
count_id = 1
ans.append([a[0][0],str(a[0][1]).zfill(6)+str(count_id).zfill(6)])

for i in range(1,M):
    if a[i][1]==a[i-1][1]:
        count_id += 1
    else:
        count_id = 1

    id_set = str(a[i][1]).zfill(6)+str(count_id).zfill(6)

    ans.append([a[i][0],id_set])


ans = sorted(ans,key=itemgetter(0))

for j in range(M):
    print(ans[j][1])
    

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

#define fio                           \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define ld long double
#define endl "\n"
#define ff first
#define ss second
#define pi pair<ll, ll>
#define PI 3.141592653589793238462643383279502884L
#define mp make_pair
#define pb push_back
#define fall(i, a, b) for (int i = a; i < b; i++)
#define sz(x) (ll) x.size()
#define all(x) x.begin(), x.end()
#define ed cout << "ed";
ll MOD = 1e9 + 7;
ll MOD1 = 1e9 + 123;
ll MOD2 = 1e9 + 321;
ll co(vector<vector<char>> &v, int h, int w, int r, int c)
{
	ll f = 0;
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			if ((r & (1 << i)) && (c & (1 << j)) && v[i][j] == '#')
				f++;
	return f;
}
int main()
{
	fio;
	ll t, a, n, q, k, i, m, c, u, f, j, p, r, x, y, s, b, d;
	ll h, w;

	cin >> n;
	vector<int> v(n, 0);
	for (i = 0; i < n; i++)
		cin >> v[i];
	sort(all(v), greater<int>());
	queue<int> Q;
	Q.push(v[0]);
	for (i = 1; i < n; i++)
		Q.push( v[i]), Q.push( v[i]);
	c = 0;
	for (i = 0; i < n - 1; i++)
		c += Q.front(), Q.pop();
	cout << c;
	return 0;
}


Measured memory_bytes: 5548
#include <bits/stdc++.h>
using namespace std;
int n,m,a[1000][1000],sum;
int main()
{
    scanf("%d%d",&n,&m);
    sum=0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        {
            scanf("%d",&a[i][j]);
            sum+=a[i][j];
        }
    for(int i=1;i<=n;i++)
    {
        int s=0;
        for(int j=1;j<=m;j++) s+=a[i][j];
        a[i][m+1]=s;
    }
    for(int j=1;j<=m;j++)
    {
        int s=0;
        for(int i=1;i<=n;i++) s+=a[i][j];
        a[n+1][j]=s;
    }
    a[n+1][m+1]=sum;
    for(int i=1;i<=n+1;i++)
    {
        for(int j=1;j<=m;j++)
            printf("%d ",a[i][j]);
        printf("%d\n",a[i][m+1]);
    }
}



Measured memory_bytes: 3560
#include<bits/stdc++.h>
#define ll                 long long int
#define mod                9000000000000000000
#define pi                 3.14159265358979323846264338327950288419716939937510
#define setbit(x)          __builtin_popcountll(x)
#define db                 long double
#define pp(x)              pair<x,x>
#define ff                 first
#define ss                 second
#define FIO                ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc                 ll tc; cin>>tc; for(ll number = 1 ; number <= tc ; number ++ )
#define vv(x)              vector<x>
#define pb                 push_back
#define pob                pop_back
#define pf                 push_front
#define pof                pop_front
#define endl               "\n"
#define pq                 priority_queue
#define dbg(x)             { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y)          { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define bp                 ll kkk; cin >>kkk;
#define dbgArr(a,n)        cout<<"Array "<<#a<<endl; for(ll i=0 ; i<n ; i++) cout<<a[i]<<" "; cout<<endl;
#define maxE(a,n)          *max_element(a,a+n);
#define minE(a,n)          *min_element(a,a+n);
#define forn(i,s,n)        for(ll i=s ; i<n ; i++)
#define fornr(i,e,s)       for(ll i=e-1 ; i>=s ; i--)
#define arr(a,n)           for(ll i=0;i<n;i++){ cin>>a[i]; }
#define arr1(a,n)          for(ll i=1;i<=n;i++){ cin>>a[i]; }
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define print cout<<"Case #"<<number<<": "
#define all(x) x.begin(), x.end()
ll power(ll x, ll b) {ll p = 1;while (b > 0) {if(b&1) {p = p * x; p %= mod;} b >>= 1; x *= x; x %= mod;} return p % mod;}
using namespace std;
# define INF 1e15
struct lex_compare {
    bool operator() (const pair<db,ll>  p1, const pair<db,ll> p2){
        return (p1.first ==  p2.first) ? p1.ss < p2.ss : p1.first > p2.first;
    }
};
ll MAXT = 10000000;
ll dp[10000001] = {0};
ll first[10000001] = {0};

int main(){
    FIO;
    dp[1] = 1;
    first[1] = 1, first[2] = 2;
    forn(i,1,10000001){
        first[i] = i;
    }
    forn(i,2,10000001){
        if(first[i] == i){
            for(ll j = i*i ; j <= 10000000;j+=i){
                if(first[j] == j) first[j] = i;
            }
        }
    }
    for(ll i = 2;i<=10000000;i++){
        ll x = i;
        ll ans1 = 1;
        while(x > 1){
            ll newx = first[x];
            ll c = 0;
            while(x > 1 && first[x] == newx){
                x /= newx;
                c++;
            }
            ans1 *= (c+1);
        }
        dp[i] = ans1;
    }
    //dbgArr(dp,15);
    //dbgArr(first,15);
    ll n; cin >> n;
    ll ans = 0;
    forn(i,1,n+1){
        ans += i*dp[i];
    }
    cout << ans << endl;
    return 0;
}


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

string lcs(string s, string t){
	int n = s.size();
	int m = t.size();

	int dp[n+1][m+1];
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			dp[i][j]=0;
		}
	}

	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(s[i-1]==t[j-1]){
				dp[i][j] = 1 + dp[i-1][j-1];
			}else{
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}

	if(dp[n][m]){
		int i = dp[n][m];
		char ans[i+1];
		ans[i] = '\0';
		i = i-1;
		while(n>0 && m>0){
			if(s[n-1]==t[m-1]){
				ans[i] = s[n-1];
				n=n-1;
				m=m-1;
				i--;
			}else{
				if(dp[n][m]==dp[n-1][m]){
					n=n-1;
				}else{
					m=m-1;
				}
			}
		}
		return ans;
	}else{
		string ans = "";
		return ans;
	}
}

int main(){
	string s;
	string t;
	cin>>s>>t;
	cout<<lcs(s,t);
}

Measured memory_bytes: 35456
def main():
	n = int(input())
	xi, yi, hi = [0]*n, [0]*n, [0]*n
	stack = []
	result = []
	for i in range(n):
		xi[i], yi[i], hi[i] = map(int, input().split())
		if hi[i] > 0:
			stack = [xi[i], yi[i], hi[i]]
	for i in range(101):
		for j in range(101):
			guess = stack[2] + abs(stack[0]-i) + abs(stack[1]-j)
			is_result = True
			for k in range(n):
				result = guess - abs(xi[k]-i) - abs(yi[k]-j)
				result = max(result, 0)
				if hi[k] != result:
					is_result = False
					break
			if is_result:
				print(str(i)+" "+str(j)+" "+str(guess))
				return


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
/*-- ILSH  --*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back 
#define pop pop_back
#define mp make_pair
#define vii vector < int >
#define vll vector < ll > 
#define dt cout<<"HERE\n";
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpi vector < pll >
#define vpl vector < pll >
#define fi first
#define se second 
#define sz size 
#define len length 

const ll inf=1e18+1e17;
const ll mod =1e9+7;
//const ll mod = 998244353;

ll modInverse(ll a,ll m){ll m0=m;ll y=0,x=1;if(m == 1)return 0;while(a> 1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;}  
ll powm(ll a,ll b){a=a%mod;ll res=1;while(b){if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return (res%mod);}


const ll N =5e5+5;



void solve(){
	ll n,m;
	cin>>n>>m;
	ll arr[n], brr[m],crr[n],drr[m];
	for ( int i=0;i<n;i++)
		cin>>arr[i];
	for ( int j=0;j<m;j++)
		cin>>brr[j];
	for ( int i=1;i<n;i++){
		crr[i]=arr[i]-arr[i-1];
	}
	for ( int i=1;i<m;i++)
		drr[i]=brr[i]-brr[i-1];
	for ( int i=2;i<n;i++)
		crr[i]=(crr[i]*i+crr[i-1])%mod;
	for ( int i=2;i<m;i++)
		drr[i]=(drr[i]*i+drr[i-1])%mod;
	ll tot1=0,tot2=0,ans=0;
	for ( int i=1;i<n;i++)
		tot1=tot1+crr[i];
	for ( int j=1;j<m;j++)
		tot2=tot2+drr[j];
	tot2=tot2%mod;
	tot1=tot1%mod;
	ans=(tot1*tot2)%mod;
	cout<<ans<<'\n';

}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie( NULL);
	cout.tie(NULL);
	// #ifndef
	// 	freopen( "INPUT.txt", "r" , stdin);
	// 	freopen( "OUTPUT.txt","w", stdout);
	// #endif

	int t=1;

	//cin>>t;

	for ( int i=1;i<=t;i++){
   // 	cout<<"Case #"<<i<<": ";
    	solve();
 	}
}

Measured memory_bytes: 3328
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll; const ll MM = 1000000000;ll mod = MM + 7;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(int i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;

int main() {
  string s; cin >> s;
  ll n = s.size();
  ll i=0, res=0;
  while(i<n) {
    ll counts=0, countd=0;
    while(i<n && s[i] == '<') {
        counts++;
        i++;
    }
    while(i<n && s[i] == '>') {
        countd++;
        i++;
    }
    res += max(countd, counts);
    res += counts * (counts-1) / 2;
    res += countd * (countd-1) / 2;
  }
  cout << res << endl;
}

Measured memory_bytes: 900
S = input()

count={"a":0, "b":0, "c":0}
for i in range(len(S)):
  count[S[i]]+=1
  
a = count["a"]
b = count["b"]
c=count["c"]
if abs(a-b)<=1 and abs(b-c)<=1 and abs(c-a)<=1:
  print("YES")
else:
  print("NO")

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N-1);
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  for(int i=0;i<N;i++){
    cin >> B[i];
  }
  for(int i=0;i<N-1;i++){
    cin >> C[i];
  }
  int ans=0;
  ans+=B[A[0]-1];
  for(int i=1;i<N;i++){   
    if(A[i] <= N){
      if(A[i]==A[i-1]+1){
        ans+=B[A[i]-1]+C[A[i]-2];
      }
      else {
        ans+=B[A[i]-1];
      }
    }
    else{
      ans+=B[A[i]-1];
    }
  }
  cout<< ans <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 300005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pii pair<int,int>
const int mod = 1e9 + 7;
#define putchar putchar_unlocked
#define getchar getchar_unlocked

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int ans[n + 5] = {};
    f1(n) {
        int x;
        cin >> x;
        ans[x] = i;
    }
    f1(n) {
        cout << ans[i] << ' ';
    }
    cout << '\n';
}


Measured memory_bytes: 1280
object Main {
  var mul_limit = 12000
  var depth_limit = 7
  def dfs(p: Int, q: Int, depth: Int, sub: Int, mul: Int): Int = {
    p match {
      case 0 => return 1
      case _ =>
        var ret = 0
        for{
          i <- (sub to mul_limit).takeWhile(x =>
            mul * x <= mul_limit &&
            (depth_limit - depth) * q >= p * x)
          if p * i >= q
        } ret += dfs(p * i - q, q * i, depth + 1, i, mul * i)
        return ret
    }
  }
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    var p, q = sc.nextInt
    mul_limit = sc.nextInt
    depth_limit = sc.nextInt
    while(p != 0) {
      println(dfs(p, q, 0, 1, 1))
      p = sc.nextInt
      q = sc.nextInt
      mul_limit = sc.nextInt
      depth_limit = sc.nextInt
    }
  }
}

Measured memory_bytes: 255176
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	ll n;
	scanf("%lld",&n);
	printf("%lld",(n+110)/111*111);
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv,  digitDP//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal ,RMQ, LCA//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007; ll INF = 1LL << 60; ll ans = 0; ll z = 0, o = 1;
vl flag; vll path; vl D;
//***********//
int main() {
	cin >> N >> M;
	vll path(N, vl(N, 0));
	for (i = 0; i < M; i++) {
		ll a, b;
		cin >> a >> b;
		a--; b--;
		path[a][b] = 1;
		path[b][a] = 1;
	}
	vl A(N);
	iota(A.begin(), A.end(),0);
	do {
		if (A[0] == 0) {
			ll valid = 1;
			//debug(A);
			for (i = 0; i < N - 1; i++) {
				if (!path[A[i]][A[i + 1]]) valid = 0;
			}
			ans += valid;
		}
	} while (next_permutation(A.begin(), A.end()));
	cout << ans;
}


Measured memory_bytes: 256
n = int(input())
x = list(map(int, input().split()))

x.sort()
cnt = 0
minimum = 0
for i in range(x[0], x[-1] + 1):
    for j in range(n):
        cnt += (x[j] - i) ** 2

    if i == x[0]:
        minimum = cnt

    minimum = min([minimum, cnt])
    cnt = 0

print(minimum)

Measured memory_bytes: 3064
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
total = sum(a)

for i in range(n):
    if a[i]+a[i+1] <= b[i]:
        a[i+1] = 0
    elif a[i] > b[i]:
        total -= a[i]-b[i]
    else:
        a[i+1] -= (b[i]-a[i])

print(total-a[-1])


Measured memory_bytes: 18624
#include <bits/stdc++.h>
using namespace std;
int main()
{
  char a, b, c, d;
  cin >> b >> a >> d >> c;
  int mm = a-'0' + 10 * (b-'0');
  int yy = c-'0' + 10 * (d-'0');
  if ( mm >= 1 && mm <= 12  && yy >= 1 && yy <= 12 ) puts("AMBIGUOUS");
  else if ( mm >= 1 && mm <= 12 || yy >= 1 && yy <= 12 ) {
    if ( mm >= 1 && mm <= 12 ) puts("MMYY");
    else puts("YYMM");
  }
  else puts("NA");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf (1<<29)
#define sq(n) ((n)*(n))
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define MEMSET(a) memset(a,0,sizeof(a))
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define int long long
using namespace std;
using ll = long long;

signed main(){
    int n,m,ans=0;
    cin>>n>>m;
    vector<int> x(n),y(n),z(n);
    rep(i,n)cin>>x[i]>>y[i]>>z[i];
    rep(k,8){
        vector<int> w(n);
        rep(i,n){
            if(k&1)w[i]=x[i];
            else w[i]=-x[i];
            if(k&2)w[i]+=y[i];
            else w[i]-=y[i];
            if(k&4)w[i]+=z[i];
            else w[i]-=z[i];
        }
        sort(w.begin(),w.end());
        reverse(w.begin(),w.end());
        int t=0;
        rep(i,m)t+=w[i];
        ans=max(ans,t);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pi pair<ll, ll>
#define mp make_pair
#define pb push_back
#define vi vector<ll>
#define pd pair<double, double>
#define vp vector<pi>
#define f(i, n) for(int i = 0; i < n; i++)
#define fo(i, a, n) for(int i = a; i < n; i++)
#define mod (1000*1000*1000+7)
#define sz(x) int((x).size())
#define all(x) x.begin(),x.end()
#define DBG(v) cerr << #v << " = " << (v) << endl;
ll INF = (1ll<<61);

using namespace std;

ll solve(ll x){
  if(x == 1) return 1;
  return 1 + 2 * solve(x/2);
}

int main(int argc, char* argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll h; cin >> h;
    cout << solve(h) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>
#include<stack>
#include<queue>
#include<map>
#include<deque>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define ALLOF(c) (c).begin(), (c).end()
#define Pa pair<ll,ll>
const ll mod=1000000007;
const ll INF=10e12;
const ll inf=-1;
ll ABS(ll a){return max(a,-a);}


int main(void){
    ll N;
    cin>>N;
    ll ans=0;
    for(ll i=1;i*i<N;i++){
        if(i*(i+1)==N) break;
        if(N%i==0) ans+=N/i-1;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define dbg(x) cerr<<#x": "<<(x)<<endl
#define dbg_p(x) cerr<<#x": "<<(x).first<<' '<<(x).second<<endl
#define dbg_v(x, n) {cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<(x)[_]<<' ';cerr<<endl;}
#define all(v) v.begin(), v.end()
#define fi first
#define se second

template<typename T1, typename T2>
ostream& operator <<(ostream &out, const pair<T1, T2> &item) {
	out << '(' << item.first << ", " << item.second << ')';
	return out;
}

template <typename T>
ostream& operator <<(ostream &out, const vector<T>& v) {
	for(const auto &item : v) out << item << ' ';
	return out;
}

int main()
{
	ios_base::sync_with_stdio(false);
	
  string s;
  cin >> s;
  
  for(int i = 0; i < s.length(); ++i) {
    if(i % 2 == 1 && s[i] == 'R') return cout << "No\n", 0;
    if(i % 2 == 0 && s[i] == 'L') return cout << "No\n", 0;
  }
  cout << "Yes\n";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>                                                                                               
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

signed main(){
    int a;
    cin >> a;
    if(a / 100 > 12 && a % 100 > 12) cout << "NA\n";
    else if(a % 100 == 0){ 
        if(a / 100 > 12 || a / 100 == 0) cout << "NA\n";
        else cout << "MMYY\n";
    }   
    else if(a / 100 == 0){ 
        if(a % 100 > 12 || a % 100 == 0) cout << "NA\n";
        else cout << "YYMM\n";
    }   
    else if((a / 100 <= 12 ) && (a % 100 <= 12 )) cout << "AMBIGUOUS\n";
    else if(a / 100 > 12 && a % 100 <=12) cout << "YYMM\n";
    else cout<< "MMYY\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int n,i;
	cin>>n;
	string s;
	cin>>s;
	for(i=0;i<s.size();i++){
		if(s[i]+n<=90)s[i]=char(s[i]+n);
		else
		s[i]=char(s[i]+n-26);
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  // 余事象を引く
  int N;
  cin >> N;
  string S;
  cin >> S;
  int r = 0, g = 0, b = 0;
  for (char s : S) {
    if (s == 'R') r++;
    if (s == 'G') g++;
    if (s == 'B') b++;
  }
  ll ans = (ll)r * g * b;
  for (int i = 0; i < N; i++) {
    for (int j = i+1; j < N; j++) {
      if (S[i] == S[j]) continue;
      int k = j + (j-i);
      if (k >= N) continue;
      if (S[i] != S[k] && S[j] != S[k]) ans--;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3516
#define E 0.00000001
#define zero(n) (fabs(n)<E)
main(n,a,b,c,d,p,q,r,D,f){
	for(scanf("%d",&n);n;n--){
		int k[2]={0};
		scanf("%d%d%d%d",&a,&b,&c,&d); //fx=ax3+bx2+cx+d
		if(a<0)a=-a,b=-b,c=-c,d=-d;// won't lose generality
		p=3*a,q=2*b,r=c,D=q*q-4*p*r; //f'x=3ax2+2bx+c D: f'x=0?
		if(D>0){
			double x1=(-q-sqrt(D))/p/2,x2=(-q+sqrt(D))/p/2;
			double y1=a*x1*x1*x1+b*x1*x1+c*x1+d;
			double y2=a*x2*x2*x2+b*x2*x2+c*x2+d;
			if(!zero(y1)&&!zero(y2)>E&&y1*y2>0)goto one;
			if(zero(x1)){
				if(d==0)k[0]=1,k[1]=0;
				else k[0]=2,k[1]=1;
			}else if(zero(x2)){
				if(d==0)k[0]=0,k[1]=1;
				else k[0]=1,k[1]=2;
			}else if(x1>0){
				if(d>0)k[0]=2,k[1]=1;
				else if(d<0)k[0]=3,k[1]=0;
				else k[0]=2,k[1]=0;
			}else if(x2<0){
				if(d>0)k[0]=0,k[1]=3;
				else if(d<0)k[0]=1,k[1]=2;
				else k[0]=0,k[1]=2;
			}else{
				if(d>0)k[0]=2,k[1]=1;
				else if(d<0)k[0]=1,k[1]=2;
				else k[0]=1,k[1]=1;
			}
		}else if(D==0){
			if(d>0)k[0]=0,k[1]=1;
			else if(d<0)k[0]=1,k[1]=0;
		}else{
one:
			if(d>0)k[0]=0,k[1]=1;
			else if(d<0)k[0]=1,k[1]=0;
		}
		printf("%d %d\n",k[0],k[1]);
	}
	return 0;
}

Measured memory_bytes: 600
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    public static void Main()
    {
        hoge();
        //System.Console.ReadLine();
    }

    public static void hoge()
    {
        var vars = System.Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        var a = System.Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        long[] n = new long[a.Length + 2];

        foreach(var v in a)
        {
            n[v]++;
        }

        for(int i = 1; i < n.Length; i++)
        {
            System.Console.WriteLine(n[i]);
        }
    }
}

Measured memory_bytes: 45332
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/



string S;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> S;

    rep(msk, 0, 1 << 3) {
        int sm = S[0] - '0';
        rep(i, 0, 3) {
            if (msk & (1 << i)) sm += S[i + 1] - '0';
            else sm -= S[i + 1] - '0';
        }
        if (sm == 7) {
            cout << S[0];
            rep(i, 0, 3) {
                if (msk & (1 << i)) cout << "+";
                else cout << "-";
                cout << S[i + 1];
            }
            cout << "=7" << endl;
            return;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    string s;
    cin >> s;
    VI a;
    int x = 0;
    char d = 'R';
    for (char c : s){
        if (c == d) x++;
        else {
            d = c;
            a.push_back(x);
            x = 1;
        }
    }
    a.push_back(x);
    int n = s.length();
    VI ans(n);
    int p = 0;
    REP(i,a.size()){
        int x = a[i];
        REP(j,x){
            if ((x - j) % 2 == 0){
                if (i % 2 == 0) ans[p + x]++;
                else ans[p - 1]++;
            }else{
                if (i % 2 == 0) ans[p + x - 1]++;
                else ans[p]++;
            }
        }
        p += x;
    }
    REP(i,n) printf("%d ", ans[i]);
    cout << endl;

    return 0;
}


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

using namespace std;

int main(){

  int N, M; cin >> N >> M;

  vector <bool> bridge(N - 1);

  vector < pair <int, int> > BA(M);
  for (int i = 0; i < M; i++){
    int a, b; cin >> a >> b;
    a--; b--;
    BA[i].first = b;
    BA[i].second = a;
  }
  
  sort(BA.begin(), BA.end());

  int ans = 0, now = -1;
  for (int i = 0; i < M; i++){
    
    bool flag = false;

    int A = BA[i].second, B = BA[i].first;

    if (now < A || B <= now){
      now = B - 1;
      ans++;
    }
  }
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
import java.io.PrintWriter;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int N = sc.nextInt();
		pw.print(N*N*N);
		pw.close();
	}
}

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

int main(){
    ll n;cin>>n;
    vl d(n);rep(i,n)cin>>d[i];

    sort(d.begin(),d.end());

    cout<<d[n/2]-d[n/2-1]<<endl;
}

Measured memory_bytes: 1152
#pragma comment(linker, "/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
//#define dprintf(...) 
#define hash _hash
//#define dprintf(...) fprintf(outFile,__VA_ARGS__)
 
#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 100010
 
template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}
 
//FILE* outFile;
 
inline void add(int &a,int b){a+=b;while(a>=mod)a-=mod;}
 
 
int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=ans*(ll)a%mod;
        a=(ll)a*a%mod;b>>=1;
    }
    return ans;
}
 
string s;
int c[N];
void out(int x){
    cout<<x<<"\n";
    fflush(stdout);
    cin>>s;
    if(s[0]=='V')exit(0);
    c[x]=s[0]=='M';
}
int main(){
    //freopen("atlarge.in","r",stdin);
    //freopen("atlarge.out","w",stdout);
    //cout<<setprecision(9)<<fixed;
    int T,j,i,k,ca=0,K,n,m;
    scanf("%d",&n);
    int l=1,r=n-1;
    out(0);
    while(l<=r){
        //cerr<<l<<" "<<r<<"\n";
        m=(l+r)>>1;
        out(m);
        if(c[m]==c[l-1]){
            if((m-l+1)%2==0)l=m+1;
            else r=m-1;
        }
        else{
            if((m-l+1)&1)l=m+1;
            else r=m-1;
        }
        //cerr<<l<<" "<<r<<"\n";
    }
    //cerr<<1.*clock()/CLOCKS_PER_SEC<<"ms"<<"\n";
    return 0;
}   

Measured memory_bytes: 852
import java.io.*;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {

    void solve() {
        int N = in.nextInt();
        HashSet<Integer> sheet = new HashSet<>();
        for(int i = 0 ; i < N ; i++) {
            int A = in.nextInt();
            if (sheet.contains(A)) {
                sheet.remove(A);
            }else {
                sheet.add(A);
            }
        }
        out.println(sheet.size());
    }


    FastScanner in;
    PrintWriter out;

    void run() {
        in = new FastScanner();
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    public class FastScanner {
        BufferedReader br;
        StringTokenizer st;

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

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

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

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

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

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

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

}

Measured memory_bytes: 42416
from collections import deque, Counter as cnt
from collections import defaultdict as dd
from operator import itemgetter as ig
from bisect import bisect_right as bsr
from math import factorial, ceil, floor
import sys
sys.setrecursionlimit(1000000)

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def nlist(n, v):
    if not n:
        return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]


def yesno(v, yes="Yes", no="No"):
    print([yes, no][not v])


def main():
    """エントリーポイント"""
    S, T, A, B, U = input(str, str, int, int, str)
    if (S == U):
        print(A - 1, B)
    else:
        print(A, B - 1)


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()


Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <vector>

int main() {
    int N, Q;
    std::string S;
    std::cin >> N >> Q >> S;

    std::vector<int> cnt(N + 1, 0);
    for (int i = 2; i <= N; ++i) {
        cnt[i] = cnt[i - 1];
        if (S.substr(i - 2, 2) == "AC") ++cnt[i];
    }

    for (int q = 0; q < Q; ++q) {
        int l, r;
        std::cin >> l >> r;
        std::cout << cnt[r] - cnt[l] << '\n';
    }
    return 0;
}


Measured memory_bytes: 1408
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
	static int n;
	static double[] x;
	static double[] y;
	static double[] l;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		while (true) {
			n = sc.nextInt();
			if (n == 0)
				break;
			x = new double[n];
			y = new double[n];
			l = new double[n];
			for (int i = 0; i < n; ++i) {
				x[i] = sc.nextDouble();
				y[i] = sc.nextDouble();
				l[i] = sc.nextDouble();
			}

			double xl = -100;
			double xr = 100;

			for (int i = 0; i < 100; ++i) {
				double mxl = (2 * xl + xr) / 3;
				double mxr = (xl + 2 * xr) / 3;
				double Lmxl = len(mxl);
				double Lmxr = len(mxr);
				if (Lmxl < Lmxr) {
					xl = mxl;
				} else {
					xr = mxr;
				}
			}
			pw.println(Math.sqrt(len(xl)));
		}
		sc.close();
		pw.close();
	}

	static double len(double x) {
		double yl = -100;
		double yr = 100;

		for (int i = 0; i < 100; ++i) {
			double myl = (2 * yl + yr) / 3;
			double myr = (yl + 2 * yr) / 3;
			double Lmyl = calc(x, myl);
			double Lmyr = calc(x, myr);
			if (Lmyl < Lmyr) {
				yl = myl;
			} else {
				yr = myr;
			}
		}
		return calc(x, yl);
	}

	static double calc(double cx, double cy) {
		double len2 = Double.MAX_VALUE / 4;
		for (int i = 0; i < n; ++i) {
			len2 = Math.min(len2, l[i] * l[i] - (cx - x[i]) * (cx - x[i]) - (cy - y[i]) * (cy - y[i]));
		}
		return len2;
	}
}

Measured memory_bytes: 66080
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let a: usize = sc.read();
    let b: usize = sc.read();
    if a < 10 && b < 10 {
        println!("{}", a * b);
    } else {
        println!("-1");
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        long N = in.l();
        int X = in.i();
        int M = in.i();
        long ans = -1;

        long a = X;
        long[] sum = new long[(int)Math.min(N + 1, M + 2)];
        sum[1] = a;
        int[] r = new int[M];
        Arrays.fill(r, -1);
        r[X] = 0;

        for (int i = 1; i < N; i++) {
            int b = (int)(a * a % M);
            sum[i + 1] = sum[i] + b;
            if (r[b] > -1) {
                ans = sum[r[b]] + (N - r[b]) / (i - r[b]) * (sum[i] - sum[r[b]]);
                int j = (int)((N - r[b]) % (i - r[b]));
                if (j > 0) {
                    ans += sum[r[b] + j] - sum[r[b]];
                }
                break;
            }
            r[b] = i;
            a = b;
        }
        if (ans == -1) ans = sum[(int)N];
        out.println(ans);
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    void back() {
        head--;
    }

    boolean minus() {
        boolean minus;
        while (true) {
            char c = next();
            if (!isDelimiter(c)) {
                if (!(minus = c == '-')) back();
                return minus;
            }
        }
    }

    void skip() {
        while (isDelimiter(next()));
        back();
    }

    char[] s(int N) {
        char[] cbuf = new char[N];
        read(cbuf, 0, N);
        return cbuf;
    }

    public int read(char[] cbuf, int off, int len) {
        skip();
        int i;
        for (i = 0; i < cbuf.length; i++) {
            char c = next();
            if (isDelimiter(c)) {
                break;
            }
            cbuf[i] = c;
        }
        return i;
    }

    boolean isDelimiter(char c) {
        return c == ' ' || c == '\n' || c == '\r';
    }

    int i() {
        boolean minus = minus();
        int n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        boolean minus = minus();
        long n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }
}


Measured memory_bytes: 33944
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] rb = new int[N + 1];
        for (int i = 0; i < N; ++i) {
            rb[i + 1] = sc.nextInt();
        }
        sc.close();

        int res = 0;
        for (int i = 1; i <= N; ++i) {
            if (i == rb[rb[i]]) {
                res++;
            }
        }

        System.out.println(res / 2);
    }
}

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

using namespace std;

int n;
int A[100000];

int search() {
    //int max = A[0];
    int count = 0;
    int maxcount = 0;

    for ( int i = 0; i < n - 1; i++ ) {
        if ( A[i + 1] <=  A[i] ) { 
            count++;
        } else if ( count > maxcount ) {
            maxcount = count;
            count = 0;
        } else {
            count = 0;
        }
    }

    if (  count > maxcount ) {
        maxcount = count;
    }

    return maxcount;

}      

int main() {
    cin >> n;
    for ( int i = 0; i < n; i++ ) {
        cin >> A[i];
    }

    cout << search() << endl;

    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
    int flag, i, j, k, M, N;
    scanf("%d%d%*c", &N, &M);
    char A[60][60], B[60][60];
    char tmp1[60], tmp2[60];
    memset(A,0,3600);
    memset(B,0,3600);
    memset(tmp1,0,60);
    memset(tmp2,0,60);
    for (i=0;i<N;i++) {
        scanf("%s", &A[i]);
    }
    for (i=0;i<M;i++) {
        scanf("%s", &B[i]);
    }

    flag = 0;
    if (N == M) {
        for (k=0;k<M;k++) {
            memmove(tmp1, A[k], M);
            memmove(tmp2, B[k], M);
            if (!strcmp(tmp1, tmp2)) {
                flag = 1;
            } else {
                flag = 0;
                break;
            }
        }
    } else for (i=0;i<N-M;i++) {
        for (j=0;j<N-M;j++) {
            for (k=0;k<M;k++) {
                memmove(tmp1, A[i+k]+j, M);
                memmove(tmp2, B[k], M);
                if (!strcmp(tmp1, tmp2)) {
                    flag = 1;
                } else {
                    flag = 0;
                    break;
                }
            }
            if (flag) break;
        }
        if (flag) break;
    }

    if (flag) printf("Yes\n");
    else printf("No\n");
    return 0;
}

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

using namespace std;

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

	int n,x,y;
	vector <pair<int,int>> p;
	double res = 0;

	cin >> n;

	for(int i=0;i<n;i++)
	{
		cin >> x >> y;
		p.push_back(make_pair(x,y));
	}

	vector <int> perm;
	for(int i=0;i<n;i++)
	{
		perm.push_back(i);
	}

	int total = 0;
	do
	{
		total++;
		double dist = 0;
		for(int i=1;i<n;i++)
		{
			double dx = p[perm[i]].first - p[perm[i-1]].first;
			double dy = p[perm[i]].second - p[perm[i-1]].second;
			double d = sqrt(dx*dx + dy*dy);
			dist += d;
		}
		res += dist;
	}while(next_permutation(perm.begin(),perm.end()));
	res/=total;

	cout << fixed;
	cout.precision(16);

	cout << res << '\n';

	return 0;
}


Measured memory_bytes: 3788
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<string>> vvstring;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================



int main() {

	////==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	////==================================



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

	for (int i = 0; i < N; i++)
	{
		A[i] -= i + 1;
	}
	
	sort(A.begin(), A.end());


	ll b;
	if (N % 2 == 1)
	{
		b = A[N / 2];
	}
	else
	{
		b = (A[N / 2] + A[N / 2 - 1]) / 2;
	}

	ll ans = 0;
	for (int i = 0; i < N; i++)
	{
		ans += abs(A[i] - b);
	}

	cout << ans << endl;
}





Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
  int n;
  std::cin >> n;
  std::vector<int> a(n+1);
  for (int i = 1; i < n+1; i++) {
    /* code */
    std::cin >> a[i];
  }
  bool han=false;
  int counter=0;
  for (int i = 1; i <n; i++) {
    /* code */
    if(i==a[i]){
      counter++;
      swap(a[i],a[i+1]);
    }
  }
  if(a[n]==n)counter++;
  std::cout << counter << std::endl;
}

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

int main(){
	int A, B, C, X;
	cin >> A >> B >> C >> X;
	int num = 0;
	REP(i, A + 1){
		REP(j, B + 1){
			REP(k, C + 1){
				if(500 * i + 100 * j + 50 * k == X)
					num++;
			}
		}
	}
	cout << num << endl;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define all(x) (x).begin(), (x).end()

using namespace __gnu_pbds;
using namespace std;

using ull = unsigned long long;
using ll = long long;
using ld = long double;
template <typename T> using ordered_set = tree<T, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;

const int mod = 1e9 + 7;
const int inf = INT_MAX;

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

    int n;
    cin >> n;

    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    int ans = 0;
    sort(all(a), greater<>());

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = j + 1; k < n; k++) {
                if (a[i] == a[j] or a[i] == a[k] or a[j] == a[k]) continue;
                if (a[i] < a[j] + a[k])
                    ans++;
            }
        }
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3660
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  var [x,k,d] = nexts(3);
  x = Math.abs(x);
  if(x >= k*d)return x - k*d;
  var t = Math.floor(x/d);
  k -= t;
  x -= t*d;
  return k%2 ? d-x : x;
}

Measured memory_bytes: 29688
// ABC 026 C

#include <bits/stdc++.h>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(v) int(v.size())

using namespace std;

const int mod = 1000000007;

inline int calcHeight(int x1, int y1, int x2, int y2, int h) {
  return max((h + abs(x1 - x2) + abs(y1 - y2)), 0);
}

int main(int argc, char** argv) {
  int n;
  cin >> n;
  int cx = 0;
  int cy = 0;
  int ch = 1;

  vector<vector<int>> blocks;
  vector<vector<int>> blocks2;

  rep(i, n) {
    int x, y, h;
    cin >> x >> y >> h;
    vector<int> block = {x, y, h};
    if (h != 0) {
      blocks.push_back(block);
    } else {
      blocks2.push_back(block);
    }
  }

  int height;

  rep(i, 101) {
    rep(j, 101) {
      bool flag = true;
      height = -1;
      for (auto block : blocks) {
        int tmp = calcHeight(i, j, block[0], block[1], block[2]);

        if (height != -1 && height != tmp) {
          flag = false;
          height = -1;
          break;
        } else {
          height = tmp;
        }
      }
      for (auto block : blocks2) {
        int tmp = calcHeight(i, j, block[0], block[1], 0);
        if (height > tmp) {
          flag = false;
        }
      }
      if (flag) {
        cout << i << " " << j << " " << height;
        return 0;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 256