akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;


public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        System.out.println((a - b) < c ? c - a + b : 0);

    }


    static class FastScanner {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

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

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

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


        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}

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

int main(){
	string s,t;
	cin>>s>>t;
	int c=0,m=0,k=s.size()-t.size();
	for(int i=0;i<=k;i++){
		int l=i;
		for(int j=0;j<t.size();j++){
			if(s[i]==t[j]){
				c++;m=max(c,m);
			}
			i++;
		}
		i=l;c=0;
	}
	cout<<t.size()-m;



}

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

int const N = 100000, T = 14348907;
int n, fr[N][16], an, dp[T];
vector<pair<int, int> > tr[N];

void go(int v = 0, int p = -1, int c = 0){
	f(i, 0, tr[v].size()){
		int u = tr[v][i].first;
		if (u == p)continue;
		go(u, v, tr[v][i].second);
		f(j, 1, 16)fr[v][j] += fr[u][j];
	}
	f(i, 1, 16)an += fr[v][i] >> 1, fr[v][i] &= 1;
	int x = 0;
	f(i, 1, 16)if (fr[v][i])x ^= i;
	if (v)++fr[v][x ^ c];
}

int main(){
	scanf("%d", &n);
	f(i, 1, n){
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		tr[a].push_back(make_pair(b, c));
		tr[b].push_back(make_pair(a, c));
	}
	go();
	f(i, 0, T){
		int old = 0, nw = 0, x = 0, t = i, j = 1, th = 2;
		bool br = false;
		while (t){
			int z = t % 3;
			if (z == 1 && fr[0][j] == 0) { br = true; break; }
			if (z == 1)x ^= j;
			++j;
			t /= 3;
			old += (z > 1) * th;
			nw += (z > 0) * th;
			th *= 3;
		}
		if (br || x || old == nw)continue;
		dp[nw] = max(dp[nw], dp[old] + 1);
	}
	int z = dp[T - 1], ff = 0;
	f(i, 1, 16)if (fr[0][i])++ff;
	an += ff - z;
	printf("%d\n", an);
}

Measured memory_bytes: 52352
local s = io.read()
local n = #s
local t = {}
local sstr = ""
for i = 1, n do
  sstr = s:sub(i, i)
  if not t[sstr] then
    t[sstr] = 1
  else
    t[sstr] = t[sstr] + 1
  end
end
local ret = 0
for i = 1, n do
  sstr = s:sub(i, i)
  ret = ret + n - t[sstr]
end
print(1 + math.floor(ret / 2))


Measured memory_bytes: 640
//بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيمِ
//لا إله إلا الله محمد رسول الله

#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")

#define ll long long
#define pb push_back
#define fr first
#define sc second
#define in freopen("input.txt", "r" , stdin)
#define out freopen("snakes.out", "w", stdout)
using namespace std;

ll n, k;
ll h[100005];
ll dp[100005];
int main(){
    //in;
    //out;
    ios_base::sync_with_stdio(false);
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> h[i];
    }

    for (int i = 1; i <= k; i++) dp[i] = abs (h[i] - h[1]);

    for (int i = k + 1; i <= n; i++) {
        dp[i] = 1e18;
        for (int j = i-1; j >= i - k; j--) dp[i] = min (dp[i] , dp[j] + abs (h[i] - h[j]));
    }

    cout << dp[n];
}




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

int main()
{
    int a, b;
    long long m = 1;
    scanf("%d%d", &a, &b);
    for(int i = a; i <= b; i++)
    {
        if(i == 0)
        {
            m = 0;
            break;
        }
        else if(i < 0)
            m = -m;

    }
    if(m == 0)
        printf("Zero");
    else if(m < 0)
        printf("Negative");
    else
        printf("Positive");
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<cmath>
#include<set>
#include<stack>
#define ll long long
#define pb push_back
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)>(y)?(y):(x))
#define cls(name,x) memset(name,x,sizeof(name))
#define pos first
#define index second
#define mp make_pair
using namespace std;
const int inf=1e9+10;
const ll llinf=1e16+10;
const int maxn=3e2+10;
const int maxm=2e5+10;
const int mod=1e9+7;
int n,m;
int dp[maxn][maxn][maxn];//dp[i][j][k]带表R最后出现在i,G最后出现在j,B最后出现在k的方案数
vector<pair<int,int> > v[maxn];
bool check(int posR,int posG,int posB)
{
    int k=max(max(posR,posG),posB);
    for(int i=0;i<v[k].size();i++)
    {
        int l=v[k][i].first;
        int c=v[k][i].second;
        if((posR>=l)+(posG>=l)+(posB>=l)!=c)
            return false;
    }
    return true;
}
int main()
{
    //freopen("in.txt","r",stdin);
    while(~scanf("%d %d",&n,&m))
    {
        cls(dp,0);
        for(int i=1;i<=m;i++)
        {
            int l,r,c;
            scanf("%d %d %d",&l,&r,&c);
            v[r].pb(mp(l,c));
        }
        dp[0][0][0]=1;
        int ans=0;
        for(int i=0;i<=n;i++)
            for(int j=0;j<=n;j++)
                for(int k=0;k<=n;k++)
                {
                    if(dp[i][j][k]==0)//dp[i][j][k]==0代表这种方案不满足题意
                        continue;
                    if(!check(i,j,k))
                    {
                        dp[i][j][k]=0;
                        continue;
                    }
                    int t=max(max(i,j),k)+1;
                    if(t-1==n)
                        ans=(ans+dp[i][j][k])%mod;
                    dp[t][j][k]=(dp[t][j][k]+dp[i][j][k])%mod;
                    dp[i][t][k]=(dp[i][t][k]+dp[i][j][k])%mod;
                    dp[i][j][t]=(dp[i][j][t]+dp[i][j][k])%mod;
                }
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 116608
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1000000007;
const ll MOD = 1000000000000000001;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);


ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b){
  ll r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return b;
}


