akhauriyash/Code-Regression huggingface dataset:
import sys
import math

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    R = int(input())
    print(2 * R * math.pi)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9168
/*
    AUTHOR:hruday pabbisetty
    NIT ROURKElA
*/
#include <bits/stdc++.h>
#include <tr1/unordered_map>
using namespace std;
using namespace std::tr1;
#define opt ios_base::sync_with_stdio(0)
#define lli long long int
#define ulli unsigned long long int
#define I int
#define S string
#define D double
#define rep(i,a,b) for(i=a;i<b;i++)
#define repr(i,a,b) for(i=a;i>b;i--)
#define in(n) scanf("%lld",&n)
#define in2(a,b) scanf("%lld %lld",&a,&b)
#define in3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define out(n) printf("%lld\n",n)
#define inu(a) scanf("%lld",&a)
#define outu(a) printf("%llu",a)
#define ins(s) scanf("%s",&s)
#define outs(s) printf("%s",s)
#define mod 1000000007
#define inf 100000000000000
typedef long long       ll;
typedef pair<lli,lli>  plli;
typedef vector<lli>     vlli;
typedef vector<ulli>    vulli;
typedef vector<ll>      vll;
typedef vector<string>  vs;
typedef vector<plli>     vplli;
#define MM(a,x)  memset(a,x,sizeof(a));
#define ALL(x)   (x).begin(), (x).end()
#define P(x)       cerr<<"{"#x<<" = "<<(x)<<"}"<<endl;
#define P2(x,y)       cerr<<"{"#x" = "<<(x)<<", "#y" = "<<(y)<<"}"<<endl;
#define P3(x,y,z)  cerr<<"{"#x" = "<<(x)<<", "#y" = "<<(y)<<", "#z" = "<<(z)<<"}"<<endl;
#define P4(x,y,z,w)cerr<<"{"#x" = "<<(x)<<", "#y" = "<<(y)<<", "#z" = "<<(z)<<", "#w" = "<<(w)<<"}"<<endl;
#define PP(x,i)     cerr<<"{"#x"["<<i<<"] = "<<x[i]<<"}"<<endl;
#define TM(a,b)     cerr<<"{"#a" -> "#b": "<<1000*(b-a)/CLOCKS_PER_SEC<<"ms}\n";
#define UN(v)    sort(ALL(v)), v.resize(unique(ALL(v))-v.begin())
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define sz() size()
#define nl cout<<"\n"
#define MX1 100005
#define MX2 1000005
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
lli dx[]={0,0,-1,1,-1,-1,1,1};
lli dy[]={1,-1,0,0,1,-1,-1,1};
lli power(lli a,lli b)
    {
    lli value;
    if(b==0)
        {
        return 1;
    }
    else if(b%2==0)
        {
        value=power(a,b/2)%mod;
        return(value*value)%mod;
    }
    else
        {
        value=power(a,b/2)%mod;
        return ((a*value)%mod*(value))%mod;
    }
}
int main()
{
      /*  #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        #endif*/
    opt;

    lli N,i,K;
    cin>>N>>K;

    vector<lli>w(N),d(N);
    rep(i,0,N)
    {
        cin>>w[i]>>d[i];
    }

    lli low=0,high=3000000000000000000,ans=1;

    while(low<=high)
    {
        lli mid=(low+high)/2,flag=0;

        lli cnt=0;
        rep(i,0,N)
        {
            if(mid >= w[i])
            {
                cnt+=(mid-w[i])/d[i]+1;
            }

            if(cnt >= K)
            {
                break;
            }
        }

        if(cnt>=K)
        {
            ans=mid;
            high=mid-1;
        }
        else
        {
            low=mid+1;
        }
    }

    cout<<ans;


    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <set>
#include <map>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll A, B;
  std::cin >> A >> B;
  if(A%2!=B%2) std::cout << "IMPOSSIBLE" << '\n';
  else std::cout << (A+B)/2 << '\n';
  return 0;
}


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

int n, m;

const int UFSIZE = 110;
int P[UFSIZE]; // 親

void init() {
  for (auto i=0; i<n; i++) {
    P[i] = i;
  }
}

int root(int a) {
  if (a == P[a]) return a;
  return (P[a] = root(P[a]));
}

bool issame(int a, int b) {
  return root(a) == root(b);
}

void unite(int a, int b) {
  P[root(a)] = root(b);
}


int main() {
  while (cin >> n >> m && n) {
    vector< tuple<int, int, int> > V; // cost, node1, node2
    for (auto i=0; i<m; i++) {
      int a, b, cost;
      cin >> a >> b >> cost;
      V.push_back(make_tuple(cost, a, b));
    }
    sort(V.begin(), V.end());
    int sum = 0;
    init();
    for (auto i=0; i<m; i++) {
      int cost = get<0>(V[i]);
      int nodea = get<1>(V[i]);
      int nodeb = get<2>(V[i]);
      if (!issame(nodea, nodeb)) {
	unite(nodea, nodeb);
	sum += cost;
      }
    }
    cout << sum << endl;
  }
}

Measured memory_bytes: 1204
#include <stdio.h>
int main(void){
  int n,d[100],i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&d[i]);
  }
  int count=1,max,index,tmp;
  for(i=0;i<n-1;i++){
    max=0;
    index=i;
    for(j=i;j<n;j++){
      if(max<d[j]){
        max=d[j];
        index=j;
      }
    }
    tmp=d[i];
    d[i]=d[index];
    d[index]=tmp;
  }
  for(i=1;i<n;i++){
    if(d[i]<d[i-1]) count++;
  }
  printf("%d",count);
  return 0;
}

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

