akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#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 all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

ll gcd(ll x, ll y) {return y ? gcd(y,x%y) : x;};

vector<pair<ll,int>> factorize(ll n) {
    vector<pair<ll,int>> res;
    for (ll i=2; i*i<=n; ++i) {
        if (n%i) continue;
        res.emplace_back(i,0);
        while(n%i==0) {
            res.back().se++;
            n/=i;
        }
    }
    if (n != 1) res.emplace_back(n,1);
    return res;
};

int main() {
    ll a, b; cin >> a >> b;
    ll g = gcd(a,b);
    auto f = factorize(g);
    int ans = f.size() + 1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>


using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<n;++i)
#define FOR(i, a, b) for(int i=a;i<b;++i)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=b-1;i>=a;--i)

#define all(x) begin(x),end(x)
#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

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

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


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> p) {
    os << p.first << ":" << p.second;
    return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T1, class T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "[";
    for (auto it = mp.begin(); it != mp.end(); ++it) {
        if (it != mp.begin()) {
            os << ", ";
        }
        os << *it;
    }
    return os << "]";
}

// edit

ll calc(ll K) {
    if (K % 2 == 0 || K % 5 == 0) return -1;

    ll ans = 1;
    ll val = 7;
    while (true) {
        if (val % K == 0) return ans;
        val *= 10;
        val += 7;
        val %= K;
        ans++;
    }

}

void solve() {
    int K;
    cin >> K;
    cout << calc(K) << endl;
//    for (ll i = 0; i < 1000000; ++i) {
//        cout << i << " " << calc(i) << endl;
//    }
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();


    return 0;
}


Measured memory_bytes: 3132
#include<iostream>
using namespace std;
int main(){
  int n,k,anshalf;
  cin>>n>>k;
  int x[n];
  for(int i=0;i<n;i++)cin>>x[i];
  for(int i=0;i<n;i++){
    if(x[i]<k-x[i])anshalf+=x[i];
    else anshalf+=k-x[i];
  }
  cout<<anshalf*2<<endl;
  return 0;
}
    

Measured memory_bytes: 256
using System;
using System.Linq;

namespace AtCoderBiginnerContest154
{
	class Program
	{
		static void Main(string[] args)
		{
			var numbers = ReadIntArray();
			var inputs = ReadIntArray();

			var totals = new long[numbers[0]];
			totals[0] = inputs[0];
			for(var i = 1; i < numbers[0]; i++)
			{
				if(i < numbers[1])
				{
					totals[i] = totals[i - 1] + inputs[i];
				}
				else
				{
					totals[i] = totals[i - 1] + inputs[i] - inputs[i - numbers[1]];
				}
			}

			var max = totals.Skip(numbers[1] - 1).Max();
			var index = numbers[0] - 1;
			while(totals[index] != max)
			{
				index--;
			}

			var expect = 0d;
			for (var i = index - numbers[1] + 1; i <= index; i++)
			{
				var tmp = inputs[i];
				expect += tmp * (tmp + 1) / (double)(2 * tmp);
			} 

			Console.WriteLine(expect);
		}

		public static int ReadInt()
			=> int.Parse(Console.ReadLine());

		public static int[] ReadIntArray()
			=> Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

		public static long ReadLong()
			=> long.Parse(Console.ReadLine());

		public static long[] ReadLongArray()
			=> Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();

		public static string ReadString()
			=> Console.ReadLine();

		public static string[] ReadStringArray()
			=> Console.ReadLine().Split();
	}
}


Measured memory_bytes: 32988
#!/usr/bin/env python3
A, B, K = map(int, input().split())
if A > B:
    A, B = B, A
c = 0
for i in range(1, B + 1)[::-1]:
    if A % i == 0 and B % i == 0:
        c += 1
    if c == K:
        print(i)
        break


Measured memory_bytes: 2940
#define _USE_MATH_DEFINES
//#include <bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <complex>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

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

void solve(long long N){
  long long cnt=0;
  for(int i=1;i<N;i++){
    cnt+=(N-1)/i;
  }
  cout<<cnt<<endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  solve(N);
  return 0;
}


Measured memory_bytes: 3760
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#define REP(i,n) for (int i=0;i<(n);++i)
using namespace std;

int middle(int n, vector<int> p){
    int ans = 0;
    REP(i, n-2){
        vector<int> num(3);
        num[0] = p[i];
        num[1] = p[i+1];
        num[2] = p[i+2];
        sort(num.begin(), num.end());

        if(num[1] == p[i+1]) ++ans;
    }
    return ans;
}

