akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ALDS1_11_C_BreadthFirstSearch
{
	class Program
	{
		static void Main ( string[] args )
		{
			int vertexCount = int.Parse (Console.ReadLine ());
			Graph graph = new Graph (vertexCount);

			for (int lp = 0; lp < vertexCount; lp++)
			{
				int[] inputNum = Array.ConvertAll (Console.ReadLine ().Split (' '), int.Parse);

				for (int lp2 = 0; lp2 < inputNum[1]; lp2++)
				{
					graph.GetPath (inputNum[0], inputNum[lp2 + 2]);
				}
			}

			int[] result = graph.BreadthFirstSeach (1);
			StringBuilder output = new StringBuilder (result.Length * 2);

			for (int lp = 0; lp < result.Length; lp++)
			{
				output.Append (lp + 1);
				output.Append (" ");
				output.Append (result[lp]);
				output.AppendLine ();
			}

			Console.Write (output);
		}
	}

	class Graph
	{
		public Graph ( int size )
		{
			this.Size = size;
			this.Path = new bool[this.Size][];

			for (int lp = 0; lp < this.Path.Length; lp++)
			{
				this.Path[lp] = new bool[this.Size];	
			}
		}

		private bool[][] Path { set; get; }
		private int Size { set; get; }
		private const bool Exist = true;

		public void GetPath ( int beginPoint, int adjacencyPoint )
		{
			Path[beginPoint - 1][adjacencyPoint - 1] = Exist;
		}

		public int[] BreadthFirstSeach ( int beginSearchPoint )
		{
			beginSearchPoint -= 1;

			//initialize
			Queue<int> searchQueue = new Queue<int> (Size);

			const int CannotVisit = -1;
			int[] distance = Enumerable.Repeat (CannotVisit, Size).ToArray ();

			//process
			searchQueue.Enqueue (beginSearchPoint);
			distance[beginSearchPoint] = 0;

			while (searchQueue.Count != 0)
			{
				int item = searchQueue.Dequeue ();

				for (int lp = 0; lp < Size; lp++)
				{
					//??£??\????????????
					if (Path[item][lp] == Exist)
					{
						//????¨??????????
						if (distance[lp] == CannotVisit)
						{
							//????´¢????±??????\??????
							searchQueue.Enqueue (lp);
							distance[lp] = distance[item] + 1;
						}
					}
				}
			}

			return distance;
		}
	}
}

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

int main(){
	int N,M;
	cin>>N>>M;
	vector<int> L(M);
	vector<int> R(M);
	for(int i=0;i<M;i++){
		cin>>L.at(i)>>R.at(i);
	}

	int Rmin,Lmax;
	Rmin = 5*N;
	Lmax = -10;
	for (int i = 0;i<M;i++){
		if(Rmin>R.at(i)){
			Rmin = R.at(i);
		}
		if(Lmax<L.at(i)) {
			Lmax = L.at(i);
		}
	}
	if(Rmin>=Lmax){
		cout<<Rmin-Lmax+1<<endl;
	}
	else{
		cout<<0<<endl;
	}
}


Measured memory_bytes: 1024
#include <iostream>
#include <unordered_map>

int main()
{
	std::unordered_map<int, int> mapa;
	int n;
	std::cin >> n;
	for (int i = 0; i < n; ++i)
	{
		int x;
		std::cin >> x;
		std::unordered_map<int, int>::iterator it = mapa.find(x);
		if (it != mapa.end())
		{
			++it->second;
		}
		else
		{
			mapa.insert(std::make_pair(x, 1));
		}
	}
	
	int m;
	std::cin >> m;
	for (int i = 0; i < m; ++i)
	{
		int x;
		std::cin >> x;
		std::unordered_map<int, int>::iterator it = mapa.find(x);
		if (it != mapa.end())
		{
			if (it -> second > 0)
			{
				--it->second;
			}
			else
			{
				std::cout << "NO";
				return 0;
			}
		}
		else
		{
			std::cout << "NO";
			return 0;
		}
	}
	
	std::cout << "YES";
	return 0;
}

Measured memory_bytes: 8520
n=int(input())
s=list(input())
cnt_w = [0]*(n+1)
for i in range(1,n+1):
  cnt_w[i] = cnt_w[i-1] + (s[i-1]=='W')
ans = n + 1
for i in range(n):
  tmp = cnt_w[i] + (n-i-1) - (cnt_w[n] - cnt_w[i+1])
  ans = min(tmp,ans)
print(ans)

Measured memory_bytes: 87032
n = int(input())
a = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))
c = list(map(int, input().split(" ")))

beforeA = 0
sum = 0
for i in range(n):
    sum += b[a[i] - 1]
    if beforeA != 0 and a[i] - 1 == beforeA:
        sum += c[beforeA - 1]
    beforeA = a[i]

print(sum)


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

typedef long long ll;

ll N;

