akhauriyash/Code-Regression huggingface dataset:
mod = 1000000007
n = int(input())
s = input()
l = []
for i in range(1, n):
  if s[i - 1] == s[i]:
    l.append(2)
  elif i < 2 or s[i - 2] != s[i - 1]:
    l.append(1)
if n < 2 or s[n - 2] != s[n - 1]:
  l.append(1)
if l[0] == 1:
  ans = 3
else:
  ans = 6
for i in range(1, len(l)):
  if l[i - 1] == 1:
    ans = 2 * ans % mod
  elif l[i] == 2:
    ans = 3 * ans % mod
print(ans)


Measured memory_bytes: 3064
#include <stdio.h>

void trace(int A[],int N)
{
    int i;
    for(i=0;i<N;i++)
    {
        if(i>0)
            printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
}

void insertionSort(int A[],int N)
{
    int i,j,v;
    for(i=1;i<N;i++)
    {
        v=A[i];
        j=i-1;
        while(j>=0&&A[j]>v)
        {
            A[j+1]=A[j];
            j--;
        }
        A[j+1]=v;
        trace(A,N);
    }
}

int main()
{
    int N,i,j;
    int A[100];

    scanf("%d",&N);
    for(i=0;i<N;i++)
        scanf("%d",&A[i]);
    trace(A,N);
    insertionSort(A,N);
    return 0;
}

Measured memory_bytes: 1768
using System;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
using System.Text.RegularExpressions;

namespace CsTest
{
    class Program
    {
        static void Main()
        {
            int[] NAB = AtCoder.ReadInt32Array();
            int N = NAB[0];
            int A = NAB[1];
            int B = NAB[2];

            long[] vals = AtCoder.ReadInt64Array();
            Array.Sort<long>(vals, (x, y) => -x.CompareTo(y));

            long[] aves = new long[A];
            Array.Copy(vals, 0, aves, 0, A);


            Console.WriteLine(aves.Average());

            int avenum = aves.Count(l => l == aves[A - 1]);
            int allnum = vals.Count(l => l == aves[A - 1]);

            long maxnum = Math.Min(allnum, B - (A - avenum));
            BigInteger ret = nCr(allnum, avenum);
            if (avenum == aves.Length)
            {
                for (int i = avenum + 1; i <= maxnum; i++)
                {
                    ret += nCr(allnum, i);
                }
            }
            Console.WriteLine(ret);
        }

        static BigInteger factorial(int n)
        {
            if (n == 1) return n;
            else return n * factorial(n - 1);
        }
        static BigInteger nPr(int n, int r)
        {
            BigInteger ret = 1;
            for (int l = n; l > n - r; l--)
            {
                ret *= l;
            }
            return ret;
        }
        static BigInteger nCr(int n, int r) => nPr(n, r) / factorial(r);
    }

    public class AtCoder
    {
        public static string[] ReadStringArray() => Console.ReadLine().Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries);
        public static int[] ReadInt32Array() => ReadStringArray().Select(s => int.Parse(s)).ToArray();
        public static long[] ReadInt64Array() => ReadStringArray().Select(s => long.Parse(s)).ToArray();
    }
}

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


Measured memory_bytes: 3624
#include<stdio.h>
int main(){
        int x,y;
        
        scanf("%d %d",&x,&y);
        
		//xとyが0ではない間
        while(!(x == 0 && y == 0)){
                //xがy以下のとき
                if(x <= y){
                	//そのまま
                        printf("%d %d\n",x,y);
                }
			//xがyより大きいとき
                else{
                	//入れ替え
                        printf("%d %d\n",y,x);
                }
                scanf("%d %d",&x,&y);
        }
        return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define assign(x,val) memset(x,val,sizeof(x))
#define motherfucker  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define for0(i,n) for(ll i=0;i<n;++i)
#define for1(i,n) for(ll i=1;i<=n;++i)
#define ford(i,n) for(ll i=n;i>=1;--i)
#define forg(i,a,b) for(ll i=a;i<b;++i)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpl;
long long mod = 1000000007;
const long double PI = (long double)(3.1415926535897932384626433832795);
inline void yes(){cout<<"YES\n";}
inline void no(){ cout<<"NO\n";}
inline void notposs(){cout<<-1<<endl;}
bool tests = 0;

void solve(){
	int n;cin>>n;
	string s;cin>>s;
	set<int> se[26];
	for0(i, n){
		se[s[i]-'a'].insert(i);
	}
	int q;cin>>q;
	while(q--){
		int x;cin>>x;
		--x;
		if(x){
			int l, r;cin>>l>>r;
			--l;--r;
			int ans = 0;
			for(auto &x : se){
				if(x.lower_bound(l)!=x.end() && *x.lower_bound(l) <=r){
					ans++;
				}
			}
			cout<<ans<<endl;
		} else{
			int x;char c;cin>>x>>c;--x;
			se[s[x] - 'a'].erase(x);
			s[x] = c;
			se[c - 'a'].insert(x);
		}
	}
}
 
int main(){
	
	motherfucker
	ll t = 1;
	if(tests) cin>>t;
	for0(i, t){
		solve();
	}
	return 0;
}



Measured memory_bytes: 24220
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#define INF INT_MAX
using namespace std;

int a, b, c;
int ans;

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


	return 0;
}

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

