akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int K = sc.nextInt();
    int N = sc.nextInt();
    int[] A = new int[N];

    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
    }
    int max = 0 ;

    for (int i = 0; i < N -1 ; i++) {
      int tmp = (A[i +1] - A[i]);
      // System.out.println(A[i]); 
      if(tmp >= max){
        max = tmp;
        }
      // System.out.println(max); 
      }
    int tmp2 = (K - A[N-1]) + A[0];
    if(tmp2 > max){
      max = tmp2;
    }
    System.out.println(K - max);   
    return;
  }
}



Measured memory_bytes: 80472
#include <cstdio>
const int MAXN = 5005, mod = 1e9 + 7;
inline int addmod(int a, int b) { return (a + b) % mod; }
int n, k, a[MAXN];
int cnt[MAXN * 2];
int main() {
	scanf("%d%d", &n, &k);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	cnt[0] = 1;
	for(int i = 0; i < n; i++) {
		for(int j = 2 * k - a[i]; j >= 0; j--) cnt[j + a[i]] = addmod(cnt[j + a[i]], cnt[j]);
	}
	int ans = n;
	for(int i = 0; i < n; i++) {
		if(a[i] >= k) ans--;
		else {
			for(int j = a[i]; j <= 2 * k; j++) cnt[j] = addmod(cnt[j], mod - cnt[j - a[i]]);
			for(int j = k - a[i]; j < k; j++) if(cnt[j] > 0) {
				ans--;
				break;
			}
			for(int j = 2 * k - a[i]; j >= 0; j--) cnt[j + a[i]] = addmod(cnt[j + a[i]], cnt[j]);
		}
	}
	printf("%d\n", ans);
	return 0;
}

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


int main(){

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

    if( abs(a - c) <= d || ( abs(a-b) <=d && abs(b-c) <= d ) ) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;

}

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