ll LCM(ll a,ll b){
  ll c=a,d=b,r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return c/b*d;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

vector<pair<char,ll>> runlength(string s,vector<pair<char,ll>> p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
    return p;
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
  return p;
}



/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  string s;
  cin>>s;
  ll n=s.size(),ans=0,num=0;
  rep(i,(1<<(n-1))){
    num=s[0]-'0';
    rep(j,n-1){
      if(i&(1<<j)){
        ans+=num;
        num=0;
      }
      num=num*10+(s[j+1]-'0');
    }
    ans+=num;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 256
#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(){
   ll n,d;
   cin >> n >> d;
   int count = 0;
   for(int i=0;i<n;i++){
      ll p,q;
      cin >> p >> q;
      if(p*p+q*q<=d*d)
         count++;
   }
   cout << count << endl;
   return 0;  
}

Measured memory_bytes: 3592
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    int R, S, P; cin >> R >> S >> P;
    string T; cin >> T;
    int ans = 0;
    rep(i, K) {
        char prev = '0';
        for(int j = i; j < T.length(); j += K) {
            if(prev == '0' || prev != T[j]) {
                if(T[j] == 'r') ans += P;
                if(T[j] == 's') ans += R;
                if(T[j] == 'p') ans += S;
                prev = T[j];
            } else {
                prev = '0';
            }
        }
        //cout << i << " " << ans << endl;
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 512
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var a int
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &a)

	for i := 0; ; i++ {
		a -= 1000
		if a <= 0 {
			break
		}
	}
	fmt.Println(-a)
}


Measured memory_bytes: 1840
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt(),x = scanner.nextInt();
		int[] a = new int[n];
		long count = 0;
		for(int i=0;i<n;i++){
			a[i] = scanner.nextInt();
			if(a[i] > x){
				count += a[i] - x;
				a[i] = x;
			}
		}
		for(int i=1;i<n;i++){
			int y = a[i] + a[i-1];
			if(y > x){
				y = y - x;
				count += y;
				a[i] -= y;
			}
		}
		System.out.println(count);

	}

}


Measured memory_bytes: 51792
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;
using System.IO;

namespace paiza
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = GetInt();
            var A = GetLongs(N);

            long ans = new long();
            ans = 1;

            Array.Sort(A);
            var check = Math.Pow(10, 18);

            for (int i = 0; i < N; i++)
            {
                try
                {
                    checked
                    {
                        ans *= A[i];
                    }
                }
                catch
                {
                    ans = -1;
                    break;
                }
                
                if (ans > (decimal)check)
                {
                    ans = -1;
                    break;
                }

                if (ans == 0)
                {
                    break;
                }
            }

            Console.WriteLine(ans);

            return;
        }

    }
}

public static class MyIO
{
    private static string[] args = null;
    private static int num = -1;
    private static int used = -1;

    private static string getArg()
    {
        if (used == num)
        {
            args = Console.ReadLine().Split(' ');
            num = args.Length;
            used = 0;
        }
        return args[used++];
    }

    public static int GetInt() => int.Parse(getArg());
    public static long GetLong() => long.Parse(getArg());
    public static double GetDouble() => double.Parse(getArg());
    public static string GetString() => getArg();
    public static char GetChar() => getArg()[0];
    public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
    public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
    public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
    public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}

Measured memory_bytes: 42744
#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 dp[3300][3300];

int main() {
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            if (i == 0 || j == 0) {
                dp[i][j] = 0;
                continue;
            }
            dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            if (s[i-1] == t[j-1]) {
                dp[i][j] = max(dp[i-1][j-1] + 1, dp[i][j]);
            }
        }
    }
    string ans;
    while (n > 0 && m > 0) {
        if (dp[n][m] == dp[n-1][m]) n--;
        else if (dp[n][m] == dp[n][m-1]) m--;
        else {
            ans += s[n-1];
            n--;
            m--;
        }
    }
    int sz = ans.size();
    rep(i,sz) {
        cout << ans[sz-i-1];
    }
    cout << endl;
}

Measured memory_bytes: 39168
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int h,w;
	cin>>h>>w;
	string s[1000];
	for(int i=1;i<=h;i++){
		cin>>s[i];
	}
	for(int j=1;j<=h;j++){
		cout<<s[j]<<endl<<s[j]<<endl;
	}
	return 0;
}

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

int n, a[20], res;

int solve(int i, int m) {
    if (m==0) return 1;
    if (i>=n) return 0;
    res = solve(i + 1, m) || solve(i + 1, m - a[i]);
    return res;
}