int main(){
	string s;
	cin>>s;
	int mi=999;
	for(int i=0;i<s.size()-2;i++){
		int l=(s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
		if(l<753){
			mi=min(mi,753-l);
		}else{
			mi=min(mi,l-753);
		}
	}
	cout<<mi<<endl;
	return 0;
}

Measured memory_bytes: 256
/*input
100 0
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define pie 3.141592653589793238
#define ll long long
#define ld long double
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define F first
#define S second
#define endl '\n'

using namespace std;
using namespace __gnu_pbds; 

template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}


void init(ll* a,ll n,ll val){
	for(ll i=0;i<n;i++)
		a[i]=val;
}

void solve(){
	ll i,j,k;
	ll x,n;
	cin>>x>>n;
	ll a[n];
	map<ll,ll> mp;
	rep(i,0,n)cin>>a[i],mp[a[i]]=1;
	ll ans;
	i=x;
	while(mp[i]){
		i--;
	}
	j=x;
	while(mp[j])j++;
	if(x-i<=j-x)ans=i;
	else ans=j;	
	cout<<ans<<endl;

}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);	
	ll T=1;
	//cin>>T;
	while(T--){
		solve();
	}
	return 0;
}




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

using namespace std;

typedef long long ll;

const ll INF = 1e18;
const int MAXN = 100005;

ll f[MAXN][2];

int a[MAXN];

int n;

template<typename T> inline bool updmax(T &a, T b) { return (a < b ? a = b, 1 : 0); }

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for (int i = 0; i <= n; i++)
		for (int j = 0; j < 2; j++)
			f[i][j] = -INF;
	f[2][0] = a[1] + a[2];
	f[2][1] = -(a[1] + a[2]);
	for (int i = 2; i < n; i++)
	{
		updmax(f[i + 1][0], f[i][0] + a[i + 1]);
		updmax(f[i + 1][0], f[i][1] + a[i + 1]);
		updmax(f[i + 1][1], f[i][0] - 2ll * a[i] - a[i + 1]);
		updmax(f[i + 1][1], f[i][1] + 2ll * a[i] - a[i + 1]);
	}
	ll res = 0;
	updmax(res, f[n][0]);
	updmax(res, f[n][1]);
	cout << res << endl;
	return 0;	
}


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

int main () {
  int N, Q;
  long K;
  cin >> N >> K >> Q;
  vector<int>challengers (N, K - Q);
  for (int i = 0; i < Q; i++) {
    int challenger_no;
    cin >> challenger_no;
    challengers[challenger_no - 1]++;
  }
  for (int challenger : challengers) {
    if(challenger <= 0 ){
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  }
}

Measured memory_bytes: 1024
package main

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

var ar []int
var br []bool
var g map[int][]int
var qr []int

func main() {
	sc.Split(bufio.ScanWords)
	n, q := ri(), ri()
	g = map[int][]int{}
	for i := 1; i < n; i++ {
		a, b := ri(), ri()
		g[a] = append(g[a], b)
		g[b] = append(g[b], a)
	}
	qr = make([]int, n+1)
	for i := 0; i < q; i++ {
		p, x := ri(), ri()
		qr[p] += x
	}
	ar = make([]int, n+1)
	br = make([]bool, n+1)
	dfs(1, 0)
	ans := fmt.Sprint(ar)
	fmt.Println(ans[3 : len(ans)-1])
}

func dfs(key, sum int) {
	if br[key] {
		return
	}
	br[key] = true
	sum += qr[key]
	ar[key] = sum
	ret := g[key]
	for i := 0; i < len(ret); i++ {
		dfs(ret[i], sum)
	}
}

var sc = bufio.NewScanner(os.Stdin)

func ri() int {
	sc.Scan()
	s := sc.Text()
	a, _ := strconv.Atoi(s)
	return a
}


Measured memory_bytes: 58240
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;
 
int main() {
  ll n,cn;
  cin >> n >> cn;
  vector<pair<pll,ll>> a(n);
  for(ll i=0;i<n;i++) {
    ll s,t,c;
    cin >> s >> t >> c;
    c--;
    a[i]={pll(s,t),c};
  }
  sort(a.begin(),a.end());
  ll ans=0;
  ll idx=0;
  ll temp=0;
  vec q(cn,-1);
  for(ll i=0;i<1e5+10;i++) {
    while(idx<n&&a[idx].first.first<=i) {
      if(q[a[idx].second]<0) {
        temp++;
      }
      q[a[idx].second]=max(q[a[idx].second],a[idx].first.second);
      idx++;
    }
    ans=max(ans,temp);
    
    for(ll j=0;j<cn;j++) {
      if(q[j]==i) {
        temp--;
        q[j]=-1;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace StartFinish
{

    class Program
    {
        static void Main(string[] args)
        {
            string word = Console.ReadLine();
            string str;
            int count=0;
            while ((str = Console.ReadLine()) != "END_OF_TEXT")
            {
                string[] strdivision = str.ToLower().Split(' ').ToArray();
                foreach(var x in strdivision)
                {
                    if (x == word)
                    {
                        count++;
                    }
                }
            }
            Console.WriteLine(count);
        }
    }
}

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

int main() {
  int a,b;
  cin >> a >> b;
  
  int ans = 0;
  
  for(int i = 0; i < 2; i++){
    if(a>=b){
      ans += a;
      a--;
    }
    else{
      ans += b;
      b--;
    }
  }
  
  cout << ans << endl;
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
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; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
//template end

int bit[100010]={};
void add(int i,int x){
	while(i<100010)bit[i]+=x,i+=(i&-i);
}
int sum(int i){
	int res=0;
	while(i)res+=bit[i],i-=(i&-i);
  return res;
}

int main(){
	int n,m; scanf("%d%d",&n,&m);
	vector<P> range(n);
	rep(i,0,n){
		int l,r; scanf("%d%d",&l,&r);
		range[i]={r-l+1,l};
	}
	sort(ALL(range)); int ans,pre=0,idx;
	rep(i,1,m+1){
		if(i==1){
			printf("%d\n",n); continue;
		}
		idx=lower_bound(ALL(range),P{i,-1})-range.begin();
		ans=n-idx;
		rep(j,pre,idx){
			add(range[j].second,1);
			add(range[j].first+range[j].second,-1);
		}
		rep(j,1,m/i+1)ans+=sum(j*i);
		printf("%d\n",ans); pre=idx;
	}
}

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

int investment = 0;
double rate = 0;
int commision = 0;

int simple(int y){
	int wage = investment;
	int InterestTotal = 0;
	
	for (int i = 0; i < y; i++){
		InterestTotal += wage * rate;
		wage -= commision;
	}
	wage += InterestTotal;
	return wage;
}

int compound(int y){
	int wage = investment;

	for (int i = 0; i < y; i++){
		wage = (wage * (1+rate)) - commision;
	}

	return wage;
}

int main(){
	int m; //????????????????????°
	int Max = 0;
	cin >> m;

	for (int i = 0; i < m; i++){
		int y, n; //?????¨??´??°????¨??????°
		cin >> investment >> y >> n;

		for (int j = 0; j < n; j++){
			int type; //??????:0, ??????:1
			cin >> type >> rate >> commision;
			int tmp;

			if (type == 0){
				tmp = simple(y);
				if (Max < tmp){
					Max = tmp;
				}
			}
			else{
				tmp = compound(y);
				if (Max < tmp){
					Max = tmp;
				}
			}
		}
		cout << Max << endl;
		Max = 0;
	}
	return 0;
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const int MOD = 1000000007;

void solve() {
  int a, p;
  cin >> a >> p;
  cout <<(a * 3 + p) / 2 << endl;
} 

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

Measured memory_bytes: 3580
#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 RREP(i,n) for(int i = (n) - 1; (i) >= 0; --i)
#define SZ(n) (int)(n).size()
#define ALL(n) (n).begin(), (n).end()
#define MOD LL(1e9 + 7)
#define INF 1000000
using namespace std;
using LL = long long;

int main() {
	int n, m;
	cin >> n >> m;
	int a[100][100] = {};
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> a[j][i];
		}
	}
	int b[100] = {};
	for (int i = 0; i < m; i++) {
		cin >> b[i];
	}
	int c[100] = {};
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			c[i] += a[j][i] * b[j];
		}
		cout << c[i] << endl;
	}
	return 0;
}



Measured memory_bytes: 3124
#include<stdio.h>
#include<math.h>
int main()
{
    int N,a[10000],count=0;

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

        scanf("%d",&a[i]);
    }
    for(int i=0; i<N; i++)
    {
        k=sqrt(a[i]);
        int j=2;
        for(; j<=k; j++)
        {
            if(a[i]%j==0)
                break;
        }
        if(j>k)
            count++;
    }
    printf("%d\n",count);
    return 0;
}



Measured memory_bytes: 2148
from bisect import bisect_left, bisect_right

n = int(input())
L = list(map(int, input().split()))
L.sort()
# a,b,cの順序に大きいとして、6倍…はしなくていいのか。組み合わせらしい
# a-c<b<a+c
cnt = 0
for i in range(n):
    for j in range(i + 1, n):
        p = L[i]
        q = L[j]
        hidari = max(i + 1, bisect_left(L, q - p + 1))
        migi = min(j - 1, bisect_right(L, p + q - 1))
        delta = migi - hidari
        if delta >= 0:
            cnt += delta + 1
print(cnt)


Measured memory_bytes: 50652
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll INFLL = (1ll<<60);
const int INF = (int)(1e9);

#define l_ength size

bool used[225816],visited[100100],color[100100];
int a[225816],b[225816],ans[225816],d[100100];

vector<P> g[100100];

void dfs(int u){
	int i,v,e;
	visited[u] = true;
	for(i=(g[u].l_ength()-1); i>=0; --i){
		v = g[u][i].first;
		e = g[u][i].second;
		if(!used[e]){
			continue;
		}
		if(visited[v]){
			continue;
		}
		color[v] = (!color[u]);
		dfs(v);
	}
}

int main(void){
	int n,m,u,v,i,j,e;
	bool flag;
	P tmp;
	fill(ans,ans+225816,INF);
	cin >> n >> m;
	for(i=0; i<n; ++i){
		cin >> d[i];
	}
	for(j=0; j<m; ++j){
		cin >> a[j] >> b[j];
		--a[j]; --b[j];
		g[a[j]].push_back(P(b[j],j));
		g[b[j]].push_back(P(a[j],j));
	}
	for(u=0; u<n; ++u){
		tmp = P(INF,INF);
		for(i=(g[u].l_ength()-1); i>=0; --i){
			v = g[u][i].first;
			e = g[u][i].second;
			tmp = min(tmp,P(d[v],v));
		}
		if(tmp.first > d[u]){
			cout << "-1" << endl;
			return 0;
		}
		for(i=(g[u].l_ength()-1); i>=0; --i){
			v = g[u][i].first;
			e = g[u][i].second;
			if(tmp.second == v){
				ans[e] = d[u];
				used[e] = true;
				break;
			}
		}
	}
	for(i=0; i<n; ++i){
		if(!visited[i]){
			dfs(i);
		}
		cout << ((color[i])?"B":"W");
	}
	cout << endl;
	for(j=0; j<m; ++j){
		cout << ans[j] << endl;
	}
	return 0;
}


Measured memory_bytes: 13568
#include <cstdio>
#include <cstdint>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <unordered_map>

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

    int cnt = 0;
    for (std::size_t i = 0; i < N.size(); ++i) {
        if (N[i] == '2') {
            ++cnt;
        }
    }

    std::cout << cnt << std::endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.parseLong;
//import static java.lang.Long.*;
//import static java.lang.Math.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		int[] a = new int[n];
		for(i=0;i<n;i++) {
			a[i] = parseInt(sc.next());
		}
		sc.close();
		Arrays.parallelSort(a);
		out.println(a[n-1]-a[0]);
	}
}


Measured memory_bytes: 19924
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int i,n,x,cnt=0,j,flag=0;
    //freopen("test.txt","r",stdin);
    cin>>n;
    int ara[n+5];
    for(i=1;i<=n;i++)
        cin>>ara[i];
    for(i=1,j=1;i<=n;i++)
    {
        if(ara[i]==j)
        {
            flag=1;
            j++;
        }
        else
            cnt++;
    }
    if(flag==0)
        cout<<-1<<endl;
    else
        cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define pc __builtin_popcount

using namespace std;

const int N=2e5+100;
int n,m,w,a,b,lg[N];

int lowbit(int x){return x&-x;}

void solve(int a,int b,int k,int vis){
	if (k==1){printf("%d ",b); return;}
	int x=a^b,c;
	x=lg[lowbit(x)]-1; vis|=1<<x;
	rep (i,0,n-1) if (!(vis>>i&1)){c=a^(1<<i); break;}
	solve(a,c,k-1,vis);
	printf("%d ",c^(1<<x));
	solve(c^(1<<x),b,k-1,vis);
}

int main(){
	scanf("%d%d%d",&n,&a,&b); m=1<<n;
	rep (i,1,m-1) lg[i]=lg[i>>1]+1;
	if (pc(a^b)%2==0) return puts("NO"),0;
	printf("YES\n%d ",a); solve(a,b,n,0);
	return 0;
}

Measured memory_bytes: 1536
var lines = [];

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var ABC = lines[0].split(" ").map(i => Number(i));
    var K = Number(lines[1]);

    ABC.sort((a, b) => b - a);

    var ans = ABC[0];
   
    for (var i = 0; i < K; i++) { ans = ans * 2 }
    console.log(ans + ABC[1] + ABC[2]);
});

Measured memory_bytes: 7628
#![allow(unused_imports)]
#![allow(unused_variables)]
use proconio::input;
use proconio::marker::*;
use std::cmp::{min, max};
use std::collections::{HashSet, HashMap, BinaryHeap};

fn main() {
    input! {
        a: i64,
        b: i64,
        n: i64,
    }
    let t = min(n, b - 1);
    let ans = a * t / b - a * (t / b);
    println!("{}", ans);
}


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

typedef long long ll;
const int N = 100005;
int n, fa[2 * N], size[2 * N], val[2 * N];
ll tag[2 * N];
struct edge
{
	int a, b, c;
} e[N];
vector<int> g[2 * N];
bool operator<(const edge &x, const edge &y) { return x.c > y.c; }

int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }

void dfs(int u)
{
	if (u <= n) size[u] = 1;
	for (int v : g[u]) dfs(v), size[u] += size[v];
	for (int v : g[u]) tag[v] += 1ll * (size[u] - size[v]) * val[u];
}
void get(int u)
{
	for (int v : g[u]) tag[v] += tag[u], get(v);
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i < n; i++) scanf("%d%d%d", &e[i].a, &e[i].b, &e[i].c);
	sort(e + 1, e + n);
	for (int i = 1; i <= n; i++) fa[i] = i;
	for (int i = 1; i < n; i++)
	{
		int s = find(e[i].a), t = find(e[i].b);
		fa[n + i] = n + i, val[n + i] = e[i].c;
		fa[s] = fa[t] = n + i;
		g[n + i].push_back(s), g[n + i].push_back(t);
	}
	dfs(2 * n - 1);
	get(2 * n - 1);
	for (int i = 1; i <= n; i++) printf("%lld\n", tag[i]);
}


Measured memory_bytes: 20864
#include<stdio.h>
#include<stdlib.h>
#define INF 1000000

int matrixChainOrder(int*);
int min(int,int);
int n;

int main(){
  int *p,i;
  
  scanf("%d",&n);
  
  p = (int *)malloc(sizeof(int)*(n+2));

  for(i=0;i<n;i++){
    scanf("%d %d",&p[i],&p[i+1]);
  }

  printf("%d\n",matrixChainOrder(p));

  return 0;
}

int matrixChainOrder(int* p){
  int i,j,l,k,q;
  int m[100][100];

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

  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j = i+l-1;
      m[i][j] = INF;
      for(k=i;k<j;k++){
	q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
	m[i][j] = min(m[i][j],q);
      }
    }
  }

  return m[1][n];
}

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

Measured memory_bytes: 632
import sys

field = []
for i in range(0, 10):
	lst = []
	for j in range(0, 10):
		lst.append(0)
	field.append(lst)

for line in sys.stdin:
	x, y, s = map(int, line.split(','))
	field[x][y] += 1
	for i in range(0, 2):
		nextx = x-1+2*i
		nexty = y-1+2*i
		if 0 <= nextx and nextx < 10: field[nextx][y] += 1
		if 0 <= nexty and nexty < 10: field[x][nexty] += 1
	if s >= 2:
		for i in range(0, 2):
			nextx = x-1+2*i
			if 0 <= nextx and nextx < 10:
				for j in range(0, 2):
					nexty = y-1+2*j
					if 0 <= nexty and nexty < 10:
						field[nextx][nexty] += 1
	if s == 3:
		for i in range(0, 2):
			nextx = x-2+4*i
			nexty = y-2+4*i
			if 0 <= nextx and nextx < 10: field[nextx][y] += 1
			if 0 <= nexty and nexty < 10: field[x][nexty] += 1

cnt = 0
max = 0
for i in range(0, 10):
	for j in range(0, 10):
		if field[i][j] == 0: cnt += 1
		else:
			if max < field[i][j]: max = field[i][j]
print cnt
print max


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

const int INF = 1e9;

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

    int x;
    cin >> x;
    if (x >= 30)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3640
#include<stdio.h>
#define N 501

static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n,M[N][N],color[N],d[N],f[N],tt;

void dfs_visit(int u){
  int v;

  color[u] = GRAY;
  tt++;
  d[u] = tt;
  for(v = 0;v < n;v++){
    if(M[u][v] == 0) continue;
    if(color[v] == WHITE){
      dfs_visit(v);
    }
  }
  
  color[u] = BLACK;
  f[u] = ++tt;
}

void dfs(){
  int i;

  for(i = 0;i < n;i++){
    color[i] = WHITE;
  }
  
  tt = 0;

  for(i = 0;i < n;i++){
    if(color[i] == WHITE){
      dfs_visit(i);
    }
  }

  for(i = 0;i < n;i++){
    printf("%d %d %d\n",i + 1,d[i],f[i]);
  }
}

int main(){
  int u,k,v,i,j;

  scanf("%d",&n);

  for(i = 0;i < n;i++){
    for(j = 0;j < n;j++){
      M[i][j] = 0;
    }
  }

  for(i = 0;i < n;i++){
    scanf("%d %d",&u,&k);
    u--;

    for(j = 0;j < k;j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }

  dfs();
  
  return 0;
}



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

char str1[100],str2[100],str3[200];
int main(){
cin>>str1>>str2;
/*for(int i=0,i<strlen(str1),i++)
	{if(strstr(str1,str2)==NULL 1;
		else {cout<<"Yes"<<endl; break;}
	if(i+1==strlen(str1)) {cout<<"No"<<endl; break;}
	}
*/
strcpy(str3,str1);
strcat(str3,str1);
if(strstr(str3,str2)==NULL) cout<<"No"<<endl;
else cout<<"Yes"<<endl;
return 0;
}


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