int main(){
    int n;
    cin >> n;
    vector <int> p(25);
    REP(i, n) cin >>p[i];

    cout << middle(n, p) << endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
#define MAX 1000
int dp[MAX + 1][MAX + 1];
int LCS(string STR1, string STR2)
{
	int length1 = STR1.size();
	int length2 = STR2.size();
	STR1 = ' ' + STR1;
	STR2 = ' ' + STR2;
	for (int i = 0; i <= length1; i++)
	{
		for (int l = 0; l <= length2; l++)dp[i][l] = 0;
	}
	for (int i = 1; i <= length1; i++)
	{
		for (int l = 1; l <= length2; l++)
		{
			if (STR1[i] == STR2[l])dp[i][l] =dp[i-1][l-1]+1;
			else
			{
				dp[i][l]=max(dp[i - 1][l], dp[i][l - 1]);
			}
		}
	}
	return dp[length1][length2];
}
int main()
{
	int q;
	cin >> q;
	for (int i = 0; i < q; i++)
	{
		string str1, str2;
		cin >> str1 >> str2;
		cout << LCS(str1, str2) << endl;
	}
	return 0;
}

Measured memory_bytes: 7048
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

const int N = 3001;
const int MOD = 1e9 + 7;
char s[N];
int dp[N][N];

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n;
	scanf("%d%s", &n, s);

	for (int i = 1; i <= n; i++) dp[1][i] = 1;
	for (int i = 2; i <= n; i++) {
		for (int j = 1; j <= i; j++) {
			if (s[i-2] == '<')
				dp[i][j] = dp[i-1][j-1];
			else
				dp[i][j] = (dp[i-1][i-1] - dp[i-1][j-1] + MOD) % MOD;
			dp[i][j] = (dp[i][j-1] + dp[i][j]) % MOD;
		}
	}
	/*
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) printf("%d ", dp[i][j]);
		puts("");
	}
	*/
	printf("%d\n", dp[n][n]);
}


Measured memory_bytes: 34176
#include <bits/stdc++.h>
 
using namespace std;
 
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl
ll a,b,c;
int main()
{
	SPEED;
	cin>>a>>b>>c;
	if(a%2==0||b%2==0||c%2==0)
		return cout<<0<<endl,0;
	cout<<min({a*b,c*b,a*c})<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
#include <ios>
#include <iomanip>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pi=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
using vstr=vector<string>;

void solve() {
    int N,M;
    cin >> N >> M;
    vi k(M),p(M);
    vector<vi> s;
    rep(i,M){
        cin >> k[i];
        vi sk(k[i]);
        rep(j,k[i]){
            cin >> sk[j];
            sk[j]--;
        }
        s.pb(sk);
    }
    rep(i,M) {
        cin >> p[i];
    }
    int ans = 0;
    rng(bit,0,pow(2,N)){
        bool ok = 1;
        vi on_switch(N);
        rep(j,N){
            on_switch[j] = (bit>>j&1);
        }
        rep(j,M){
            int on_count = 0;
            for(auto sij:s[j]){
                on_count += on_switch[sij];
            }
            if(on_count%2!=p[j]) {
                ok = 0;
                break;
            }
        }
        if(ok) ans++;
    }
    print(ans);
}
 
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}

Measured memory_bytes: 4012
#[derive(Debug)]
struct Kruskal<T> {
    edges: Vec<(usize, usize, T)>,
    zero: T,
    inf: T,
}

impl<T> Kruskal<T>
where
    T: Clone + Ord + std::ops::AddAssign,
{
    fn new(zero: T, inf: T) -> Self {
        Kruskal {
            edges: Vec::new(),
            zero: zero,
            inf: inf,
        }
    }

    fn add_edge(&mut self, from: usize, to: usize, cost: T) {
        self.edges.push((from, to, cost));
    }

    fn solve(&mut self) -> T {
        self.edges.sort_by(|&(_, _, ref c1), &(_, _,  ref c2)| c1.cmp(&c2));
        let mut uf = UnionFind::new(self.edges.len());
        let mut ret = self.zero.clone();
        for e in &self.edges {
            if !uf.same(e.0, e.1) {
                uf.unite(e.0, e.1);
                ret += e.2.clone();
            }
        }
        ret
    }
}

#[derive(Debug)]
struct UnionFind {
    par: Vec<usize>,
    rank: Vec<usize>,
}

impl UnionFind {
    fn new(n: usize) -> UnionFind {
        UnionFind {
            par: (0..n).collect(),
            rank: vec![0; n],
        }
    }

    fn find(&mut self, x: usize) -> usize {
        let par = self.par[x];
        if par != x {
            self.par[x] = self.find(par);
        }
        self.par[x]
    }

    fn unite(&mut self, x: usize, y: usize) {
        let x = self.find(x);
        let y = self.find(y);
        if x == y {
            return;
        }

        let rx = self.rank[x];
        let ry = self.rank[y];
        if rx < ry {
            self.par[x] = y;
        } else {
            self.par[y] = x;
            if rx == ry {
                self.rank[x] += 1;
            }
        }
    }

    fn same(&mut self, x: usize, y: usize) -> bool {
        self.find(x) == self.find(y)
    }
}
use std::io::*;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let mut kr = Kruskal::new(0, 1_i64 << 60);
    for i in 0..n {
        for j in 0..n {
            let a: i64 = read();
            if a != -1 {
                kr.add_edge(i, j, a);
            }
        }
    }
    println!("{}", kr.solve());
}

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


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