int main(){
    cin >> n;
    for (int j=0; j<n; j++) {
        cin >> a[j];
    }
    int num, M;
    cin >> M;
    for (int j=0; j < M; j++) {
        cin >> num;
        if (solve(0, num) == 1) {
            cout << "yes" <<endl;
        } else {
            cout << "no" << endl;
        }
    }
    
}


Measured memory_bytes: 3096
#include <iostream>
#include <string>
using namespace std;
int main(void){
    
   int A, B;
   int pow0, pow1, pow2, pow3, pow4;
   int counter;
   
   cin >> A >> B;
   
   counter = 0;
   
   for(int i = A; i <= B; i++){
       
       pow0 = i % 10;
       pow1 = i / 10 % 10;
       pow2 = i / 100 % 10;
       pow3 = i / 1000 % 10;
       pow4 = i / 10000 % 10;
       
       if(pow0 == pow4 && pow1 == pow3) counter++;
       
   }
    
    cout << counter << endl;
    
    return 0;
    
}

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

using namespace std;

int main() {
	string abc = "abcdefghijklmnopqrstuvwxyz";
	string s;
	cin >> s;
	//cout << 3 << endl;
	vector<int> no(26, 0);
	//cout << 2 << endl;
	for (int i = 0; i < s.size(); i++) {
		for (int j = 0; j < abc.size(); j++) {
			if (s[i] == abc[j]) {
				no[j]++;
				break;
			}
		}
	}
	//cout << 1 << endl;
	bool h = true;
	for (int i = 0; i < 26; i++) {
		if (no[i] % 2 == 1) {
			h = false;
			break;
		}
	}
	if (h) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int64_t N, sum = 0, even = 0;
    cin >> N;
    vector<int64_t> A(N), ans(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
        sum += A.at(i);
        if (i % 2 == 1) {
            even += A.at(i);
        }
    }
    ans.at(0) = sum - even * 2;
    for (int i = 0; i < N - 1; i++) {
        ans.at(i + 1) = (A.at(i) - ans.at(i) / 2) * 2;
    }
    for (int i = 0; i < N; i++) {
        cout << ans.at(i) << endl;
    }

}


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


#define F first
#define PB push_back
#define MP make_pair

typedef  long long ll;

ll p = pow(10, 9) + 7;





int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int s, w;
    cin >> s >> w;
    if(s > w){
        cout << "safe" << endl;
    }else{
        cout << "unsafe" << endl;
    }

}


Measured memory_bytes: 3644
// ダイクストラ法
// Dijkstra's Algorithm
// Single Source Shortest Path 1 単一始点最短経路
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <vector>
using namespace std;

static const int MAX = 100;
static const int INF = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

void dijkstra() {

    int minv;
    int d[MAX], color[MAX];

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

    d[0] = 0;
    color[0] = GRAY;

    while (true) {
        minv = INF;
        int u = -1;

        for(int i = 0; i < n; i++) {
            if (minv > d[i] && color[i] != BLACK) {
                u = i;
                minv = d[i];
            }
        }

        if (u == -1) break;

        color[u] = BLACK;

        for(int v = 0; v < n; v++) {
            if (color[v] != BLACK && M[u][v] != INF) {
                if (d[v] > d[u] + M[u][v]) {
                    d[v] = d[u] + M[u][v];
                    color[v] = GRAY;
                }
            }
        }
    }

    for(int i = 0; i < n; i++) {
        cout << i << " " << (d[i] == INF ? -1 : d[i]) << endl;
    }
}

int main() {

    cin >> n;

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

    int k, c, u, v;

    for(int i = 0; i < n; i++) {
        cin >> u >> k;
        for(int j = 0; j < k; j++) {
            cin >> v >> c;
            M[u][v] = c;
        }
    }

    dijkstra();

    return 0;
}



Measured memory_bytes: 3128
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod (ll)1000000007
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, a[25], b[25], c[25];
signed main() {
	cin >> n;
	REP(i, n)cin >> a[i];
	REP(i, n)cin >> b[i];
	REP(i, n - 1)cin >> c[i];
	int ans = 0;
	REP(i, n) {
		ans += b[a[i]];
		if (i && a[i - 1] + 1 == a[i])ans += c[a[i - 1]];
	}
	cout << ans << endl;
}

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

#define ll long long int
#define rep(i,a,n) for(ll i=(a); i<(n); i++)
#define chmin(x,y) {x = min(x,y); }
#define chmax(x,y) {x = max(x,y); }

using namespace std;

signed main() {
	ll N;
	string s;
	cin>>s;	
	N = s.size();
	s = " " + s;
	if (s[1] != '1' || s[N] != '0') {
		cout<<-1<<endl;
		return 0;
	}
	vector<ll> v;
	for (int i=2; i<N; i++) {
		if (s[i] != s[N-i]) {
			cout<<-1<<endl;
			return 0;
		}
		if (s[i] == '1')
			v.push_back(i);
	}
	ll prev_k = 1;
	for (ll k : v) {
		for (int i=prev_k; i<k; i++) {
			cout<<i<<" "<<k<<endl;
		}
		prev_k = k;
	}
	cout<<prev_k<<" "<<N<<endl;
	return 0;
}