map<ll, ll> prime_factors(ll n) {
    map<ll, ll> res;
    if(n == 1) { // n=1 の素因数分解は n^1
        res[n] = 1;
        return res;
    }
    for(ll i = 2, _n = n; i*i <= _n; ++i) {
        while(n % i == 0) {
            ++res[i]; // 素数i^{res[i]}
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;
    return res;
}
vector<ll> divisors(ll n) {
    vector<ll> res;
    for(ll i = 1; i*i <= n; ++i) {
        if(n % i != 0) continue;
        res.push_back(i);
        if(n/i == i) continue; // 上の行で追加済み。
        res.push_back(n/i);
    }
    return res;
}

int main() {
    cin >> N;
    vector<ll> v = divisors(N);
    sort(v.begin(), v.end());

    ll ans = 11;
    rep(i, v.size()) {
        // cout << v[i] << endl;
        ll other = N / v[i];
        ll tmp = max(to_string(v[i]).size(), to_string(other).size());
        ans = min(tmp, ans);
    }

    cout << ans << endl;
}

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

using namespace std;
using ll = long long;


int main()
{
	int n, m; cin >> n >> m;
	vector<int> num(n, 1);
	vector<int> red(n);
	red[0] = true;

	for(int i = 0; i < m; i++) {
		int x, y; cin >> x >> y; x--, y--;
		num[x]--, num[y]++;
		if(!red[x]) {
			continue;
		}

		if(num[x] == 0) {
			red[x] = false;
			red[y] = true;
		} else {
			red[y] = true;
		}
	}
	cout << count(red.begin(), red.end(), 1) << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(){
  int n,q,s[100000],t[50000],i,sum=0,l=0,m,r;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&s[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&t[i]);
  }
  for(i=0;i<q;i++){
    r=n;
    l=0;
    m=(r+l)/2;
    while(l<r){
      m=(l+r)/2;
      if(s[m]==t[i]){
	sum++;
	break;
      }else if(t[i]<s[m]){
	r=m;
      }else{
	l=m+1;
      }
    }
  }
  printf("%d\n",sum);
}



Measured memory_bytes: 2272
H, W = map(int, input().split())

a = []
for i in range(H):
    a.append(input())

def func(H,W,a):
  for i in range(H):
    for j in range(W):
      if a[i][j] == '#':
        if i > 0 and a[i-1][j] == '#':
          continue
        if j > 0 and a[i][j-1] == '#':
          continue
        if i < H-1 and a[i+1][j] == '#':
          continue
        if j < W-1 and a[i][j+1] == '#':
          continue
        print('No')
        return 0
  print('Yes')
  return 0

func(H,W,a)


Measured memory_bytes: 3064
N = int(input())
ans = []
lis = []
for i in range(N):
    lis.append(i + 1)
if N % 2 == 0:
    M = (N - 2) * N // 2
    for i in range(1, N):
        for j in range(1, N):
            if j != i and i != lis[-j]:
                if sorted([i, lis[-j]]) not in ans:
                    ans.append(sorted([i, lis[-j]]))
    print(M)
    for i in range(M):
        print(' '.join(map(str, ans[i])))
else:
    M = (N - 1) ** 2 // 2
    for i in range(1, N):
        for j in range(2, N):
            if j != i + 1 and i != lis[-j]:
                if sorted([i, lis[-j]]) not in ans:
                    ans.append([i, lis[-j]])
    for i in range(1, N):
        ans.append([N, i])
    print(M)
    for i in range(M):
        print(' '.join(map(str, ans[i])))

Measured memory_bytes: 3848
package main

import (
	"fmt"
	"math"
)

func main() {
	n := scanInt()
	for i := 0; i < n; i++ {
		circleTriangle()
	}
}

func scanInt() int {
	var n int
	fmt.Scanf("%d", &n)
	return n
}

func circleTriangle() {
	var x1, y1, x2, y2, x3, y3 float64
	fmt.Scanf("%f%f%f%f%f%f", &x1, &y1, &x2, &y2, &x3, &y3)
	a := 2 * (x1 - x2)
	b := 2 * (y1 - y2)
	c := 2 * (x1 - x3)
	d := 2 * (y1 - y3)
	e := x1*x1 - x2*x2 + y1*y1 - y2*y2
	f := x1*x1 - x3*x3 + y1*y1 - y3*y3

	px := (d*e - b*f) / (a*d - b*c)
	py := (a*f - c*e) / (a*d - b*c)

	r := math.Sqrt((x1-px)*(x1-px) + (y1-py)*(y1-py))
	fmt.Printf("%.3f %.3f %.3f\n", px, py, r)
}



Measured memory_bytes: 1156
import java.util.Scanner;
import java.util.HashMap;
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
import java.lang.Math;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int[] xx = new int[n];
        int[] yy = new int[m];
        for (int i = 0; i < n; i++) {
            xx[i] = sc.nextInt();
        }
        for (int i = 0; i < m; i++) {
            yy[i] = sc.nextInt();
        }
        int j = x+1;
        for (int i = 0; i < Math.abs(y-x); i++) {
            boolean flag = true;
            for (int k = 0; k < xx.length; k++) {
                if (xx[k] >= j) {
                    flag = false;
                }
            }
            if (flag) {
                for (int l = 0; l < yy.length; l++) {
                    if (yy[l] < j) {
                        flag = false;
                    }
                }
            }
            if (flag) {
                System.out.println("No War");
                System.exit(0);
            }
            j++;
        }
        System.out.println("War");
    }

}


Measured memory_bytes: 21844
// This amazing code is by Eric Sunli Chen.
#include<bits/stdc++.h>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

const int maxn=200111;
const int maxm=200111;
struct max_flow
{
	struct edge{int to,cap;};
	int head[maxn],nxt[maxm<<1],iter[maxn],tot;
	edge e[maxm<<1];
	void clear()
	{
		memset(head,0,sizeof(head));
		tot=1;
	}
	max_flow(){clear();}
	void addedge(int u,int v,int cap)
	{
		nxt[++tot]=head[u];
		head[u]=tot;
		e[tot]=edge{v,cap};
		nxt[++tot]=head[v];
		head[v]=tot;
		e[tot]=edge{u,0};
	}
	