int main(){
  int64_t n,k;
  cin >>n>>k;
  vector<int64_t>wrp(n);
  vector<int>miti(n);
  for(int64_t i=0;i<n;i++){
    cin >> wrp.at(i);
  }
  vector<int64_t>memo(n);
  int64_t owari,now=1;
  for(int64_t i=0;i<n;i++){
    miti.at(i)=now-1;
    if(memo.at(now-1)==0){
      memo.at(now-1)=1;
      now=wrp.at(now-1);
    }
    else {owari=i;break;}
  }
  int64_t hajime=0;
  for(int i=0;i<n;i++){
    if(miti.at(i)==miti.at(owari)){
      hajime=i;break;}
  }
  if(hajime>=k){
    cout << miti.at(k)+1<<endl;
  }
  else{
    int64_t tmp=(k-hajime)%(owari-hajime)+(hajime);
    cout << miti.at(tmp)+1<<endl;
  }
}

Measured memory_bytes: 7224
def f():
 for c in range(n):
  for d in a[c+1:]:
   for p in('012345','152043','215304','302541','410352','514320'):
    f=[d[int(i)]for i in p]
    if f[::5]==a[c][::5]:
     f=f[1:5]*2
     for k in range(4):
      if f[k:k+4]==a[c][1:5]:return"No"
 return"Yes"
b=0
n=int(input())
a=[input().split()for _ in[0]*n]
for b in a:b[3:5]=b[4],b[3]
print(f())