Measured memory_bytes: 2416
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
ll llmax = LLONG_MAX;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
vi d1 = {1, 0, -1, 0}, d2 = {0, 1, 0, -1};
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if (s < t) Yes();
  else No();
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		double sum = 0.0;
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			sum += a[i];
		}
		int ave = (int)(sum/n + ((sum/n > 0) ? 0.50 : -0.50));
		int cost = 0;
		for(int i = 0; i < n; i++)
			cost += (a[i] - ave)*(a[i] - ave);
		System.out.println(cost);
	}
}

Measured memory_bytes: 22868
#include <stdio.h>
#include <math.h>

int main(void) {
	int n;
	int i;
	double theta;

	while(1) {
		scanf("%d", &n);
		if(n == -1)
			break;
		for(i = 0, theta = 0; i < n - 1; i++) {
			theta += (double)atan((double)1 / sqrt(i + 1));
		}

		printf("%lf\n%lf\n", sqrt(n) * cos(theta), sqrt(n) * sin(theta));
	}

	return 0;
}

Measured memory_bytes: 692
#include <bits/stdc++.h>
 
#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pi 3.14159265
#define oo 1000000007
#define loo 1000000000000000007
 
using namespace std;
#define prime 1000000007
 
#define W(x) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << "\n";
 
int n, m, v[10] = {0,2,5,5,4,5,6,3,7,6};
pair<ii, int> dp[10100];
ii c[10];
vi ans;
 
pair<ii, int> f(int at){
	if(at < 0) return {{-prime, -prime}, -prime};
	if(at == 0) return {{0, 0}, 0};
	if(dp[at] != mp(mp(-1, -1), -1)) return dp[at];
	pair<ii, int> res =  {{-prime, -prime}, -prime};
	for (int i = 0; i < m; ++i){
		pair<ii, int> aux = f(at-c[i].ff);
                aux.ff.ff++;
                aux.ss = at-c[i].ff;
                aux.ff.ss = c[i].ss;

		if(aux > res){
                     res = aux;
		}
	}
	return dp[at] = res;
}
 
int main(){
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; ++i){
		int x;
		scanf("%d", &x);
		c[i] = {v[x], x};
	}
	sort(c, c+m);
	for (int i = 0; i <= n; ++i){
		dp[i] = {{-1, -1}, -1};
	}
	auto a = f(n);
	int at = n;
	while(at){
		ans.pb(dp[at].ff.ss);
		at = dp[at].ss;
	}
	if(a.ff.ff != (int)ans.size()) while(1);
	sort(ans.begin(), ans.end());
	reverse(ans.begin(), ans.end());
	for(int l : ans) printf("%d", l);
	printf("\n");
 
	return 0;
}


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