const long long MOD = 1000000007;
using ll = long long;

const int MAX = 5100000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

void solve(long long N){
    ll ans = 0;
    for(int i = 2;i <= N;i++){
        ll cnt = modpow(8, N - i, MOD) %MOD * COM(N, i)%MOD;
        cnt %= MOD;
        cnt *= (modpow(2, i, MOD) - 2 + MOD);
        cnt %= MOD;
        ans += cnt;
        ans %= MOD;
    }
    cout<<ans%MOD<<endl;
}

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


Measured memory_bytes: 123292
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vvl d(N,vl(N));
    rep(i,N){
        rep(j,N){
            cin >> d[i][j];
        }
    }
    vvl dd=d;
    rep(i,N){
        rep(j,N){
            rep(k,N){
                if(dd[j][k]==dd[j][i]+dd[i][k]&&j!=i&&i!=k){
                    d[j][k]=0;d[k][j]=0;
                }
                if(chmin(dd[j][k],dd[j][i]+dd[i][k])){
                    cout << -1 << endl;
                    return 0;
                }
            }
        }
    }
    ll sum=0;
    rep(i,N){
        rep(j,N){
            sum+=d[j][i];
        }
    }
    cout << sum/2 << endl;
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/

Measured memory_bytes: 4772
#include <iostream>
#include <cmath>
#include <string>

using namespace std;

int main(){
 int n;
  cin >> n;
 string s;
  cin >> s;
 
  
  int res=0;
  
  for(int i=1;i<n;i++){
   int cnt=0;
   
    for(char c='a';c<='z';c++){
    bool left=false;
   bool right=false;
     for(int j=0;j<i;j++){
      if(s[j]==c) left=true;
     }
     for(int j=i;j<n;j++){
      if(s[j]==c) right=true;
     } 
    if(left&&right) cnt++;
  }  
    res=max(res,cnt);
  }
 cout << res << endl;

}

Measured memory_bytes: 256
N, K = map(int, input().split())
s = input()

right = 0
maxS = [0] * N

# 左端から順に、各点を始まりとした時の逆立ち数の最大値をしゃくとりで求める
zeroFlg = False
actCnt = 0
hsCnt = 0

# rint("action, actCnt, left, right, hsCnt")
for left in range(N):
  if left > 0 and s[left] == "1" and s[left - 1] == "0":
    actCnt -= 1
  while right < N:
    if not (actCnt < K or (actCnt == K and (s[right]=="1" or zeroFlg == True))):
      break
#    print("while", actCnt, left, right, hsCnt)
    if s[right] == "0" and zeroFlg == False:
      actCnt += 1
      zeroFlg = True
    elif s[right] == "1":
      zeroFlg = False
    hsCnt += 1
    right += 1
  right -= 1
  actCnt = min(K,actCnt)
  maxS[left] = hsCnt
  if right != N:
    hsCnt -= 1
#  print("set", actCnt, left, right, hsCnt)
  hsCnt -= 1
print(max(maxS))

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int ans[501][501];

int main(){
    int N, M, Q;
    cin >> N >> M >> Q;
    int l, r;
    REP(i, M) {
        cin >> l >> r;
        RREP(j, l) {
            ans[j][r] += 1;
        }
    }

    REP(i, N+1) {
        REP(j, N) {
            ans[i][j+1] += ans[i][j];
        }
    }

    REP(i, Q){
        cin >> l >> r;
        cout << ans[l][r] << endl;
    }
}


Measured memory_bytes: 1920
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iomanip>
#include <map>
#include <cstdlib>

using namespace std;