Measured memory_bytes: 5608
// inputに入力データ全体が入る
function Main(input) {
    var S = input;
    var targetStr = S[0]
    var targetStr2 = S[2]
    var count = (S.match(new RegExp(targetStr, "g" ))||[]).length;
    var count2 = (S.match(new RegExp(targetStr2, "g" ))||[]).length;
    if(count == 2 && count2 == 2){
        console.log("Yes")
    }else{
        console.log("No")
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;


int main(){
  ll n;
  cin >> n;
  
  vector<pair<int,int>> v(n);
  rep(i,0,n){
    int x, y;
    cin >> x >> y;
    v.at(i) = {x, y};
  }
  
  sort(all(v));
  ld sum = 0;
  int cnt = 0;
  
  do{
    rep(i,0,n-1){
      sum += sqrt(pow((v.at(i).fi-v.at(i+1).fi),2)+pow((v.at(i).se-v.at(i+1).se),2));
    }
    cnt++;
  }while(next_permutation(all(v)));
  
  cnt = (ld)cnt;
  
  cout << fixed << setprecision(10);
  cout << sum/cnt << endl;
}

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

using namespace std;

#define TIMES(i_, n_) for(int i_ = 0; i_ < (n_); ++i_)

struct DisjointSet/*{{{*/
{
  vector<int> parent;

  int root(int x)
  {
    if (parent[x] < 0) {
      return x;
    } else {
      parent[x] = root(parent[x]);
      return parent[x];
    }
  }

  explicit DisjointSet(int n) : parent(n, -1) {}

  bool unite(int x, int y)
  {
    const int a = root(x);
    const int b = root(y);
    if (a != b) {
      if (parent[a] < parent[b]) {
        parent[a] += parent[b];
        parent[b] = a;
      } else {
        parent[b] += parent[a];
        parent[a] = b;
      }
      return true;
    } else {
      return false;
    }
  }

  bool find(int x, int y) { return root(x) == root(y); }
  int size(int x) { return -parent[root(x)]; }
};/*}}}*/

bool solve() {
    int W, H;
    if(!(cin >> W >> H)) return false;
    if(!W && !H) return false;

    vector<string> field(H);
    int goal_id = 0;
    TIMES(i, H) {
        cin >> field[i];
        TIMES(j, W) {
            if(field[i][j] == 't') {
                goal_id = i*W + j;
            }
        }
    }

    static const int DR[] = {0, -1, 0, 1};
    static const int DC[] = {1, 0, -1, 0};
    DisjointSet ds(W*H);
    TIMES(r, H) {
        TIMES(c, W) {
            const int cur = r*W + c;
            if(field[r][c] != '#') {
                TIMES(dir, 4) {
                    const int nr = r + DR[dir];
                    const int nc = c + DC[dir];
                    if(nr < 0 || nr >= H || nc < 0 || nc >= W) continue;
                    if(field[nr][nc] == '#') continue;
                    ds.unite(cur, nr*W + nc);
                }
            }
        }
    }
    int K;
    cin >> K;
    vector<int> query;
    TIMES(_, K) {
        int c, r;
        cin >> c >> r;
        query.push_back(r*W + c);
    }
    if(ds.root(0) == ds.root(goal_id)) {
        cout << 0 << endl;
        return true;
    }
    TIMES(i, K) {
        const int cur = query[i];
        const int r = cur / W;
        const int c = cur % W;
        TIMES(dir, 4) {
            const int nr = r + DR[dir];
            const int nc = c + DC[dir];
            if(nr < 0 || nr >= H || nc < 0 || nc >= W) continue;
            if(field[nr][nc] == '#') continue;
            ds.unite(cur, nr*W + nc);
        }
        field[r][c] = '.';
        if(ds.root(0) == ds.root(goal_id)) {
            cout << i+1 << endl;
            return true;
        }
    }
    cout << -1 << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 5944
n ,y = map(int, input().split())

for a in range(n+1):
  for b in range((n-a)+1):
    s = a*10000 + b*5000 + (n-a-b)*1000
    if s == y :
      print(a,b,(n-a-b))
      exit()

print('-1 -1 -1')

Measured memory_bytes: 8912
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;

int main() {

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

    for (int i = 0; i <= N ; i++) {
        for (int j = 0; j <= M; j++) {
            if (M * i + N * j - 2 * i * j == K) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(int i = (a); i<(b); ++i)
#define rep(i, n) for (int i=0; i<(n); ++i)
#define out(x) cout << x << endl

int main() {
    int N, a;
    int sum=0;
    double ave;
    int P;
    ll ans=0;
    cin >> N;
    vector<int> X(N);
    rep(i, N){
        cin >> a;
        X.at(i) = a;
        sum += a;
    }
    ave = ((double)sum)/N;
    if((ave-(int)ave) < ((int)ave+1-ave)) P = (int)ave;
    else P = (int)ave+1;
    for(int x: X) ans += (x-P)*(x-P);
    out(ans);
}


Measured memory_bytes: 256
import java.util.*;

class City {
	public int no;
	public String id;
	public int pref;
	public long year;

	public City(int no, int pref, long year) {
		this.no = no;
		this.pref = pref;
		this.year = year;
	}
}

class CityComparator implements Comparator<City> {
	@Override
	public int compare(City c1, City c2) {
		if (c1.pref != c2.pref) {
			return c1.pref < c2.pref ? -1 : 1;
		} else {
			return c1.year < c2.year ? -1 : 1;
		}
	}
}

class CityResetComparator implements Comparator<City> {
	@Override
	public int compare(City c1, City c2) {
		return c1.no < c2.no ? -1 : 1;
	}
}

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		List<City> cities = new ArrayList<City>();
		for (int i = 0; i < M; i++) {
			int pref = sc.nextInt();
			long year = sc.nextLong();
			cities.add(new City(i, pref, year));
		}

		// sort
		Collections.sort(cities, new CityComparator());
		int[] prefCnt = new int[N + 1];
		Arrays.fill(prefCnt, 1);

		for (City city : cities) {
			// create identifier id
			city.id = paddingZero(city.pref) + paddingZero(prefCnt[city.pref]);
			prefCnt[city.pref]++;
		}

		// re-sort
		Collections.sort(cities, new CityResetComparator());

		for (City city : cities) {
			System.out.println(city.id);
		}

		sc.close();
	}

	public static String paddingZero(int val) {
		String str = String.valueOf(val);
		String paddingStr = String.format("%6s", str).replace(" ", "0");
    return paddingStr;
	}
}


Measured memory_bytes: 76512
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long LL;
typedef unsigned long long ULL;
const LL LINF = 0x3f3f3f3f3f3f3f3f; 
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int mod = 1e9+7;
const ULL P = 131;
const int N = 2e5+7;


int main()
{
	int n,m;
	cin>>n>>m;
	int num=0;
	if(n%2==0) n--;
	for(int i=1;i<=n/4&&num<m;i++){
		cout<<i<<" "<<n/2-i+1<<"\n";
		num++;
	}
	for(int i=n/2+1,j=0;num<m;i++,j++){
		cout<<i<<" "<<n-j<<"\n";
		num++;
	}
	return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>

void swap(int *a, int *b)
{
	int temp;

	temp = *a;
	*a = *b;
	*b = temp;
}

int main(void)
{
	int a, b, c;		//Value a, b, c.

	scanf("%d %d %d", &a, &b, &c);
	if(a > b)
		swap(&a, &b);
	if(b > c)
		swap(&b, &c);
	if(a > b)
		swap(&a, &b);

	printf("%d %d %d\n", a, b, c);
}



Measured memory_bytes: 2072
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
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 long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}

long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }


int main(){
    long long MOD = 1000000007;
    int N;
    cin >> N;

    long long all = 1;
    long long zero = 1;
    long long both = 1;

    for(int i = 0; i < N; i++){
        all = all * 10 % MOD;
        zero = zero * 9 % MOD;
        both = both * 8 % MOD;
    }

    long long ans = all - ((zero * 2 % MOD)-both);
    if (ans<0)ans += MOD;

    cout << ans << endl;


}



Measured memory_bytes: 3624
//~ #pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
//~ #pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
//~ #pragma GCC target("avx2")  //Enable AVX
#include<bits/stdc++.h>
using namespace std;
#define int ll
#define all(a) begin(a),end(a)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int mod=1e9+7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int mul(int a,int b){
  return ((a)*1ll*(b))%mod;
}

void add(int &a,int b){
  a+=b;
  if(a>=mod)a-=mod;
}

int sub(int a,int b){
  a-=b;
  if(a<0){
    a+=mod;
  }
  return a;
}

int powz(int a,int b){
  int res=1;
  while(b){
    if(b&1){
      res=mul(res,a);
    }
    b/=2;
    a=mul(a,a);
  }
  return res;
}

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
  input>>x.F>>x.S;
  return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
  for(auto& i:x)
    input>>i;
  return input;
}

template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
  for(auto& i:x)
    output<<i<<' ';
  return output;
}

