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

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

int main(){
  int a;
  cin >> a;
  int hp= 0;
  
  while(a >= 500){
    hp += 1000;
    a -= 500;
  }
  while(a >= 5){
    hp += 5;
    a -= 5;
  }
  
  cout << hp << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
#include <set>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

ll llmin(ll x, ll y){
	if (x > y) return y;
	return x;
}

bool reached[200001];
ll first[200001];
ll a[200001];


int main(){
	ll n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++){
		cin >> a[i];
	}
	ll tele = 0, now = 1, roop;
	reached[1] = true;
	first[1] = 0;
	while(1){
		tele++;
		now = a[now];
		if (reached[now] == true){
			k -= first[now];
			roop = tele - first[now];
			break;
		}
		reached[now] = true;
		first[now] = tele;
		if (tele == k){
			cout << now << endl;
			return 0;
		}
	}
	ll num = k%roop;
	for (int i = 0; i < num; i++){
		now = a[now];
	}
	cout << now << endl;
	return 0;
}


Measured memory_bytes: 6944
#include <iostream>
#include <cmath>

using namespace std;
using ll = long long;

ll f(ll n){
    ll res = 1;
    for (ll i = 1; n >= i * i; ++i) {
        if (n % i == 0) {
            res = i;
        }
    }
    return res;
}

int getDigit(ll n){
	 return (int)log10((long double)n) + 1;
}

int main(){
	ll N;
	cin >> N;

	ll x = f(N);
	ll y = N / x;

	cout << max(getDigit(x), getDigit(y)) << endl;
}

Measured memory_bytes: 640
#include"bits/stdc++.h"
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if((a+b)>(c+d))
		cout<<"Left";
	else if((a+b)==(c+d))
		cout<<"Balanced";
	else
		cout<<"Right";
}

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

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) (a).begin(),(a).end()

template<typename T1, typename T2> inline void chkmin(T1 & x, const T2 & y) {if (y < x) x = y;}
template<typename T1, typename T2> inline void chkmax(T1 & x, const T2 & y) {if (x < y) x = y;}

void read() {
    int x;
    cin >> x;
    cout << (x ^ 1);
}

void run() {

}

void write() {

}

signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(20), cout.setf(ios::fixed);
    read();
    run();
    write();
    return 0;
}

Measured memory_bytes: 3648
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass : Scanner
{
    static void Main()
    {
        int N = RInt();
        var A = new int[N];
        for (int i = 0; i < N; i++)
        {
            A[i] = RInt();
        }
        var B = new int[N];
        Array.Copy(A, B, N);
        Array.Sort(B);
        int max = B.Last();
        for (int i = 0; i < N; i++)
        {
            if (A[i] == max) WriteLine(B[N-2]);
            else WriteLine(max);
        }

    }
}



class Scanner
{
    public static string RString() => Console.ReadLine();
    public static int RInt() => ReadTuple<int>();
    public static long RLong() => ReadTuple<long>();
    public static double RDouble() => ReadTuple<double>();

    public static string[] RStrings() => Console.ReadLine().Split();
    public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
    public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
    public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray();
    //public static string[] RStrings(Func<string, string> func) => Console.ReadLine().Split().Select(func).ToArray();

    public static T1 ReadTuple<T1>()
    {
        var r = RString();
        var r1 = (T1)Convert.ChangeType(r, typeof(T1));
        return r1;
    }
    public static (T1, T2) ReadTuple<T1, T2>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        return (r1, r2);
    }
    public static (T1, T2, T3) ReadTuple<T1, T2, T3>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        return (r1, r2, r3);
    }
    public static (T1, T2, T3, T4) ReadTuple<T1, T2, T3, T4>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        var r4 = (T4)Convert.ChangeType(r[3], typeof(T4));
        return (r1, r2, r3, r4);
    }
}


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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e15;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;

vector<int> route(int start, int end, int prev, vector<vector<int>> &edges) {
    if (start == end) return {end};

    for (int next : edges[start]) {
        if (next == prev) continue;
        vector<int> ans = route(next, end, start, edges);
        if (ans.empty()) continue;
        ans.push_back(start);
        return ans;
    }
    return {};
}

class UnionFind {
public:
    // 親の番号を格納する。親だった場合-size
    vector<int> parents;

    UnionFind(int n) {
        parents = vector<int>(n, -1);
    }

    // aがどのグループに属しているか
    int root(int a) {
        if (parents[a] < 0) {
            return a;
        }
        return parents[a] = root(parents[a]);
    }

    int size(int a) {
        return -parents[root(a)];
    }

    // aとbをくっつける
    bool connect(int a, int b) {
        int ra = root(a);
        int rb = root(b);
        if (ra == rb) {
            return false;
        }
        // 大きいほうにA
        if (size(ra) < size(rb)) {
            swap(ra, rb);
        }
        parents[ra] += parents[rb];
        parents[rb] = ra;
        return true;
    }