	int lvl[maxn],q[maxn];
	bool bfs(int s,int t)
	{
		memset(lvl,-1,sizeof(lvl));
		lvl[s]=0;int rr=0;q[rr++]=s;
		for(int fr=0;fr<rr;fr++)
		{
			int x=q[fr];if(x==t)return true;
			for(int i=head[x];i;i=nxt[i])if(e[i].cap&&lvl[e[i].to]==-1)
			{
				lvl[e[i].to]=lvl[x]+1;
				q[rr++]=e[i].to;
			}
		}
		return false;
	}
	int dfs(int x,int t,int f)
	{
		if(x==t||f==0)return f;
		int ret=0;
		for(int&i=iter[x];i;i=nxt[i])if(e[i].cap&&lvl[e[i].to]==lvl[x]+1)
		{
			int d=dfs(e[i].to,t,min(f,e[i].cap));
			e[i].cap-=d;e[i^1].cap+=d;
			f-=d;ret+=d;
			if(!f)break;
		}
		return ret;
	}
	int maxflow(int s,int t)
	{
		int flow=0;
		while(bfs(s,t))
		{
			memcpy(iter,head,sizeof(head));
			flow+=dfs(s,t,inf);
		}
		return flow;
	}
}thor;

int n,p[maxn],q[maxn],tot1,tot2,ip[maxn],iq[maxn];
int decomp(int*p,int*id)
{
	int ret=0;
	for(int i=1;i<=n;i++)if(!id[i])
	{
		int tmp=i;ret++;
		while(!id[tmp])
		{
			id[tmp]=ret;
			tmp=p[tmp];
		}
	}
	return ret;
}

int main()
{
	get1(n);
	for(int i=1;i<=n;i++)get1(p[i]),p[i]++;
	for(int i=1;i<=n;i++)get1(q[i]),q[i]++;
	
	tot1=decomp(p,ip);
	tot2=decomp(q,iq);
	
	int ans=n,S=tot1+tot2+1,T=S+1;
	for(int i=1;i<=n;i++)
	{
		if(p[i]==q[i])
		{
			if(p[i]==i)ans--;
			else
			{
				thor.addedge(ip[i],iq[i]+tot1,1);
				thor.addedge(iq[i]+tot1,ip[i],1);
			}
		}
		else
		{
			if(q[i]==i)thor.addedge(S,ip[i],1);
			else if(p[i]==i)thor.addedge(iq[i]+tot1,T,1);
			else thor.addedge(iq[i]+tot1,ip[i],1);
		}
	}
	ans-=thor.maxflow(S,T);
	printendl(ans);
	return 0;
}


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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;
const ll MAXN = 10;
const ll MAXM = 10;

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

struct C
{
    ll from, to, dist, score;
};

ll n, m, q;
vector<C> conds;

ll rec(vector<ll> pos)
{
    if (pos.size() >= n)
    {
        ll score = 0;
        for (C cond : conds)
        {
            if (pos[cond.to - 1] - pos[cond.from - 1] == cond.dist)
            {
                score += cond.score;
            }
        }
        return score;
    }
    ll maxscore = 0;
    for (ll j = pos.back(); j <= m; j++)
    {
        vector<ll> newpos = pos;
        newpos.push_back(j);
        maxscore = max(rec(newpos), maxscore);
    }
    return maxscore;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cin >> n >> m >> q;
    for (ll i = 0; i < q; i++)
    {
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        conds.push_back(C({a, b, c, d}));
    }
    vector<ll> pos = {1};
    cout << rec(pos) << endl;
}


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}
          
  
int main() {
  int N, M;
  cin >> N >> M;
  ll ans;
  ll submit = pow(2,M);
  ans=1900*M+100*(N-M);
  ans*=submit;
  cout << ans << endl;
}
  



Measured memory_bytes: 512
#include <iostream>
#define ll long long
using namespace std;

int main()
{
    ll n, m, sum;   
    cin >> m >> n;
    sum = 0;

    for (int i = 0; i < n; i++)
    {
        ll x;
        cin >> x;
        sum += x;
    }

    if (sum > m) cout << -1 << endl;
    else cout << m - sum << endl;
}

Measured memory_bytes: 3584
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;





int main(){
    ll H,W,h,w;
    cin>>H>>W>>h>>w;
    if(H%h==0 && W%w==0){
        cout<<"No"<<endl;
    }
    else if(H%h!=0){
        cout<<"Yes"<<endl;
        vector<ll> a(h,0);
        a[0]=100001;
        for(int i=1;i+1<h;i++){
            a[i]=1;
        }
        a[h-1]-=100001+h;
        for(int i=0;i<H;i++){
            for(int t=0;t<W;t++){
                cout<<a[i%h];
                if(t+1!=W){cout<<" ";}
            }
            cout<<endl;
        }
    }
    else{
        cout<<"Yes"<<endl;
        vector<ll> a(w,0);
        a[0]=100001;
        for(int i=1;i+1<w;i++){
            a[i]=1;
        }
        a[w-1]-=100001+w;
        for(int i=0;i<H;i++){
            for(int t=0;t<W;t++){
                cout<<a[t%w];
                if(t+1!=W){cout<<" ";}
            }
            cout<<endl;
        }
    }
    
    
    
    
    return 0;
}



Measured memory_bytes: 2048
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include<vector>