template<typename T>
vector<pair<T,int>> getvec(int n){
  vector<pair<T,int>>a(n);
  for(int i=0;i<a.size();i++){
    cin>>a[i].F;
    a[i].S=i;
  }
  return a;
}

const int N=1000005;

void solve(){
	int n;
	cin>>n;
	vector<pi>a(n);
	cin>>a;
	set<pair<int,int>>lef,rig;
	for(int i=0;i<n;i++){
		lef.insert({a[i].S,i});
		rig.insert({a[i].F,i});
	}
	ll ans=0;
	int lst=0;
	for(int i=0;i<n;i++){
		if(i%2==0){
			auto it=*lef.begin();
			lef.erase(it);
			rig.erase({a[it.S].F,it.S});
			if(lst>a[it.S].S||lst<a[it.S].F){
				ans+=abs(lst-it.F);
				lst=it.F;
			}
		}
		else{
			auto it=*--rig.end();
			rig.erase(it);
			lef.erase({a[it.S].S,it.S});
			if(lst>a[it.S].S||lst<a[it.S].F){
				ans+=abs(lst-it.F);
				lst=it.F;
			}
			
		}
	}
	ans+=abs(lst);
	for(int i=0;i<n;i++){
		lef.insert({a[i].S,i});
		rig.insert({a[i].F,i});
	}
	ll ans2=0;
	lst=0;
	for(int i=0;i<n;i++){
		if(i%2){
			auto it=*lef.begin();
			lef.erase(it);
			rig.erase({a[it.S].F,it.S});
			if(lst>a[it.S].S||lst<a[it.S].F){
				ans2+=abs(lst-it.F);
				lst=it.F;
			}
		}
		else{
			auto it=*--rig.end();
			rig.erase(it);
			lef.erase({a[it.S].S,it.S});
			if(lst>a[it.S].S||lst<a[it.S].F){
				ans2+=abs(lst-it.F);
				lst=it.F;
			}
		}
	}
	ans2+=abs(lst);
	cout<<max(ans,ans2);
}

signed main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc=1;
  //cin>>tc;
  for(int _=0;_<tc;_++){
    // cout<<"Case #"<<_+1<<": ";
    solve();
    if(_!=tc-1){
      cout<<'\n';
    }
  }
}



Measured memory_bytes: 14336
if __name__ == "__main__":
    W, H, N = map(int, input().split())
    XYA = [list(map(int, input().split())) for _ in range(N)]

    grid = [[0]*(W + 1) for _ in range(H + 1)]
    for x, y, a in XYA:
        sx = 1
        sy = 1
        fx = W
        fy = H
        if a == 1:
            fx = x
        elif a == 2:
            sx = x + 1
        elif a == 3:
            fy = y
        else:
            sy = y + 1
        for i in range(sx, fx + 1):
            for j in range(sy, fy + 1):
                grid[j][i] = 1
    ans = W*H
    for i in range(1, W + 1):
        for j in range(1, H + 1):
            if grid[j][i]:
                ans -= 1
    print(ans)


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

 

 
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;
 

 

 

 

int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
    
	ll s;cin>>s;
	ll dp[s+1];
	for(ll i=1;i<=s;i++) dp[i]=1;
	dp[0]=0;dp[1]=0;dp[2]=0;dp[3]=1;
	for(ll i=4;i<=s;i++)
	{
		ll ans=1ll;
		for(ll j=3;j<=i-3;j++)
		{
			ans+=dp[j];ans%=INF;
		}
		dp[i]=ans;
	}
	cout<<dp[s]<<'\n';
	return 0;
}




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

bool check(string s, int &p, int n){
    if(p >= n) return true;
    if(s[p] != 'm') return false;
    p++;
    if(s[p] != 'e'){
        bool ret = check(s, p, n);
        if(!ret) return false;
    }
    if(s[p] != 'e') return false;
    p++;
    if(s[p] != 'w'){
        bool ret = check(s, p, n);
        if(!ret) return false;
    }
    if(s[p] != 'w') return false;
    p++;
    return true;
}

int main(){
    string s;
    cin >> s;
    int p=0, n=s.length();
    if(check(s, p, n) && p==n){
        cout << "Cat" << endl;
    }else{
        cout << "Rabbit" << endl;
    }
    return 0;
}