int main() {
  int N, i;
  int c = 0;
  string S;
  
  cin >> N;
  
  for(i=0; i<N; i++){
    cin >> S;
    if((S == "P" || S == "W" || S == "G") == 0){
      if(S == "Y"){
        c = 1;
        break;
      }
    }
  }
  
  if(c == 1){
    cout << "Four" << endl;
  }
  else if(c == 0){
    cout << "Three" << endl;
  }
  else{
	cout << "error" << endl;
  }
}


Measured memory_bytes: 256
package main

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

func main() {
	sc := NewScanner()
	N, C := sc.NextInt(), sc.NextInt()
	D := make([][]int, C)
	mp := make([][]int, C)

	for i := 0; i < C; i++ {
		D[i] = sc.NextIntArray()
		mp[i] = make([]int, C)
	}

	c := make([][]int, N)
	for i := 0; i < N; i++ {
		c[i] = sc.NextIntArray()
	}

	for x := 0; x < N; x++ {
		for y := 0; y < N; y++ {
			k := ((x + 1) + (y + 1)) % 3
			mp[k][c[x][y]-1]++
		}
	}

	min := -1

	for i := 0; i < C; i++ {
		for j := 0; j < C; j++ {
			if i == j {
				continue
			}
			for k := 0; k < C; k++ {
				if i == k || j == k {
					continue
				}
				s := 0
				for c := 0; c < C; c++ {
					s += D[c][i] * mp[0][c]
					s += D[c][j] * mp[1][c]
					s += D[c][k] * mp[2][c]
				}
				if min == -1 || min > s {
					min = s
				}
			}
		}
	}
	fmt.Println(min)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 4608
#include <iostream>
#include <algorithm>
using namespace std;
int a[200001]; 
int b[200001];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		b[i]=a[i];
	}
	sort(b,b+n);
	for(int i=0;i<n;i++){
		if(b[n-1]!=a[i])cout<<b[n-1]<<endl;
		else cout<<b[n-2]<<endl;
	}
}