void solve(){
  double l; cin >> l;
  cout << fixed << setprecision(7) << pow(l / 3, 3) << endl;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
import math
A, B, C, D = map(int, input().split())
c = B // C - A // C + int(A % C == 0)
d = B // D - A // D + int(A % D == 0)
E = int((C * D) / math.gcd(C, D))
e = B // E - A // E + int(A % E == 0)
print(B - A + 1 - c - d + e)

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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
const long long INF = 1LL << 60;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll a, b, x;
  cin >> a >> b >> x;

  a = (a + x - 1) / x;
  b = b / x;

  cout << b - a + 1 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define int long long
//#define _GLIBCXX_DEBUG

signed main() {
  int N; cin >> N;
  unordered_map<int,int> map;

  rep(i, N) {
    int a; cin >> a;
    map[a-1]++;
    map[a]++;
    map[a+1]++;
  }
  
  int ans = 0;
  for(auto p : map) {
    ans = max(ans, p.second);
  }
  cout << ans << endl;

}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int n;
    int a[100001];

    unordered_map<ll, ll> m;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        /*
        m.erase(a[i]);
        m.insert(make_pair(a[i], tmp + 1));
        */
        m[a[i]] = m[a[i]] + 1;
    }

    int cnt = 0;
    for (auto it = m.begin(); it != m.end(); it++)
    {
        if (it->second % 2 == 1)
            cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 5156
#![allow(clippy::needless_range_loop)]
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use proconio::input;
use proconio::marker::*;

fn main() {
    input! {
        a: [usize]
    }
    let (ans, _) = a.iter().fold((0, 0), |(sum, max), x| {
        let max = std::cmp::max(max, *x);
        let sum = max - x + sum;
        (sum, max)
    });
    println!("{}", ans);
}


Measured memory_bytes: 5492
from heapq import heappop, heappush, heapify
from collections import deque
n = int(input())
li_a = []
for i in range(n):
  li_a.append(int(input()))
m1 = []
M1 = []
m2 = []
M2 = []
for i in li_a:
    heappush(m1, i)
    heappush(M1, -i)
    heappush(m2, i)
    heappush(M2, -i)
l1 = deque()
l2 = deque()
if n % 2 == 0:
    l1.append(-heappop(M1))
    l2.append(heappop(m2))
    while True:
        l1.append(heappop(m1))
        l2.append(-heappop(M2))
        if len(l1) == n:
            break
        l1.appendleft(heappop(m1))
        l2.appendleft(-heappop(M2))
        if len(l1) == n:
            break
        else:
            l1.append(-heappop(M1))
            l2.append(heappop(m2))
            if len(l1) == n:
                break
            l1.appendleft(-heappop(M1))
            l2.appendleft(heappop(m2))
            if len(l1) == n:
                break
if n % 2 == 1:
    l1.append(-heappop(M1))
    l2.append(heappop(m2))
    while True:
        l1.append(heappop(m1))
        l2.append(-heappop(M2))
        l1.appendleft(heappop(m1))
        l2.appendleft(-heappop(M2))
        if len(l1) == n:
            break
        else:
            l1.append(-heappop(M1))
            l1.appendleft(-heappop(M1))
            l2.append(heappop(m2))
            l2.appendleft(heappop(m2))
            if len(l1) == n:
                break
ans1 = 0
ans2 = 0
for i in range(n-1):
    ans1 += abs(l1[i+1]-l1[i])
    ans2 += abs(l2[i+1]-l2[i])
print(max(ans1, ans2))

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

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

    int n;
    cin >> n;

    long long total = 0;
    vector<long long> A(n);
    REP(i, n){
        cin >> A[i];
        total += A[i];
    }

    long long mini = 1e18, x = 0;
    //すぬけくんもアライグマくんも一枚以上カードを取るのでn-1まで
    REP(i, n - 1){
        x += A[i];
        //残り:(総和 - 今見てるところまでの和) - (今見てるところまでの和)
        mini = min(mini, abs(total - x - x));
    }
    cout << mini << endl;

    return 0;
}

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