Measured memory_bytes: 3224
a,b,c,k = gets.chomp.split(/ /).map {|i| i.to_i}

n = k
na = if a >= n
       n
     else
       a
     end

n -= na
if n > 0
  nb = if b >= n
         n
       else
         b
       end

  n -= nb
else
  nb = 0
end


if n > 0 
  nc = if c >= n
         n
       else
         c
       end
else
  nc = 0
end
#puts na
#puts nb
#puts nc
x = na*1 + nc*(-1)

puts x


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String s = sc.next();

		char[] list = s.toCharArray();

		Arrays.sort(list);

		if (list[0] == list[1] && list[2] == list[3] && list[0] != list[2]) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		sc.close();
	}
}

Measured memory_bytes: 26984
N,Y = map(int, input().split())

x = 0
flgA = False

while x <= N and flgA == False:
  y = 0
  while x + y <= N:
    z = N - (x + y)
    if Y == 10000*x + 5000*y + 1000*z:
      flgA = True
      print(str(x) + " " + str(y) + " " + str(z))
      break
    y = y + 1
  x = x + 1

if flgA == False:
  print('-1 -1 -1')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
typedef pair<int,int> PII;
const int mod = 1e9+7,INF = 1e9;
const int mx = 1e6+5;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    int a[n];
    int sum =0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum= sum^a[i];
    }
    vector<int>v;
    for(int i=0;i<n;i++)
    {
        int c = sum^a[i];
        v.push_back(c);
    }
    for(auto it:v)
        cout<<it<<" ";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 4968
#include <bits/stdc++.h>
     
#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair
     
using namespace std;
     
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;

int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = min(count(all(s), 'W'), count(all(s), 'R'));
  int x = count(all(s), 'R');
  int ans2 = 0;
  for (int i = 0; i < x; i++) {
    if (s[i] == 'W') ans2++;
  }
  cout << min(ans, ans2) << '\n';
  return (0);
}


Measured memory_bytes: 3744
///*/////////////////////////////*///
/// IN THE NAME OF ALMIGHTY ALLAH ///
///*/////////////////////////////*///

///*////////////////////*///
/// Author : SAIFULLAH29 ///
///*////////////////////*///

///*//////////////////////////////////////////*///
/// "When you want something, all the universe ///
///  conspires in helping you to achieve it."  ///
///              - Paulo Coelho, The Alchemist ///
///*//////////////////////////////////////////*///

#include <bits/stdc++.h>

#define SS           " "
#define endl         "\n"
#define EPS          1e-9
#define gcd          __gcd
#define pb           push_back
#define pi           acos(-1.0)
#define Ars          greater<int>()
#define vi           vector<int>
#define vvi          vector<vector<int> >
#define flush        cin.ignore(numeric_limits<streamsize>::max(),'\n');
#define wow          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

typedef long long              ll;
typedef double                 dbl;
typedef unsigned long long     ull;

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

void solve()
{
    char s[4][4];

    for(int i=0; i<3; i++)
        cin>>s[i];

    cout<<s[0][0]<<s[1][1]<<s[2][2]<<endl;
}

int main()
{
    wow

    int t=1;
    //cin>>t;

    while(t--)
        solve();

    return 0;
}

///*////////////////////////////////////////////*///
/// "There is only one thing that makes a dream  ///
/// impossible to achieve: the fear of failure." ///
///                - Paulo Coelho, The Alchemist ///
///*////////////////////////////////////////////*///


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

#define N 10000000

int n;

long sumArithmeticSeq(int a){
    long max = n/a;
    return max*(max+1)/2;
}