Measured memory_bytes: 3200
import java.util.*;

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

    int N = scn.nextInt();

    int count = 0;
    for (int i = 1; i <= N; i++) {
      int p = scn.nextInt();
      if (p != i) {
        count++;
      }

    }
    if (count == 2 || count == 0) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }
}

Measured memory_bytes: 21844
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    int ci=0;
    if(n>=2)
        ci+=(n*(n-1))/2;
    if(m>=2)
        ci+=(m*(m-1))/2;
    printf("%d\n",ci);
    return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
    
using namespace std;

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  string str,s1,s2,s3;
    getline(cin,str);
    int flag=0;
  for(int i=0;i<str.length();i++)
  {
    if(str[i]!=' ' && flag==0)
      s1+=str[i];
      else if(str[i]==' ')
      {
        flag=1;
        s2=s1;
        s1="";
      }
    else if(str[i]!=' ' && flag==1)
    {
      s3+=str[i];
    }
  }
  
  cout<<(s3+s2)<<endl;
  return 0;
}
  

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

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

fn main() {
    let mut grid = vec![vec![0; 3]; 3];
    let mut cols = vec![0; 2];
    let mut row = vec![0; 2];
    for i in 0..3 {
        for j in 0..3 {
            grid[i][j] = read::<i64>();
        }
    }
    for i in 1..3 {
        row[i-1] = grid[0][i] - grid[0][i-1];
        cols[i-1] = grid[i][0] - grid[i-1][0];
    }
    for i in 1..3 {
        for j in 1..3 {
            if row[j-1] != grid[i][j] - grid[i][j-1] ||
               cols[j-1] != grid[j][i] - grid[j-1][i] {
                println!("No");
                return
            }
        }
    }
    println!("Yes");
}


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