using namespace std;
typedef long long ll;
//#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i =0;i<n;++i)
//#define mod (ll)(1e9+7)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int yaku[201] = {0};
    yaku[1] = 1;
    for(int i = 2;i<=200;i++){
        for(int j=1;j<=i;j++){
            if(i%j==0){
                yaku[i]++;
            }
        }
        //cout <<i <<":" << yaku[i] <<endl;
    }
    int N;
    cin >> N;
    int count = 0;
    for(int i=1;i<=N;i=i+2){
        if(yaku[i]==8)count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(){
    int N;
    cin >> N;
    int cntac = 0, cntwa = 0, cnttl = 0, cntre = 0;
    for(int i = 0; i < N; i++){
        string s;
        cin >> s;
        if(s == "AC") cntac++;
        else if(s == "WA") cntwa++;
        else if(s == "TLE") cnttl++;
        else cntre++;
    }
    cout << "AC" << " x " << cntac << endl;
    cout << "WA" << " x " << cntwa << endl;
    cout << "TLE" << " x " << cnttl << endl;
    cout << "RE" << " x " << cntre << endl;
}

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

int main() {
	int i, j, k, n;
	long long int cnt=0;
	cin>>n;
	int arr[n];
	for(i=0; i<n; i++){
	    cin>>arr[i];
	}
	for(i=1; i<n; i++){
	    if(arr[i-1]>arr[i]){
	        cnt = cnt + arr[i-1]-arr[i];
	        arr[i] = arr[i-1];
	    }
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 4440
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    long K, A, B;
    cin >> K >> A >> B;
    long cnt;
    
    if(B - A < 2){
        cnt = 1 + K;
    }
    else{
        cnt = 1;
        bool flug = false;
        for(int i = 1; i <= K; i++){
            if(flug == false && i == K){
                cnt++;
                break;
            }
            
            if(flug == true){
                cnt += B;
                flug = false;
            }
            else{
                if(cnt < A){
                    cnt++;
                }
                else{
                    cnt -= A;
                    flug = true;
                }
            }
        }
    }
    
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,i,count;
    string S;
    cin >> N >> S ;
    count = N;
    for(i=0;i<N;i++){
        if(S[i]==S[i+1])
            count--;
    }
    cout << count << endl;
    return 0;

}


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

typedef pair<int, int> P;

int main() {

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

    sort(v.begin(), v.end(), less<int>());
    rep(i,n-1){
        v[0] = (v[0]+v[i+1])/2;
    }
    
    cout << fixed;
    cout << setprecision(5)<< v[0] << endl;

    return 0;
}

Measured memory_bytes: 256
def gcd(a,b):
  if a%b == 0:
    return b
  return gcd(b,a%b)


N,M = [int(i) for i in input().split()]

S = input()
T = input()

x = N * M // gcd(N,M)
flag = True

#print(S[0 * (N / math.gcd(N,M)) + 1])
for i in range(gcd(N,M)):
  if not(S[i * (N //gcd(N,M))] == T[i * (M // gcd(N,M))]):
    flag = False
#    print(S[i * (N // math.gcd(N,M))]  , T[i * (M // math.gcd(N,M))])
if flag:
  print(x)
else:
  print('-1')

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define reps(i, a, n) for (int i = (a); i < (n); ++i)
#define rep(i, n) reps(i, 0, n)
#define deps(i, a, n) for (int i = (a); i >= (n); --i)
#define dep(i, n) deps(i, n, 0)
#define inf 2147483647
#define int long long

signed main(void)
{
	int a, b; cin >> a >> b;
	cout << a * b << endl;
}


Measured memory_bytes: 3592
N = int(input())
A = [int(x) for x in input().split()]

A_set = sorted(set(A))
if len(A_set) == 1:
    print("Yes" if A_set[0] <= N // 2 or A_set[0] == N - 1 else "No")
elif len(A_set) == 2 and A_set[0] + 1 == A_set[1]:
    cnt_min = A.count(A_set[0])
    cnt_max = N - cnt_min
    if cnt_min <= A_set[0] and cnt_min + 1 <= A_set[1] <= cnt_min + cnt_max // 2:
        print("Yes")
    else:
        print("No")
else:
    print("No")


Measured memory_bytes: 14564
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int main(){
    ll n,m; cin>>n>>m;
    cout<<(n-1)*(m-1)<<endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES // for C++  
#include "bits/stdc++.h"
#define LL long long
#define NUM 1000000007

using namespace std;

int main()
{
    string s;
    cin >> s;
    for (size_t i = 0; i < s.size(); i++)
    {
        if (i%2==0)
        {
            cout << s[i];
        }
    }
    cout << endl;
}

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

int main(){
    int Q;
    cin >> Q;
    vector<int> ans(Q);
    bool isPrime[100005];
    for (int i=2; i<=100000; i++) isPrime[i] = true;
    for (int i=2; i<=100000; i++) {
        if (isPrime[i]) {
            for (int j=i+i; j<=100000; j+=i) {
                isPrime[j] = false;
            }
        }
    }
    vector<int> sum(100005, 0);
    for (int i=3; i<=100000; i++) {
        if (i%2 == 1) {
            sum[i] = sum[i-1] + (isPrime[i] && isPrime[(i+1) / 2]);
        } else {
            sum[i] = sum[i-1];
        }
    }
    rep(i, Q) {
        int l, r;
        cin >> l >> r;
        ans[i] = sum[r] - sum[l-1];
    }
    rep(i, Q) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 1536
n = int(input())
tn,xn,yn = 0,0,0
for _ in range(n):
  to,xo,yo = tn,xn,yn
  tn,xn,yn = map(int,input().split())
  if tn-to >= abs(xn-xo)+abs(yn-yo) and (tn-to)%2 == (abs(xn-xo)+abs(yn-yo))%2:
    continue
  else:
    print("No")
    break
else:
  print("Yes")


Measured memory_bytes: 3060
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort()
b.sort()
c.sort()

if a[0] > b[-1] or b[0] > c[-1]:
    print(0)
    exit()

# fix index of b
bi = 0
lb = []
for ai in range(n):
    while bi < n and a[ai] >= b[bi]:
        lb.append(ai)
        bi += 1
while bi < n:
    lb.append(n)
    bi += 1

ans = 0
ci = n - 1
for bi in range(n-1, -1, -1):
    while ci >= 0 and b[bi] < c[ci]:
        ci -= 1
    ans += lb[bi] * (n - ci - 1)

print(ans)

Measured memory_bytes: 103156
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	int n1=s.length();
	int n2=t.length();
	int f=0;
	string temp=s+s;
	if(n1!= n2)
	{
		cout<<"No\n";
	}
	
	else if(temp.find(t) != string::npos)
	{
		cout<<"Yes\n";
	}
	else
		cout<<"No\n";

}


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
hp=sum(A)
for i in range(N):
    if A[i]-B[i]<=0:
        A[i+1]=A[i+1]+A[i]-B[i]
        A[i]=0
        if A[i+1]<0:
            A[i+1]=0
    else:
        A[i]=A[i]-B[i]
ans=hp-sum(A)
print(ans)
        

Measured memory_bytes: 18624
def main():
    import heapq
    def root(index):
        if tree[index][0]==index:
            return index
        else:
            tree[index][0]=root(tree[index][0])
            return tree[index][0]

    def unite(index1,index2):
        r1=root(index1)
        r2=root(index2)
        if r1!=r2:
            d1,d2=tree[r1][1],tree[r2][1]
            if d1<=d2:
                tree[r1][0]=r2
                tree[r2][1]=max(d1+1,d2)
            else:
                tree[r2][0]=r1
                tree[r1][1]=max(d2+1,d1)

    def same(index1,index2):
        return root(index1)==root(index2)
    
    n=int(input())
    xy=[list(map(int,input().split())) for _ in [0]*n]
    xyz=[xy[i]+[i] for i in range(n)]
    x_sort=sorted(xyz,key=lambda x:x[0])
    y_sort=sorted(xyz,key=lambda x:x[1])
    
    tree=[[i,1] for i in range(n)]#root,depth
    g=[]
    heapq.heapify(g)
    for i in range(n-1):
        heapq.heappush(g,[abs(x_sort[i+1][0]-x_sort[i][0]),x_sort[i][2],x_sort[i+1][2]])
    for i in range(n-1):
        heapq.heappush(g,[abs(y_sort[i+1][1]-y_sort[i][1]),y_sort[i][2],y_sort[i+1][2]])

    cnt=0
    while g:
        d,i,j=heapq.heappop(g)
        if same(i,j)==False:
            cnt+=d
            unite(i,j)
    print(cnt)
main()

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

int f(int n) {
  if (n % 2 == 0) {
    return n / 2;
  } else {
    return 3 * n + 1;
  }
}

int main(){
  int s;
  cin >> s;
  set<int> a;
  int i = 1;

  a.insert(s);
  
  while (1) {
    int next = f(s);
    // cout << "next=" << next << endl;
    // set<int>::iterator it;
    if (a.find(next) == a.end()) {
      // not in a
      a.insert(next);
      i++;
      s = next;
    } else {
      cout << i + 1;
      break;
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <cctype>
#include <map>
#include <vector>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main() {
	int n;
	cin >> n;
	vector <pair<pair<string, int>,int>> pr(n);
	rep(i, 0, n) {
		string s;int num;
		cin >> s >> num;
		pr[i].first = make_pair(s, -1*num);
	}
	rep(i, 0, n) {
		pr[i].second = i + 1;
	}
	sort(pr.begin(), pr.end());
	rep(i, 0, n)cout << pr[i].second<< endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<max(a*b,c*d)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using intl = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define repid(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin,(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define int intl
#define itn intl
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl digit10(intl a){
    if(!a)return 1;
    intl b = 0;
    while(a){
        a /= 10;
        b++;
    }
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl a[3];
    cin(i,a);
    sort(a,a+3);
    cout << a[0] + a[1] << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#define INF 2e9
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

int main()
{
	int n, x, a;
	cin >> n >> x;
	while (x--)
	{
		cin >> a;
		n -= a;
	}
	if (n < 0)cout << -1 << endl;
	else cout << n << endl;
	return 0;
}

Measured memory_bytes: 3608
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while(true) {
			int m=Integer.parseInt(in.next()),n=Integer.parseInt(in.next());
			if(m==0)break;
			solve(m,n);
		}


	}

	static void solve(int m, int n) {
		boolean sieve[] = new boolean[10000000];
		Arrays.fill(sieve, true);
		List<Integer> list = new ArrayList<>();
		for(int i=m; i<sieve.length; i++) {
			if(sieve[i]) {
				list.add(i);
				for(int j=i*2; j<sieve.length; j+=i)sieve[j]=false;
			}

			if(list.size()==(n+1))break;
		}

		System.out.println(list.get(n));
	}

}



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

void trace(int A[], int n) {
	for (int i = 0; i < n; i++) {
		if (i) cout << " ";
		cout << A[i];
	}
	cout << endl;
}

int selectionsort(int A[], int n) {
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		int minj = i;
		for (int j = i; j < n; j++) {
			if (A[j] < A[minj]) {
				minj = j;
			}
		}
		swap(A[i], A[minj]);
		if (i != minj) cnt++;
	}

	return cnt;
}

int main() {
	int n; cin >> n;
	int A[110];
	for (int i = 0; i < n; i++) cin >> A[i];

	int ans = selectionsort(A, n);
	trace(A, n);
	cout << ans << endl;
	return 0;
}


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

int main() {
    std::string S;
    int Q;
    std::cin >> S >> Q;

    int current_rev = 0;
    int q, pos = 0;
    int F[Q] = {0};
    char C[Q];
    for (int i = 0; i < Q; ++i) {
        std::cin >> q;
        if (q == 1) {
            ++current_rev;
        } else {
            std::cin >> F[pos] >> C[pos];
            if (current_rev % 2 != 0) {
                if (F[pos] == 1) {
                    F[pos] = 2;
                } else {
                    F[pos] = 1;
                }
            }
            ++pos;
        }
    }

    std::ostringstream hoss;
    std::ostringstream toss;
    for (int i = 0; i < pos; ++i) {
        if (F[i] == 1) {
            hoss << C[i];
        } else {
            toss << C[i];
        }
    }

    std::string hstr = hoss.str();
    std::reverse(hstr.begin(), hstr.end());

    std::string out = hstr + S + toss.str(); 
    if (current_rev % 2 != 0) {
        std::reverse(out.begin(), out.end());
    }

    std::cout << out << std::endl;

    return 0;
}


Measured memory_bytes: 2524
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <tuple>
#include <cmath>
#include <map>

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp( a, b ) make_pair( a, b )
#define mt( ... ) make_tuple( __VA_ARGS__ )

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()

#define MOD ( (ll)( 1e9 + 7 ) )

ll N;
vector<map<string, ll>> dp;

bool chk( const string &acgt )
{
	rep( i, 4 )
	{
		string tmp = acgt;
		if ( i >= 1 )
		{
			swap( tmp[i], tmp[i - 1] );
		}

		if ( tmp.find( "AGC" ) != string::npos )
		{
			return ( false );
		}
	}

	return ( true );
}

ll dfs( ll current, const string str3 )
{
	if ( dp[current][str3] != 0 )
	{
		return ( dp[current][str3] );
	}

	if ( current == N )
	{
		return ( 1 );
	}

	ll ret = 0;
	const string acgt = "ACGT";
	rep( i, 4 )
	{
		if ( chk( str3 + acgt[i] ) )
		{
			ret = ( ret + dfs( current + 1, str3.substr( 1, 2 ) + acgt[i] ) ) % MOD;
		}
	}
	dp[current][str3] = ret;

	return ( ret );
}

int main()
{
	cin >> N;
	dp.resize( N + 1 );

	cout << dfs( 0, "TTT" ) << endl;

	return ( 0 );
}


Measured memory_bytes: 768
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <cinttypes>
#include <string.h>
#include <bits/stdc++.h>

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define pi pair<int,int>
#define fi first
#define se second

#define FOR(var, to)          for (register s64 var = 0; var < (s64)to; var++)
#define FROMTO(var, from, to) for (register s64 var = from; var <= (s64)to; var++)

#define INIT(var) FOR(i,countof(var)) var[i] = 0
#define INPUT(var) FOR(i,countof(var)) var[i] = ri()
#define INPUT1(var) FOR(i,countof(var)) var[i] = ri() - 1

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)

#define MOD 1000000007
#define INF (1 << 30)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

using namespace std;

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

static inline s64 rs64() {
  s64 a;
  scanf("%" SCNd64, &a);
  return a;
}

static inline void wi(int a) {
  printf("%d", a);
}

static inline void wu64(u64 a) {
  printf("%" PRIu64, a);
}

static inline void ws64(s64 a) {
  printf("%" PRId64, a);
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

int main() {
  int h = ri();
  int w = ri();
  char s[h][w+1];
  FOR(i,h) scanf("%s", s[i]);
  FOR(i,h) {
      bool flag = true;
      FOR(j,w) if (s[i][j] == '#') flag = false;
      if (flag) FOR(j,w) s[i][j] = 'A';
  }
  FOR(i,w) {
      bool flag = true;
      FOR(j,h) if (s[j][i] == '#') flag = false;
      if (flag) FOR(j,h) s[j][i] = 'A';
  }
  FOR(i,h) {
      bool flag = false;
      FOR(j,w) {
          if (s[i][j] == 'A') continue;
          flag = true;
          cout << s[i][j];
      }
      if (flag)
        cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(java.util.Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun solve(sc: java.util.Scanner, pw: java.io.PrintWriter) {
        val A = sc.next().toInt()
        val B = sc.next().toInt()

        pw.println(listOf(A + B, A - B, A * B).max()!!)
    }
}


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

template<typename T>
bool is_prime(T x){
    if (x % 2 == 0) return false;
    T k = 3;
    while (k * k <= x){
        if (x % k == 0) return false;
        k += 2;
    }
    return true;
}

int main(){
    int x;
    cin >> x;
    if (x > 2){
        if (x % 2 == 0) x += 1;
        while (!is_prime(x)) {
            x += 2;
        }
    }
    cout << x << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define eps 1e-6
#define INF 1e12
using namespace std;

long long keta(long long a,long long b){
	double p=log(a)/log(10),q=log(b)/log(10);
	if(p>q)return p+1;
	else return q+1;
}

int main(){
	long long n,ans=INF;
	cin>>n;
	loop(i,1,sqrt(n)+1){
		if(abs((double)n/i-n/i)<eps){
			ans=min((double)ans,(double)keta(i,n/i));
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    int a[3];
    int s;
    for(int i = 0; i < 3; i ++){
        cin >> s;
        a[i] = s;
    }
    sort(a, a + (sizeof(a)/sizeof(a[0])));
    for(int i = 0; i < 2; i ++){
        cout << a[i] << " ";
    }
    cout << a[2] << endl;
    return 0;
}


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

int getMin(int a, int b);

int absValue1, absValue2;

int main(){
    int n;
    scanf("%d",&n);
    int h[n+1];
    int dpTable[n+1];
    for(int index=1; index<=n; index++) scanf("%d",&h[index]);
    dpTable[1] = 0;
    dpTable[2] = abs(h[2] - h[1]);

    for(int i=3; i<=n; i++){
        absValue1 = dpTable[i-1] + abs(h[i-1] - h[i]);
        absValue2 = dpTable[i-2] + abs(h[i-2] - h[i]);
        dpTable[i] = getMin(absValue1, absValue2);
    }
    /*dpTable表示*/
    printf("%d",dpTable[n]);
}

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

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

const int N = 100 * 1000 + 5;

vector <int> adj[N];

int t[N];
int d[N];
int c[N];
int dp[N][12];
int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	int q;
	cin >> q;
	for (int i = 1; i <= q; i++) {
		cin >> t[i] >> d[i] >> c[i];
		dp[t[i]][d[i]] = max(dp[t[i]][d[i]], i);
	}
	for (int j = 9; j >= 0; j--) {
		for (int i = 1; i <= n; i++) {
			dp[i][j] = max(dp[i][j + 1], dp[i][j]);
			for (auto u : adj[i]) {
				dp[i][j] = max(dp[i][j], dp[u][j + 1]);
			}
		//	cout << i << " " << j << " " << dp[i][j] << endl;
		}
	}
	for (int i = 1; i <= n; i++) {
		cout << c[dp[i][0]] << endl;
	}
	return 0;
}


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

int main(){
    int x;
    cin>>x;
    ll ans=0;
    ll maxv=1;
    for(int i=1;i<x;i++){
        for(int j=2;j<11;j++){
            ans=pow(i,j);
            if(x>=ans) maxv=max(maxv,ans);
            //cout<<ans<<" "<<i<<" "<<j<<"\n";}

            else break;
        }
    }
    cout<<maxv<<"\n";
    return 0;
}

Measured memory_bytes: 3988
#include <bits/stdc++.h>
#define int long long
#define ll long long 
#define rep(i,a,b) for(signed i=a;i<(b);++i)
#define erep(i,a,b) for(signed i=a;i<=(b);++i)
#define per(i,a,b) for(signed i=(a);i>(b);--i)
#define eper(i,a,b) for(signed i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define pb emplace_back
#define mp make_pair
#define ALL(x) begin(x),end(x)
#define F first
#define S second
#define debug(x)  cout << #x << ": " << (x) << '\n';
const long long INF=1001001001001001001;
const int MOD=(int)1e9 + 7;
const double EPS=1e-9;
using namespace std;
using Pii = pair<int,int>;
using vii = vector<int>;
template<class T>using  PS_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>using vv = vector<T>;
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 (b<a) { 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 );}
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> ostream& operator<<(ostream &os,const vector<vector<T> > &v) {
    ITR(u,begin(v),end(v))ITR(w,begin(*u),end(*u))os<<*w<<(w==end(*u)-1?"\n":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct edge { int from, to, cost; };
int dy[]={0, 1, -1, 0}; int dx[]={1, 0, 0, -1};
// cout << fixed << setprecision(10) << val;

int N, K;

void pnode(int i, int j) {
  cout << i << " " << j << endl;
}

signed main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  cin >> N >> K;
  int M = (N - 1) * (N - 2) / 2 - K;
  if (M < 0) {
    cout << -1 << endl;
    return 0;
  }
  cout << M + N - 1 << endl;
  erep(i, 2, N) pnode(1, i);
  rep(i, 2, N) erep(j, i+1, N) {
    if (M) pnode(i, j);
    else return 0;
    M--;
  }
}




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

int N, M, R, d[200][200], r[8], ans = INT_MAX;
bool used[8];

void dfs(int cnt, int las, int dis) {
  if (cnt >= R) {
    if (ans > dis) ans = dis;
    return;
  }
  for (int i=0; i<R; i++) {
    if (!used[i]) {
      used[i] = true;
      if (las == -1) dfs(cnt+1, i, 0);
      else dfs(cnt+1, i, dis + d[r[las]][r[i]]);
      used[i] = false;
    }
  }
  return ;
}

int main() {
  cin >> N >> M >> R;
  for (int i=0; i<R; i++) {
    cin >> r[i];
    r[i]--;
  }
  int A, B, C;
  for (int i=0; i<N; i++)
    for (int j=0; j<N; j++)
      d[i][j] = INF;
  for (int i=0; i<N; i++)
    d[i][i] = 0;
  for (int i=0; i<M; i++) {
    cin >> A >> B >> C;
    A--;
    B--;
    if (d[A][B] > C) d[A][B] = d[B][A] = C;
  }
  for (int k=0; k<N; k++)
    for (int i=0; i<N; i++)
      for (int j=0; j<N; j++)
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  for (int i=0; i<R; i++)
    used[i] = false;
  dfs(0, -1, 0);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b)) < EPS)
using namespace std;
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

struct Point{
  double x,y;
  Point(){}
  Point(double x,double y) :x(x),y(y){}
  Point operator + (Point p) {return Point(x+p.x,y+p.y);}
  Point operator - (Point p) {return Point(x-p.x,y-p.y);}
  Point operator * (double k) {return Point(x*k,y*k);}
  Point operator / (double k) {return Point(x/k,y/k);}
  double norm(){return x*x+y*y;}
  double abs(){return sqrt(norm());}
  bool operator < (const Point &p) const{
    return x!=p.x ? x < p.x : y < p.y;
  }

  bool operator == (const Point &p) const{
    return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
  }
};

typedef Point Vector;
typedef vector<Point> Polygon;

struct Segment{
  Point p1,p2;
  Segment(){}
  Segment(Point p1, Point p2):p1(p1),p2(p2){}
};
typedef Segment Line;

double norm(Vector a){
  return a.x*a.x+a.y*a.y;
}
double abs(Vector a){
  return sqrt(norm(a));
}
double dot(Vector a,Vector b){
  return a.x*b.x+a.y*b.y;
}
double cross(Vector a,Vector b){
  return a.x*b.y-a.y*b.x;
}

int ccw(Point p0,Point p1,Point p2){
  Vector a = p1-p0;
  Vector b = p2-p0;
  if(cross(a,b) > EPS) return COUNTER_CLOCKWISE;
  if(cross(a,b) < -EPS) return CLOCKWISE;
  if(dot(a,b) < -EPS) return ONLINE_BACK;
  if(a.norm()<b.norm()) return ONLINE_FRONT;
  return ON_SEGMENT;
}

bool intersect(Point p1,Point p2,Point p3,Point p4){
  return (ccw(p1,p2,p3)*ccw(p1,p2,p4) <= 0 &&
	  ccw(p3,p4,p1)*ccw(p3,p4,p2) <= 0 );
}

bool intersect(Segment s1,Segment s2){
  return intersect(s1.p1,s1.p2,s2.p1,s2.p2);
}

Point getCrossPoint(Segment s1,Segment s2){
  Vector base=s2.p2-s2.p1;
  double d1=fabs(cross(base,s1.p1-s2.p1));
  double d2=fabs(cross(base,s1.p2-s2.p1));
  double t=d1/(d1+d2);
  return s1.p1+(s1.p2-s1.p1)*t;
}

int main(){
  int n;
  while(cin>>n,n){
    vector<Segment> vs;
    vector<Point> vc;
    int i,j,k,ans=1,f;
    Point p1,p2,c;
    for(i=0;i<n;i++){
      cin>>p1.x>>p1.y>>p2.x>>p2.y;
      Segment s=Segment(p1,p2);
      for(j=0;j<vs.size();j++){
	if(!intersect(s,vs[j])) continue;
	c=getCrossPoint(s,vs[j]);
	f=(equals(c.x,100.0)||equals(c.x,-100.0)||equals(c.y,100.0)||equals(c.y,-100.0));
	for(k=0;k<vc.size();k++) f|=(vc[k]==c);
	if(!f) vc.push_back(c);
      }
      ans+=vc.size()+1;
      vc.clear();
      vs.push_back(s);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

int n, q;
string s, t[200000], d[200000];

bool f(int p) {
	p--;
	inc(i, q) {
		if(s[p] == t[i][0]) {
			if(d[i] == "L") { p--; } else { p++; }
		}
		if(p == -1) { return true; }
		if(p == n) { return false; }
	}
	return false;
}

bool g(int p) {
	inc(i, q) {
		if(s[p] == t[i][0]) {
			if(d[i] == "L") { p--; } else { p++; }
		}
		if(p == -1) { return false; }
		if(p == n) { return true; }
	}
	return false;
}

int main() {
	cin >> n >> q >> s;
	inc(i, q) { cin >> t[i] >> d[i]; }
	
	int x1;
	{
		int L = 0, H = n + 1;
		while(H - L > 1) {
			int M = (L + H) / 2;
			(f(M) ? L : H) = M;
		}
		x1 = L;
	}
	
	int x2;
	{
		int L = -1, H = n;
		while(H - L > 1) {
			int M = (L + H) / 2;
			(g(M) ? H : L) = M;
		}
		x2 = H;
	}
	
	// cout << "x1: " << x1 << endl;
	// cout << "x2: " << x2 << endl;
	
	cout << x2 - x1 << endl;
	
	return 0;
}


Measured memory_bytes: 22276
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import bisect
 
def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

K = read()

N = 50
print(N)
q, r = divmod(K, N)
ans = [q + 2 * N - r] * r + [q + N-1 - r] * (N - r)
print(' '.join(str(a) for a in ans))

Measured memory_bytes: 38384
from collections import defaultdict

#A,B=map(inr,input().split())
#a=list(map(int,input().split()))
from bisect import bisect_left as bl
from bisect import bisect_right as br
from math import log

from fractions import gcd
import sys
input=sys.stdin.readline

N,M=map(int,input().split())
def prime_factor(n):
    i = 2
    table = defaultdict(int)
    while i * i <= n:
        while n % i == 0:
            n //= i
            table[i]+=1
        i += 1
    if n > 1:
        table[n]+=1
    return table
table=prime_factor(M)
l=[1]
l_=[]
for i,j in table.items():
    for m in range(1,j+1):
        l_.extend([k*i**m for k in l])
    l.extend(l_)
    l_=[]
a=M
for L in l:
    if L>=N:
        a=min(a,L)
print(M//a)


Measured memory_bytes: 64108
#include<stdio.h>
int main(){
    int a,b,c,reg;
    scanf("%d%d%d",&a,&b,&c);
    if(a>b){
        reg = a; a = b; b = reg;
    }
    if(b>c){
        reg = b; b = c; c = reg;
    }
    if(a>b){
        reg = a; a = b; b= reg;
    }
    printf("%d %d %d\n",a,b,c);
    return 0;
}


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

namespace B___Palindromic_Numbers
{
    class Program
    {
        static void Main(string[] args)
        {
            var A_B = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var A = A_B[0];
            var B = A_B[1];
            int cnt = 0;

            for (int i = A; i <= B; i++)
            {
                if (i - int.Parse(new string(i.ToString().Reverse().ToArray())) == 0)
                    cnt++;
            }

            Console.WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 17472