int main(void)
{      
    long sum = 0;
    cin >> n;
    
    for (int i = 1; i <= n; i++){
        sum += i*sumArithmeticSeq(i); 
    }

    cout << sum << endl;
    
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
long long a,b;
int main()
{
    cin>>a>>b;
    if(a>0&&b>0)cout<<"Positive";else
    	if(a<=0&&b>=0)cout<<"Zero";else
    	  if((b-a+1)%2)cout<<"Negative";
    	    else cout<<"Positive";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int n, m, i, j, x, A;
  int a[1000], b[1000], c[1000] = {0};
  scanf("%d %d", &n, &m);
  for(i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for(i = 0; i < m; i++) {
    scanf("%d", &b[i]);
  }
  for(i = 0; i < m; i++) {
    x = n;
    for(j = 0; j < n; j++) {
      if(b[i] >= a[j] && x > j){
        x = j;
      }
    }
    c[x] = c[x] + 1;
  }
  x = 0;
  for(i = 0; i < n; i++) {
    if(x < c[i]){
      x = c[i];
      A = i + 1;
    }
  }
  printf("%d\n", A);
  return 0;
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
const int M = 1000000007;

int main() {
    while (1) {
        int m, n;
        cin >> m >> n;
        if (!m) return 0;

        int lim = 7400000;
        bitset<7400000> isok;
        for (int i = m; i < lim; ++i) {
            if (isok[i]) continue;
            if (!n) {
                cout << i << "\n";
                break;
            }
            --n;
            for (int j = i; j < lim; j += i)
                isok.set(j);
        }
    }
}

Measured memory_bytes: 3972
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
	int stack[100],last=0;
	char s[100];
	while(scanf("%s",s)!=EOF)
	{
		switch(s[0]){
		case '+':
			stack[last-2]=stack[last-2]+stack[last-1];
			last--;
			break;
		case '-':
			stack[last-2]=stack[last-2]-stack[last-1];
			last--;
			break;
		case '*':
			stack[last-2]=stack[last-2]*stack[last-1];
			last--;
			break;
		default :
			stack[last]=atoi(s);
			last++;
			break;
		}
	}
	printf("%d\n",stack[last-1]);

	return 0;
}

Measured memory_bytes: 548
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll cnt=0;
	ll num;
	cin>>num;
	ll des=100;
	while(des<num){
		des*=1.01;
		cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int a, b;
    char ch[100][100];
    for(int i=0; i<50; i++){
        for(int j=0; j<100; j++){
            ch[i][j] = '#';
        }
    }
    for(int i=50; i<100; i++){
        for(int j=0; j<100; j++){
            ch[i][j] = '.';
        }
    }
    cin >> a >> b;
    a--;
    b--;
    while(true){
        for(int y=0; y<50; y+=2){
            for(int x=0; x<100; x+=2){
                if(a>0){
                    ch[y][x] = '.';
                    a--;
                }
                else break;
            }
            if(a==0) break;
        }
        if(a==0) break;
    }
    while(true){
        for(int y=51; y<100; y+=2){
            for(int x=0; x<100; x+=2){
                if(b>0){
                    ch[y][x] = '#';
                    b--;
                }
                else break;
            }
            if(b==0) break;
        }
        if(b==0) break;
    }
    cout << "100 100" << endl;
    for(int i=0; i<100; i++){
        for(int j=0; j<100; j++){
            cout << ch[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define maxx 100010
#define mp make_pair
typedef pair<int,int> ii;
int ans[maxx],visitado[maxx];
vector < ii > ladj[maxx];
map <int, int> dicio;
int n,m,p = 0;
int nos = 0;
vector < int > dist;

void dfs(int x){
	visitado[x] = 1;
	for(auto e: ladj[x]){
		if(visitado[e.second] == 0) dfs(e.second);
	}
}

const int INF = -1e9;
bool spfa(int s) {
    int N = n+1;
    dist.assign(N, INF);
    vector < int > cnt(N, 0);
    vector < bool > inqueue(N, false);
    queue < int > q;
	N = nos;
	
    dist[s] = 0;
    q.push(s);
    inqueue[s] = true;
	while (!q.empty()) {
  
		int atual = q.front();
       	
        q.pop();
    	inqueue[atual] = false;
        for (auto edge : ladj[atual]) {
                int peso = edge.first - p;
		int next = edge.second;

                if (dist[atual] + peso > dist[next] && ans[next] == 1) {
                       dist[next] = dist[atual] + peso;

                       if (!inqueue[next]) {
                              q.push(next);
                              inqueue[next] = true;
                              cnt[next]++;
                    if (cnt[next] > N)
                        return false;  // negative cycle
                }
            }
        }
    }
    return true;
}
vector < int > help; 

int main() {
	cin >> n >> m >> p;
	
	int a,b,w;
	for(int i = 1; i <= m; i++){
		cin >> a >> b >> w;
		ladj[a].push_back(mp(w,b));

	}
	dfs(1);
	bool c = true;
	if(visitado[n] == 1){
		ans[1] = 1;
		nos++;
		for(int i = 2; i <= n;i++){
			for(int j = 1; j <= n+1; j++)visitado[j] = 0;
			dfs(i);
			if(visitado[1] == 1 || visitado[n] == 1){nos++;ans[i] = 1;}

		}
		c = spfa(1);
	}	

	if(c == true) cout << max(0,dist[n]) << endl;
	else cout << -1 << endl;
	return 0;
}


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

int main(){
  
  int house[4][3][10];
  int b,f,r,v;
  int i,j;
  
  for(b=0;b<4;b++){

    for(f=0;f<3;f++){

      for(r=0;r<10;r++){

	house[b][f][r] = 0;

      }

    }

  }
  
  cin >>i;
  
  for(j=0;j<i;j++){
    
    cin >>b >>f >>r >>v ;

    house[b-1][f-1][r-1] =house[b-1][f-1][r-1]+ v;

    if(house[b-1][f-1][r-1] < 0)
      house[b-1][f-1][r-1] = 0; 

    if(house[b-1][f-1][r-1] > 9)
      house[b-1][f-1][r-1] = 9;  
  
  }
  
  for(b=0;b<4;b++){
    
    for(f=0;f<3;f++){
      
      for(r=0;r<10;r++){
	
	if(r==9){
	  cout <<" " <<house[b][f][9] <<"\n";
	  
	}else{
	  cout <<" " <<house[b][f][r]  ;
	}
      }
      if(b ==0||b==1||b==2){
	if(f == 2)
	  cout <<"####################" <<"\n";
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1160
def getSpecialNum(x, n):	
	if int(x) > n:
		return 0
	ans = 0
	if x.count('3') > 0 and x.count('5') > 0 and x.count('7') > 0:
		ans = 1
	ans += getSpecialNum(x+'3',n)
	ans += getSpecialNum(x+'5',n)
	ans += getSpecialNum(x+'7',n)
	return ans
N = int(input())
print(getSpecialNum('0',N))


Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var rdr = bufio.NewReaderSize(os.Stdin, 1000)

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	s := readLine()

	ans := int64(0)
	cnt := 0
	for i, ch := range s {
		if ch == 'W' {
			ans += int64(i - cnt)
			cnt++
		}
	}

	fmt.Println(ans)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func readLine() string {
	buf := make([]byte, 0, 1000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextI64() int64 {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func max(a int, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

func anser(b bool, y string, n string) string {
	if b {
		return y
	}
	return n
}

Measured memory_bytes: 2048
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
      	String t = sc.next();
      	String ss;
      	int lim = s.length()-t.length()+1;
      	int cnt=0;
      	int cnt_min = t.length();
      
      	for(int i = 0;i < lim;i++){
          ss = s.substring(i,i+t.length());
          cnt = 0;
          for(int j = 0; j < t.length();j++){
            if(ss.charAt(j) != t.charAt(j)) cnt++;
          }
          if(cnt_min > cnt) cnt_min = cnt;
        }
      
      	System.out.println(cnt_min);
	}
}


Measured memory_bytes: 36724
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){
	
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	string s;
	cin>>s;
	ll i,j,k,l,n=s.length();
	i=0; j=n-1; k=0;
	while(j>i){
		if(s[i]!=s[j]){
			k++;
		}
		i++; j--;
	}
	cout<<k;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, k, v[200100], t[200100];

int main() {
    cin.tie(0); ios::sync_with_stdio(0);
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> v[i];

    ll pos = 1, time = 1;
    while (true) {
        if (t[pos])
            break;
        t[pos] = time++;
        pos = v[pos];
    }

    time--;
  
    if (k < time) {
        for (int i = 1; i <= n; i++)
            if (t[i] - 1 == k)
                cout << i;
        return 0;
    }
  
    ll offset = t[pos] - 1;
    ll dif = (k - offset) % (time - offset) + 1;

    for (int i = 1; i <= n; i++)
        if (t[i] - offset == dif)
            cout << i;
    return 0;
}

Measured memory_bytes: 6768
k = gets.chomp.to_i
ln = (1..9).to_a
(k - 1).times do |_|
  n = ln.shift
  ln.push(10 * n + (n % 10) - 1) if n % 10 != 0
  ln.push(10 * n + (n % 10))
  ln.push(10 * n + (n % 10) + 1) if n % 10 != 9
end
res = ln[0]
puts res

Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> > 
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;
int main()
{
	boost;
	int n, m;
	cin >> n >> m;
	cout << (n == m ? "Yes" : "No");
}

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

int main() {
    int N, K;
    cin >> N >> K;
    string str;
    cin >> str;
    
    int sum=1;
    
    for(int n=1; n<N; n++) {
        if(str[n]!=str[n-1]) {
            sum++;
        }
    }
    
    cout << N + min(-1, -sum+K*2) << endl;

    return 0;
    
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int N, K;
int a[200100];
int cnt[200100];

int main(void) {
	cin >> N >> K;
	rep(i, N) cin >> a[i];
	rep(i, N) cnt[a[i]]++;

	vector<pair<int, int>> v;
	rep(i, N + 1) if(cnt[i] > 0) v.pb(mp(cnt[i], i));
	sort(all(v));
	reverse(all(v));

	/*
	for(auto u : v) printf("%d ", u);
	printf("\n");
	*/

	
	ll ans = 0;
	reps(i, K, v.size()) ans += v[i].fi;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3956
#include <stdio.h>

int main(void){
	int n, m, tmp;
	int bibs[101] = {}, num[101] = {};
	int i, j, k;
	
	scanf("%d %d", &n, &m);
	
	for (i = 0; i < n; i++) scanf("%d", &bibs[i]);
	
	for (i = 1; i <= m; i++){
		for (j = 0; j < n; j++) num[j] = bibs[j]%i;
		
		for (j = 0; j < n-1; j++){
			if (num[j] > num[j+1]){
				tmp = num[j+1];
				num[j+1] = num[j];
				num[j] = tmp;
				
				tmp = bibs[j+1];
				bibs[j+1] = bibs[j];
				bibs[j] = tmp;
			}
		}
	}
	
	for (i = 0; i < n; i++) printf("%d\n", bibs[i]);
	
	return 0;
}

Measured memory_bytes: 596