int main() {

  int n;
  cin >> n;

  set<string> st;
  vector<string> answer;
  for (int i = 0; i < n; i++) {
    string command, value;
    cin >> command >> value;
    if (command == "insert") {
      st.insert(value);
    } else if (command == "find") {
      if (st.find(value) != st.end()) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }

  return 0;

}


Measured memory_bytes: 32128
#include <iostream>
#include <cstring>

using namespace std;

const int MAX_N = 7;
const int MAX_S = 3000;

int dp[MAX_N * MAX_N + 1][MAX_S + 1];

int main()
{
	int N, M, S;
	
	while (cin >> N >> M >> S, N) {
		memset(dp, 0, sizeof dp);

		N *= N;

		dp[0][0] = 1;

		for (int i = 1; i <= M; ++i) {
			for (int j = N; j >= 1; --j) {
				for (int k = S; k >= i; --k) {
					dp[j][k] += dp[j - 1][k - i];
					dp[j][k] %= 100000;
				}
			}
		}

		cout << dp[N][S] << endl;
	}
}

Measured memory_bytes: 1752
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();

		if (b - a == c - b) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

	}

}


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

int dp[100005];
map<int,bool> visited;

void dfs(int src,vector<int> v[]){
	visited[src]=true;
	for(int i=0;i<v[src].size();i++){
		int ver=v[src][i];
		if(!visited[ver]){
			dfs(ver,v);
		}
		dp[src]=max(dp[src],1+dp[ver]);
	}
}
int main(){
	int n,m;
	cin>>n>>m;
	vector<int> v[n+5];
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		v[a].push_back(b);
	}

	//map<int,bool> visited;
	//map<int,int> d;
	//memset(d,0,sizeof(d));
	memset(dp,0,sizeof(dp));

	for(int i=0;i<n;i++){
		if(!visited[i+1]){
			dfs(i+1,v);
		}
	}

	int ans=-1;
	for(int i=0;i<100005;i++){
		ans=max(ans,dp[i]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 14208
#include <bits/stdc++.h>
using namespace std;
int main(){
  int sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;
  for(int i =0;i < tx-sx;i++){
    cout << "R";
  }
  for(int i =0;i < ty-sy;i++){
    cout << "U";
  }
  for(int i =0;i < tx-sx;i++){
    cout << "L";
  }
  for(int i =0;i < ty-sy;i++){
    cout << "D";
  }
  cout << "D";
  for(int i =0;i < tx-sx+1;i++){
    cout << "R";
  }
  for(int i =0;i < ty-sy+1;i++){
    cout << "U";
  }
  cout << "L";
  cout << "U";
  for(int i =0;i < tx-sx+1;i++){
    cout << "L";
  }
  for(int i =0;i < ty-sy+1;i++){
    cout << "D";
  }
  cout << "R";
}
  
  
  
  

Measured memory_bytes: 256
#import<bits/stdc++.h>
int main(){long long H,W;int N,h,w,h0,w0,z,t;scanf("%lld%lld%d",&H,&W,&N);std::vector<long long>v(10);std::set<std::pair<int,int>>se;v[0]=(H-2)*(W-2);for(;N--;)for(scanf("%d%d",&h,&w),h--,w--,se.emplace(h,w),h0=-2;++h0<2;)for(w0=-2;++w0<2;)if(1<=h+h0&&h+h0<H-1 && 1<=w+w0&&w+w0<W-1){for(t=z=0;z<9;z++)t+=se.find({h+h0+z/3-1,w+w0+z%3-1})!=se.end();v[t-1]--,v[t]++;}for(auto &e:v)printf("%lld\n",e);}

Measured memory_bytes: 4992
/*
digu_J - Digvijay Janartha
NIT Hamirpur - INDIA
 
***********************IN COLABRATION WITH -----AJrockstar   :)*********************
*/
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
 
using namespace std;
using namespace __gnu_pbds;
 
//template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
//template<typename T> using MinPriorityQueue = priority_queue <T, vector <T>, greater <T>>;
 
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef complex<double> com;
 
#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define loop(x,n) for(ll x = 0; x < n; x++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
 
const ll LINF = LLONG_MAX, SZ = 1e3, MOD = 1e9 + 7, N = 1e5 + 5, M = 1e3 + 5, LG = 21;
const int INF = INT_MAX;
const db PI = acos(-1), EPS = 1e-6;
//mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
 
 
 
 
int main() {
	
    fast_io();
    ll i,j,t,n,p,k,q,o,ca=0,cb=0,x,y,s;
    
    
    cin>>n;
    ll a[n],b[n],c[n],dp[n+1],dp0[n+1],dp1[n+1],dp2[n+1];
    for(i=0;i<n;i++)
    {
    	cin>>a[i]>>b[i]>>c[i];
	}
    
    dp0[0]=a[0];
    dp1[0]=b[0];
    dp2[0]=c[0];
    
    dp[0]=max(max(a[0],b[0]),c[0]);
    
    for(i=1;i<n;i++)
    {
    	
    	//dp[i]=max(max(dp0[i-1]+max(b[i],c[i]),dp1[i-1]+max(a[i],c[i])),dp2[i-1]+max(b[i],a[i]));
    	dp0[i]=a[i]+max(dp1[i-1],dp2[i-1]);
    	dp1[i]=b[i]+max(dp0[i-1],dp2[i-1]);
    	dp2[i]=c[i]+max(dp1[i-1],dp0[i-1]);
    	dp[i]=max(max(dp0[i],dp1[i]),dp2[i]);
    	//cout<<dp[i]<<" ";
	}
	
	cout<<dp[n-1];
	
    return 0;
}
 
 

Measured memory_bytes: 9120
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        sc.close();

        int min = 0;
        for(int i=1; i<n; i++){
            if(s.charAt(i) == 'E'){
                min++;
            }
        }

        int c = min;

        for(int i=1; i<n; i++){
            if(s.charAt(i) == 'E') c--;
            if(s.charAt(i-1) == 'W') c++;
            if(c < min) min = c;
        }

        System.out.println(min);
    }
}

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