class Program
{
    static void Main(string[] args) {
#if DEBUG
        using (var reader = new StreamReader("../TextFile1.txt")) {
            var count = 1; string str;
            while((str=Debugger.ReadBlock(reader))!= null) {
                Debug.WriteLine("----------" + count++ + "----------");
                Debug.WriteLine(process(new StringReader(str)));
            }
        }
        Debug.WriteLine("-----END DEBUG-----");
#endif
#if !DEBUG
        object ret = process(new System.IO.StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static long mod = 1000000007L;

    static object process(TextReader input) {
        var s     = input.ReadLine();
        var spl   = s.Split(' ');
        var n    = int.Parse(spl[0]);
        var k    = int.Parse(spl[1]);

        List<int>[] arrow = new List<int>[n];
        for (int i = 0; i < n; i++) arrow[i] = new List<int>();

        for (int i=0; i<n-1; i++) {
            var tmp = ToIntArray(input.ReadLine(), 2);
            arrow[tmp[0]-1].Add(tmp[1]-1);
            arrow[tmp[1]-1].Add(tmp[0]-1);
        }

        return (k * calc(arrow, 0, -1, k)) % mod;
    }

    static long calc(List<int>[] arrow, int pos, int root, int k) {
        long ret = 1;

        if(root == -1) { 
            ret = Permitation(k-1, arrow[pos].Count);
        } else {
            ret = Permitation(k-2, arrow[pos].Count-1);
        }

        foreach(int child in arrow[pos]) {
            if(child != root)
                ret = (ret % mod) * calc(arrow, child, pos, k);
        }
        return ret % mod;
    }

    static long Permitation(long m, long n) {
        long ret = 1;
        for (long i = 0; i < n; i++) {
            ret = (ret % mod) * (m - i);
        }
        return (ret % mod);
    }
    static int[] ToIntArray(string strs, int n) {
        int[] ret = new int[n];
        var spl =strs.Split(' ');
        for (int i = 0; i < n; i++) ret[i] = int.Parse(spl[i]);
        return ret;
    }
}

Measured memory_bytes: 38148
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 100005
#define F first
#define S second
using namespace std;

typedef long long ll;
ll n, m, z, s, st, a[N];
pair<ll, ll> b[N];
int main()
{
	ll i, j;
	cin >> n >> m;
	for (i = 0; i < n; i++) {
		scanf ("%lld", &a[i]);
	}
	for (i = 0; i < m; i++) {
		scanf ("%lld %lld", &b[i].S, &b[i].F);
	}
	sort(a, a + n);
	sort(b, b + m);
	j = 0;
	for(i = m - 1; i >= 0; i--) {
		st = j;
		for (; j < st + b[i].S && j < n; j++) {
			if (a[j] > b[i].F) {z = 1; break;}
			a[j] = b[i].F;
		}
		if (z) break;
	}
	for (i =0; i < n; i++) {
		s += a[i];
	}
	cout << s;
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

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

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

  vector<int> lm(n);
  vector<int> rm(n);
  for (int i=1; i<n; i++) lm[i] = max(lm[i-1], a[i-1]);
  for (int i=n-2; i>=0; i--) rm[i] = max(rm[i+1], a[i+1]);

  rep(i,n) cout << max(lm[i], rm[i]) << endl;
  return 0;
}


Measured memory_bytes: 3968
n=int(input())
X=[]*n

for i in range(n):
	a=int(input())
	xy = [list(map(int,input().split())) for _ in range(a)]
	X.append(xy)

ans=0
for i in range(2**n):
	cnt=0
	for j in range(n):
		if (i>>j)&1:
			for k,l in X[j]:
				if not ((i>>(k-1))&1)==l:
					cnt=1
					break

	if cnt==0:
		ans = max(ans,bin(i).count("1"))

print(ans)

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

int main()
{
  vector<vector<int>> c(3, vector<int>(3, 0));
  rep(i, 3)
  {
    rep(j, 3)
    {
      cin >> c[i][j];
    }
  }
  string ans = "Yes";
  rep(i, 3)
  {
    int A = c[(0 + i) % 3][i] - c[(0 + i) % 3][(i + 1) % 3];
    int B = c[(1 + i) % 3][i] - c[(1 + i) % 3][(i + 1) % 3];
    int C = c[(2 + i) % 3][i] - c[(2 + i) % 3][(i + 1) % 3];

    if (A != B || B != C)
      ans = "No";
  }

  rep(i, 3)
  {
    int A = c[i][(0 + i) % 3] - c[(i + 1) % 3][(0 + i) % 3];
    int B = c[i][(1 + i) % 3] - c[(i + 1) % 3][(1 + i) % 3];
    int C = c[i][(2 + i) % 3] - c[(i + 1) % 3][(2 + i) % 3];
    if (A != B || B != C)
      ans = "No";
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static readonly int MAX = 100;

        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            string input;

            while (!string.IsNullOrEmpty(input = Console.ReadLine()))
            {
                int[] cp = new int[MAX + 1];
                string[] temp = input.Split(' ');
                int a = int.Parse(temp[0]);
                int b = int.Parse(temp[1]);

                while (a != 0 && b != 0)
                {
                    cp[a]++;
                    cp[b]++;

                    temp = Console.ReadLine().Split(' ');
                    a = int.Parse(temp[0]);
                    b = int.Parse(temp[1]);
                }
                sb.AppendLine(IsNegative(cp) ? "NG" : "OK");
            }
            Console.Write(sb);
        }

        static bool IsNegative(int[] cp)
        {
            if (cp[1] % 2 == 0) return true;
            if (cp[2] % 2 == 0) return true;

            for (int i = 3; i <= MAX; i++)
            {
                if (cp[i] % 2 == 1) return true;
            }
            return false;
        }
    }
}

Measured memory_bytes: 8852
#include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define pb push_back
    #define mem(a,b) memset(a,b,sizeof(a)) 
     
