akhauriyash/Code-Regression huggingface dataset:
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
int l[10];
const int INF = 1e9;
int n, A, B, C;  

ll dfs(int cur,int a, int b, int c){
  if(cur == n){
    if(min(min(a, b), c) > 0){
      return abs(a-A)+abs(b-B)+abs(c-C)-30;
    }
    else return INF;
  }
  ll ret0 = dfs(cur+1, a, b, c);
  ll ret1 = dfs(cur+1, a+l[cur], b, c)+10;
  ll ret2 = dfs(cur+1, a, b+l[cur], c)+10;
  ll ret3 = dfs(cur+1, a, b, c+l[cur])+10;
  return min(min(ret0, ret1), min(ret2, ret3));
}

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

  cin >> n;
  cin >> A >> B >> C;
  REP(i, n) cin >> l[i];

  cout << dfs(0, 0, 0, 0) << endl; 
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = k; i < n; i++)
    {
        if (a[i] > a[i - k])
            cout << "Yes" << endl;
        else
        {
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 4048
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long n;
	cin>>n;
	 double sum;
	 double a[n];
	 for(int i=0;i<n;i++)
	  	cin>>a[i];
	 sort(a,a+n);
	 sum=(a[0]+a[1])/2;
	 for(int i=2;i<n;i++)
	  sum=(sum+a[i])/2;
	cout<<sum;
 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  ll a[n + 1] = {}, b[m + 1] = {};

  //累積和
  rep(i, n) {
    ll tmp;
    cin >> tmp;
    a[i + 1] = a[i] + tmp;
  }
  rep(i, m) {
    ll tmp;
    cin >> tmp;
    b[i + 1] = b[i] + tmp;
  }

  ll ans = 0;
  for (ll i = 0; i <= n; i++) {
    //二分探索
    ll t = a[i];
    int l = 0, r = m + 1;
    while (l + 1 < r) {
      int c = (r + l) / 2;
      if (t + b[c] <= k)
        l = c;
      else
        r = c;
    }
    if (a[i] + b[l] <= k) ans = max(ans, i + l);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6744
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*
n
d1
...
dn
 */
int n;
set<int> st;

int main(){
  cin>>n;
  REP(i,n){
    int a;
    cin>>a;
    st.insert(a);
  }

  cout<<st.size()<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
using namespace std;

typedef long long LL;
const int p=1000000007;
int n,m,f[310][310][310],l[310],r[310],x[310],ans;

int main()
{
    scanf("%d%d",&n,&m);
    repu(i,1,m)
        scanf("%d%d%d",&l[i],&r[i],&x[i]);
    f[1][0][0]=3;
    repu(i,1,n)
    {
        int l1=-1,r1=n+1,l2=-1,r2=n+1;
        repu(j,1,m)
            if (r[j]==i)
            {
                if (x[j]==1)
                    r1=min(r1,l[j]-1);
                if (x[j]==2)
                    l1=max(l1,l[j]),r2=min(r2,l[j]-1);
                if (x[j]==3)
                    l2=max(l2,l[j]);
            }
        repu(j,0,i)
            repu(k,0,j)
                if (f[i][j][k] && l1<=j && r1>=j && l2<=k && r2>=k)
                {
                    if (i==n)
                        (ans+=f[i][j][k])%=p;
                    (f[i+1][j][k]+=f[i][j][k])%=p;
                    (f[i+1][i][j]+=f[i][j][k])%=p;
                    (f[i+1][i][k]+=f[i][j][k])%=p;
                }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 112896
#include <iostream>
#include <iomanip>
#include <string>
#include <set>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
    int N, H, a, b;
    cin >> N >> H;
    int aMax = 0;
    vector<int> B(N);
    for(int i = 0; i < N; i++) {
        cin >> a >> b;
        if(a > aMax) {
            aMax = a;
        }
        B[i] = b;
    }
    sort(B.begin(), B.end(), greater<int>());
    for(int i = 0; i < B.size(); i++) {
        if(B[i] < aMax) {
            cout << (i + int(ceil((double)H / aMax))) << endl;
            return 0;
        }
        H -= B[i];
        if(H <= 0) {
            cout << (i+1) << endl;
            return 0;
        }
    }
    cout << (N + int(ceil((double)H / aMax))) << endl;
    return 0;
}


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

int main(){
  int n,m;
  cin>>n>>m;

  int H[n];
  for(int i=0;i<n;i++) cin>>H[i];
  int h[n];
  for(int i=0;i<n;i++)h[i]=1;
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;

    if (H[a-1]>=H[b-1]) h[b-1]=0;
    if (H[b-1]>=H[a-1]) h[a-1]=0;
  }

  int counter=0;
  for(int i=0;i<n;i++){
    if (h[i]==1) counter++;
  }

  cout<<counter<<endl;
}

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

int main(){
    int N, K;
    cin >> N >> K;
    vector<long long> cnt(K);
    for(int i=1; i<=N; i++){
        cnt[i%K]++;
    }
    long long ans = 0;
    for(int i=0; i<K; i++){
        if((i+i)%K==0){
            ans += cnt[i]*cnt[i]*cnt[i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  cin >> A >> B;
 
  if(A + B == 3) cout << 3 << endl;
  else if(A + B == 5) cout << 1 << endl;
  else cout << 2 << endl;
  
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"I=lambda:map(int,input().split());*_,k=I();s=lambda*a:sorted(i+j for i in I()for j in a)[:~k:-1];print(*s(*s(*I())))\n"
"\"";
  system(s);
  return 0;
}

Measured memory_bytes: 164952
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
struct Doubling{
    const int ub_log;               // 要素数の二進表記の桁数
    vector<vector<int>> table;      // ダブリングテーブル
 
    Doubling(int sz, int limit) : ub_log(64 - __builtin_clzll(limit)){
        table.assign(ub_log, vector<int>(sz, -1));
    }
 
    // k 番目の要素から 1(=2^0) 個先の要素をテーブルに埋める
    void set_next(int k, int x){
        table[0][k] = x;
    }
 
    // ダブリングテーブルの構築
    void build(){
        for(int k = 0; k + 1 < ub_log; ++k){
            for(int i = 0; i < table[k].size(); ++i){
                if(table[k][i] == -1)   table[k+1][i] = -1;
                else    table[k+1][i] = table[k][table[k][i]];
            }
        }
    }
 
    // k 番目から t 個先の要素を返す
    int query(int k, int64_t t){
        for(int i = ub_log - 1; i >= 0; --i){
            if((t >> i) & 1)    k = table[i][k];
        }
        return k;
    }
};

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

	int N, K;
    cin >> N >> K;
	Doubling table(N, K+1);
	rep(i,N){
		int a;
		cin >> a;
		--a;
		table.set_next(i,a);
	}
	table.build();
	int ans = table.query(0, K);
	cout << ans + 1 << endl;
}

Measured memory_bytes: 98704
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const vi d8x = {1, 0, -1, 0, 1, -1, -1, 1};
const vi d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vi d4x = {1, 0, -1, 0};
const vi d4y = {0, 1, 0, -1};

//---------------from here-----------------

int main(){
    ll A,B; cin>>A>>B;
    cout<<A / __gcd(A,B) *B <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int n, a, b;
  cin >> n >> a >> b;

  int ans = min(n * a, b);
  cout << ans << endl;
}


Measured memory_bytes: 3600
#include <stdio.h>

int zero[4] = {1, 2, 4, 3};

int one[4] = {0, 3, 5, 2};

int two[4] = {0, 1, 5, 4};

// chooseIndex chooses to search zero, one, or two.
int chooseIndex(int top, int front)
{
  int i;
  int indices[3] = {};
  indices[front <= 2 ? front : 5 - front] = 1;
  indices[top <= 2 ? top : 5 - top] = 1;
  for (i = 0; i < 3; i++)
    if (!indices[i])
      return i;
}

// findRightIndex determines the right index.
int findRightIndex(int index, int topindex, int frontindex)
{
  int *toSearch, i;
  switch (index)
    {
    case 0:
      toSearch = zero;
      break;
    case 1:
      toSearch = one;
      break;
    case 2:
      toSearch = two;
      break;
    }
  for (i = 0; i < 4; i++)
    {
      if (toSearch[i] == topindex)
	if (toSearch[(i + 1) % 4] == frontindex)
	  return index;
	else
	  return 5 - index;
    }
}

int main(void)
{
  int die[6], i, q, top, front, topindex, frontindex, j, index;
  for (i = 0; i < 6; i++)
    scanf(" %d", die + i);
  scanf(" %d", &q);
  for (i = 0; i < q; i++)
    {
      scanf(" %d %d", &top, &front);
      for (j = 0; j < 6; j++)
	{
	  if (die[j] == top)
	    topindex = j;
	  else if (die[j] == front)
	    frontindex = j;
	}
      // determines if the index is 0 or 5, 1 or 4, or 2 or 3 
      index = chooseIndex(topindex, frontindex);
      printf("%d\n", die[findRightIndex(index, topindex, frontindex)]);
    }
  return 0;
}



Measured memory_bytes: 2080
import sys
input=sys.stdin.readline
n,q=map(int, input().split())
*a,=map(int, input().split())
bit=[0]*(n+1)

def add(t,x):
    while t<=n:
        bit[t]+=x
        t+=t&(-t)

def que(t):
    res=0
    while t:
        res+=bit[t]
        t-=t&(-t)
    return res

for i in range(n):
    add(i+1,a[i])


for _ in range(q):
    i,p,x=map(int, input().split())
    if i:
        ans=que(x)-que(p)
        print(ans)
    else:
        add(p+1,x)


Measured memory_bytes: 142116
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
#include <iomanip>

using namespace std;
#define int long long

signed main(){
    string S;
    cin >> S;
    
    if(S[0]==S[2]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#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 max=101010;
	
	//素数なら1の配列準備
	vector<int> prime(max);
	for(int i=2;i<max;i++)prime[i]=1;
	for(int i=2;i<max;i++){
		if(prime[i]==1){
			for(int j=i*2;j<max;j+=i)prime[j]=0;
		}
	}
	
	//like2017なら1の配列を準備
	vector<int> like(max);
	for(int i=3;i<max;i+=2){
		if(prime[i]==1&&prime[(i+1)/2]==1)like[i]=1;
	}
	
	//累積和
	vector<int> s(max+1,0);
	for(int i=0;i<max;i++)s[i+1]=s[i]+like[i];
	
	int q;
	cin>>q;
	for(int i=1;i<=q;i++){
		int l,r;
		cin>>l>>r;
		
		cout<<s[r+1]-s[l]<<endl;
	}
	
	
}


Measured memory_bytes: 1792
#import
#import math
#import numpy as np
#= int(input())
S = input()
#= map(int, input().split())
#= list(map(int, input().split()))
#= [input(), input()]
#= [list(map(int, input().split())) for _ in range(N)]
#= [int(input()) for _ in range(N)]
#= {i:[] for i in range(N)}
ans = 0
for s in S:
    if s == "+":
        ans += 1
    else:
        ans -= 1

print(ans)

Measured memory_bytes: 8980
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) long long((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
typedef pair<ll, ll> P;
typedef map<string, ll> M;
typedef unordered_map<ll, ll> HM;
typedef set<ll> S;
typedef multiset<ll> MS;
typedef queue<ll> Q;

int main(){
    int a,b; cin>>a>>b;
    int cnt = 1, ans = 0;
    while(cnt < b){
        cnt += a - 1;
        ans++;
    }
    OUT(ans);
}


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

typedef long long ll;

#define REP(i, N) for (int i = 0; i < (int)(N); i++)

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

int main() {
    int N;
    cin >> N;
    vector<ll> L(N);
    REP(i,N) cin >> L[i];
    
    int count = 0;
    REP(i,N)REP(j,N)REP(k,N){
        if ( L[i] == L[j] or L[j] == L[k] or L[k] == L[i] ) continue;
        
        if ( L[i] + L[j] > L[k] and L[j] + L[k] > L[i] and L[k] + L[i] > L[j] ){
            ++count;
        }
    }
    
    //cout << count << endl;
    count /= 6;
    cout << count << endl;
    
    return 0;
}


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

using namespace std;

#define intt long long 
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 100005;

int n;
int a[N];

int main() {

	FAST;

	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i ++) {
		s[i] = 'x';
	}
	cout << s << '\n';
	return 0;
}

Measured memory_bytes: 256
/*Coded by::
    **Avinash Tiwary**
    **BE/10298/2015**
    **Production Engineer**
    **Producing <code>**
*/
#include<bits/stdc++.h>
#define buf ios_base::sync_with_stdio (0), cin.tie (0)
typedef long long ll;
typedef double dob;
#define MAX 1300009
#define M 1000000007
#define INF 5e17
using namespace std;
typedef vector<ll> V;
typedef queue<ll > Q;
typedef stack<ll> S;
typedef pair<ll,ll> P;
#define mp make_pair
#define mt make_tuple
#define pb push_back
bool desc(ll i, ll j) { return i > j; }
ll power(ll x,ll n)
{   if(n==0||x==0) return 1;
    else if(n%2 == 0) return power((x*x)%M,n/2);
    else return (x*power((x*x)%M,(n-1)/2))%M;
}
ll fac[MAX],not_prime[MAX],ar[MAX],dp[MAX];
string s[MAX];
void fact(){
    fac[0]=1;
    for(ll i=1;i<=1000009;i++) fac[i]=(i*fac[i-1])%M;
}
void sieve(){
    not_prime[1]=1; not_prime[0]=1;
    for(ll p=2;p*p<=MAX;p++){
        if(!not_prime[p]){
            for(ll i=p*2;i<=MAX;i+=p) not_prime[i]=1;
        }
    }
}
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b%a, a);
}
int main(){
    //buf; 
    //sieve(); 
    //fact();
    ll i,j,test,ans,a,b,c,d,n,z,m,p,k,flag; string sk; 
    test=1;
    while(test--){
        cin>>n;
        ans=1;
        for(i=1;i<=n;i++){
            cin>>k;
            ans=ans*(k/gcd(ans,k));
        }
        cout<<ans;
    }
    return 0;
} 

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            char[] step = S.ToCharArray();
            int count = 0;
            for (int i = 0; i < step.Length; i++)
            {
                if ((i + 1) % 2 == 1 && (step[i] == 'R' || step[i] == 'U' || step[i] == 'D')) count++;
                else if ((i + 1) % 2 == 0 && (step[i] == 'L' || step[i] == 'U' || step[i] == 'D')) count++;
                else count = 0;
            }
            if (count == step.Length) Console.WriteLine("Yes");
            else Console.WriteLine("No");
//            Console.Read();
        }
    }
}

Measured memory_bytes: 13140
#include <cstdio>
#define Maxn 200000
#define Mod 998244353
char s[Maxn+5];
int a[Maxn+5];
int n;
int sum[Maxn+5];
int f[Maxn+5];
int check(int x){
	int now=1,f=0;
	for(int i=1;i<=n;i++){
		if((s[now]^48^f)>(s[i]^48)){
			return 0;
		}
		else if((s[now]^48^f)<(s[i]^48)){
			return 1;
		}
		else{
			now++;
			if(now>x){
				now=1;
				f^=1;
			}
		}
	}
	return 1;
}
int get(int x){
	if((n/x)&1){
		return (sum[x]+check(x))%Mod;
	}
	return 0;
}
int main(){
	scanf("%d",&n);
	scanf("%s",s+1);
	for(int i=1;i<=n;i++){
		a[i]=(s[i]^48);
		sum[i]=((sum[i-1]<<1)+a[i])%Mod;
	}
	for(int i=1;i*i<=n;i++){
		if(n%i==0){
			f[i]=get(i);
		}
		if(i*i!=n&&n%(n/i)==0){
			f[n/i]=get(n/i);
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=i+i;j<=n;j+=i){
			f[j]=(f[j]-f[i]+Mod)%Mod;
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(n%i==0){
			ans+=2ll*f[i]%Mod*i%Mod;
			ans%=Mod;
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 2688
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    string O, E;
    cin >> O >> E;
    if (O.size() == E.size()) {
        for (int i = 0; i < O.size(); ++i) {
            cout << O[i]  << E[i];
        }
        cout << endl;
    } else {
        for (int i = 0; i < O.size()-1; ++i) {
            cout << O[i] << E[i];
        }
        cout << O[O.size() - 1] << endl;
    }
    return 0;
}

Measured memory_bytes: 3032
#include<iostream>
#include <string>
#include<algorithm>
#include <set>
#include <cmath>
using namespace std;

int main(void){
	ios::sync_with_stdio(false);
	int a[3] ,l1, l2, l3;
	cin >> a[0]>> a[1] >> a[2];
	sort(a, a + 3);
	cout << a[0] * a[1] / 2;
	return 0;
}


Measured memory_bytes: 256
h, w = map(int,input().split())
si, sj = map(int,input().split())
gi, gj = map(int,input().split())
S = [input() for i in range(h)]
n = h * w

si-=1
sj-=1
gi-=1
gj-=1

# M = [[] for i in range(h*w)]

A = [[-1,0],[1,0],[0,1],[0,-1]]
B = []
for i in range(-2, 3):
    for j in range(-2, 3):
        if (i!=0 or j!=0) and (not ([i, j] in A)):
            B.append([i, j])

# for i in range(h):
#     for j in range(w):
#         if S[i][j] == ".":
#             for a in A:
#                 ai = i + a[i]
#                 aj = j + a[j]
#                 if 0 <= ai < h and 0 <= aj < w and S[ai][aj] == ".":
#                     M[i*w+j].append([ai*w+aj, 0])
#             for a in B:
#                 ai = i + a[i]
#                 aj = j + a[j]
#                 if 0 <= ai < h and 0 <= aj < w and S[ai][aj] == ".":
#                     M[i*w+j].append([ai*w+aj, 1])

from collections import deque
D = deque()

V = [0] * n
DI = [float("inf")] * n
s = si*w+sj
g = gi*w+gj
DI[s] = 0

D.append([s, 0])

while len(D) > 0:
    d = D.popleft()
    x = d[0]
    we = d[1]
    if V[x] == 0:
        V[x] = 1
        DI[x] = we
        i = x//w
        j = x%w
        for a in A:
            ai = i + a[0]
            aj = j + a[1]
            if 0 <= ai < h and 0 <= aj < w and S[ai][aj] == ".":
                D.appendleft([ai*w+aj, we])
        for a in B:
            ai = i + a[0]
            aj = j + a[1]
            if 0 <= ai < h and 0 <= aj < w and S[ai][aj] == ".":
                D.append([ai*w+aj, we+1])

# print(DI)
# print(DI[g])
ans = DI[g]
if DI[g] == float("inf"):
    ans = -1
print(ans)

Measured memory_bytes: 242840
#include<stdio.h>
int main(){
    int i, n, a[100], flag=1, tmp, count=0;
    scanf("%d", &n);
    for(i=0; i<n; i++)scanf("%d", &a[i]);
    while(flag){
        flag=0;
        for(i=n-1; i>0; i--)if(a[i]<a[i-1]){
            tmp=a[i];
            a[i]=a[i-1];
            a[i-1]=tmp;
            flag=1;
            count++;
        }
    }
    for(i=0; i<n-1; i++)printf("%d ", a[i]);
    printf("%d\n%d\n", a[n-1], count);
    return 0;
}

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

int main() {
  int N, A;
  cin >> N >> A;
  
  if (A - (N - (N / 500) * 500) >= 0) {
    cout << "Yes" << endl;
  }
  else {
        cout << "No" << endl;
  }

    
  


  
  // ここにプログラムを追記
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define int long long int
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mii map<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define MOD 1000000007
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define FORD(i,a,n) for(int i=n-1;i>=0;i--)
using namespace std;
 
 
int32_t main(){
 
    
    int n,m;
    cin>>n>>m;
    char a[1001][1001];
    int dp[1001][1001];  //dp[i][j] reps no. of paths to reach i,j
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>a[i][j];
            dp[i][j]=0;
        }
    }

    for(int i=0;i<n;i++)
    {
        if(a[i][0]!='#')
            dp[i][0]=1;
        else
        {
            dp[i][0]=0;
            break;
        }
    }

   for(int i=0;i<m;i++)
    {
        if(a[0][i]!='#')
            dp[0][i]=1;
        else
        {
            dp[0][i]=0;
            break;
        }
    }
    for(int i=1;i<n;i++)
    {
        for(int j=1;j<m;j++)
        {
             if(a[i][j]!='#')
             {
                dp[i][j]=dp[i-1][j]%MOD+dp[i][j-1]%MOD;
             }
             else
             {
                dp[i][j]=0;
             }
             dp[i][j]%=MOD;
        }
    }
    cout<<dp[n-1][m-1];
    

 
    return 0;
 
}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  string S;
  int ans=0;
  cin >> S;
  for (int i=0; i<4; i++) {
    if (S.at(i)=='+') {
      ans=ans+1;
    }
    else {
      ans=ans-1;
    }
  }
  cout <<ans <<endl;
}


Measured memory_bytes: 3560
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

int main()
{
	string s;
	int K;
	cin >> s >> K;

	vector<pair<int, int>> list;
	for (auto i = 0; i < s.length(); ++i)
	{
		for (auto j = i; j < s.length() && j - i < K; ++j)
		{
			auto num = j - i + 1;
			auto add = true;
			for (auto it = list.begin(); it != list.end(); ++it)
			{
				auto comp = s.compare(it->first, it->second, s, i, num);
				if (comp == 0)
				{
					add = false;
					break;
				}
				else if (comp > 0)
				{
					list.insert(it, make_pair(i, num));
					add = false;
					break;
				}
			}
			if (add)
			{
				list.push_back(make_pair(i, num));
			}
			if (list.size() > K)
			{
				list.pop_back();
			}
		}
	}

	auto& result = list[K - 1];
	cout << s.substr(result.first, result.second) << endl;

	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int N = 101010 << 1;
int n , a[N] , b[N];

bool check(int m){
    rep(i,1,n+n) b[i]=a[i]>=m;
    for(int l=n,r=n;l>1;--l,++r){
        if(b[l] == b[l-1]) return b[l];
        if(b[r] == b[r+1]) return b[r];
    }
    return b[n] ^ ((n-1)&1);
}

int main(){
    scanf("%d",&n);
    rep(i,1,n+n) scanf("%d",a + i);
    int l = 2 , r = n + n - 1;
    while(l + 1 < r){
        int m=(l+r)>>1;
        check(m) ? l = m : r = m;
    }
    printf("%d\n",l);
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
int main(){
  int i,len;
  char input[12];
  char input2[12];
  
  scanf("%s",input);
  scanf("%s",input2);
  len=strlen(input);
  
  for(i=0;i<len;i++){
    if(input[i]!=input2[i]){
      printf("No");
      return 0;
    }
  }
  printf("Yes");
}

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


int main(){
    char weather[10];
    scanf("%s", weather);
    int ans;
    if(strcmp(weather, "Sunny") == 0)ans = 0;
    else if(strcmp(weather, "Cloudy") == 0)ans = 1;
    else if(strcmp(weather, "Rainy") == 0)ans = 2;

    if(ans < 2)ans++;
    else ans = 0;

    if(ans == 0)printf("Sunny");
    else if(ans == 1)printf("Cloudy");
    else if(ans == 2)printf("Rainy");

    return 0;


}

Measured memory_bytes: 128
#include <stdio.h>

int main(){
	int mass[14][14];
	int x,y,size;
	
	int i,j;
	
	int max = 0;
	int n = 0;
	
	for(i = 0;i < 14;i++){
		for(j = 0;j < 14;j++){
			mass[i][j] = 0;
		}
	}
	
	while(scanf("%d,%d,%d",&x,&y,&size) != EOF){
		x += 2;
		y += 2;
		if(size == 1){
			for(i = -1,mass[x][y]--;i < 2;i++){
				mass[x+i][y]++;
				mass[x][y+i]++;
			}
		}else if(size == 2){
			for(i = -1;i < 2;i++){
				for(j = -1;j < 2;j++){
					mass[x+i][y+j]++;
				}
			}
		}else{
			for(i = -1;i < 2;i++){
				for(j = -1;j < 2;j++){
					mass[x+i][y+j]++;
				}
			}
			
			for(i = -2;i <= 2;i += 4){
				mass[x+i][y]++;
				mass[x][y+i]++;
			}
		}
	}
	
	for(i = 2;i < 12;i++){
		for(j = 2;j < 12;j++){
			if(mass[j][i] == 0){
				n++;
			}else if(mass[j][i] > max){
				max = mass[j][i];
			}
		}
	}
	
	printf("%d\n",n);
	printf("%d\n",max);
	
	return 0;
}

Measured memory_bytes: 1028
#include<iostream>
#include<math.h>
using namespace std;

int main()
{
	int n;
	cin>>n;
	
	int t=n,v=0;
	while(t>1){
		t/=2;
		v++;
	}
	
	cout<<pow(2,v)<<endl;
	
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=sys.stdin.readline
def resolve():
    N=int(input())
    dp=[[[[0]*4 for _ in range(4)] for _ in range(4)] for _ in range(N+1)]
    # initialize(n=3)
    NG={(0,1,2),(1,0,2),(0,2,1)}
    from itertools import product
    for i,j,k in product(range(4),repeat=3):
        if (i,j,k) in NG: continue
        dp[3][i][j][k]=1
    # iterate
    for n in range(4,N+1):
        for i,j,k,l in product(range(4),repeat=4):
            if dp[n-1][i][j][k]==0: continue
            if (j,k,l) in NG: continue
            if (i,j,l)==(0,1,2): continue
            if (i,k,l)==(0,1,2): continue
            dp[n][j][k][l]+=dp[n-1][i][j][k]
            dp[n][j][k][l]%=MOD
    # calculate
    ans=0
    for i,j,k in product(range(4),repeat=3):
        ans+=dp[N][i][j][k]
    print(ans%MOD)

resolve()

Measured memory_bytes: 42608
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define dfor(i,a,b) for(int i=(a);i>=(b);i--)
#define ll long long
#define ull unsigned long long
#define MOD  1000000007
#define MAX  1e9
#define pb   push_back
#define F    first
#define S    second


int comp(const void* a, const void* b) { return *(int*)a > *(int*)b ; } 

 
int findNumberOfTriangles(int arr[], int n) { 
	
	qsort(arr, n, sizeof( arr[0] ), comp); 
 
	int count = 0; 

	for (int i = 0; i < n - 2; ++i) { 
		
		int k = i + 2; 
 
		for (int j = i + 1; j < n; ++j) { 

			while (k < n && arr[i] + arr[j] > arr[k]) 
			++k; 
			if(k > j) 
			count += k - j - 1; 
		} 
	} 

	return count; 
} 

int main() { 
	int n;
	cin>>n;
	int arr[n];
	rep(i,n){
		cin>>arr[i];
	}
	cout<<findNumberOfTriangles(arr,n);

	return 0; 
} 
 

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

int main(){
  ll n, x;
  cin >> n >> x;
  vll a(n);
  vin(a);
  sort(all(a));
  ll rem =x;
  ll ans = 0;
  while(rem - a.at(ans) >= 0){
    rem -= a.at(ans);
    if(ans == n - 1 && rem != 0) break;
    ans++;
    if(ans == n) break;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define lower(a,x) lower_bound(all(a), x) - a.begin();
#define COUNT(a,x)  upper_bound(all(a), x) - lower_bound(all(a), x);
#define MCOUNT(a,x,y) upper_bound(all(a), y) - lower_bound(all(a), x);
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end());
#define scan(x) scanf("%lld",&x);
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
typedef double D;
const ll inf = 5555555555555555555;
const ll mod = 1000000007;
const D pi = acos(-1);
const D eps = 1e-10;

ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool ok, flag;
ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111


int main(void) {
  cin >> n;
  rep(i, n) {
	cin >> tmp;
	while (tmp % 2 == 0) {
	  tmp /= 2;
	  ans++;
	}
  }
  cout << ans << endl;

  return 0;
}

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

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

	int h;
	int w;
	cin >> h;
	cin >> w;
	char a[h][w];
	for(int i = 0; i < h; i++){
		string s;
		cin >> s;
		for(int j = 0; j < w; j++){
			a[i][j] = s[j];
		}
	}
	for(int i = 0; i < h; i++){
		bool flag3 = false;
		for(int k = 0; k < w; k++){
			bool flag = true;
			for(int j = 0; j < w; j++){
				if(a[i][j]=='#'){
					flag = false;
					flag3 = true;
					break;
				}
			}
			bool flag2 = true;
			for(int j = 0; j < h; j++){
				if(a[j][k]=='#'){
					flag2 = false;
					break;
				}
			}
			if(!(flag||flag2)){
				cout << a[i][k];
			}
		}
		if(flag3)cout << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
constexpr int MOD = 998244353;
int a, b, c, d;
ll dp[3005][3005][3];
int main(){
	scanf("%d%d%d%d", &a, &b, &c, &d);
	dp[a][b][0] = 1;
	dp[a+1][b+1][0] = a*b;
	dp[a+1][b+1][1] = b;
	dp[a+1][b+1][2] = a;
	if(a == c || b == d){
		if(b == d){
			swap(a,b); swap(c,d);
		}
		d -= b;
		ll ans = 1;
		rep(i,d) (ans *= a) %= MOD;
		printf("%lld\n", ans);
		return 0;
	}
	for(int i=a+1; i<=c; i++) dp[i][b][0] = dp[i-1][b][0] * b % MOD;
	for(int j=b+1; j<=d; j++) dp[a][j][0] = dp[a][j-1][0] * a % MOD;
	for(int i=a+1; i<=c; i++) for(int j=b+1; j<=d; j++){
		if(i==a+1 && j==b+1) continue;
		dp[i][j][0] = (dp[i-1][j][0] + dp[i-1][j][1]) * (j-1) % MOD;
		dp[i][j][1] = (dp[i][j-1][0] + dp[i][j-1][2] + dp[i][j-1][1] * i) % MOD;
		dp[i][j][2] = (dp[i-1][j][0] + dp[i-1][j][1] + dp[i-1][j][2] * j) % MOD;
	}
	printf("%lld\n", (dp[c][d][0] + dp[c][d][1] + dp[c][d][2]) % MOD);
}

Measured memory_bytes: 215084
N=int(input())
lst=[list(map(int, input().split())) for _ in range(N)]
ans=0
cnt=1
for i in range(N):
  cnt*=i
for i in range(N):
  for j in range(i+1, N):
    ans+=(((lst[i][0]-lst[j][0])**2+(lst[i][1]-lst[j][1])**2)**0.5)/N*2
print(ans)

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


int main(){
  int N;
  cin >> N;
  int tmp, parity=0;
  for (int i=0;i<N;i++){
    cin >> tmp;
    parity += tmp%2;
  }
  cout << (parity%2? "NO" : "YES") << endl;
}
 

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MOD = int(1e9) + 7; constexpr ll LINF = 1ll << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int main() {
    ll N, A, B;
    cin >> N >> A >> B;
    vll h(N);
    rep(i, N) cin >> h[i];
    ll C = A - B;

    int ng = 0;
    int ok = 1e9;
    while (ok - ng > 1) {
        int mid = ng + (ok - ng) / 2;

        ll cnt = 0;
        rep(i, N) {
            if (h[i] > B * mid) {
                cnt += (h[i] - B * mid + C - 1) / C;
            }
        }

        if (cnt > mid) ng = mid;
        else ok = mid;
    }

    write(ok);
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n
#define endl '\n'

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const ll mod=1000000007;
const ll mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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;}

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,m;
	cin >> n >> m;
	vpll key;
	rep(i,m){
		ll a,b;
		cin >> a >> b;
		ll s=0;
		rep(j,b){
			ll c;
			cin >> c;
			c--;
			s|=1<<c;
		}
		key.emplace_back(s,a);
	}
	vll dp(1<<n,INF);
	dp[0]=0;
	rep(s,1<<n){
		rep(i,m){
			ll t=s|key[i].first;
			ll cost=dp[s]+key[i].second;
			chmin(dp[t],cost);
		}
	}
	if(dp.back()==INF) cout << -1 << endl;
	else cout << dp.back() << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int n;
int d;
int s[100005];
int ans = 0;

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &d);

        s[d]++;
    }

    for (int i = 1; i <= 100000; i++) {
        s[i] += s[i - 1];
    }

    for (int i = 1; i <= 100000; i++) {
        if (s[i] == s[100000] - s[i]) {
            ans++;
        }
    }

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static int[][] Solve(int N, int K)
        {
            int max = (N - 1) * (N - 2) / 2;
            if (K > max) { return null; }
            var edges = new List<int[]>();
            for (int i = 2; i <= N; ++i) { edges.Add(new[] { 1, i }); }
            for (int i = 2; i <= N && max > K; ++i)
            {
                for (int j = i + 1; j <= N && max > K; ++j)
                {
                    edges.Add(new[] { i, j });
                    --max;
                }
            }
            return edges.ToArray();
        }

        static void Main(string[] args)
        {
            int[] V = ReadInts();
            var edges = Solve(V[0], V[1]);
            if (edges != null)
            {
                Console.WriteLine(edges.Length);
                foreach (int[] edge in edges)
                {
                    Console.WriteLine(string.Join(" ", edge));
                }
            }
            else
            {
                Console.WriteLine(-1);
            }
        }
    }
}


Measured memory_bytes: 13396
package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	a := make([][]int, m)

	for i:=0; i<m; i++ {
		var ca, cb int
		fmt.Scan(&ca, &cb)

		a[i] = make([]int, 2)
		a[i][0] = ca
		a[i][1] = cb
	}

	for i:=0; i<n; i++ {
		var cnt int
		for j:=0; j<m; j++ {
			if a[j][0] == i + 1 || a[j][1] == i + 1 {
				cnt++
			}
		}
		fmt.Println(cnt)
	}
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1LL<<60;
constexpr int inf = 1e9;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

int main(){
  int N;
  cin >> N;
  set<int> se;
  for(int i=0; i<N; i++){
    int x;
    cin >> x;
    if(se.count(x)){
      cout << "NO" << endl;
      return 0;
    }else{
      se.insert(x);
    }
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 9600
def main():
    N, M = map(int, input().split())
    A = tuple(tuple(map(int, input().split())) for _ in range(M))

    if M == 1:
        print('IMPOSSIBLE')
        return

    relay = []
    for a, b in A:
        if a == 1:
            relay.append(b)
        elif b == N:
            relay.append(a)

    if len(relay) > len(set(relay)):
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')

main()


Measured memory_bytes: 40688
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<limits>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1000000000 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main() {
	int n,m;
	cin >> n >> m;
	vector<pair<int, int>> p(m),p2;
	VI  memo(n + 1);
	rep(i, m) cin >> p[i].first >> p[i].second;
	
	sort(all(p));
	copy(all(p), back_inserter(p2));
	sort(all(p),
		[](const pair<int, int>& a, const pair<int, int>& b) { return a.second > b.second; });

	rep(i, m) {
		if (p[i].second == n) {
			memo[p[i].first]++;
		}
	}

	rep(i, m) {
		if (p2[i].first == 1 && memo[p2[i].second]>0) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;

	/*rep(i, m) {
		cout<<p2[i].first<< " " << p[i].second << "\n";
	}*/
	//cout << "\n";
	//rep(i, m) cout << p[i].first << " " << p[i].second << "\n";
	
	return 0;
}

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



int main() {

//変数の宣言

	int i,j,temp;
	vector<int> hight;


/////メイン処理/////

	for(i=0;i<10;i++){
		cin >> temp;
		hight.push_back(temp);
	}
	
	for(j=0;j<hight.size()-1;j++){
		for(i=0;i<hight.size()-1-j;i++){
			if (hight[i] > hight[i+1]) {
				temp = hight[i];
				hight[i] = hight[i+1];
				hight[i+1] = temp;
			}
		}
	}
	
	for(i=0;i<3;i++){
		cout << hight[hight.size() -i -1] <<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1212
#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;// >> ;
	
	float c=0.0;
	
	rep(i,N){
		if((i+1)%2==1) c+=1;
	}
	
	float ans=(float)c/(float)N;

	cout << ans << "\n";

    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,x,y,sum;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x>>y;
		sum+=y-x+1;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#else
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
 public:
  void solve() {
    string s, t;
    cin >> s >> t;
    s.push_back(t.back());
    if (s == t) {
      cout << "Yes\n";
    } else {
      cout << "No\n";
    }
  }
} NSPACE;
int main() {
  FPEN;
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  NSPACE.solve();
}

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

int main() {
  int H, W, N;
  cin >> H >> W >> N;
  vector<int> a(N);
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
  }

  vector<vector<int>> ans(H, vector<int>(W));
  int i = 0, j = 0;
  for (int k = 0; k < N; ++k) {
    for (int l = 0; l < a[k]; ++l) {
      ans[i][j] = k + 1;

      if (i % 2 == 0) {
        ++j;
      } else {
        --j;
      }

      if (i % 2 == 0 && j == W) {
        ++i, j = W - 1;
      } else if (i % 2 == 1 && j == -1) {
        ++i, j = 0;
      }
    }
  }

  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (j == W - 1) {
        cout << ans[i][j] << endl;
      } else {
        cout << ans[i][j] << ' ';
      }
    }
  }
}


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

int main() {
  int a,b,k; cin>>a>>b>>k;
  vector<int> div(200);
  int cnt=1;
  for(int i=min(a,b);i>=1;i--) {
    if(a%i==0&&b%i==0) {
      div[cnt]=i;
      cnt++;
    }
  }
  cout<<div[k]<<endl;
}


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

bool check(const vector<int> &ps) {
    for (int i = 1; i < ps.size(); i++) {
        if (ps[i - 1] > ps[i]) {
            return false;
        }
    }
    return true;
}

int main() {
    int n; cin >> n;
    vector<int> ps(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> ps[i];
    }
    bool ans = check(ps);
    for (int i = 0; i < n; i++) {
        if (ans) {
            break;
        }
        for (int j = i + 1; j < n; j++) {
            vector<int> tmp = ps;
            swap(tmp[i], tmp[j]);
            if (check(tmp)) {
                ans = true;
                break;
            }
        }
    }
    if (ans) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256