    bool is_union(int a, int b) {
        int ra = root(a);
        int rb = root(b);
        return ra == rb;
    }
};

int main() {
    int n;
    cin >> n;
    vector<vector<int>> edges(n);
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;

        edges[a].push_back(b);
        edges[b].push_back(a);
    }

    vector<int> ans = route(0, n - 1, -1, edges);
    reverse(ans.begin(), ans.end());

    int bi = (ans.size() + 1) / 2 - 1;
    int wi = bi + 1;
    int w = ans[wi];
    int b = ans[bi];

    UnionFind uf(n);

    rep(from, n) {
        for (int to : edges[from]) {
            if (from == w && to == b) continue;
            if (from == b && to == w) continue;
            uf.connect(from, to);
        }
    }

    int ws = uf.size(w), bs = uf.size(b);

    if (ws == bs) {
        cout << "Snuke" << endl;
        ret();
    }

    if (ws < bs) {
        cout << "Fennec" << endl;
    } else {
        cout << "Snuke" << endl;
    }


}



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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

/*--------------------------*/
const int kMax_n = 1001; //頂点数の最大値

int n; //頂点数
vvi G(kMax_n);
vi match(kMax_n); //マッチングのペア
vi used(kMax_n);

// uとvを結ぶ辺をグラフに追加する
void add_edge(int u, int v){
    G[u].pb(v);
    G[v].pb(u);
}

// 増加パスをDFSで探す
bool dfs(int v){
    used[v] = true;
    
    for(auto u : G[v]){
        int w = match[u];

        if(w < 0 || !used[w] && dfs(w)){
            match[v] = u;
            match[u] = v;

            return true;
        }
    }

    return false;
}

//二分グラフの最大マッチングを求める
int b_match(void){
    int res = 0;

    fill(all(match), -1);

    rep(i, n){
        if(match[i] < 0){
            fill(all(used), false);

            if(dfs(i)) res++;
        }
    }

    return res;
}

void init_G(void){
    for(auto & g : G) g.clear();
}
/*--------------------------*/

int main(void){
    for(int mm, nn; cin >> mm >> nn, mm;){
        vi b(mm), r(nn);
        for(auto & bb : b) cin >> bb;
        for(auto & rr : r) cin >> rr;

        n = mm + nn;
        init_G();

        rep(i, mm){
            rep(j, nn){
                if(__gcd(b[i], r[j]) == 1) continue;

                add_edge(i, mm + j);
            }
        }

        cout << b_match() << endl;
    }

	return 0;
}

Measured memory_bytes: 3420
macro_rules! input {
     (source = $s:expr, $($r:tt)*) => {
         let mut iter = $s.split_whitespace();
         input_inner!{iter, $($r)*}
     };
     ($($r:tt)*) => {
         let s = {
             use std::io::Read;
         let mut s = String::new();
         std::io::stdin().read_to_string(&mut s).unwrap();
         s
     };
     let mut iter = s.split_whitespace();
     input_inner!{iter, $($r)*}
     };
}
     
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
 
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
 
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
 
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
 
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
 
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
 
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::{i32, i64, u32, u64};
#[allow(unused_imports)]
use std::io::{stdout, Write, BufWriter};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
//#[allow(unused_imports)]
//use proconio::marker::{Isize1, Usize1, Bytes, Chars};

//#[proconio::fastout]
fn main() {
    input!{
        n: usize,
        s: [i64; 3*n],
    }
    let mut s = s;
    s.sort();
    s.reverse();
    let mut ans = 0;
    for i in 0..n { ans += s[2*i + 1]; }
    println!("{}", ans);
}


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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

int main(){
    long double A,B;
    cin>>A>>B;
    cout<<LL(A*B+0.001)<<endl;
    return 0;
}

Measured memory_bytes: 3636
def main():
    m, *a = map(int, open(0).read().split())
    a = [0] + a + [0]
    s = 0
    p = [abs(i - j) for i, j in zip(a, a[1:])]
    s = sum(p)
    t = [str(s - abs(i - j) - abs(j - k) + abs(k - i)) for i, j, k in zip(a, a[1:], a[2:])]
    ans = "\n".join(t)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 22340
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for(ll i = a; i < (ll)(b); i++)

#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

using namespace std;
using ll = long long;
using vel = vector<ll>;
using ves = vector<string>;
using veb = vector<bool>;
using qul = queue<ll>;

void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}

int binary_search(ll x, vel a){
    auto ite = lower_bound(ALL(a), x);
    if(ite != a.end() && *ite == x) {
        return ite - a.begin() ;
    } else {
        return -1;
    }

}