int main()
{
    int K, S;

    cin >> K >> S;
    long long ans = 0;
    for (int a = 0; a <= K; a++)
    {
        for (int b = 0; b <= K; b++)
        {
            if (0 <= S - a - b && S - a - b <= K)
            {
                ans++;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = 1e9 + 7;


int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };

const int MOD = 1e9 + 7;



//ユークリッド互除法
template<typename T>
T gcd(T x, T y) {

	if (y == 0) {
		return x;
	}
	else {
		return gcd(y, x % y);
	}
}
/*最小公倍数*/
template<typename T>
T lcm(T x, T y) {
	T tmp = gcd(x, y);
	return (x / tmp) * y;
}


/******************************************************************************************/


int main() {


	ll n, k;
	cin >> n >> k;
	

	if (k > (n - 1)*(n - 2) / 2) {
		cout << "-1" << endl;
	}
	else
	{
		int ans = (n - 1)*(n - 2) / 2;
		set<pii> st;
		for (int i = 2; i <= n; i++)
		{
			st.insert(pii(1, i));
		}
		while (ans != k) {

			for (int i = 2; i <= n; i++)
			{
				bool flag = true;
				for (int j = i + 1; j <= n; j++) {
					if (st.find(pii(i, j)) == st.end()) {
						st.insert(pii(i, j));
						ans--;
						if (ans == k) {
							flag = false;
							break;
						}
					}
				}
				if (!flag) {
					break;
				}
			}
		}
		cout << st.size() << endl;
		for (auto itr : st) {
			cout << itr.first << " " << itr.second << endl;
		}
	}




	return 0;
}


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

int main() {
    string O, E; cin >> O >> E;
    vector<char> ans;
    for (int i = 0; i < O.size(); i++) {
        ans.push_back(O.at(i));
        if (i == O.size()-1 && O.size() != E.size()) {
            break;
        }
        ans.push_back(E.at(i));
    }
    for (int i = 0; i < ans.size(); i++) {
        cout << ans.at(i);
    }
    cout << endl;
}

Measured memory_bytes: 3620
/*input
1 7 9 4
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
int a[4];
int main()
{
	IOS;
	
	REP(i,4) cin>>a[i];
	sort(a,a+4);

	if(a[0]*1000+a[1]*100+a[2]*10+a[3]==1479) cout<<"YES\n";
	else cout<<"NO\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using vin=vector<int>;
const int inf=1e9+7;
const ll INF=1e18;


int main() {
  int n;
  cin>>n;
  vin a(n);
  rep(i,n) cin>>a[i];
  /////////
  vector<bool> b(8,false);
  int ans=0;
  int cnt=0;
  rep(i,n){ //a[i]について
    rep(j,8){  //何色か
       if(a[i]>=3200){
         cnt++;
         break;
       }
       else if(a[i]/400==j){
         b[j]=true; 
       }
      
    }//repj
    
  }//repi
  rep(i,8){
    if(b[i]) {ans++;}
  }
  if(ans==0) {
    ans++;
    cnt--;
  }
  cout<<ans<<" "<<ans+cnt<<endl;
}

Measured memory_bytes: 256
n = gets.to_i

arr = []
n.times do
	arr << gets.split.map(&:to_i)
end

arr.sort_by!{|n|n[1]}
flag = true
arr.inject(0) do |sum,a|
	flag = false if (sum + a[0]) > a[1]
	sum + a[0]
end

puts flag ? "Yes" : "No"

Measured memory_bytes: 22648
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,s;
bool check(ll x){
	if(n/x>=x)return 0;
	ll k=n/x;ll r=n%x;
	if(s==k+r)return 1;
	return 0;
}
ll js(ll x,ll b){
	ll ans=0;
	while(x){
		ans+=x%b;
		x/=b;
	}
	return ans;
}
int main()
{
	//freopen("H:\\c++1\\in.txt","r",stdin);
	//freopen("H:\\c++1\\out.txt","w",stdout);
	cin>>n>>s;
	ll b=1e18;
	if(n==s)b=n+1;
	if(n>s){
		ll temp=n-s;
		for(ll t=1;t<=sqrt(temp);t++){
			if(temp%t==0){
				ll x=t+1,y=temp/t+1;
				if(check(y))b=min(b,y);
			}
		}
	}
	for(ll t=2;t<=1000000;t++){
		ll cnt=js(n,t);
		if(cnt==s){
			b=min(b,t);
			break;
		}
	}
	if(b==1e18)printf("-1\n");
	else printf("%lld\n",b);
	return 0;
}

Measured memory_bytes: 3728
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	          int i;

	      	  cin.tie(0);  ios_base::sync_with_stdio(false);

	      	  int a,b,c,d,e,f;
	      	  cin >> a >> b >> c >> d >> e >> f;

	      	  int p,q,r,s;
	      	  int x=1000000000;
	      	  int m=f/c,n=f/d;
	      	  REP(i,31){
	      		  REP(j,16){
	      			  REP(k,m+1){
	      				  REP(l,n+1){
	      					  int t=100*a*i+100*b*j+c*k+d*l;
	      					  if(t>f || t<=0) continue;
	      					  int v=c*k+d*l;
	      					  int u=t*e-(100+e)*v;
	      					  if(u>=0){
	      						  if(x>=u){
	      							  x=u;
	      							  p=i; q=j; r=k; s=l;
	      						  }
	      					  }

	      				  }
	      			  }
	      		  }
	      	  }

	      	  cout << 100*a*p+100*b*q+c*r+d*s << ' ' << c*r+d*s << endl;

	          return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    char S[1001];
    int n;

    scanf("%s",&S);

    for(n=0;;n++){
        if(S[n]=='\0')break;
    }

    if(S[n-1]=='s'){
        printf("%ses",S);
    }
    else printf("%ss",S);
    
    
        return 0;
}

Measured memory_bytes: 1672
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	S,T = map(str, sys.stdin.readline().split())
	A,B =MI()
	d = {S:A,T:B}
	U = IS()
	d[U]-=1
	print("{} {}".format(d[S], d[T]))

main()

Measured memory_bytes: 38256
n,y = map(int,input().split())
kekkas = []
for a in range(2001):
  for b in range(2001):
    kekka = 9000*a + 4000*b - (y - 1000*n)
    if kekka == 0:
      c = n - a - b
      if c >= 0:
        kekkas.append((a,b,c))
if len(kekkas) > 0 :
  print(str(kekkas[0][0]) + " " + str(kekkas[0][1]) + " " + str(kekkas[0][2]))
else:
  print("-1 -1 -1")

Measured memory_bytes: 3064
import java.util.*;
import java.util.Collections;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    Set<Integer> A = new HashSet<Integer>();
    int N = sc.nextInt();
    for (int i = 0; i < N; i++) {
      A.add(sc.nextInt());
    }
    if (A.size() == N) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }
}


Measured memory_bytes: 101048
package main

import (
	"fmt"
	"strings"
)

type counter map[rune]int

func newCounter(s string) counter {
	ret := make(counter)
	for _, b := range s {
		ret[b]++
	}
	return ret
}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func (c0 counter) intersect(c1 counter) counter {
	ret := make(counter)
	for k, v := range c0 {
		ret[k] = min(c1[k], v)
	}
	return ret
}

func main() {
	var n int
	fmt.Scan(&n)
	ss := make([]string, n)
	for i := range ss {
		fmt.Scan(&ss[i])
	}

	cntr := newCounter(ss[0])
	for _, s := range ss {
		cntr = cntr.intersect(newCounter(s))
	}

	ans := ""
	for c := 'a'; c <= 'z'; c++ {
		ans += strings.Repeat(string(c), cntr[c])
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define CYES cout<<"Yes"<<"\n";
#define CNO cout<<"No"<<"\n";
#define CFS cin.tie(nullptr);ios::sync_with_stdio(false);
#define CST(x) cout<<fixed<<setprecision(x);
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
const int IINF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = (int) 1e9 + 7;
const string MM = " ";

int main(){
    int n, m;
    cin >> n >> m;
    if (n == m) {
        CYES;
    }
    else {
        CNO;
    }
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {
	class Node {
		int key;
		Node left;
		Node right;

		public Node(int key) {
			this.key = key;
		}

	}

	Node root;

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

	private void run() throws NumberFormatException, IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		for (int i = 0; i < n; i++) {
			String s = scanner.next();
			if (s.startsWith("i")) {
				insert(scanner.nextInt());
			} else {
				inorder(root);
				System.out.println();
				preorder(root);
				System.out.println();
			}
		}
	}

	private void preorder(Node u) {
		if (u == null)
			return;
		System.out.print(" " + u.key);
		preorder(u.left);
		preorder(u.right);
	}

	private void inorder(Node u) {
		if (u == null)
			return;
		inorder(u.left);
		System.out.print(" " + u.key);
		inorder(u.right);
	}

	private void insert(int key) {
		Node y = null;
		Node x = root;
		Node z = new Node(key);
		while (x != null) {
			y = x;
			if (z.key < y.key) {
				x = x.left;
			} else {
				x = x.right;
			}
		}
		if (y == null) {
			root = z;
		} else if (z.key < y.key) {
			y.left = z;
		} else {
			y.right = z;
		}
	}
}

Measured memory_bytes: 312604