int main(){
    string N;
    int K;
    cin >> N >> K;
    int sz = N.size();
    static int64_t dp[102][5][2];
    dp[0][0][0] = 1;
    for(int i=0; i<sz; i++) for(int j=0; j<=K; j++) for(int k=0; k<2; k++){
        for(int l=0; l<10; l++){
            int c = N[i]-'0';
            if(k == 0 && l > c) continue;
            dp[i+1][j+(l>0)][k|(l<c)] += dp[i][j][k];
        }
    }
    int64_t ans = 0;
    for(int k=0; k<2; k++) ans += dp[sz][K][k];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
using namespace std;
inline ll read(){
    ll f=1,x=0;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//******head by yjjr******
const int maxn=1e6+6,mod=1e9+7;
int n,a[maxn];
ll inv[maxn],fac=1,ans;
int main(){
    n=read();
    rep(i,1,n)a[i]=read();
    inv[1]=1;
    rep(i,2,n)inv[i]=inv[mod%i]*(mod-mod/i)%mod;
    rep(i,1,n)inv[i]=(inv[i]+inv[i-1])%mod;
    rep(i,1,n)ans=(ans+inv[n-i+1]*a[i]%mod+(inv[i]-1)*a[i]%mod)%mod;
    rep(i,2,n)fac=fac*i%mod;
    cout<<(1ll*fac*ans)%mod<<endl;
    return 0;
}

Measured memory_bytes: 5120
#include <iostream>
#include <vector>


using namespace std;

int main(void)
{
    vector<string> s;
    int a, b, c;
    cin >> a >> b >> c;
    if(a==b && b!=c){
        cout << "Yes" << endl;
    }
    else if(b==c && c!=a){
        cout << "Yes" <<endl;
    }
    else if(c==a && a!=b){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
inp = list(map(int, input().split()))

A = inp[0]
B = inp[1]
K = inp[2]

# 約数を求める
yakusuu_a = []
yakusuu_b = []

for i in range(1,A+1):
    if A % i == 0:
        yakusuu_a.append(i)

for i in range(1,B+1):
    if B % i == 0:
        yakusuu_b.append(i)

c = []
for i in yakusuu_a:
  if i in yakusuu_b:
    c.append(i)

c.sort(reverse=True)
if len(c) == 0:
  print(1)
else:
  print(c[K-1])

Measured memory_bytes: 3064
import java.util.*;
public class Main {
	static int p = 1000000007;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int x = sc.nextInt();
		int y = sc.nextInt();
		
		int m = (x+y)/3;
		int n =  y-m;
		if((x+y) % 3 != 0 || m < n || n < 0)
			System.out.println(0);
		else{
			long[] mm = new long[1000005];
			long[] nn = new long[1000005];
			
			mm[0] = 1;
			for(int i=1;i<mm.length;i++){
				mm[i] = mm[i-1] * i % p;
			}

			nn[0] = 1;
			nn[1] = 1;
			for(int i=2;i<nn.length;i++){
				nn[i] = nn[i-1] * fp(i, p-2) % p;
			}
			
			System.out.println(mm[m] * nn[n] % p * nn[m-n] % p);
		}
	}
	static long fp(int a, int k){
		
		if(k == 0)
			return 1;
		
		long num = fp(a, k/2);
		if(k % 2 != 0)
			return a * num % p * num % p;
		else
			return num * num % p;
	}
}

Measured memory_bytes: 40276
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  # 最後に食べたら勝ち
  # 1を引けば勝ち
  # 奇数調整をする
  # 相手に全て偶数を与えるよう調整する
  # all偶数だと負け

  n=I()
  f=False
  for _ in range(n):
    if I()%2==1:
      f=True
  if f:
    return 'first'
  return 'second'

# main()
print(main())


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

int main() {
  int Ans = 0;  // 回答：

  int X; cin >> X;  // 元の金額

  int M500=0; // 500円玉の枚数
  int M5  =0; // 5円玉の枚数

  M500 = X / 500;
  M5 = ( X - (500 * M500 ) ) / 5;

  Ans = M500 * 1000 + M5 * 5;
  
  cout << Ans << endl;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

typedef long long LL;
typedef unsigned long UL;

using namespace std;


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

	vector<int> a(5, 0);
	int sum = 0;

	REP(i, 5)
	{
		cin >> a[i];
		sum += a[i];
		a[i] = (130 - a[i]) % 10;
	}

	sort(a.begin(), a.end());

	cout << sum + a[0] + a[1] + a[2] + a[3] << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N = 200010 , LOG = 19;

int n , arr[N];
map < int , bool > idx;
int main(){
	scanf("%d",&n);
	for(int i = 0 ;i < n;i++){
		scanf("%d",&arr[i]);
		idx[arr[i]] = i & 1;
	}
	sort(arr,arr+n);
	int ans = 0;
	for(int i = 0 ;i < n;i++){
		if(idx[arr[i]] != (i & 1)){
			ans++;
		}
	}
	ans /= 2;
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5376
#input
A = list(input())
#print(A)
##    print(A[i],end = "")
#print(len(A))
sum = 0
#Stack
Stack1 = [] #各水たまりの面積
Stack2 = [] #
for i in range(len(A)):
    if A[i] == "\\":
        Stack1.append(i)
    elif A[i] == "/":
        if Stack1 != []:
            ip = Stack1.pop()
            tmp_sum = i-ip
            sum += i-ip

            xp, yp = ip,tmp_sum

            #-----------------------#
            if Stack2 == []:
                Stack2.append((i, tmp_sum))
            #-----------------------
            else:

                x, y = Stack2.pop()
                # x < ip(xp)
                while ( x- xp >= 0):
                    yp = y + yp
                    if Stack2 == []:
                        xp = x
                        Stack2.append((xp, yp))
                        break
                    else:
                        x, y = Stack2.pop()
                    #Stack2.append((xp, y + yp))
                else:
                    Stack2.append((x, y))
                    Stack2.append((xp, yp))

#print(Stack2)
print(sum)
if sum == 0:
    print(0)
else:
    print(len(Stack2), end=' ') #k
    for i in range(len(Stack2)):
        x, y = Stack2[i]
        if i < len(Stack2)-1:
            print(y, end=' ')
        else:
            print(y)


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

int main() {
  int64_t N;
  cin>>N;
  int64_t Z=0;
  for(int64_t i=2;i<=1000000;i++){
    if(N%i==0){
      int a=0,b=1;
      while(N%i==0){
        a++;
        N/=i;
        if(a*2==b*(b+1)){
          b++;
        }
      }
      Z+=b-1;
    }
    if(N==1){
      break;
    }
  }
  if(N!=1){
    Z++;
  }
  cout<<Z<<endl;
    
}

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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);
//const ll mod = 998244353;

ll lcm(ll a, ll b){
    return a / __gcd(a, b) * b;
}

ll f(ll n){
    ll ret=1;
    rep(i,5) ret*=n;
    return ret;
}

int main(void)
{
    ll x;
    cin >> x;
    for(ll i=-1000; i<=1000; i++){
        for(ll j=-1000; j<=1000; j++){
            if(f(i)-f(j) == x){
                printf("%lld %lld\n",i,j);
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3728
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
#include <string.h>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

int a, b, c;

int main(){
  cin >> a >> b >> c;
  if ( a == b && b == c) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 45
typedef long long ll;

int n;
map<string,int> mp;
vector<string> g[MAX_N];
vector<int> G[MAX_N];
int a[MAX_N];
ll S[MAX_N];
int total;
int ans=0;

string change(ll x){
  string res="";
  for(int i=0;i<n;i++){
    if(x>>i&1)res.push_back('1');
    else res.push_back( '0' );
  }
  reverse(res.begin(),res.end());
  return res;
}

void init(){
  total=ans=0;
  mp.clear();
  for(int i=0;i<MAX_N;i++){
    g[i].clear();
    G[i].clear();
  }
}

void solve(int k,int sum,ll bit,ll bit2){
  if(total-sum<=ans)return;
  if(k==n){
    ans=max(ans,total-sum);
    return;
  }
  if(k)solve(k+1,sum+a[k],bit,bit2);
  if((bit>>k)&1)return;
  bit+=(1LL<<k);
  bit2|=S[k];
  if(bit&bit2)return;
  solve(k+1,sum,bit,bit2);
}

int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    init();
    for(int i=0;i<n;i++){
      string str,to;
      int k;
      cin>>str>>a[i]>>k;
      mp[str]=i;
      total+=a[i];
      for(int j=0;j<k;j++){
	cin>>to;
	g[i].push_back(to);
      }
    }
    for(int i=0;i<n;i++){
      S[i]=0;
      for(int j=0;j<(int)g[i].size();j++){
	G[i].push_back(mp[g[i][j]]);
	S[i]+= (1LL<< (G[i].back()));
      }
    }
    solve(0,0,0,0);
    cout<<ans<<endl;
  }  
  return 0;
}

Measured memory_bytes: 1372
def funcion_a(n):
  count = 0
  i = 2
  while i*i <= n:
    count += 1
    j = i + 1
    while i*j <= n:
      count += 2
      j += 1
    i += 1
  return count
  
n = int(input())
answer = funcion_a(n-1) + (n-2)*2 + 1
print(answer)


    

Measured memory_bytes: 9136
#include <bits/stdc++.h>
using namespace std;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
 
typedef long long ll;
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define forr(i, a, b) for(int i = (a); i < (int) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define DBG(x) cerr << #x << " = " << (x) << endl
#define DBGV(v,n) forn(i,n) cout << v[i] << " "; cout << endl
#define esta(x,c) ((c).find(x) != (c).end())
#define RAYA cerr << "===============================" << endl
 
struct item
{
	int w, v;
};

ll knapsack(vector <item> &v, int n, int w)
{
	vector <ll> dp(w+1,0), aux(w+1,0);
	forn(i,n)
	{
		forn(j,w+1)
		{
			aux[j]=dp[j];
			if(j-v[i].w < 0) continue;
			aux[j]=max(aux[j],dp[j-v[i].w]+v[i].v);
		}
		forn(j,w+1) dp[j]=aux[j];
	}
	ll ans = 0;
	forn(i,w+1) ans=max(ans,dp[i]);
	return ans;
}
 
int main()
{ 
	FIN;
	
	#ifdef input
		freopen("test1.txt", "r", stdin);
	#endif
	
	int n, w;
	cin >> n >> w;
	vector <item> v(n);
	forn(i,n) cin >> v[i].w >> v[i].v;
	cout << knapsack(v,n,w) << endl;
	return 0;
}


Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

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

int main() {
	IOS();
	ll n = 1, m = 1;
	while (1) {
		cin >> n >> m;
		if (n * m == 0) break;
		vector<ll> h(n), sh(n + 1, 0), w(m), sw(m + 1, 0);
		map<ll, ll> mp1, mp2;
		for (int i = 0; i < n; i++) {
			cin >> h[i];
			sh[i + 1] = sh[i] + h[i];
		}
		for (int i = 0; i < m; i++) {
			cin >> w[i];
			sw[i + 1] = sw[i] + w[i];
		}
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j <= n; j++) {
				mp1[sh[j] - sh[i]]++;
				//dump(sh[j] - sh[i]);
			}
		}
		for (int i = 0; i < m; i++) {
			for (int j = i + 1; j <= m; j++) {
				mp2[sw[j] - sw[i]]++;
			}
		}
		ll ans = 0;
		for (auto it = mp1.begin(); it != mp1.end(); it++) {
			ans += it->second * mp2[it->first];
			//cout << it->first << " " << it->second << endl;
		}
		dump(ans);
	}

	return 0;
}


Measured memory_bytes: 44812
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<bitset>
using namespace std;
#define rep(i, n) for (long long int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
typedef long long int ll;
typedef long double ld;
const ll INF = (1 << 31);
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
const int MAX = 510000;
const int MOD = 1000000007;
ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
ll MD(ll a) {
    ll temp = a % MOD;
    if (temp < 0) temp += MOD;
    return temp;
}
int main() {
    int n, k; cin >> n >> k; ll sum = 0, t,p;
    int xx[100010]; Fill(xx, 0);
    for (int i = k; i > 0; i--) {
        int x = k / i;
        t = mod_pow(x, n, MOD);
        int j = 2;
        while (j*i <= k) {
            t = MD(t - xx[j * i] % MOD);
            j++;
        }
        xx[i] = t;
    }
    rep(i, k + 1) sum = (sum + xx[i] * i % MOD) % MOD;
    cout << sum << endl;
}

Measured memory_bytes: 4032
#include<bits/stdc++.h>
#define EM 100000000
using namespace std;
using LL = long long;
using P = pair<LL, LL>;
LL LINF = 1e18;
int INF = 1e9;
LL mod = 1e9+7;
using vint = vector<int>;
using vLL = vector<LL>;
using vvint = vector<vector<int>>;
using vvLL = vector<vector<LL>>;
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; }

vint Gused(100010, 0);
vint GGused(100010, 0);
vvint G(100010), GG(100010);
void dfs(int v){
	for(auto g1 : GG[v]){
		if(Gused[g1])	continue;
		Gused[g1] = 1;
		for(auto g2 : G[g1]){
			if(GGused[g2])	continue;
			GGused[g2] = 1;
			dfs(g2);
		}
	}
}
int main(){
	int N, M;
	cin >> N >> M;
	vint K(N+1);
	for(int i = 1;i <= N;i++){cin >> K[i];for(int j = 0;j < K[i];j++){int g;cin >> g;G[g].push_back(i);GG[i].push_back(g);}}
	GGused[1] = 1;
	dfs(1);
	int cnt = 0;
	for(int i = 1;i <= N;i++)	cnt += GGused[i];
	if(cnt == N)	cout << "YES" << endl;
	else 	cout << "NO" << endl;
}  

Measured memory_bytes: 9728
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long ll;


int main() {
    int n; cin >> n;
    string s; cin >> s;
    vector<vector<int>> dp(5005, vector<int>(5005));

    for (int i = n-1; i >= 0; i--)
    {
        for (int j = n-1; j >= 0; j--)
        {
            if(s[i] == s[j]) {
                dp[i][j] = dp[i+1][j+1] + 1;
            } else {
                dp[i][j] = 0;
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if(i >= j) continue;
            int now = min(dp[i][j], j-i);
            ans = max(ans, now);
        }
        
    }
    cout << ans << endl;
    
    return 0;
}

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

int main(){
    int n,m,x;
    cin>>n>>m>>x;
    vector<int> c(n);
    int a[n][m];
    rep(i, n){
        cin>>c[i];
        rep(j, m) cin>>a[i][j];
    }
    int ans = 1001001001;
    for (int i=0; i < (1<<n); i++){  //bit全探索 
        int temp_c = 0;
        vector<int> temp_a(n, 0);
        rep (j, n){ //j番目の本
            if (i & (1<<j)) {
                temp_c += c[j];
                rep(k, m){ //k番目のアルゴリズム
                    temp_a[k] += a[j][k];
                }
            }
            bool flag = true;
            rep(l, m){
                if (temp_a[l] < x) flag = false;
            }
            if(flag) ans = min(ans, temp_c);
        }
    }
    if(ans==1001001001) ans = -1;
    cout<<ans<<endl;
}

Measured memory_bytes: 3636
use proconio::input;

#[allow(non_snake_case)]
fn main() {
    input! {
        N: usize,
        A: [u64; N]
    }

    let M: u64 = 1_000_000_007;

    let mut ans = 0;
    let mut cum = 0;
    for a in A.iter().rev() {
        ans = (ans % M + (a * cum) % M) % M;
        cum = (cum % M + a % M) % M;
    }

    println!("{}", ans % M);
}


Measured memory_bytes: 5588
/*In the name of Allah*/
#include <bits/stdc++.h>
using namespace std;
#define inf 1000000111
#define MAX 105
#define mod 1000000007
#define ll long long
int mat[MAX][MAX];
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n,k,edge;
	cin>>n>>k;
	int temp = (n - 1) * (n - 2) / 2;
	if(temp < k)return cout<<-1, 0;
	edge = n - 1;
	for(int i = 1 ;i <= n; i++){
		mat[n][i] = 1;
		mat[i][n] = 1;
	}
	if(temp == k){
		cout<<edge<<endl;
		for(int k = 1 ; k <= n ;k ++){
			for(int t = k + 1; t <= n ; t++){
				if(mat[k][t])cout<<k<<" "<<t<<endl;
			}
		}
		return 0;
	}

	for(int i = 1; i < n; i++){
		for(int j = i + 1 ; j < n ;j ++){
			mat[i][j] = 1;
			mat[j][i] = 1;
			temp --;
			edge++;
			if(temp == k){
				cout<<edge<<endl;
				for(int k = 1 ; k <= n ;k ++){
					for(int t = k + 1; t <= n ; t++){
						if(mat[k][t])cout<<k<<" "<<t<<endl;
					}
				}
				return 0;
			}
		}
	}
	return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll mod = 1e9+7;
int inf = 1000000000; //10e9
 
int main() {

    vector<vector<int>> A(3, vector<int>(3));
    rep(i,3) rep(j,3) cin >> A[i][j];
    int N;
    cin >> N;
    vector<int> B(N);
    rep(i,N) cin >> B[i];
    bool ok[3][3];

    rep(i,3){
        rep(j,3){
            ok[i][j] = false;
            rep(k,N){
                if(A[i][j]==B[k]){
                    ok[i][j] = true;
                }
            }
        }
    }

    string ANS = "No";

    rep(i,3){
        if(ok[i][0] && ok[i][1] && ok[i][2]){
            ANS = "Yes";
            break;
        }
        if(ok[0][i] && ok[1][i] && ok[2][i]){
            ANS = "Yes";
            break;
        }
    }
    if(ok[0][0] && ok[1][1] && ok[2][2]){
        ANS = "Yes";
    }
    if(ok[0][2] && ok[1][1] && ok[2][0]){
        ANS = "Yes";
    }
    
    cout << ANS <<endl;

    return 0;

}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 100005;

/* ...o(^-^)o... */
int c[13];

int main(){
    int n; cin >> n;
    vector<int> d;
    rep(i, n){
        int x; cin >> x; c[x]++;
    }

    lint M = pow(2, 11);
    int res = 0;
    rep(k, M){
        int l = k;
        vector<int> e;
        if(c[0]) break;
        e.push_back(0); e.push_back(24);
        if(c[12]) e.push_back(12);

        bool brk = false;
        repn(i, 11){
            if(!c[i]) continue;
            int m = l % 2; l /= 2;
            if(c[i] == 1){
                if(m == 0) e.push_back(i);
                else if(m == 1) e.push_back(24-i);
            }
            else if(c[i] == 2){
                e.push_back(i); e.push_back(24-i);
            }
            else{ brk = true; break; }
        }
        if(brk) continue;

        sort(all(e));
        int gap = 30;
        rep(i, e.size()-1) gap = min(gap, abs(e[i]-e[i+1]));
        res = max(res, min(gap, 24-gap));
    }
    out(res);
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

int main(){
	int i, j, n, a, b, a_min, b_min;

	scanf("%d", &n);

	scanf("%d%d", &a_min, &b_min);
	for (i = 1; i < n; i++) {
		scanf("%d%d", &a, &b);
		
		if (a > a_min) {
			a_min = a;
			b_min = b;
		}
	}
	printf("%d\n", a_min + b_min);

	return 0;
}


Measured memory_bytes: 128
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int zero_inc[] = {0,1,2,3,4,5,6,7,8,9};
		int not_zero_inc[] = {1,2,3,4,5,6,7,8,9};
		
		while(sc.hasNextLine()){
			String ex[] = sc.nextLine().split("[+=]");
			
			boolean zero_ok = true;
			for(String tmp : ex){
				if(tmp.startsWith("X", 0) && tmp.length() >= 2){
					zero_ok = false;
					break;
				}
			}
			
			int ok_num = -1;
			for(int i : zero_ok ? zero_inc : not_zero_inc){
				BigInteger a = new BigInteger(ex[0].replaceAll("X", i+""));
				BigInteger b = new BigInteger(ex[1].replaceAll("X", i+""));
				BigInteger c = new BigInteger(ex[2].replaceAll("X", i+""));
				
				if(a.add(b).equals(c)){
					ok_num = i;
					break;
				}
			}
			
			System.out.println((ok_num != -1 ? ok_num+"" : "NA"));
		}
	}
}

Measured memory_bytes: 12000
import java.util.Scanner;
import java.util.Arrays;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[][] c = new int[3][3];
        for(int i = 0;i < 3;i++){
            for(int j = 0;j < 3;j++){
                c[i][j] = sc.nextInt();
            }
        }
        int[] a = new int[3];
        int[] b = new int[3];
        for(int i = 0;i <= 100;i++){
            a[0] = i;
            for(int j = 0;j < 2;j++){
                b[j] = c[0][j] - a[0];
            }
            a[1] = c[1][0] - b[0];
            a[2] = c[2][0] - b[0];
            if(infomation(a,b,c)){
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
    public static boolean infomation(int[] a,int[] b,int[][] c){
        for(int i = 0;i < 3;i++){
            for(int j = 0;j < 3;j++){
                if(a[i] + b[j] != c[i][j]){
                    return false;
                }
            }
        }
        return true;
    }
}


Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m;
int read(){
	int num = 0, flag = 1; char c = getchar();
	for(; c < '0' || c > '9'; c = getchar())
		if(c == '-') flag = 0;
	for(; c >= '0' && c <= '9'; c = getchar())
		num = (num<<3)+(num<<1)+c-48;
	return flag ? num : -num;
}

void work_1(int x){
	if(x == 1) printf("1");
	else printf("%d",x-2);
	exit(0);
}

int main(){
	n = read(); m = read();
	if(n == 1) work_1(m);
	if(m == 1) work_1(n);
	printf("%lld",1LL * (n - 2) * (m - 2));
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")  
#pragma GCC target("avx,avx2,fma") 
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MOD=1e9+7;
template <class Q>
void clearQueue(Q & q) {
    q=Q();
}
void solve(){
	int a,b,c,d;cin>>a>>b>>c>>d;
	int p1=a*c;
	int p2=a*d;
	int p3=b*c;
	int p4=b*d;
	cout<<max({p1,p2,p3,p4});
}	
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL); 
//#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
//#endif
	int T=1;
	// cin>>T;
	while(T--){
		solve();
	}
}

Measured memory_bytes: 3664
#include <stdio.h>

int main(){
	int a, b;
	scanf("%d%d", &a, &b);
	if(a <= 0 && 0 <= b){
		printf("Zero\n");
	}
	else if(a > 0){
		printf("Positive\n");
	}
	else if((b - a) % 2 == 0){
		printf("Negative\n");
	}
	else{
		printf("Positive\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cstdio>

#define int long long
#define macrocat_impl(a, b) a##b
#define macrocat(a, b) macrocat_impl(a, b)
#define dotimes_impl(i, n, x) for (int i = 0, x = n; i < x; i++)
#define dotimes(i, n) dotimes_impl(i, (n), macrocat(dotimes_n_, __COUNTER__))

using namespace std;

int rint() {
  int n;
  scanf("%lld", &n);
  return n;
}

void wint(int n) {
  printf("%lld\n", n);
}

template<typename T>
inline int size(T container) {
  return static_cast<int>(container.size());
}

signed main() {
  int H = rint();
  int W = rint();
  int c[10][10];
  dotimes(i, 10)
    dotimes(j, 10)
      c[i][j] = rint();
  dotimes(k, 10)
    dotimes(i, 10)
      dotimes(j, 10)
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
  int r = 0;
  dotimes(i, H)
    dotimes(j, W) {
      int a = rint();
      if (a >= 0 && a != 1)
        r += c[a][1];
    }
  wint(r);
  return 0;
}


Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
//#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//ここまでテンプレ
int main(){
	ll A,B,C;
	cin>>A>>B>>C;
	ll K;
	cin>>K;
	if(abs(A-B)>(ll)1e18)
		cout<<"Unfair"<<endl;
	else if(K%2==0)
		cout<<A-B<<endl;
	else
		cout<<B-A<<endl;

	/*
	for(int i=0;i<K;i++){
		ll a,b,c;
		a=(B+C);
		b=(C+A);
		c=(A+B);
		A=a;
		B=b;
		C=c;
		cout<<A<<" "<<B<<" "<<C<<endl;
	}
	*/
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
   long n,rem;
   int sum=0;
   cin>>n;
   long tem=n;
   while(n)
    {
        rem=n%10;
        sum+=rem;
        n/=10;
    }
    if(tem%sum==0)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }

   return 0;
}


Measured memory_bytes: 3576
module Main where

import Data.Functor

main :: IO ()
main = do
  { [a, b] <- getInts
  ; if a < b then putStrLn "a < b"
    else if a > b then putStrLn "a > b"
         else putStrLn "a == b"
  }

getInts :: IO [Int]
getInts = map read . words <$> getLine

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

int main(){
	int n,i;
	cin >> n;
	vector<int> a(n);
	map<int,long long> cnt;
	
	for(i=0;i<n;i++)
	{
		cin >> a[i];
		cnt[a[i]]++;
	}
	
	long long ret=0;
	map<int,long long>::iterator p;
	
	for(p=cnt.begin();p!=cnt.end();p++){
		ret+=(p->second-1)*p->second/2;
	}
	
	for(i=0;i<n;i++)
	{
	    long long n=cnt[a[i]];
	    long long tmp=ret-(n-1)*n/2+(n-1)*(n-2)/2;
	    cout << tmp <<"\n";
	}
	
	return 0;
}

Measured memory_bytes: 10240
N,M,K = map(int,input().split())
import bisect
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
sa = [0]*(N+1)
lim = N
for i in range(N):
    sa[i+1] = sa[i] + A[i]
    if sa[i+1] > K:
        lim = i
        break

sb = [0]*(M+1)
for i in range(M):
    sb[i+1] = sb[i] + B[i]
sb = sb[1:]

# print(sa)
# print(sb)

for reada in range(lim+1): # Nまで読む
    temp = sa[reada]
    # print(K-temp)
    cand = bisect.bisect_right(sb,K-temp)
    # print(reada, cand + reada,cand)
    ans = max(ans,cand + reada)
print(ans)

Measured memory_bytes: 42272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
double pi = 3.14159265359;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
    int n;
    cin >> n;
    int a[n], b[n];
    rep (i, 0, n) cin >> a[i] >> b[i];
    sort (a, a + n);
    sort (b, b + n);
    if (n % 2 == 1) {
        cout << b[n / 2] - a[n / 2] + 1 << "\n";
    } else {
        cout << b[n / 2] + b[n / 2 - 1] - (a[n / 2] + a[n / 2 - 1]) + 1 << "\n";
    }
}


Measured memory_bytes: 5188
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while (scan.hasNextInt()) {
            int n = scan.nextInt();
            int z = 0;

            for (int a = 0; a < 10; a++) {
                for (int b = 0; b < 10; b++) {
                    for (int c = 0; c < 10; c++) {
                        for (int d = 0; d < 10; d++) {
                            if (a + b + c + d == n) {
                                z++;
                            }

                        }
                    }
                }
            }
            System.out.println(z);

        }

    }
}



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


int main() {
  int X, A, B, C; cin >> A >> B >> C >> X;
  int ans = 0;


  for(int i=0; i<=A; i++){
    for(int j=0; j<=B; j++){
      for(int k=0; k<=C; k++){
        if(500*i+100*j+50*k == X) ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
/*
  Author: @yash_31
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
#define ll long long int
#define eb emplace_back
#define fatafat ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
#define ft first
#define sd second
#define mkpr make_pair
#define deb(x) std::cout<<#x<<":"<<x<<endl;
#define whole(x) (x).begin(),(x).end()
#define revwhole(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define fbo find_by_order
#define ook order_of_key
#define init0(x) memset(x,0,sizeof(x));

using namespace std; 
using namespace __gnu_pbds;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> gharKaSet;
 
const int maxlimit=2e5+2;
const ll inf=1e18;
//TTBDC

ll dp[100005][2];
// 0 -black
bool vis[100005];

void dfs(int s,vector<int> g[]){
  vis[s]=true;
  // leaf node
  if(g[s].size()==1 && s!=1){
    dp[s][0]=dp[s][1]=1;return;
  }
  for(int x:g[s]){
    if(!vis[x]){
      dfs(x,g);
      dp[s][0] = (dp[s][0]*dp[x][1])%MOD;
      dp[s][1] = (dp[s][1]*(dp[x][0]+dp[x][1])%MOD)%MOD;
    }
  }
}

int main()
{
  fatafat
  int n,u,v;
  cin>>n;
  if(n==1){cout<<2;return 0;}
  vector<int> gx[n+1];
  for(int i=0;i<n-1;i++){
    dp[i+1][0]=dp[i+1][1]=1;
    cin>>u>>v;
    gx[u].eb(v);
    gx[v].eb(u);
  }
  dp[n][0]=dp[n][1]=1;
  dfs(1,gx);
  ll ans = (dp[1][1]+dp[1][0])%MOD;
  cout<<ans;
  return 0;
}

Measured memory_bytes: 17600
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	Scanner sc = new Scanner(System.in);
	public void run() {
		while(sc.hasNext()){
			int a = sc.nextInt();
			int b = sc.nextInt();
			int d = sc.nextInt();
			if(a == 0 && b == 0 && d == 0)break;
			else calc(a,b,d);
			
		}
	}
	public void calc(int a, int b, int d){
		int minX = -1;
		int minY = -1;
		
		int sum = 0;
		while(minX == -1){
			for(int i = 0; i <= sum; i++){
				int j = sum - i;
				if(Math.abs(i*a-j*b) == d || i*a+j*b == d){
					if(minX == -1 || i*a+j*b < minX*a+minY*b){
						minX = i;
						minY = j;
					}
				}
			}
			sum++;
		}
		
		System.out.println(minX + " " + minY);
	}

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

Measured memory_bytes: 20156
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin>>S;
  int count=0;
  for(int i=0;i<S.size()/2;i++){
  	if(S.at(i)!=S.at(S.size()-1-i))
      count++;
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
n,m,q = map(int,input().split())

abcdl = []
for _ in range(q):
    a,b,c,d = map(int,input().split())
    abcdl.append((a,b,c,d))

cl = []
def dfs(i):
    global cl
    if len(i) == n:
        cl.append(i)
        return
    for j in range(i[-1], m+1):
        dfs(i + [j])


for i in range(1,m+1):
    dfs([i])


ans = 0
for cc in cl:
    tmp = 0
    for a,b,c,d in abcdl:
        if cc[b-1] - cc[a-1] == c:
            tmp += d
    # print(tmp)
    ans = max(tmp, ans)

print(ans)




Measured memory_bytes: 95488
n = int(input())
if n == 2:
    print(-1)
elif n == 3:
    print("aab")
    print("c.b")
    print("cdd")
elif n == 4:
    print("aabc")
    print("ddbc")
    print("efgg")
    print("efhh")
elif n == 5:
    print("abbcc")
    print("a..da")
    print("b..da")
    print("bqq.b")
    print("ccaab")
else:
    if n % 2 == 0:
        r = n // 2
        for i in range(r - 1):
            if i == 0:
                print("a" + "." * (r - 2) + "zz" + "." * (r - 3) + "aa")
            else:
                if i % 2 == 1:
                    print(
                        "." * (i - 1) + "ab" + "." * (n - i * 2 - 3) + "bb" + "." * (i)
                    )
                else:
                    print(
                        "." * (i - 1) + "ba" + "." * (n - i * 2 - 3) + "aa" + "." * (i)
                    )
        if r % 2 == 0:
            print("z" + "." * (r - 3) + "a" + "." * (n - r) + "z")
            print("z" + "." * (n - r) + "a" + "." * (r - 3) + "z")
        else:
            print("z" + "." * (r - 3) + "b" + "." * (n - r) + "z")
            print("z" + "." * (n - r) + "b" + "." * (r - 3) + "z")
        for i in range(r - 2, -1, -1):
            if i == 0:
                print("aa" + "." * (r - 3) + "zz" + "." * (r - 2) + "a")
            else:
                if i % 2 == 1:
                    print(
                        "." * (i) + "bb" + "." * (n - i * 2 - 3) + "ba" + "." * (i - 1)
                    )
                else:
                    print(
                        "." * (i) + "aa" + "." * (n - i * 2 - 3) + "ab" + "." * (i - 1)
                    )
    else:
        r = n // 2
        for i in range(r - 1):
            if i == 0:
                print("a" + "." * (r - 2) + "zz" + "." * (r - 2) + "aa")
            else:
                if i % 2 == 1:
                    print(
                        "." * (i - 1) + "ab" + "." * (n - i * 2 - 3) + "bb" + "." * (i)
                    )
                else:
                    print(
                        "." * (i - 1) + "ba" + "." * (n - i * 2 - 3) + "aa" + "." * (i)
                    )
        if r % 2 == 0:
            print("." * (r - 2) + "a..p" + "." * (r - 2) + "z")
            print("z" + "." * (r - 2) + "..p" + "." * (r - 2) + "z")
            print("z" + "." * (r - 2) + "qq.a" + "." * (r - 2))
        else:
            print("." * (r - 2) + "b..p" + "." * (r - 2) + "z")
            print("z" + "." * (r - 2) + "..p" + "." * (r - 2) + "z")
            print("z" + "." * (r - 2) + "qq.b" + "." * (r - 2))

        for i in range(r - 2, -1, -1):
            if i == 0:
                print("aa" + "." * (r - 2) + "zz" + "." * (r - 2) + "a")
            else:
                if i % 2 == 1:
                    print(
                        "." * (i) + "bb" + "." * (n - i * 2 - 3) + "ba" + "." * (i - 1)
                    )
                else:
                    print(
                        "." * (i) + "aa" + "." * (n - i * 2 - 3) + "ab" + "." * (i - 1)
                    )


Measured memory_bytes: 40944
using System;

namespace test
{
  class Program
  {
  static void Main(string[] args)
  {
    string[] s = Console.ReadLine().Split(' ');
    int x = int.Parse(s[0]);
    int a = int.Parse(s[1]);
    
    if(x<a)
    {
      Console.WriteLine(0);
    }
    else
    {
      Console.WriteLine(10);
    }
    
  }
  }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define Mod 1000000007
#define Max 1000001
 
 
 
 
//void func(){
//    ll n;
//    cin>>n;
//    map<ll, ll>p1;
//    map<ll, ll>p2;
//    for(int i=1;i<=(4*n-1); i++){
//        ll a, b;
//        cin>>a>>b;
//        p1[a]++;
//        p2[b]++;
//    }
//    vector<ll>v;
//    for(auto it=p1.begin(); it!=p1.end(); it++){
//        if(it->second==1){
////            cout<<it->first<<" ";
//            v.push_back((it->first));
////            break;
//        }
//    }
//    for(auto it=p2.begin(); it!=p2.end(); it++){
//        if(it->second==1){
////            cout<<it->first<<endl;
//            v.push_back(it->first);
////            break;
//        }
//    }
//    if(v.size()==2)
//        cout<<v[0]<<" "<<v[1]<<endl;
//    else{
//        
//    }
//}
 
 
void func(){
    ll n;
    cin>>n;
    vector<ll>v(4, 0);
    for(int i=0; i<n; i++){
        string s;
        cin>>s;
        if(s=="AC")
        v[0]+=1;
        else if(s=="WA")
            v[1]+=1;
        else if(s=="TLE")
            v[2]+=1;
        else 
            v[3]+=1;
    }
    cout<<"AC"<<" "<<"x"<<" "<<v[0]<<endl; 
        cout<<"WA"<<" "<<"x"<<" "<<v[1]<<endl;
            cout<<"TLE"<<" "<<"x"<<" "<<v[2]<<endl;
                cout<<"RE"<<" "<<"x"<<" "<<v[3]<<endl;
}
int main(){
 
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
 
 
//int t;
//cin >> t;
//for(ll i=1; i<=t; i++)
//{
    
    func();
//    cout<<endl;
//cout<<func()<<endl;
 
//if(func())
//    cout<<"Yes"<< endl;
//else
//    cout <<"No"<<endl; 
//cout<<"Case:"<<i<<" "<<     <<endl;
//}
 
 
return 0;
}

Measured memory_bytes: 3652
//(・ω・)
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, atoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
#include <stdlib.h>
#include <list>
#include <iterator>//std::advance()
using namespace std;

int main(){
   int n;
   cin >> n;
   if(n%1000==0){
      cout << n%1000 << endl;
   }
   else{
      cout << 1000-(n%1000) << endl;
   }
}



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


using namespace std;
int   main(){
   string s;
   cin>>s;
   if(s[0]=='R'){
        if(s[1]=='R'){
            if(s[2]=='R'){
                cout<<3;
                return 0;
            }else{
                cout<<"2";
                return 0;
            }
        }
        cout<<"1";
        return 0;
   }else{
       if(s[1]=='R'){
           if(s[2]=='R'){
               cout<<"2";
               return 0;
           }else{
               cout<<"1";
               return 0;
           }
       }else{
           if(s[2]=='R'){
               cout<<"1";
               return 0;
               }
               else{
                   cout<<"0";
                   return 0;
               }
       }
      
   }
    return 0;

}

Measured memory_bytes: 3620
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>; // intの2次元の型に vvi という別名をつける
const ll llMAX=9223372036854775807LL; 
const ll llMIN=-9223372036854775808LL;

//mapの使い方
#include <map>
ll n,q;


int main(){
  ll ans=0;

  map<ll,ll> nums_x;
  map<ll,ll> nums_y;
  
  cin >> n >> q;
  ans=(n-2)*(n-2);
  nums_x[n]=n;
  nums_y[n]=n;

  ll a,b;

  REP(i,q) {
    cin>>a>>b;
    if (a==1)
    {
      auto iter=nums_y.upper_bound(b);
      ll doko=iter->second;
      ans-=doko-2;
      //cout<<(doko-2)<<endl;
      if (nums_x.find(doko)!=nums_x.end()){
        b=min(b,nums_x[doko]);
      }
      nums_x[doko]=b;
    }
    else
    {
      auto iter=nums_x.upper_bound(b);
      ll doko=iter->second;
      ans-=doko-2;
      //cout<<(doko-2)<<endl;
      
      if (nums_y.find(doko)!=nums_y.end()){
        b=min(b,nums_y[doko]);
      }
      nums_y[doko]=b;
    }
  }
    
/*
  cout<<endl;
  for (auto elem : nums_y)
  {
    cout<<elem.first<<" "<<elem.second<<endl;
  }
  cout<<endl;
  for (auto elem : nums_x)
  {
    cout<<elem.first<<" "<<elem.second<<endl;
  }
  */  
  cout<<ans<<endl;
  return 0;
}
/*
5 3
1 3
2 3
1 4
*/

Measured memory_bytes: 9732
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        MyScanner scn = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        // Solution Start
        int a = scn.nextInt();
        int b = scn.nextInt();
        int c = scn.nextInt();
        int k = scn.nextInt();
        while (b <= a && k > 0) {
            b *= 2;
            k--;
        }
        while (c <= b && k > 0) {
            c *= 2;
            k--;
        }
        if (a < b && b < c) {
            out.println("Yes");
        } else {
            out.println("No");
        }

        //Solution end
        out.close();
    }


    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;

    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
    //--------------------------------------------------------
}


Measured memory_bytes: 32904
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    int n,k; cin >> n >> k;
    cout << ((n%k == 0) ? 0:1) << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    final Scanner sc = new Scanner(System.in);

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

    private void run() {
        int n = sc.nextInt();
        Map<Long, Long> add = new TreeMap<>();
        long[] arr = new long[n+1];

        for (int i = 1; i <= n; i++) {
            long a = sc.nextLong();
            arr[i] = a;
            add.put(i+a, add.getOrDefault(i + a, 0L)+1);
        }

        long ans = 0;
        for (int i = 1; i <= n; i++) {
            ans += add.getOrDefault(i-arr[i], 0L);
        }
        System.out.println(ans);
    }
}


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

typedef long long int ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<ll, ll> Pair;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mk make_pair
#define out(x) cout << (x) << endl;
#define DU(x) cerr << #x << " = " << (x) << endl;

template <typename _Ty>ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "[]";return ostr;}ostr << "[" << v.front();for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}ostr << "]";return ostr;}

int main() {
    int N;
    ll K;
    VL A, F;

    cin >> N >> K;
    rep(i, N) { int v; cin >> v; A.pb(v); }
    rep(i, N) { int v; cin >> v; F.pb(v); }

    sort(all(A));
    sort(all(F), greater<ll>());
    ll left= 0, right = 0;
    rep(i, N) right = max(right, A[i] * F[i]);
    while(left < right) {
        ll x = (left + right) / 2, k = K;
        bool ok = true;
        rep(i, N) {
            ll time = A[i] * F[i];
            if(x == 13) { DU(A[i]) DU(F[i]) DU(k) }
            ll diff = (ll)ceil((time - x)/(double)F[i]);
            if (time <= x || (k > 0 && diff <= k)) {
                k -= max(0LL, diff);    
            } else {
                ok = false; break;
            }
        }
        if (x == 13) DU(ok)
        if (ok) {
            right = x;
        } else {
            left = x + 1;
        }
    }
    out(right);
    return 0;
}

Measured memory_bytes: 4848