ll modpow(ll a, ll n, ll mod) {
    if(n == 0)
        return 1;
    if(n == 1)
        return a % mod;
    if(n % 2 == 1)
        return (a * modpow(a, n - 1, mod)) % mod;
    ll t = modpow(a, n / 2, mod);
    return (t * t) % mod;
}

int main() {
    string N;
    int num, sum=0, num2;
    cin >> N;
    num = N.size();
    REP(i, num){
        num2 = (int)(N[i]-'0');
        sum += num2;
    }

    if(sum % 9 == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3752
#include<stdio.h>

int main()
{
  int a,b,c,d,e,f;
  int i,j,k,l,I,J;
  int w=0,s=0;
  double p=0,q=0;
  double x,y;
  scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
  for(i=0;;i++){
    x=100*b*i;
    if(x<=f){
      for(j=0;100*a*j+100*b*i<=f;j++){
        x=100*a*j+100*b*i;
        if(x<=f){
          for(k=0;;k++){
            x=100*a*j+100*b*i+d*k;
            if(x<=f && d*k<=(a*j+b*i)*e){
              for(l=0;;l++){
                x=(double)100*a*j+100*b*i+c*l+d*k;
                y=(double)d*k+c*l;
                if(0<x && x<=f && y<=(a*j+b*i)*e){
                  q=100*y/x;
                  if(q>p){
                    p=q;
                    w=x;
                    s=y;
                  }
                }else break;
              }
            }else break;
          }
        }else break;
      }
    }else break;
  }
  if(w==0 && s==0) w=100*a;
  printf("%d ",w);
  printf("%d\n",s);
  return 0;
}


Measured memory_bytes: 1716
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
#define fir first
#define sec second
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){
	int t,x;
	cin >> t >> x ;

	printf("%.7f\n",(double)t/x);


	ret 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
int mod = 1000000000+7;

int main(){

	int n;
	cin>>n;
	int a[n];
	rep(i,n)cin>>a[i];
	
	sort(a,a+n);
	ll ans=0+a[n-1];
	int k=n-2;
	for(int i=0;i<n-2;i++){
		if(i<n-2-1){
			ans=ans+a[k]*2;
			k--;
			i++;
		}
		else ans = ans+a[k];
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 4420
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define MM(i, n, m) for (int i = m; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;

/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
 * pair<型, 型> 変数名
 * map<型, 型> 変数名  // 連想配列
 * priority_queue<型> 変数名  // 最大値から出てくるヒープ
*/
int main()
{
    string S;
    cin >> S;
    if (S != "AAA" && S != "BBB")
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

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

using namespace std;

#define fo(i, n)  for(int i = 0; i < n; ++i)

int main()
{
	string s;
	cin>> s;
	long size = s.size();
	long ans = 0;
	fo(i, size-1)
	{
	    if(s[i] == s[i+1])
	    {
	        ans ++;
	        if(s[i] == '0')
    	        s[i+1] = '1';
    	    else
    	        s[i+1] = '0';
	    }
	}
	cout<<ans;
 	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>

int getCost(int N, int *x, int *y, int p, int q) {
  int c = 1;
  if (N == 1) return c;
  if (N == 2) {
    return c;
  }else {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
	if ((x[i]-x[j] == p) && (y[i]-y[j] == q) && i != j) {
	  c++;
	}
      }
    }
    c--; // c = 0;
    return N-c;
  }
}

int main() {
  int N,p,q;
  scanf("%d", &N);
  int x[N];
  int y[N];
  for (int i = 0; i < N; i++) {
    int px,py;
    scanf("%d %d", &px, &py);
    x[i] = px;
    y[i] = py;
  }
  int c;
  if (N == 1) {
    c = 1;
  }else {
    c = N-1;
  }
  for( int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i != j) {
	p = x[i]-x[j];
	q = y[i]-y[j];
	int pc = getCost(N, x, y, p, q);
	if ( c > pc) c = pc;
      }
    }
  }
  printf("%d", c);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <map>
 
using namespace std;
typedef long long ll;


int main(){
	string s;
	cin>>s;
	for(int i = 0; i<s.size(); i++)
		cout<<"x";
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
bool coffeeMatch(string str){
	if( str[2] == str[3] && str[4] == str[5]){
		return true;
	}else{
		return false;
	}
}

int main()
{
	string str;
	cin>>str;
	if(coffeeMatch(str) == true){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}



Measured memory_bytes: 384
import java.util.Scanner;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   char[] c = sc.next().toCharArray();
   int ans =0;
   boolean a = false;
   boolean b = false;
     for(int i =0;i<N;i++)
     {
       if(a)
       {
         if(c[i]!='A') a = false;
         if(c[i]=='B') b = true;
       }
       else if(b)
       {
         b = false;
         if(c[i]=='C') ans++;
       }
       else if(c[i]=='A')
       {
         a = true;
       }
     }
     System.out.println(ans);
 }
}

Measured memory_bytes: 23636
#include<iostream>
using namespace std;
#define ll long long
int main()
{
	ll n;
	scanf("%lld",&n);
	ll a[n];
	ll sum=0;
	for(int i=1;i<n;i++)
	{
		sum+=i;
	}
	printf("%lld",sum);
	return 0;
}

Measured memory_bytes: 256
object Main extends App {

  import scala.io.StdIn._
  implicit val memo = Array.tabulate(1000001){_ ⇒ -1}
  solve
  def solve: Unit = {
    val n = readLine.trim.toInt
    if (n != 0){
      println(calCollatz(n))
      solve
    }
  }
  def calCollatz(num: Int)(implicit memo: Array[Int]): Int = {
    if (num == 1) 0
    else {
      if (memo(num) < 0) {
        memo(num) = if (num % 2 == 0) 1 + calCollatz(num / 2)
        else 1 + calCollatz(num * 3 + 1)
      }
      memo(num)
    }
  }
  implicit class ScopeFunc[T](val value:T){
    def let[A](func: T ⇒ A): A = func(value)
  }
}


Measured memory_bytes: 51344
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def yes():
    print("Yes")  # type: str


def no():
    print("No")  # type: str


def solve(a: int, b: int, c: int):
    if c-a-b > 0 and (4*a*b < (c-a-b)**2):
        yes()
    else:
        no()
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    c = int(next(tokens))  # type: int
    solve(a, b, c)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
def solve(n, a, q, b, c):
    D = {}
    for x in a:
        if not x in D:
            D[x] = 0
        D[x] += 1
    total = sum(a)
    res = []
    for x, y in zip(b, c):
        if not x in D:
            D[x] = 0
        if not y in D:
            D[y] = 0
        diff = y*(D[x]+D[y]) - (x*D[x] + y*D[y])
        D[x], D[y] = 0, (D[x]+D[y])
        total += diff
        res.append(total)
    return "\n".join(map(str, res))

n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = [0] * q
c = [0] * q
for i in range(q):
    b[i], c[i] = map(int, input().split())
print(solve(n, a, q, b, c))

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

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

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define precise(x) fixed << setprecision(x) 

const int MOD = 1e9+7;

int mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}


void solve()
{
  int n;
    cin >> n;
    
   int a[n];
    f(i,n) cin >> a[i];
    
    int res=  0;
    map<int,int> mp;
    
    f(i,n) mp[a[i]]++;
    
    int mm = 0;
    
    for(auto x : mp) mm+=(x.S*(x.S-1))/2;
    
    f(i,n)
    {
        res = mm;
        
        int xx = mp[a[i]];
        
        res-=(xx*(xx-1))/2;
        res+=((xx-1)*(xx-2))/2;
        
        cout << res << '\n';
    }
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

Measured memory_bytes: 12800
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)


#define INF (1e9)
typedef long long unsigned int ll;


int main()
{

    int n,m;
    cin >> n>>m;

    int b[m];

    REP(i,m){
        b[i] = 1;
    }

    REP(i,n){
        int k;
        cin >> k;
        int l[m];
        REP(j,m){
            l[j] = 0;
        }
        REP(j, k)
        {
            int h;
            cin >> h;
            l[h-1] = 1;
        }
        REP(j,m){
            if(l[j]==0){
                b[j] = 0;
            }
        }
    }
    int sum = 0;
    REP(i, m)
    {

        if (b[i] == 1)
        {
            sum += 1;
        }
    }
    cout << sum;


    return 0;
}


Measured memory_bytes: 256
n = int(input())
l = list(map(int,input().split()))
c = len([i for i in l if i%4==0])
l1 = [i for i in l if  (i%2==0 and i%4!=0)]
if len(l1)>=1:
  a = n-len(l1)+1
  a = a-c
  if a<=c+1:
    print("Yes")
  else:
    print("No")
else:
  a = n-c
  if a<=c+1:
    print("Yes")
  else:
    print("No")

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

using namespace std;

typedef long long ll;

int calc(string s){
	if(s == "SUN") return 7;
	if(s == "MON") return 6;
	if(s == "TUE") return 5;
	if(s == "WED") return 4;
	if(s == "THU") return 3;
	if(s == "FRI") return 2;
	if(s == "SAT") return 1;
}

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

	string s;
	cin >> s;
	cout << calc(s) << endl;
}


Measured memory_bytes: 256
def main():
    s = input().strip()
    carry = 0
    result = 0
    for i in range(len(s) - 1, -1, -1):
        carry, x = divmod(ord(s[i]) - ord("0") + carry, 10)
        if x > 5 or (x == 5 and i > 0 and s[i - 1] >= "5"):
            carry += 1
            result += 10 - x
        else:
            result += x
    result += carry
    print(result)


main()


Measured memory_bytes: 52588
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;

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

	string s;
	cin >> s;
	if (s[0] == '9' || s[1] == '9') {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// dp[i][j] - the number of ways to put numbers in prefix of size 'i'
// such that the last number is 'j'
 
const int nax = 3005;
string cmp;
int dp[nax][nax], pref[nax][nax];
 
const int mod = 1e9 + 7;
 
void add_self(int& a, int b) {
    a += b;
    if(a >= mod) {
        a -= mod;
    }
}
 
int main() 
{
    int n;
    scanf("%d", &n);
    cin>>cmp;
    dp[1][1] = 1;
    for(int len = 2; len <= n; ++len) 
	{
        // let's compute prefix sums on dp[len-1]
        for(int i = 1; i <= len - 1; ++i) 
		{
            pref[len-1][i] = (pref[len-1][i-1] + dp[len-1][i]) % mod;
        }
        for(int b = 1; b <= len; ++b) 
		{
            int L, R;
            
            if(cmp[len-2] == '<') 
                L = 1, R = b - 1;
            
            else 
                L = b, R = len - 1;
            
            if(L <= R) 
                add_self(dp[len][b], (pref[len-1][R] - pref[len-1][L-1] + mod) % mod);
    
        }
    }
    int answer = 0;
    for(int b = 1; b <= n; ++b) 
	{
        add_self(answer, dp[n][b]);
    }
    
    printf("%d\n", answer);
}

Measured memory_bytes: 69504
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

int d[MAXn];
int main(){
  IOS();
  int ans=0;
  int n;
  int idx=0;
  cin>>n;
  REP(i,n) cin>>d[i];
  REP(i,n){
    while( idx<n && d[idx]==d[i] ) idx++;
    ans+=(idx-i)/2;
    i=idx-1;
  }
  cout<<ans<<endl;
}


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

int main(){
  int N,K,x[101];
  cin >> N >> K;
  for(int i=0;i<N;++i){
    cin >> x[i];
  }
  
  int ans = 0,dis;
  for(int i=0;i<N;++i){
    dis = min(x[i],abs(x[i]-K));
    ans += dis*2;
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

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

  int a, b;
  cin >> a >> b;

  if (a >= 13) {
    cout << b << endl;
  } else if (a >= 6) {
    cout << b/2 << endl;
  } else {
    cout << 0 << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, N[MAX][MAX];

int prim()
{
  int u,minv;
  int d[MAX],p[MAX],color[MAX];
  int i=0;
  int v=0;
  int j=0;

  for (i=0;i<n;i++)
    {
      d[i] = INFTY;
      p[i] = -1;
      color[i] = WHITE;
    }

  d[0] = 0;

  while(1)
    {
      minv = INFTY;
      u = -1;
      for( i=0 ; i<n ;i ++)
	{
	  if(minv>d[i] && color[i]!=BLACK)
	    {
	      u=i;
	      minv=d[i];
	    }
	}
      if( u==-1 )break;
      color[u] = BLACK;
      for( v=0 ; v<n ; v++ )
	{
	  if(color[v]!=BLACK && N[u][v]!=INFTY)
	    {
	      if(d[v]>N[u][v])
		{
		  d[v] = N[u][v];
		  p[v] = u;
		  color[v] = GRAY;
		}
	    }
	}
    }
  int sum=0;
  for(i=0;i<n;i++)
    {
      if(p[i]!=-1)
	{
	  sum += N[i][p[i]];
	}
    }

      return sum;
    }

  int main()
  {
    int i=0;
    int j=0;
    cin>>n;

    for(i=0;i<n;i++)
      {
	for( j=0 ; j<n ; j++ )
	  {
	    int e;
	    cin>>e;
	    N[i][j] = (e == -1)? INFTY : e;
	  }
      }

    cout<<prim()<<endl;

    return 0;
  }
  



Measured memory_bytes: 3124
def reduce(arr,n):
    count=len(arr)*(len(arr)-1)*(n-len(arr))/2+len(arr)*(len(arr)-1)*(len(arr)-2)/6
    return count

n=int(input())
s=input()

r,g,b=[],[],[]

for i,j in enumerate(s):
    if j=='R':
        r.append(i)
    elif j=='G':
        g.append(i)
    else:
        b.append(i)

count= n*(n-1)*(n-2)/6
count-=reduce(r,n)
count-=reduce(g,n)
count-=reduce(b,n)

for i in range(n):
    for j in range(i+1,n):
        if j+(j-i)<n:
            if s[i]!=s[j] and s[j]!=s[j+(j-i)] and s[i]!=s[j+(j-i)]:
                count-=1
print(int(count))

Measured memory_bytes: 9260
n = int(input())
la = [int(input())-1 for _ in range(n)]

pushed = set()

now = 0
ans = 0
while True:
    if now in pushed:
        ans = -1
        break
    pushed.add(now)
    ans += 1
    now = la[now]
    if now == 1:
        break
print(ans)


Measured memory_bytes: 19136
let rec gcd x y =
  if y = 0L then x
  else gcd y (Int64.rem x y)

let _ =
  try
    while true do
      let x, y = Scanf.scanf "%Ld %Ld\n" (fun x y -> (x,y)) in
      let g = gcd x y in
      Printf.printf "%Ld %Ld\n" g (Int64.mul (Int64.div x g) y)
    done
  with
    End_of_file -> ()

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

int main(){
    int N;
    cin >> N;
    vector<double> p(N);
    rep(i,N)cin >> p[i];
    vector<vector<double> > dp(N+1, vector<double>(N+1));

    dp[0][0] = 1;
    for(int i = 1; i <= N; i++){
        for(int j = 0; j <= i; j++){
            if(j>0)dp[i][j] = dp[i-1][j]*(1-p[i-1])+dp[i-1][j-1]*p[i-1];
            else dp[i][j] = dp[i-1][j]*(1-p[i-1]);
        }
    }
    double ans = 0;
    for(int i = N/2+1; i <=N; i++){
        ans += dp[N][i];
    }
    printf("%.12f\n",ans);
    return 0;
}

Measured memory_bytes: 70656
#include<bits/stdc++.h>
using  namespace std;
using ll=long long int ;
int main()
{
   ll n,diff;
   cin>>n;
   
   ll arr[n];
   
   for(int i=0;i<n;i++)
   cin>>arr[i];
   ll ans=0;
   for(int i=1;i<n;i++)
   {
       if(arr[i]<arr[i-1])
       {
           diff=arr[i-1]-arr[i];
           ans+=diff;
           arr[i]+=diff;
          // i--;
       }
   }
   cout<<ans;
}

Measured memory_bytes: 5192
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)


inf = 10 ** 15
mod = 10 ** 9 + 7
n,k = map(int, input().split())
x = list(map(int, input().split()))
minus = []
plus = []
zind = bisect.bisect_left(x, 0)
if zind == n:
    minus = x
    minus.reverse()
else:
    minus = x[0:zind]
    minus.reverse()
    if x[zind] == 0:
        if k == 1:
            print(0)
            sys.exit()
        else:
            n-=1
            k-=1
            plus = x[zind+1:n]
    else:
        plus = x[zind:n]
lenp = len(plus)
lenm = len(minus)
ans = inf
if lenp >= k:
    ans = min(ans, plus[k-1])
if lenm >= k:
    ans = min(ans, abs(minus[k-1]))

for i in range(lenm):
    if 0 <= k-1-(i+1) < lenp:
        ans = min(ans, 2*abs(minus[i])+plus[k-1-(i+1)])
for i in range(lenp):
    if 0 <= k-1-(i+1) < lenm:
        ans = min(ans, 2 * plus[i] + abs(minus[k-1-(i+1)]))

print(ans)

Measured memory_bytes: 62576
package main

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

func main() {
	A, B, C := ReadInt(), ReadInt(), ReadInt()
	if A == B {
		fmt.Println(C)
	} else if B == C {
		fmt.Println(A)
	} else {
		fmt.Println(B)
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1840
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<functional>
using namespace std;
typedef long long LL;
inline LL read()
{
	LL kk=0,f=1;
	char cc=getchar();
	while(cc<'0'||cc>'9'){if(cc=='-')f=-1;cc=getchar();}
	while(cc>='0'&&cc<='9'){kk=(kk<<1)+(kk<<3)+cc-'0';cc=getchar();}
	return kk*f;
}
LL n,m,a[10000];LL sum=0;
int main()
{
	n=read();m=read();
	for(int i=1;i<=n;++i)
	{
		sum+=a[i]=read();
	}
	sort(a+1,a+1+n);
	LL k=0;
	for(int i=1;i<=n;++i)if(4*m*a[i]>=sum)k++;
	if(m<=k)printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define ll long long
#define N 100005
using namespace std;

int n;
int a[N],b[N],c[N];
ll f[N],g[N],ans;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]); sort(a+1,a+1+n);
	for(int i=1;i<=n;i++) scanf("%d",&b[i]);
	sort(b+1,b+1+n);
	for(int i=1;i<=n;i++)
		f[i]=lower_bound(a+1,a+1+n,b[i])-a-1;
	for(int i=1;i<=n;i++) g[i]=g[i-1]+f[i];
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&c[i]);
		int p=lower_bound(b+1,b+1+n,c[i])-b-1;
		ans+=g[p];
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 2944
#include <iostream>
using namespace std;
typedef pair<int,int> P;
long long dp[100][100000];//i番目のobjを入れた時の

int main(){
  int N,W;cin>>N>>W;
  P A[N];
  int mx = 0;
  for(int i = 0; N > i; i++){
    cin>>A[i].first >> A[i].second;
    mx = min(W,mx+A[i].first);
  }
  for(int j = 0; mx >= j; j++){
    if(j >= A[0].first)dp[0][j] = A[0].second;
    else dp[0][j] = 0;
  }
  for(int i = 1; N > i; i++){
    for(int j = 0; mx >= j; j++){
      if(j >= A[i].first)dp[i][j] = max(dp[i-1][j],dp[i-1][j-A[i].first]+A[i].second);
      else dp[i][j] = dp[i-1][j];
    }
  }
  long long ans = 0;
  // for(int i = 0; N > i; i++){
  //   for(int j = 0; mx >= j; j++){
  //     cout << dp[i][j] << " ";
  //   }
  //   cout << endl;
  // }
  for(int i = 0; mx >= i; i++){
    ans = max(ans,dp[N-1][i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 78336
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;
int cnt,K;
string s;
int dp[111111][2];
int f(int x,int b){
    if(x==s.size())return s.size();
    auto &r = dp[x][b];
    if(!r){
        if(s[x]==b)r=max(r,f(x+1,b));
        else r=max(r,min(max(x,(int)s.size()-x),f(x+1,'0'-b+'1')));
    }
    return r;
}
int main(){
    cin>>s;
    K=s.size();
    cout<<f(0,'0')<<'\n';
    return 0;
}

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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

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

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

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

void solve() {
    //const i64 mod = 1'000'000'007;

    i64 N;
    cin >> N;

    vector<pair<i64,i64>> ans;
    set<pair<i64,i64>> used;
    if(N%2==0){
        map<i64,i64> mp;
        rep(i,1,N+1){
            mp[i]=N-i+1;
        }
        rep(i,1,N+1){
            rep(j,1,N+1){
                if(i==j or mp[i]==j) continue;
                if(used.find(make_pair(min(i,j),max(i,j)))!=used.end()) continue;
                used.insert(make_pair(min(i,j),max(i,j)));
                ans.emplace_back(make_pair(i,j));
            }
        }
    }else{
        map<i64,i64> mp;
        rep(i,1,N){
            mp[i]=N-i;
        }
        rep(i,1,N){
            rep(j,1,N){
                if(i==j or mp[i]==j) continue;
                if(used.find(make_pair(min(i,j),max(i,j)))!=used.end()) continue;
                used.insert(make_pair(min(i,j),max(i,j)));
                ans.emplace_back(make_pair(i,j));
            }
        }
        rep(i,1,N){
            ans.emplace_back(make_pair(i,N));
        }
    }

    cout << ans.size() << endl;
    rep(i,0,ans.size()){
        cout << ans[i].first << " " << ans[i].second << endl;
    }
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    unsigned long long n,k,val[100001],wt[100001];
    cin>>n>>k;
    unsigned long long dp[101][100001],i,j;
    for(i=0;i<n;i++)
    {
        unsigned long long a,b;
        cin>>a>>b;
        wt[i]=a;
        val[i]=b;
    }
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=k;j++)
        {
            if(i==0 || j==0)
            {
                dp[i][j]=0;
            }
            else if(wt[i-1]<=j)
            {
                dp[i][j]=max(val[i-1]+dp[i-1][j-wt[i-1]],dp[i-1][j]);
            }
            else
            dp[i][j]=dp[i-1][j];
        }
    }
    cout<<dp[n][k]<<endl;
}

Measured memory_bytes: 80640
from collections import Counter

def fctr1(n): 
    f = []
    for i in range(2,int(n**0.5)+2):
        while n%i == 0:
            n = n//i
            f.append(i)
    if n != 1:
        f.append(n)
    return f


n = int(input())

p_list = []
for i in range(1,n+1):
    p_list = p_list + fctr1(i)

pc = Counter(p_list).most_common()

#print(pc)

c74 = 0
c24 = 0
c14 = 0
c4 = 0
c2 = 0

for i in range(len(pc)):
    if pc[i][1] >= 74:
        c74 += 1
    if pc[i][1] >= 24:
        c24 += 1
    if pc[i][1] >= 14:
        c14 += 1
    if pc[i][1] >= 4:
        c4 += 1
    if pc[i][1] >= 2:
        c2 += 1

ans = c74 + c24*(c2-1) + c14*(c4-1) + c4*(c4-1)//2*(c2-2)

print(ans)


Measured memory_bytes: 3444
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPL(i,f,n) for(int i=f, i##_len=(n); i<i##_len; ++i)
typedef long long ll;

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

	int N,eCnts[300010], wCnts[300010];
	string S;
	cin >> N >> S;

	int eCnt = 0,wCnt = 0;
	REP(i, N) {
		if (S[i] == 'W') wCnt++;
		if (S[N-1-i] == 'E') eCnt++;
		wCnts[i] = wCnt;
		eCnts[N - 1 - i] = eCnt;
	}
	int ans = 300010;
	REP(i, N) {
		int chgCnt = 0;
		if (i > 0) {
			chgCnt += (wCnts[i - 1]);
		}
		if (i < N-1) {
			chgCnt += (eCnts[i + 1]);
		}
		ans = min(ans, chgCnt);
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> H(N);
  for(int i=0; i<N; i++) cin >> H.at(i);
  
  int cnt=1;
  int max=H.at(0);
  for(int i=1; i<N; i++){
    if(H.at(i)>=max){
      cnt++;
      max = H.at(i);
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <cstring>
#include <tuple>
using namespace std;
typedef long long ll;
int main() {
    int a, b;
    cin >> a >> b;
    if (a < b) {
        cout << "a < b" << endl;
    } else if (a > b) {
        cout << "a > b" << endl;
    } else {
        cout << "a == b" << endl;
    }

    return 0;
}

Measured memory_bytes: 1156
import java.util.Scanner;
/**
 * ACEPTADO 
 * @author crisisanchezp
 *
 */

public class Main {

	static long n;
	static long[] stones;
	static long memo[];

	public static void main(String[] args) {

		String input1 = "";
		String input2 = "";
		Scanner scanner = new Scanner(System.in);
		input1 = scanner.nextLine();
		input2 = scanner.nextLine();

		n = Long.parseLong(input1.trim());
		String[] arr = input2.split(" ");
		stones = new long[(int) n];
		for (int i = 0; i < arr.length; i++) {
			stones[i] = Integer.parseInt(arr[i]);
		}

		memo = new long[(int) n];
		for (int i = 0; i < memo.length; i++) {
			memo[i] = -1;
		}
		System.out.println(getMinCostStone(0));
		scanner.close();
	}

	/**
	 * public static int getMinCostStone(int i, int j) { if (j == stones.length && i
	 * == stones.length - 1) { return 0; } if (j == stones.length - 1 && i ==
	 * stones.length - 2) { return memo[i] = Math.abs(stones[i] - stones[j]); } if
	 * (stones[i] == stones[j]) { return 0; } if (memo[i] != -1) { return memo[i]; }
	 * int cost1 = Math.abs(stones[i] - stones[j]) + getMinCostStone(j, j + 1);
	 * memo[i] = cost1; int cost2 = Math.abs(stones[i] - stones[j + 1]) +
	 * getMinCostStone(j + 1, j + 2);
	 * 
	 * memo[i] = cost2; return memo[i] = Integer.min(cost1, cost2); }
	 */

	public static long getMinCostStone(int i) {
		if (i >= stones.length) {
			return 0;
		}
		if (memo[i] != -1) {
			return memo[i];
		}
		if (i + 1 >= stones.length)
			return 0;
		long cost1 = Math.abs(stones[i] - stones[i + 1]) + getMinCostStone(i + 1);
		memo[i] = cost1;

		long cost2 = (long) 1e18;
		if (i != stones.length - 2) {
			cost2 = Math.abs(stones[i] - stones[i + 2]) + getMinCostStone(i + 2);
		}
		memo[i] = cost2;
		return memo[i] = Long.min(cost1, cost2);
	}

}


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

int main(){
    
    int N,K;
    cin >> N >> K;
    
    long long x[N];
    for(int i = 0; i < N;i++)cin >> x[i];
    
    long long MIN = 1LL << 60;
    for(int i = 0;i + K - 1< N;i++){
        long long left = x[i], right = x[i + K - 1];
        MIN = min(MIN, min(abs(left),abs(right)) + right - left);
    }
    cout << MIN <<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#include <queue>
#include <list>
using namespace std;
typedef long long ll;
const int N = 1e7 + 3;
vector<ll> temp(N, -1);

void sieve() {
	for (ll i = 2; i * i <= N; i++) {
		if (temp[i] == -1) {
			for (ll j = i * i; j <= N; j += i)temp[j] = i;
		}
	}
	return ;
}


void solve() {
	string s; cin >> s;
	cout << s.substr(0, 3);



}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	// int t; cin >> t;
	// while (t--)
	solve();

}

Measured memory_bytes: 81176
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i = ll(a); i <= ll(b); i++)
int main()
{
	ll n,m;
    cin>>n>>m;
    vector<string>v;
    REP(i,0,n-1)
    {
        string s;cin>>s;
        v.push_back(s);
    }
    REP(i,0,m+1)
        cout<<"#";
    cout<<endl;
    REP(i,0,n-1)
        cout<<"#"<<v[i]<<"#"<<endl;
    REP(i,0,m+1)
        cout<<"#";     
}

Measured memory_bytes: 256