int main() {
    string s;
    char rt;
    bool ok = 0;
    cin >> s;

    rep(i,27) {
        char t = 'a'+i;
        bool tok = 0;

        rep(j,s.size()-1)
            if(s.at(j)==t && s.at(j+1)==t) {
                tok=1;
                break;
            }
        if(!tok)
            rep(j,s.size()-2)
                if(s.at(j)==t && s.at(j+2)==t) {
                    tok=1;
                    break;
                }

        if(tok) {
            ok=1, rt=t;
            break;
        }
    }

    if(ok) {
        int t1=-1,t2=-1;
        rep(i,s.size()) {
            if(s.at(i)!=rt)
                continue;
            if(t1 == -1)
                t1 = i;
            else if(t2 == -1)
                t2 = i;
            if(t1!=-1 && t2!=-1) {
                if(t2-t1 < 3)
                    break;
                t1=t2, t2=-1;
            }
        }
        cout << t1+1 << " " << t2+1;
    } else
        cout << "-1 -1";
    cout << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<ctype.h>
# define pb push_back
#define fst first
#define sec second
#define For(i,a,b) for(int i=a;i<b;i++)
#define ll long long int
#define ull unsigned long long int
#define mod 1000000007
#define fo(i,n) for(ll i=0;i<n;i++)
#define endl "\n"
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define boolsize 1000001
#define pi pair<ll,ll>
#define vi vector<ll>
#define vii vector<pi>
using namespace std;
template<typename T>
void showvector(vector <T> v)
{
    for(T x:v)
        cout<<x<<" ";
    cout<<endl;

}
template<typename T>
void showvector1(vector <T> v)
{
    ll n=v.size();
    fo1(i,n-1)
        cout<<v[i]<<endl;

}
template<typename T>
void showset(set <T> s)
{
    for(T x: s)
        cout<<x<<" ";
    cout<<endl;
}
template<class T>
void showvectorpair(vector<T> v)
{
    for(auto it=v.begin();it!=v.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T,typename P>
void showmap(map <T,P> m)
{
    for(auto it=m.begin();it!=m.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T>
bool comp(T a,T b)
{
    return (a>b);
}
template<class T>
bool comppair(T a,T b)
{
    if(a.first==b.first)
        return(a.second>b.second);
    return (a.first>b.first);
}
bool sameparity(ll a,ll b)
{
    return (a%2==b%2);
}
bool difparity(ll a,ll b)
{
    return !(a%2==b%2);
}
bool isprime(ll x)
{   if(x<=1)
     return false;
    for(ll i=2;i<=sqrt(x);i++)
    {
        if(x%i==0)
            return false;
    }
    return true;
}
bool iseven(ll x)
{
    return !(x%2);
}
bool isodd(ll x)
{
    return (x%2);
}
//vector <bool> prime(boolsize,1);
//void seive()
//{
//    ll n=boolsize;
//    prime[0]=prime[1]=0;
//    for(ll i=2;i<=sqrt(boolsize);i++)
//    {
//        if(prime[i]==1)
//        {
//            for(ll j=i*i;j<=n;j+=i)
//            {
//                prime[j]=0;
//            }
//        }
//    }
//}

/// check for test case before submitting
void vfun()
{
    string s;
    cin>>s;
    set <char> se(s.begin(),s.end());
    if(se.size()==s.size())
        cout<<"yes\n";
    else cout<<"no\n";

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0); ///cant use scanf, printf
    cin.tie(0);cout.tie(0); /// no longer auto flush cout before each cin, remove for interactive
    //cout << fixed << setprecision(11); /// no scientific output
    ll test=1;
    //cin>>test;
    while(test--)
    {

        //fun();
        vfun();
//         if(vfun())
//            cout<<"YES\n";
//         else
//            cout<<"NO\n";
    }
}
///before sub
/// check for value of zero and single input in array
///loop vars,1LL in mult, equal, one, bounds, int v ll, endl, finish taking inputs
/// check whether test cases are given or not




Measured memory_bytes: 3656
#include <iostream>
#include<iomanip>
using namespace std;
int main(){
    double r,a,b;
    double pi = 3.141592653589;
    cin >> r;
    a = r * r * pi;
    b = 2 * r * pi;
    cout << fixed << setprecision(10) << a <<" "<< b << endl;
}



Measured memory_bytes: 3244
N = int(input())
arr = list(map(int,input().split()))

ans = 0
for i in range(N-1):
    if arr[i] != i+1: continue
    arr[i],arr[i+1] = arr[i+1],arr[i]
    ans += 1
if arr[-1] == N:
    ans += 1
print(ans)

Measured memory_bytes: 14008
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>
#include <functional>

using namespace std;
#define ALL(x)			(x).begin(),(x).end()
#define REP(i, n)		for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)	for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF				(int)2e9
#define MOD				(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)		(((((x))+((n)-1))/n))	
#define CeilN(x, n)		(((((x))+((n)-1))/n)*n)	
#define FloorN(x, n)	((x)-(x)%(n))			
#define IsOdd(x)		(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)		(!IsOdd((x)))						
#define M_PI			3.14159265358979323846
typedef long long			ll;
typedef unsigned long long	ull;
typedef pair<ll, ll>		P;
typedef vector<ll>			VLL;
typedef vector<VLL>			VVLL;
typedef vector<VVLL>		VVVLL;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main()
{
	int N, Q;
	string S;
	cin >> N >> S >> Q;
	
	vector<set<int>> strPos(26);
	REP(i, N) {
		int strOne = S[i] - 'a';
		strPos[strOne].insert(i);
	}

	REP(i, Q) {
		int q;
		cin >> q;
		if (q == 1) {
			int l;
			char r;
			cin >> l >> r;
			l--;;

			int strOne = S[l] - 'a';
			strPos[strOne].erase(l);
			strOne = r - 'a';
			strPos[strOne].insert(l);
			S[l] = r;
		} else {
			int l, r;
			cin >> l >> r;
			l--; r--;

			int ansOne = 0;
			REP(j, 26) {
				set<int> &posOne = strPos[j];
				auto idx1 = posOne.lower_bound(l);
				auto idx2 = posOne.lower_bound(r);
				if (idx1 != posOne.end()) {
					int lPos = *idx1;
					int rPos;
					if (idx2 != posOne.end()) {
						rPos = *idx2;
					} else {
						rPos = INF;
					}
					if ((l <= lPos && lPos <= r) || (l <= rPos && rPos <= r)) {
						ansOne++;
					}
				}
			}

			cout << ansOne << endl;
		}
	}

	return 0;
}


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

int main() {
  int N;
  long long Ans=1;
  cin >> N;
  vector<long long> A(N);
  rep(i, N) cin >> A.at(i);
  sort(A.begin(), A.end());
  rep(i, N){
    if(A.at(i)==0){
      Ans=0;
      break;
    }
    else if(A.at(i)>1000000000000000000/Ans){
      Ans=-1;
      break;
    }
    else Ans*=A.at(i);
  }
  cout << Ans << endl;
}

Measured memory_bytes: 3964
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp make_pair
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main(){
  int n;
  cin>>n;
  vector<int> v(n);
  rep(i,n) cin>>v[i];

  sort(all(v));

  int idx = lower_bound(all(v), v.back()/2) - v.begin();

  int cand = -1;
  for(int i=max(0,idx-2); i<min(n-1,idx+2); i++){
    if(abs(cand*2 - v.back()) > abs(v[i]*2 - v.back())) cand = v[i];
  }

  cout << v.back() << " " << cand << endl;


  return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

class Main{
	public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
		int n = a.length();
        int x[] = new int[n];
        for(int i = 0; i < n; i++){
            char c = a.charAt(i);
        	x[i] = c - '0';
        }
		
		long answer = 0;
		for(int i = 0; i < (Math.pow(2,n-1)); i++){
			boolean y[] = new boolean[n-1];
			for(int j = 0; j < n-1; j++){
				if((1 & i >> j) == 1){
					y[j] = false;
				}else{
					y[j] = true;
				}
			}
			
			int count = 0;
			for(int k = n-1; k >= 0; k--){
				answer += x[k] * (Math.pow(10,count));
				if(k != 0){
					if(y[k-1]){
						count += 1;
					}else{
						count = 0;
					}
				}
			}
		}
		System.out.println(answer);
	}
}

Measured memory_bytes: 22740
object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val Array(datN, datK) = readLine.split(" ").map(_.toInt)

    val ans = datK * math.pow((datK - 1), (datN - 1))
    println(ans.toInt)
  }
}


Measured memory_bytes: 25508
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MOD 1000000007
#define MOD2 998244353
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) (ll)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(ll i=a;i<=b;++i)
#define ROF(i,a,b) for(ll i=a;i>=b;--i)
#define trace(x) cerr<<#x<<": "<<x<<'\n';
typedef long long ll;
using namespace std;
using namespace __gnu_pbds;
#define T int
#define ordered_set tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
auto clk=clock();
 
ll mexp(ll a, ll b, ll m){
    ll ans=1;
    a%=m;
    while(b){
        if(b&1) ans=ans*a%m;
        b>>=1;
        a=a*a%m;
    }
    return ans;
}

const int N = 100005;
ll X[N];

int main(){
    IOS
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    ll n, a, b;
    cin >> n >> a >> b;
    FOR(i,1,n){
        cin >> X[i];
    }
    ll ans = 0;
    FOR(i,2,n){
        ans += min((X[i] - X[i-1]) * a, b);
    }
    cout << ans;

    cerr<<endl<<endl<<"Time: "<<fixed<<setprecision(12)<<(long double)(clock()-clk)/CLOCKS_PER_SEC<<" ms"<<endl<<endl;
 
    return 0;
}

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

int main(void){
  int n,ans=0;
  int cnt[100010]={0};
  
  cin >> n;
  for (int i=0; i<n; i++){
    int t; cin >> t;
    if (t>n) ans++;
    else cnt[t]++;
  }
  for (int i=1; i<=n; i++){
    if (cnt[i]>=i) ans += cnt[i]-i;
    else ans += cnt[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

#define REP(i,n) for(int i = 0; i < int(n); i++)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define ALL(obj) (obj).begin(),(obj).end()

const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template<class T> void corner(bool flg, T hoge) {
	if (flg) {
		cout << hoge << endl;
		exit(0);
	}
	else return;
}

template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {
	o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;
}

template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {
	o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}

template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {
	o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;
}

template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {
	o << "{" << obj.first << ", " << obj.second << "}"; return o;
}

template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {
	o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}

void print(void) {
	cout << endl;
}

template <class Head> void print(Head&& head) {
	cout << head;
	print();
}

template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {
	cout << head << " ";
	print(forward<Tail>(tail)...);
}

void YN(bool flg) {
	cout << ((flg) ? "YES" : "NO") << endl;
}

void Yn(bool flg) {
	cout << ((flg) ? "Yes" : "No") << endl;
}

void yn(bool flg) {
	cout << ((flg) ? "yes" : "no") << endl;
}

int main() {
	int N; cin >> N;
	V<int> a(N);
	REP(i, N) cin >> a[i];
	V<P<int, int>> ord(N);
	REP(i, N) ord[i] = { a[i],i };
	sort(ALL(ord));
	int cnt = 0;
	REP(i, N) if (i % 2 != ord[i].second % 2) cnt++;
	cout << cnt / 2 << endl;

	return 0;
}



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

using namespace std;
typedef long long ll;
const ll INF = 1e9;
 
int main(void) {
    int N; cin >> N;

    for (ll h = 1; h <= 3500; h++) {
        for (ll n = 1; n <= 3500; n++) {
            ll f = N * h * n;
            ll g = 4 * h * n - N * n - N * h;
            // cout << f << " " << g << endl;
            if (g > 1 && f % g == 0) {
                cout << h << " " << n << " " << (f / g) << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;

int main()
{

    double w, h, x, y;

    cin >> w >> h >> x >> y;

    if(x == w/2 && y == h/2) cout << setprecision(11) << w*h/2 << ' ' << 1 << endl;

    else cout << setprecision(11) << w*h/2 << ' ' << 0 << endl;

	return 0;

}

Measured memory_bytes: 256
package main

import "fmt"

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

func main() {
	var a, b, c, d, s int
	fmt.Scan(&a, &b, &c, &d)
	start := max(a, c)
	end := min(b, d)
	if end < start {
		s = 0
	} else {
		s = end - start
	}
	fmt.Println(s)
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#define eol '\n';
using namespace std;

class Node {
public:
  int id;
  int l;
  int r;
  int p;
  Node(): id(-1),l(-1),r(-1),p(-1){};
};

Node* tree;

int create_tree(int parent, vector<int> pre, vector<int> in) {
    if (pre.size() == 0 && in.size() == 0) {
      return -1;
    }

    int root_id = pre[0];
    if (root_id == -1) {
      return -1;
    }

    Node* node = &tree[root_id];
    node->p = parent;
    
    // left
    vector<int> left_pre;
    vector<int> left_in;

    int i = 0;
    int size = in.size();
    for (; i < size; i++) {
      if (in[i] == root_id) {
        break;
      }
      left_pre.push_back(pre[i+1]);
      left_in.push_back(in[i]);
    }
    node->l = create_tree(root_id, left_pre, left_in);

    vector<int> right_pre;
    vector<int> right_in;

    i++;
    for (;i < size; i++) {
      right_pre.push_back(pre[i]);
      right_in.push_back(in[i]);
    }
    node->r = create_tree(root_id, right_pre, right_in);

    return root_id;
}

vector<int> postorder(int id, vector<int> post) {
  Node* node = &tree[id];
  if (node->l != -1) {
    post = postorder(node->l, post);
  }
  if (node->r != -1) {
    post = postorder(node->r, post);
  }
  post.push_back(id);

  return post;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  int n,i;
  cin >> n;

  tree = new Node[n+1];

  vector<int> preorder(n);
  vector<int> inorder(n);

  for (i = 0; i < n; i++) {
    cin >> preorder[i];
  }
  for (i = 0; i < n; i++) {
    cin >> inorder[i];
  }

  int root = create_tree(-1, preorder, inorder);

  // post order
  vector<int> post;
  post = postorder(root, post);

  // output
  cout << post[0];
  for (i = 1; i < n; i++) {
    cout << " " << post[i];
  }
  cout << eol;
  
  return 0;
}

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

int main() {
  int n, k;
  string s;
  cin >> n >> k >> s;
  if (s.at(k-1) == 'A') {
    s.at(k-1) = 'a';
  }
  else if (s.at(k-1) == 'B') {
    s.at(k-1) = 'b';
  }
  else {
    s.at(k-1) = 'c';
  }
  cout << s << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[]args){
        Scanner scan = new Scanner(System.in);
        int x= scan.nextInt();
        int y = scan.nextInt();
        
        if  (x < y){
            System.out.println("a < b");
        }
        if  (x>y){System.out.println("a > b");}
        if  (x==y){System.out.println("a == b");}
    }
}


Measured memory_bytes: 26320
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
      	int n = Integer.parseInt(a.substring(a.length()-1));
        if (n == 0||n==1|| n==6|| n==8){
          
            System.out.println("pon");
        }
        else if (n==3){
          System.out.println("bon");
        } else {
            System.out.println("hon");
    	}
    }
}

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

int nDigit(int n){
    int d = 1;
    while((n = n/10) > 0 ){
        d++;
    }
    return d;
}

int main(){
    int n;
    cin >> n;
    int nd = nDigit(n);
    int ret = 0;
    if(nd%2 == 0){
        int k = nd-1;
        while(k > 0){
            ret += 9 * pow(10, k-1);
            k = k - 2;
        }
    }else{
        ret += n-pow(10, nd-1)+1;
        int k = nd-2;
        while(k > 0){
            ret += 9 * pow(10, k-1);
            k = k - 2;
        }
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#coding:utf-8

N = int(input())
taro = 0
hanako = 0
for i in range(N):
	strs = input().split()
	if strs[0] > strs[1]:
		taro += 3
	elif strs[0] < strs[1]:
		hanako += 3
	else:
		taro+=1
		hanako+=1

print(str(taro) + " " + str(hanako))

Measured memory_bytes: 7676
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=pow(10,9)+7

h,w=map(int,input().split())
s=[input() for i in range(h)]
d=[[1,0],[0,1],[-1,0],[0,-1]]

whitecnt=0
for i in range(h):
    for j in range(w):
        if s[i][j]==".":
            whitecnt+=1
grid=[[0]*w for i in range(h)]
grid[0][0]=1
q=deque([[0,0,1]])

if s[0][0]=="#" or s[-1][-1]=="#":
    print(-1)
    exit()

while q:
    x,y,dist=q.popleft()
    for xd, yd in d:
        if 0<=x+xd<w and 0<=y+yd<h and grid[y+yd][x+xd]==0 and s[y+yd][x+xd]==".":
            if x+xd==w-1 and y+yd==h-1:
                print(whitecnt-(dist+1))
                exit()

            # dist=1+dist
            grid[y+yd][x+xd]=1
            q.append([x+xd,y+yd,dist+1])

print(-1)

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

typedef long long ll;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007

int main() {
    int n,k;
    string s;
    cin>>n>>s>>k;


    for (int i=0;i<s.size();i++) {
        if(s[i]!=s[k-1]){
            s[i]='*';
        }
    }

    cout<<s<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define fi                      first
#define se                      second
#define pb                      push_back
#define pbb                     pop_back
#define mp                      make_pair
#define pii     	            pair<int,int>
#define all(x)                  x.begin(), x.end()
#define mem(array, value)       memset(array, value, sizeof(array))
#define fastRead 	            ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#ifdef Lollipop
    #define line                    cout << "\n===================\n"
    #define trace(...)              __f( #__VA_ARGS__ , __VA_ARGS__ )
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " = " << arg1 << "\n";
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');
        cerr.write(names, comma - names) << " = " << arg1 << " , ";
    __f(comma + 1, args...);
    }
#else
    #define line
    #define trace(...)
#endif

int tc, sz;
vector<int> input;
ll dp[2][2][10][15];
int mark[2][2][10][15];

ll cal(int is_start, int is_small, int pre, int pos)
{
    if (pos >= sz){
        if (is_start){
            return 0;
        }
        return 1;
    }
    ll &ret = dp[is_start][is_small][pre][pos];
    int &m = mark[is_start][is_small][pre][pos];
    if (m == tc){
        return ret;
    }
    m = tc;
    int limit = is_small ? 9 : input[pos];
    ret = 0;
    if (is_start){
        for (int i = 1; i <= limit; i++){
            ret += cal(0, is_small | (i < input[pos]), i, pos + 1);
        }
        ret += cal(1, 1, 0, pos + 1);
    }
    else{
        for (int i = 0; i <= limit; i++){
            if (abs(pre - i) <= 1){
                ret += cal(0, is_small | (i < input[pos]), i, pos + 1);
            }
        }
    }
    return ret;
}

ll solve(ll num)
{
    if (num <= 9)   return num;
    input.clear();
    while (num){
        input.pb(num % 10);
        num /= 10;
    }
    reverse(all(input));
    tc++;
    sz = input.size();
    return cal(1, 0, 0, 0);
}

int main ()
{
    #ifdef Lollipop
        //freopen ("in1.txt", "r", stdin);
        //freopen ("ans1.txt", "w", stdout);
    #endif
    ll n;
    cin >> n;
    ll lo = 1;
    ll hi = 3234566667;
    ll res;
    while (lo <= hi){
        ll mid = (lo + hi) / 2;
        if (solve(mid) >= n){
            res = mid;
            hi = mid - 1;
        }
        else{
            lo = mid + 1;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b, c, d;
	int n;
	int m, l;
	
	while (scanf("%d", &n) != EOF){
		m = 0;
		
		for (a = 0; a <= 9; a++){
			for (b = 0; b <= 9; b++){
				for (c = 0; c <= 9; c++){
					for (d = 0; d <= 9; d++){
						l = a + b + c + d;
						if (l == n){
							m++;
						}
					}
				}
			}
		}
		printf("%d\n", m);
	}
	
	return (0);
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1000000001;
const ll MOD = 1000000007;

int main(){
  int a, b;
  cin >> a >> b;
  if((a*b)%2 == 0) cout << "No" <<endl;
  else cout << "Yes" <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
LL N, M, S, A[50];
inline LL ceil(LL d, LL n) {return (d+n-1)/n;}
inline bool ok(LL x) {
  if(M < S-x) return false;
  return accumulate(A,A+N,0ll,[&](LL s, LL a){return s+ceil(a+x+1-N, N+1);}) <= x;
}
int main() {
  scanf("%lld", &N);
  M=N*(N-1);
  for(auto i=0; i<N; ++i) scanf("%lld", A+i), S+=A[i];
  LL l = -1, h = 1e18;
  while(l+1 < h) {
    LL m = (l+h)>>1;
    if(ok(m)) h = m;
    else      l = m;
  }
  for(auto x=max(0ll,h-M); x<=h; ++x) if(ok(x)) {
    printf("%lld\n",x);
    return 0;
  }
}

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

using namespace std;

const int MOD = 1000000007;

int a[1001][1001], dp[1001][1001];

int main() {
    int h,w;
    cin >> h >> w;
    string s;
    for(int i=0;i<h;++i) {
        cin >> s;
        for(int j=0;j<w;++j) a[i+1][j+1] = (s[j] == '#' ? 1 : 0);
    }

    dp[1][0] = 1;
    for(int i=1;i<=h;++i) {
        for(int j=1;j<=w;++j) {
            if(a[i][j]) continue;
            dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD;
        }
    }

    cout << dp[h][w] << "\n";
}

Measured memory_bytes: 8064
# 中心に1をおき、(1,2),(1,3),(1,4)...を結んだグラフを作ると
# ペアの数は(N-1)C2できてこれが最大（これを超えるKの場合-1）
# ここから条件に合わせるためには、1を含まない要素のペアを直接結んでいけばよい。
# 全部結んだ場合でNC2になり、O(N^2)で10000 (実際5000弱)

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

maxval = ((N-1)*(N-2)) // 2
if maxval < K:
  print(-1)
  exit(0)
  
ans = []

# まず1と各頂点を結んだグラフを構成する
for i in range(2,N+1):
  ans.append((1,i))
  
# そこから減らすべき頂点数
goal = maxval - K
i = 2
j = 3
while goal > 0:
  ans.append((i,j))
  if j + 1 > N:
    i += 1
    j = i + 1
  else:
    j += 1
  goal -= 1
  
print(len(ans))
for a in ans:
  print(*a)

Measured memory_bytes: 3992
N, K = input().split(" ")

okasi_nasi = set()
for i in range(int(K)*2):
    buf = input()
    if i % 2 == 1:
        if buf[0] != "":
            okasi_nasi = okasi_nasi | set(buf.split(" "))

print(int(N) - len(okasi_nasi))


Measured memory_bytes: 9176
N=int(input())
A=list(map(int,input().split()))
flag=True
count=0
while(flag):
    flag=0
    for i in range(N-1):
        if(A[N-1-i]<A[N-2-i]):
            v=A[N-1-i]
            A[N-1-i]=A[N-2-i]
            A[N-2-i]=v
            count+=1
            flag=True
s=" ".join(map(str,A))
print(s)
print(count)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
     
using namespace std;
typedef long long ll;
const int tmax=3010;
const int nmax=3010; 
long DP[nmax][tmax];
int a[nmax],b[nmax];
 

int main() {
    ll N, A,B;
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> A >> B; 
    // cout << N << " " << A << " " << B << endl;
    ll n,m;
    n = N / (A +B);
    m = N % (A+B);
    if (m <= A) {
        cout << n * A + m << endl;
    } else {
        cout << n * A + A << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=2e5+2;
vector<int> adj[maxn],vis(maxn);
int dfs(int v){
    vis[v]=1;
    int ans=1;
    for(int u:adj[v]){
        if(!vis[u]){
            ans+=dfs(u);
        }
    }
    return ans;
}
int main() {
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
	    int u,v;
	    cin>>u>>v;
	    adj[u].push_back(v);
	    adj[v].push_back(u);
	}
	int maxi=0;
	for(int i=1;i<=n;i++){
	    if(!vis[i]){
	        maxi=max(maxi,dfs(i));
	    }
	}
	cout<<maxi;
	return 0;
}

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

using namespace std;

#define li long long int

const int N 	= 3e3 + 3;
const int mod 	= 1e9 + 7;

int n;
int a[N];
li dp[N][N][2];

li go(int l, int r, int turn) {
	if (l > r) return 0;
	if (dp[l][r][turn] != -1) return dp[l][r][turn];
	li ans;
	if (turn == 0) {
		ans = -4e12;
		ans = max(ans, a[l] + go(l + 1, r, 1));
		ans = max(ans, a[r] + go(l, r - 1, 1));
	} else {
		ans = 4e12;
		ans = min(ans, -a[l] + go(l + 1, r, 0));
		ans = min(ans, -a[r] + go(l, r - 1, 0));
	}
	return dp[l][r][turn] = ans;
} 

void solve() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	memset(dp, -1, sizeof(dp));
	li ans = go(1, n, 0);
	cout << ans;
} 

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

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

#define int long long
#define ld long double

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repb(i,a,b) for(int i=a;i>b;i--)

#define pb push_back
#define mp make_pair
#define all(A) A.begin(),A.end()
#define allr(A) A.rbegin(),A.rend()
#define precise(i) fixed << setprecision(i)
#define fi first
#define se second

#define err() cout<<"\n==================================\n";
#define errA(A) for(auto i:A) cout<<i<<" "; cout<<"\n";
#define err1(a) cout<<#a<<" "<<a<<"\n";
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<"\n";
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<"\n";
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<"\n";

const int logN = 20;
const int M = 1000000007;
const int INF = 1e12;
#define PI 3.14159265;
const int N = 200005;

#define Pii pair<int,int>
#define Vi vector<int>
#define Vpii vector<Pii>

void solve()
{
       string s;
       cin>>s;
       int n=s.size();
       int ans=0;
       rep(c,0,n)
       {
              ans+=(int)(s[c]-'0');
       }
       if(ans%9==0)
       {
              cout<<"Yes";
       }
       else
       {
              cout<<"No";
       }
}

int32_t main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--)
    {
           solve();
    }
    return 0;
}

Measured memory_bytes: 3764
import java.util.Scanner;

public class Main{
	public static void main(String[] args){

		Scanner scan = new Scanner(System.in);

		int S;
		S = scan.nextInt();

		int h = S / 3600;
		int m = (S % 3600) / 60;
		int s = (S % 3600) % 60;

		System.out.println(h + ":" + m + ":" + s);
	}
}

Measured memory_bytes: 26232
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int dist = scan.nextInt();
		int home = scan.nextInt();
		int[] kyori = new int[home];
 		
		for(int i = 0; i < home;i++) {
			kyori[i] = scan.nextInt();
			
		}
		
		int min = Math.min(kyori[home -  1] - kyori[0] , dist - kyori[1] + kyori[0]);
		min = Math.min(min, dist - kyori[home - 1] + kyori[home - 2]);
		
		for(int i = 1;i < home - 1 ; i++) {
		min = Math.min(min, Math.min(dist - kyori[i] + kyori[i - 1], dist - kyori[i + 1] + kyori[i]));
		
		}
		
		System.out.println(min);
		
	}
	
}


Measured memory_bytes: 78636
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <queue>
#include <set>

using namespace std;

typedef unsigned long long int ULL;
typedef long long LL;
typedef long double LD;

const LL inf = 1000000000000000;
const LL mod = 1000000007;

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

	vector<LL> a(n);

	for (auto &e : a) {
		cin >> e;
	}

	LL ans = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = i+1; j < n; ++j) {
			ans += a[i]*a[j];
		}
	}
	cout << ans << endl;
	
	 
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
using namespace std;

const static double TSUBO_METER = 3.305785;
int main() {
  int a, b;

  scanf( "%d%d", &a, &b );
  printf( "%.7f\n", a * b / TSUBO_METER );

  return EXIT_SUCCESS;
}

Measured memory_bytes: 1064
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int N = 500005;
const double pi = acos(-1.0);

int BIT[N];

void update(int idx, int val) {
    while(idx < N) {
        BIT[idx] = max(BIT[idx], val);
        idx += idx&-idx;
    }
}

int query(int idx) {
    int ret = 0;
    while(idx) {
        ret = max(ret, BIT[idx]);
        idx -= idx&-idx;
    }
    return ret;
}

struct node{
    int x, y;
};

vector <node> A;
map<int, int>ma;
bool cmp(struct node a, struct node b) {
    return a.y < b.y;
}

int main() {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    if(y1 > y2){
        swap(x1, x2), swap(y1, y2);
    }
    int n;
    int sign = 1;
    if (x1 > x2) {
        sign = -1;
    }
    cin >> n;
    set<int>se;
    for (int i = 0 ; i < n ; i++) {
        int p, q;
        cin >> p >> q;
        if (q >= y1 && q <= y2 && ((p >= x1 && p <= x2) || (p >= x2 && p <= x1))) {
            A.push_back((node) {p * sign, q});
            se.insert(p * sign);
        }
    }
    int k = 2;

    for(auto i: se){
        ma[i] = k++;
    }

    sort(A.begin(), A.end(), cmp);
    for(int i = 0 ; i < (int)A.size(); i++) {
        update(ma[A[i].x], query(ma[A[i].x]) + 1);
    }
    int len = query(k);
//    cout << len << endl;
    double ans;
    if (min(abs(x2 - x1), abs(y2 - y1)) + 1 == len) {
        ans = (abs(x2 - x1) + abs(y2 - y1)) * 100.0 - len * 20.0 + (len + 1) * pi * 5;
    } else {
        ans = (abs(x2 - x1) + abs(y2 - y1)) * 100.0 - len * 20 + len * pi * 5;
    }

    cout.precision(15);
    cout << fixed << ans << endl;
}


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

int main(){
    int x , y;
    cin >> x >> y;
    if(y <= 4 * x && y >= 2 * x && (4 * x - y) % 2 == 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}
        

Measured memory_bytes: 3632