    map<ll,ll>mp;
    int main()
    {
    	ios::sync_with_stdio(false);
    	cin.tie(0);
    	int n;
    	cin>>n;
    	ll ans;
    	for(ll i=1;i*i<=n;i++)
    	{
    		ans=i;
    	}
    	cout<<ans*ans<<endl;
    	return  0;
    }

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

int main() {
   ll n,a,b,c,d,e;
   cin>>n>>a>>b>>c>>d>>e;
   
   ll damepo=min({a,b,c,d,e});
   cout<<(n+damepo-1)/damepo+4<<endl;   
}

Measured memory_bytes: 256
#import <stdio.h>
int main() {
    int r, g, b, n, ans = 0;
    scanf("%d %d %d %d", &r, &g, &b, &n);
    for (int x = 0; x <= n / r; x++) {
        for (int y = 0; y <= n / g; y++) {
            int p = n - r * x - g * y;
            if (p >= 0 && p % b == 0) ans++;
        }
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 7496
import fractions
from functools import reduce
import random
import copy

def gcd(numbers):
    return reduce(fractions.gcd, numbers)

n = int(input())
a = list(map(int, input().split()))
ans = 1

if n < 1000:
  for i in range(n):
    b = copy.copy(a)
    b.pop(i)
    t = gcd(b)
    if ans < t:
      ans = t
else:
  for _ in range(200):
    t = gcd(random.sample(a, 500))
    if ans < t:
      ans = t

print(ans)

Measured memory_bytes: 16484
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var nck = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var times = new int[nck[0]];
        for (var i = 0; i < nck[0]; i++)
            times[i] = ToInt32(ReadLine());
        Array.Sort(times);
        var result = 1;
        var time = times[0] + nck[2];
        var pe = 1;
        for(var i = 1; i < nck[0]; i++)
        {
            if (time >= times[i]&&pe<nck[1])
                pe++;
            else
            {
                time = times[i] + nck[2];
                pe = 1;
                result++;
            }
        }
        WriteLine(result);
    }
}


Measured memory_bytes: 17500
#include "bits/stdc++.h"
using namespace std;


int main()
{
	int n;
	cin >> n;
	vector<int> buka(n);	// 部下が何人いるか？index=社員番号-1
	for (int i = 2; i <= n; i++) {
		int a_in;
		cin >> a_in;
		buka.at(a_in - 1) += 1;
	}

	for (int i = 0; i < n; i++) {
		cout << buka.at(i) << endl;
	}
}

Measured memory_bytes: 4020
#include<bits/stdc++.h>
 using namespace std;
#define INF 1000000000
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
typedef long long LL;
int N;
int main(){
	cin>>N;
	if(N==7||N==5||N==3){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
    return 0;
}

Measured memory_bytes: 256
from math import sin, cos, radians

a, b, c = [int(i) for i in input().split()]
area = 0.5 * a * b * sin(radians(c))
print(area)
print(a + b + (a**2 + b**2 - 2*a*b*cos(radians(c)))**0.5)
print(2 * area / a)


Measured memory_bytes: 5736
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  cin>>s;
  bool ans=1;
  if(s.size()%2==1) ans=0;
  for(int i=0;i<s.size();i++){
  	if(i%2==0&&s[i]!='h') ans=0;
    if(i%2==1&&s[i]!='i') ans=0;
  }
  
  if(ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
}

Measured memory_bytes: 256
def ispalindrome(str): return 1 if str == str[::-1] else 0

s = input()
n = len(s)
s1 = s[:(n-1)//2]
s2 = s[(n+3)//2 -1 :]

if(ispalindrome(s)*ispalindrome(s1)*ispalindrome(s2) == 1):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int a,b,c[100000],d=0,e,f,i,j,k,l;
    cin>>a>>b;
    for(i=0;i<b;i++)
    {
        cin>>c[i];
        d+=c[i];
    }
    if(d>a) cout<<-1<<endl;
    else cout<<a-d<<endl;
    return 0;

}



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

using namespace std;

const int maxn=1<<25;
const int mod=1e9+9;


int main()
{
	int n,m;
	cin>>n>>m;
	int x,y;
	int minx=100000;
	for(int i=0;i<n;i++){
		cin>>x>>y;
		if(y<=m){
			minx=min(minx,x);
		}
	}
	if(minx==100000){
		cout<<"TLE";
	}else{
		cout<<minx;
	}
} 


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int n;
int price[100];
char item[100][101];
char target[101], material[101], whatWeWant[101];

int get_price(char *s)
{
  int i;
  for (i=0; i < n&&strcmp(s, item[i]); i++) ;
  return i;
}

int main(int argc, char const *argv[])
{
  int i, j, m, r, cost;
  int target_price;
  while (scanf("%d", &n), n) {
    for (i=0; i<n; i++)
      scanf("%s%d", item[i], &price[i]);
    scanf("%d", &m);
    for (i=0; i<m; i++) {
      cost = 0;
      scanf("%s%d", target, &r);
      for (j=0; j<r; j++) {
        scanf("%s", material);
        cost += price[get_price(material)];
      }
      target_price = price[get_price(target)];
      price[get_price(target)] = (cost < target_price ? cost : target_price);
    }
    scanf("%s", whatWeWant);
    printf("%d\n", price[get_price(whatWeWant)]);
  }

  return 0;
}

Measured memory_bytes: 620
def examB():
    N = I()
    ryuca = [0]*87
    ryuca[0] = 2; ryuca[1] = 1
    for i in range(2,87):
        ryuca[i] = ryuca[i-1] + ryuca[i-2]
    print(ryuca[N])

import sys,copy,bisect,itertools
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examB()


Measured memory_bytes: 3440
#include <iostream>
#include <string>
#include <deque>

using namespace std;

typedef long long ll;

int N;
string s;
deque<char> d;

int main(){
    cin >> N;
    cin >> s;
    int count = 0;
    for(int i=0;i<N;i++){
        if(s[i] == '('){
            count++;
            d.push_back(s[i]);
        }else{
            if(count > 0){
                count--;
                d.push_back(s[i]);
            }else{
                d.push_front('(');
                d.push_back(s[i]);
            }
        }
    }
    for(int i=0;i<count;i++) d.push_back(')');
    for(int i=0;i<d.size();i++) cout << d[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
/**
                 MD.Faysal Hasan
                Comilla Univesity               **/

#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include <stdlib.h>
using namespace std;

#define         rep(i,n)       for ( i=0 ; i<n ; i++ )
#define         rep1(i,n)      for ( i=1 ; i<=n ; i++ )
#define         sajo(str)      sort(str.begin(),str.end())
#define         rev(str)       reverse(str.begin(),str.end())
#define         usajo(str)     sort(str.rbegin(),str.rend())
#define         pi             2*acos(0.0)
#define         nel            printf("\n")
#define         longmx         92233720368547758
#define         gcd(a,b)       __gcd(a,b)
#define         lcm(a,b)       (a/gcd(a,b))*b
#define         yes            cout<<"Yes"<<"\n"
#define         no             cout<<"No"<<"\n"
#define         pb             push_back
#define         prl            pair< ll , ll >
#define         mkp(x,y)       make_pair(x,y)
#define         ff             first
#define         ss             second
#define         Faysal         ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef         long long int  lli;
typedef         long long      ll;

int main(){Faysal

    ll ans,sum,tot,cnt,mx,mn,idx,chk,rem,ret,tmp,mid,lft,rgt,pos;

    ll tc,n,m,a,b,c,d,g,h,l,r,x,y,i,j,k;

    vector<ll>v(3);
    rep(i,3) cin>>v[i];
    sajo(v);
    if(v[1]==v[0]&&v[1]!=v[2])
        yes;

    else if(v[1]!=v[0]&&v[1]==v[2])
        yes;

    else
        no;
    return 0;
}


Measured memory_bytes: 256
n,y=map(int,input().split())
flag=False
for i in range(0,n+1):
  if flag:
    break
  for j in range(0,n+1):
    if (n-i-j)>=0 and i*10000+j*5000+(n-i-j)*1000==y:
      print(i,j,(n-i-j))
      flag=True
      break
if flag==False:
  print(-1,-1,-1)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef long long ll;
typedef pair<int,int> pint;
const ll mod= 1e9+7;
const int inf=1e9+7;
const ll  longinf = 1LL<<60;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

ll num[3][100];
int main(){
  int n,c;
  cin>>n>>c;
  ll a[c][c];
  rep(i,c)rep(j,c)cin>>a[i][j];
  rep(i,n)rep(j,n){
    int y;cin>>y;
    y--;
    num[(i+j)%3][y]++;
    }
  ll dist[3][c];
  rep(i,3)rep(j,c)dist[i][j]=0;
  rep(i,3)rep(j,c)rep(k,c)
    dist[i][j]+=a[k][j]*num[i][k];
  ll ans=longinf;
  rep(i,c)rep(j,c)rep(k,c){
    if(i==j||j==k||k==i)continue;
    ans=min(dist[0][i]+dist[1][j]+dist[2][k],ans);
    }
  cout<<ans<<endl;
    

  return 0;
  }


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

using ll = long long;
constexpr ll inf = static_cast<ll>(1e15);
constexpr ll mod = static_cast<ll>(1e9 + 7);

int n;
int dp[110][4][4][4];

bool ng(int x1, int x2, int x3, int x4) {
	int x[] = { x1,x2,x3,x4 };

	for (int i = 0; i < 4; ++i) {
		if (x[0] == 0 && x[1] == 1 && x[2] == 2)
			return true;
		if (x[1] == 0 && x[2] == 1 && x[3] == 2)
			return true;
		if (i != 0)
			std::swap(x[i - 1], x[i]);
		if (i != 3)
			std::swap(x[i], x[i + 1]);
	}

	return false;
}

int main()
{
	std::cin >> n;

	for (int i = 0; i < 4; ++i)
		for (int j = 0; j < 4; ++j)
			for (int k = 0; k < 4; ++k) {
				if (ng(i, j, k, -1))
					continue;
				dp[3][i][j][k] = 1;
			}

	for (int i = 3; i < n; ++i)
		for (int j = 0; j < 4; ++j)
			for (int k = 0; k < 4; ++k)
				for (int l = 0; l < 4; ++l)
					for (int m = 0; m < 4; ++m) {
						if (ng(j, k, l, m))
							continue;
						dp[i + 1][k][l][m] = (dp[i + 1][k][l][m] + dp[i][j][k][l]) % mod;
					}

	int ans = 0;
	for (int i = 0; i < 4; ++i)
		for (int j = 0; j < 4; ++j)
			for (int k = 0; k < 4; ++k)
				ans = (ans + dp[n][i][j][k]) % mod;

	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin>>S;
  if(S=="hi"||S=="hihi"||S=="hihihi"||S=="hihihihi"||S=="hihihihihi"){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n, m;
  cin >> n >> m;

  int a[30] = {};
  REP(i,n){
    int k;
    cin >> k;
    REP(j,k){
      int tmp;
      cin >> tmp;
      a[tmp-1]++;
    }
  }

  int ans = 0;
  REP(i,m){
    if(a[i] == n){
      ans++;
    }
  }

  cout << ans << endl;
  return 0;
}



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

maxLinks = (n-1) * (n-2) // 2

if maxLinks < k:
  print(-1)
else:
  # とりあえず１を中心にしてぜんぶ出す
  links = [(1, x) for x in range(2, n+1)]
  linkNum_to_decrease = maxLinks - k
  num_cost_2 = maxLinks
  for i in range(2, n + 1):
    for j in range(i + 1, n + 1):
      #print(num_cost_2)
      if num_cost_2 == k:
   	    break
      else:
        links.append((i,j))
        num_cost_2 -= 1

  print(len(links))
  for link in links:
    print(link[0], link[1])

Measured memory_bytes: 43120
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int A;
int B;
int K;
int main(){
  int i;
  rd(A);
  rd(B);
  rd(K);
  if(B-A+1 >= 2*K){
    for(i=0;i<K;i++){
      wt_L(A+i);
      wt_L('\n');
    }
    for(i=0;i<K;i++){
      wt_L(B-K+1+i);
      wt_L('\n');
    }
  }
  else{
    for(i=A;i<B+1;i++){
      wt_L(i);
      wt_L('\n');
    }
  }
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// int A, B, K;
// {
//   int i;
//   rd(A,B,K);
//   if(B-A+1 >= 2K){
//     rep(i,K) wt(A+i);
//     rep(i,K) wt(B-K+1+i);
//   } else {
//     rep(i,A,B+1) wt(i);
//   }
// }


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main (String args[]){
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int k = sc.nextInt();
    
    int ans = 0;
    
    if(a >= k){
      ans = k;
    } else if (a+b >= k){
      ans = a;
    } else {
      ans = a - (k-a-b);
    }
        
    System.out.print(ans);
    
  }
}

Measured memory_bytes: 35784
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int i,j,n,l[2000],cnt,lo,hi,m,x;
	scanf("%d",&n);
	for(i=0;i<n;i++)	scanf("%d",&l[i]);
	sort(l,l+n);
	cnt=0;
	for(i=0;i<n-2;i++)	{
		for(j=i+1;j<n-1;j++)	{
			x=l[i]+l[j];
			lo=j+1;	hi=n-1;
			while(lo<=hi)	{
				m=(lo+hi)/2;
				if(x<=l[m])	hi=m-1;
				else lo=m+1;
			}
			cnt+=hi-j;
		}
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

int main()
{
    int N, K;
    cin >> N >> K;

    double ans = 0;
    for(int i = 1; i <= N; i++) {
        int n = ceil(log2((double)K / i));
        n = (n < 0) ? 0 : n;
        IFD cout << i << ": " << n << " = " << pow(0.5, n) << endl;
        ans += pow(0.5, n);
    }
    ans /= N;

    cout << setprecision(12) << ans << endl;

    return 0;
}


Measured memory_bytes: 512
N = int(input())
cnt = 0
z = False
for _ in range(N):
    d1, d2 = map(int, input().split())
    if d1 == d2:
        cnt += 1
    else:
        cnt = 0
    if cnt >= 3:
        z = True
if z:
    print("Yes")
else:
    print("No")

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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
}

int f(int x) {
	if (x == 0) return 0;
	return x%10 + f(x/10);
}

void solve() {
	int n; scanf("%d", &n);
	printf(n%f(n)==0?"Yes":"No");
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
n = input()
x = list(map(float, input().split()))
y = list(map(float, input().split()))
d1 = [abs(p-q) for p, q in zip(x, y)]
d2 = [abs(p-q)**2 for p, q in zip(x, y)]
d3 = [abs(p-q)**3 for p, q in zip(x, y)]
print(sum(d1))
print(sum(d2)**(1/2))
print(sum(d3)**(1/3))
print(max(d1))


Measured memory_bytes: 5644
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

vvi a, b, c;
bool dp[80][80][70000];

int main() {

	int h, w;
	cin >> h >> w;
	a.resize(h, vi(w));
	b.resize(h, vi(w));
	c.resize(h, vi(w));
	rep(i, h)rep(j, w)cin >> a[i][j];
	rep(i, h)rep(j, w)cin >> b[i][j];
	rep(i, h)rep(j, w)c[i][j] = abs(a[i][j] - b[i][j]);
	rep(i, h)rep(j, w)rep(k, 70000)dp[i][j][k] = false;
	dp[0][0][c[0][0]] = true;
	rep(i, h)rep(j, w)rep(k, 70000) {
		if (!dp[i][j][k])continue;
		if (i + 1 <= h - 1)if (k + c[i + 1][j] < 70000)dp[i + 1][j][k + c[i + 1][j]] = true;
		if (i + 1 <= h - 1)dp[i + 1][j][abs(k - c[i + 1][j])] = true;
		if (j + 1 <= w - 1)if (k + c[i][j + 1] < 70000)dp[i][j + 1][k + c[i][j + 1]] = true;
		if (j + 1 <= w - 1)dp[i][j + 1][abs(k - c[i][j + 1])] = true;
	}

	int ans = -1;
	rep(i, 70000)if (dp[h - 1][w - 1][i]) { ans = i;break; }
	cout << ans << endl;

}

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

//#define int long long
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
#define X first
#define Y second
#define endl '\n'
#define all(o) o.begin(), o.end()
#define IOS ios::sync_with_stdio(0), cin.tie(0)
inline int sgn(int x){
    return (!x ? 0 : (x > 0 ? 1 : -1));
}
const int mod = 1e9 + 7;
int main(){
    IOS;
    int n;
    cin >> n;
    vector<pii> p;
    for(int i=0; i<n; i++){
        int x;
        cin >> x;
        p.push_back({x, +1});
    }
    for(int i=0; i<n; i++){
        int x;
        cin >> x;
        p.push_back({x, -1});
    }
    sort(all(p));
    int s = 0, ans = 1;
    for(int i=0; i<p.size(); i++){
        int x = p[i].Y;
        if(s && sgn(s) * x == -1)
            ans = 1LL * ans * abs(s) % mod;
        s += x;
    }
    cout << ans << endl;
}


Measured memory_bytes: 2420
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;
typedef pair<string,int> P;

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

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

struct p{
	string s;
	int point;
	int id;
};

int main()
{
	int n;
	cin>>n;
	vector<struct p> x(n);
	for(int i = 0; i < n; i++){
		cin >> x[i].s>>x[i].point;
		x[i].id = i+1;
	}

	sort(all(x),[](struct p x,struct p y){
		if(x.s != y.s)
			return x.s<y.s;
		else
			return x.point>y.point;
	});

	for(int i = 0; i < n; i++){
		cout << x[i].id<< endl;
	}

	return 0;
}

Measured memory_bytes: 256