akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define inf 1000000005
#define all(a) (a).begin(), (a).end()
#define ms(a,x) memset(a, x, sizeof(a))
#define mod 1000000007
#define sz(a) ((ll)(a).size())

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcnt(s);}
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
#define eps 1e-12
typedef pair<int, int> II;
typedef pair<ll, ll> LL;
template<class T> T gcd(T a, T b){ T r; while (b != 0) { r = a % b; a = b; b = r; } return a;}
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define PI (2 * acos((ld)0))
#define linf (1ll << 60)
#define y1 y32432
#define y0 y435346

#define maxn 200005

int n, m, a[maxn];
int vao[maxn], ra[maxn];
ll fap[maxn];

int main()
{
//	freopen("in.txt", "r", stdin);

	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> m;
	ms(vao, 0); ms(ra, 0); ms(fap, 0);
	For(i, 1, n) {
		cin >> a[i];
	}
	ll res = inf * 1ll * inf;
	ll ret = 0, cur = 0;
	For(i, 1, n - 1){
		ra[a[i]]++;
		vao[a[i + 1]]++;
		int u = a[i + 1] - a[i];
		if(u < 0) u += m;
		fap[a[i + 1]] += u - 1;
	}

	For(i, 1, n - 1){
		int u = a[i], v = a[i + 1];
		if(u > v) {
			cur++;
			ret += (v - 1) + 1;
		} else ret += v - u;
	}
	cur -= vao[1];
//	cout << ret << endl; cout << cur << endl;
	res = min(res, ret);
	For(i, 2, m){
		ret -= cur;
		ret += fap[i - 1];
//		cout << cur << "  " << fap[i - 1] << " " << ret << endl;
		cur += ra[i - 1];
		cur -= vao[i];
		res = min(res, ret);
	}
	cout << res << endl;

	return 0;
}


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

using namespace std;

typedef long long int ll;
typedef pair<int,int> ii;

const int N = 1e5 + 5;

ll a[N],ans;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  for (int i = 0; i < 7; i++) {
    cin >> a[i];
  }
  ans += (a[0] - (a[0] % 2)) + (a[3] - (a[3] % 2)) + (a[4] - (a[4] % 2)) + a[1];
  if (min(a[0],min (a[3],a[4])) > 0) {
    ll k = (a[0] % 2) + (a[3] % 2) + (a[4] % 2);
    if (k == 2)
      ans ++;
    if (k == 3)
      ans += 3;
  }
  cout << ans << endl;
}

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

int main(){
  int R;
  cin >> R;
  if(R<1200){
      cout << "ABC" << endl;
  }else if(R<2800){
     cout << "ARC" << endl;
  }else{
    cout << "AGC" << endl;
  }
    }
  


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

#define rep(i,n)	for(int i=0;i<n;i++)

int main() {
	string s1 = ".,!? ", s2 = "abc", s3 = "def", s4 = "ghi",
		s5 = "jkl", s6 = "mno", s7 = "pqrs", s8 = "tuv", s9 = "wxyz";
	int n;
	cin >> n; 
	rep(i, n) {
		string str;
		cin >> str;
		int j = 0;
		int p = -114;
		while (j < str.size()) {
			int cnt = 0;
			while (true) {
				if (str[j] - '0' == 0)break;
				j++;
				cnt++;
			}
			if (j == 0) {
				j++;
				continue;
			}
			switch (str[j - 1] - '0') {
			case 1: cout << s1[(cnt - 1) % s1.size()];
				break;
			case 2: cout << s2[(cnt - 1) % s2.size()];
				break;
			case 3: cout << s3[(cnt - 1) % s3.size()];
				break;
			case 4: cout << s4[(cnt - 1) % s4.size()];
				break;
			case 5: cout << s5[(cnt - 1) % s5.size()];
				break;
			case 6: cout << s6[(cnt - 1) % s6.size()];
				break;
			case 7: cout << s7[(cnt - 1) % s7.size()];
				break;
			case 8: cout << s8[(cnt - 1) % s8.size()];
				break;
			case 9: cout << s9[(cnt - 1) % s9.size()];
				break;
			default:
				break;
			}
			j++;
		}
		cout << endl;
	}
}

Measured memory_bytes: 1212
n = gets.to_i
rs = []
n.times do
  rs << gets.to_i
end

max = -10 ** 9
max_i = 0
min = rs[0]
rs.length.times do |i|
  break if i == rs.length - 1
  next if rs[i] > min
  min = rs[i]
  if i < max_i
    max = rs[max_i] - rs[i]
  else
    (i+1..rs.length-1).each do |j|
      if rs[j] - rs[i] > max
        max = rs[j] - rs[i]
        max_i = j
      end
    end
  end
end

puts max

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

int main() {
    int n, r, dr;

    scanf("%d %d", &n, &r);

    if( n < 10)
    {
        dr = r + 100*(10-n);    
    }
    else
    {
        dr = r;
    }

    printf("%d", dr);

	return 0;
}

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

int N;
long long int A[100005], B[100005], C[100005];

long long int sum_A, sum_B;

long long int nec;

vector<pair<long long int,int> > V;

int num;
int ans;

int main(void) {

	cin >> N;
	
	for (int i = 1; i <= N; i++) {
		cin >> A[i]; sum_A += A[i];
	}

	for (int i = 1; i <= N; i++) {
		cin >> B[i]; sum_B += B[i];
	}

	//cout << "sum_A= " << sum_A << "  sm_B= " << sum_B << endl;

	if (sum_A < sum_B) { ans = -1; }
	else {

		for (int i = 1; i <= N; i++) {
			if (B[i] - A[i] > 0) { nec += B[i] - A[i]; }
		}

		for (int i = 1; i <= N; i++) {
			if (A[i] > B[i]) { V.push_back(pair<long long int, int> (A[i] - B[i],i)); }
		}

		for (int i = 1; i <= N; i++) {
		 C[i] = A[i]; 
		}

		sort(V.rbegin(), V.rend());
		int q = 0;
		while (nec>0) {
			long long int tmp = V[q].first;
			int I = V[q].second;
			nec -= tmp;  C[I] -= tmp;
			q++;
			
		}
		
		for (int i = 1; i <= N; i++) {
			if (C[i] < B[i]) { C[i] = B[i]; }
		}

		ans = 0;
		for (int i = 1; i <= N; i++) {
			if (A[i] != C[i]) { ans++; }
		}

	}

	cout << ans << endl;

	//system("pause");
	return 0;
}

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

using namespace std;
typedef long long ll;
const ll mx = 10000007;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
#define FIO ios_base::sync_with_stdio(false);  cin.tie(NULL);


int main() {
    FIO;
    ll n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    ll cnt[n] = {0};
    for (ll i = 1; i < s.size(); i++) {
        if(s[i-1] == 'A' && s[i] == 'C') {
            cnt[i] = cnt[i-1] + 1;
        }
        else {
            cnt[i] = cnt[i-1];
        }
    }
    while(k--) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;

        cout << cnt[b] - cnt[a] << endl;
    }


}


Measured memory_bytes: 4572
using System;
using System.Collections.Generic;

namespace CodeIQ
{
    class Program
    {
        static int[] coins = { 500, 100, 50, 10, 5, 1 };
        static void Main(string[] args)
        {
            String line;
            
            Dictionary<int, int> difficulity = new Dictionary<int, int>();
            for (int i=0; (line = Console.ReadLine()) != null; i++)
            {
                if (i == 1)
                {
                    string[] difficulityStr = line.Split(' ');
                    for(int j=0; j<difficulityStr.Length; j++)
                    {
                        int key = int.Parse(difficulityStr[j]);
                        if(difficulity.ContainsKey(key))
                        {
                            difficulity[key] += 1;
                        }
                        else
                        {
                            difficulity.Add(key, 1);
                        }
                    }
                }
                if (i == 3)
                {
                    string[] difficulityStr = line.Split(' ');
                    for (int j = 0; j < difficulityStr.Length; j++)
                    {
                        int key = int.Parse(difficulityStr[j]);
                        if (difficulity.ContainsKey(key))
                        {
                            difficulity[key] -= 1;
                            if(difficulity[key] < 0)
                            {
                                Console.Write("NO");
                                break;
                            }
                        }
                        else
                        {
                            Console.Write("NO");
                            break;
                        }
                        if (j == difficulityStr.Length-1)
                        {
                            Console.Write("YES");
                        }
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 48960
let (>>=) xs f = List.map f xs |> List.concat
let lower_bound p arr =
  let rec f l r =
    if l+1 >= r then r
    else
      let m = (l+r) / 2 in
      if p arr.(m) then f l m else f m r
  in f (-1) (Array.length arr)
let sign = compare 0
let inf = 10101010101010
let sentinel arr = Array.concat [[|-inf|]; arr; [|inf|]]
let () =
  Scanf.scanf "%d %d %d" @@ fun a b q ->
  let s = sentinel (Array.init a (fun _ -> Scanf.scanf " %d" ((+) 0))) in
  let t = sentinel (Array.init b (fun _ -> Scanf.scanf " %d" ((+) 0))) in
  Array.init q (fun _ -> Scanf.scanf " %d" ((+) 0))
  |> Array.iter @@ fun x ->
    let sh = lower_bound ((<=) x) s in
    let tp = lower_bound ((<=) x) t in
    ([s.(sh-1); s.(sh)] >>= fun sh ->
     [t.(tp-1); t.(tp)] >>= fun tp ->
       let v, w = min (abs (sh-x)) (abs (tp-x)), max (abs (sh-x)) (abs (tp-x)) in
       if sign (sh-x) * sign (tp-x) >= 0 then [w] else [2*v + w])
    |> List.fold_left min inf|> Printf.printf "%d\n"

Measured memory_bytes: 8448
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      n: usize,
      a: [usize; n]
   }
   let mut m = std::collections::BTreeMap::new();
   for a in a {
      let mut f = false;
      match m.get_mut(&a) {
         Some(v) => *v += 1,
         None => f = true,
      }
      if f {
         m.insert(a, 1usize);
      }
   }
   let mut ans = 0;
   for (&k, &v) in m.iter() {
      if k <= v {
         ans += v - k;
      } else {
         ans += v;
      }
   }
   println!("{}", ans);
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
#define pb emplace_back
using namespace std;
using ll = long long;
const int maxn = 300010;
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	ll a, v, b, w, t, c;
	cin >> a >> v >> b >> w >> t;
	c = v-w;
	if (c <= 0) puts("NO");
	else puts((abs(a-b)+c-1)/c > t ? "NO" : "YES");
}



Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main (){
    string S;
    cin >> S;

    int a_pos = 220000;
    int z_pos = 0;

    for(int i = 0; i<S.size() ;i++){
        if(S.at(i) == 'A'){//最小のAのいちを求める
            if(a_pos > i){
                a_pos = i;

            }
        }
        if(S.at(i) == 'Z'){
            if(z_pos < i){
                z_pos = i;
            }
        }
    }

    cout << z_pos - a_pos  +1 << endl;


    return 0;
}

Measured memory_bytes: 640
//第8回シンデレラガール総選挙は是非本田未央ちゃんに投票をお願いします！
//ファンのことも他のアイドルの子たちのことも本当に大事にしてて、今まで周りに色んなものを与えてくれました。
//今度は私たちが未央ちゃんにお返しをする番です。みんなでガラスの靴を履かせてあげましょう！
// #本田未央を一番星に #本田未央を令和のシンデレラガールに #第8回シンデレラガール総選挙
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
struct unionf{
	vector <int> data;
	unionf(int size):data(size,-1){}
	bool unions(int x,int y){
		x=root(x);y=root(y);
		if(x!=y){
			if(data[y]<data[x]){int d=x;x=y;y=d;}
			data[x]+=data[y];data[y]=x;
		}
		return x!=y;
	}
	bool finds(int x,int y){
		return root(x)==root(y);
	}
	int root(int x){
		return data[x]<0?x:data[x]=root(data[x]);
	}
	int find(int x){
		return -data[x];
	}
};
lint gcd( lint m, lint n )
{
	lint a=max(m,n),b=min(m,n);
	if(m==0) return n;if(n==0) return m;
	if(a%b==0) return b;
	return gcd(b,a-b*(a/b));
}
//vector<pint> gr[50010];
int a[50010],b[50010],c[50010];
bool aru[1141919];
int main()
{
	int n,m,q,mod,s,t,r,fc=-1,gc=0;
	cin>>n>>m>>q>>mod;
	rep(i,m){
		/*cin>>a>>b>>c;a--;b--;
		gr[a].pb(mp(b,c));
		gr[b].pb(mp(a,c));
		if(fc<0) fc=c;
		else gc=gcd(gc,abs(c-fc));*/
		cin>>a[i]>>b[i]>>c[i];a[i]--;b[i]--;
		if(fc<0) fc=c[i];
		else gc=gcd(gc,abs(c[i]-fc));
	}
	gc=gcd(gc,mod);
	int mo=fc%gc,gc2=gcd(3*gc,mod);
	/*rep(i,n) rep(j,gr[i].size()){
		gr[i][j].se%=3*gc;
		gr[i][j].se-=mo;
	}*/
	unionf uni(n*6+10);
	rep(i,m){
		c[i]%=3*gc;c[i]-=mo;
		//cout<<c[i]/gc<<endl;
		rep(j,3) rep(k,2){
			uni.unions(a[i]*6+j*2+k,b[i]*6+(j*2+c[i]/gc)%3*2+(k+1)%2);
			uni.unions(b[i]*6+j*2+k,a[i]*6+(j*2+c[i]/gc)%3*2+(k+1)%2);
		}
	}
	memset(aru,false,sizeof(aru));
	int C=mo%gc2;
	rep(i,gc2+10){
		aru[C]=true;C*=4;C%=gc2;
	}
	rep(i,q){
		cin>>s>>t>>r;s--;t--;
		string ret="NO";
		rep(j,3) rep(k,2){
			if(!uni.finds(t*6,s*6+j*2+k)) continue;
			//cout<<j<<k<<endl;
			lint tar=r+mo-j*gc;tar%=gc2;tar+=gc2;tar%=gc2;
			if(k>0) tar*=(gc2+1)/2;tar%=gc2;
			if(aru[tar]) ret="YES";
		}
		cout<<ret<<endl;
	}
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

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

    ll ans = -1;

    ll x = 0;
    srep(i,2,n)x ^= a[i];

    bitset<50> f(x);

    ll yy = a[0] + a[1];
    ll zz = 0;
    ll two[55] = {};
    two[0] = 1;
    srep(i,1,55)two[i] = two[i-1]*2;
    drep(i,50){
        if(f[i] == 1){
            // yy -= two[i];
            yy -= 1LL<<i;
        }else{
            if(two[i]*2 <= yy){
                // yy -= two[i]*2;
                yy -= 1LL<<(i+1);
                // zz += two[i];
                zz += 1LL<<i;
            } 
        }
    }

    if(yy != 0 || zz > a[0]){
        cout << -1 << endl;
        return 0;
    }

    ans = 0;

    drep(i,50){
        if(f[i] == 1){
            if(zz + two[i] <= a[0]){
                // zz += two[i];
                zz += 1LL<<i;
            }
        }
    }

    ans = a[0] - zz;
    if(ans == a[0]){
        cout << -1 << endl;
        return 0;
    }

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




Measured memory_bytes: 3684
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main() 
{
    string s,t;
    cin>>s>>t;
    int min=10000,count;
    for(unsigned int i=0;i<=s.size()-t.size();i++)
    {   count=0;
        for(unsigned int j=0;j<t.size();j++)
        {
            if (s[i+j]!=t[j])
            count+=1;
        }
        //cout<<i<<' '<<count<<' '<<min<<endl;
        if (count<min)
           min=count;
    }
    cout<<min<<endl;
    return 0;
}





Measured memory_bytes: 3592
def temp(T,A,x):
    return abs(A - (T - x * 0.006))
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

m = temp(T,A,H[0])
idx = 1
for i in range(1,len(H)):
    if m > temp(T,A,H[i]):
        m = temp(T,A,H[i])
        idx = i + 1

print(idx)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

long long int solve(long long int n){
	if(n==2){return 3;}
	else if(n==4||n==6||n==9||n==11){return 2;}
	else{return 1;}
}

int main() {
	long long int n=1,m,a,b,c,d,e;
	long double z,w;
	string str,str2,str3;
	char ch;
	long long int x[130]={};
	cout << fixed << setprecision(10);
	cin>>a>>b>>c;
	cout<<(a+b)*c/2;
} 


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>

using namespace std;
char str1[4],str2[4];
int ans;
int main(){
	scanf("%s",str1);
	scanf("%s",str2);
	for(int i=0; i<3; i++){
		if(str1[i]==str2[i]){
			ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int color[101], n, d[101], f[101], v[101][101], time;

void visit(int u){
  int i;

  color[u] = 1;
  d[u] = ++time;
  for(i=1;i<=n;i++){
   
    if(color[i] == 0&&v[u][i]==1)visit(i);
  }
  color[u]=2;
  f[u] = ++time;
}

void dfs(){
  int i;

  for(i=1;i<=n;i++){
    color[i]=0;
  }
  time=0;
  for(i=1;i<=n;i++){
    if(color[i]==0)visit(i);
  }
}

int main(){

  int i,j,k[101],u[101],l;

  scanf("%d",&n);

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

  for(i=1;i<=n;i++){
    scanf("%d %d",&u[i],&k[i]);
    for(j=1;j<=k[i];j++){
      scanf("%d",&l);
      v[i][l] = 1;
    }}
    dfs();
    
    for(i=1;i<=n;i++){
      printf("%d %d %d\n",u[i],d[i],f[i]);
  }
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()

using namespace std;

void execute()
{
	int N;
	int ans = 0;
	cin >> N;

	vector<int> card(N, 0);
	for (int i = 0; i < N; i++)
	{
		cin >> card[i];
	}
	sort(all(card), greater<int>());
	for (int i = 0; i < N; i++)
	{
		ans += i % 2 == 0 ? card[i] : -card[i];
	}
	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <vector>

int main() {
  std::string s, t;
  std::cin >> s;
  std::cin >> t;
  std::vector<int > index_vec[26];
  for (int i=0; i<s.length(); i++){
    int value = int(s[i])-int('a');
    index_vec[value].push_back(i);
    //printf("push index_vec[%d] to %d\n", value, i);
  }
  long long ans = 0;
  int current_position = -1;
  for (int i=0; i<t.length(); i++){
    int value = int(t[i])-int('a');    
    if (index_vec[value].size()==0){
      printf("-1\n");
      return 0;
    }
    auto itr = std::upper_bound(index_vec[value].begin(), index_vec[value].end(), current_position);
    if (itr==index_vec[value].end()){
      ans += index_vec[value][0]+int(s.length())-current_position;
      current_position = index_vec[value][0];
    } else {
      int index = itr-index_vec[value].begin();
      ans +=  index_vec[value][index]-current_position;
      current_position = index_vec[value][index];
    }
    /*bool exist_current_set = false;
    for (int j=0; j<index_vec[value].size(); j++){
      if (current_position<index_vec[value][j]){
        exist_current_set = true;
        ans += index_vec[value][j]-current_position;
        //printf("ans+=%d-%d=%d\n", index_vec[value][j], current_position, index_vec[value][j]-current_position);
        current_position = index_vec[value][j];
        break;
      }
    }
    if (!exist_current_set){
      ans += index_vec[value][0]+int(s.length())-current_position;
      current_position = index_vec[value][0];
      }*/
  }
  std::cout << ans << std::endl;
  return 0;
}


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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int[] cnt = new int[N];
		for(int i=0;i<K;i++){
			foreach(var n in A[i]){
				cnt[n - 1]++;
			}
		}
		
		Console.WriteLine(cnt.Where(n => n == 0).Count());
		
		
		
	}
	int N, K;
	int[] D;
	int[][] A;
	public Sol(){
		var d = ria();
		N = d[0]; K = d[1];
		D = new int[K];
		A = new int[K][];
		for(int i=0;i<K;i++){
			D[i] = ri();
			A[i] = ria();
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 28320
def chess(h, w):
  if (h + w) % 2 == 0:
    return '#'
  return'.'

while True:
  H, W = map(int , input().split())
  if H == 0 and W == 0:
    break
  for i in range(H):
    for j in range(W):
      print(chess(i, j), end='')
    print()
  print()



Measured memory_bytes: 7004
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int dy[4]={1,0,-1,0};
int dx[4]={0,1,0,-1};
vector<vector<int>> graph;

bool sort_sec(const pair<int,int> &a,const pair<int,int> &b){
   if(a.second<b.second){
      return true;
   }
   return false;
}

void swap(int *a,int *b){
   int temp=*a;
   *a=*b;
   *b=temp;
}

int gcd(int a,int b){
   if(a%b==0) return b;
   return gcd(b,a%b);
}

int main(void){
   long long A,B,C,K;
   cin>>A>>B>>C>>K;
   if(K%2==0){
      cout<<A-B<<endl;
   }else{
      cout<<B-A<<endl;
   }
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
#define Sort(v) sort(all(v))
#define Reverse(v) reverse(all(v))
#define Rsort(v) sort(all(v),greater)
#define pub(v) push_back(v)
#define pob(v) pop_back(v)
typedef long long ll;
typedef vector<ll> vel;
typedef vector<vector<ll>> vel2d;
typedef string str;
typedef pair<ll,ll> pal;
typedef vector<str> ves;


int main() {
    ll a,b,c;
    cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    printf("%lld %lld %lld\n",a,b,c);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
// vector<int> vec(3); = vector<int> vec={0,0,0}
// vec.at()
// sort(num.begin(),num.end(), greater<int>());
// reverse(num.begin(),num.end());
 
// 切り上げ　a/b+1
//  1からNの総和　N*(N+1)/2
 
int main() {
  int x;
  cin >> x;

  if(x < 1200){
  	cout << "ABC" << endl;
  }else{
    cout << "ARC" << endl;
  }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sun May 26 21:06:51 2019

@author: aono
"""

info = []
N = int(input())

for i in range(N):
    city, p = input().split()
    info.append([city, int(p), i])

info.sort(key=lambda x: x[1])
info.reverse()
info.sort(key=lambda x: x[0])

for i in range(len(info)):
    print(info[i][2] + 1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

int main(){
	string s;
	cin >> s;
	if(s[2] == s[3] && s[4] == s[5]) cout << "Yes";
	else
		cout << "No"; 
	return 0;
}


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

int main()
{
  string s;
  cin >> s;
  i64 size = s.size();
  string last = s.substr(size - 1, 1);
  i64 ans = 1, l = size - 1;
  for (i64 i = size - 2; 0 <= i; i--)
    if (last != s.substr(i, l - i))
    {
      last = s.substr(i, l - i);
      l = i;
      ans++;
    }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl '\n'
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
const ll mod=1e9+7;
bool sortbysec(const pair<int,int>&a,const pair<int,int>&b)
{
    return (a.second<b.second);
}
int main()
{
    double w,h,x,y;
    cin>>w>>h>>x>>y;
    cout<<fixed<<setprecision(6)<<(w*h)/2.0;
    if(2*x==w&&2*y==h)
        cout<<" "<<1<<endl;
    else
        cout<<" "<<0<<endl;






}

















































Measured memory_bytes: 3760
# AB = [list(map(int, input().split())) for i in range(3)]

paths = [[] for _ in range(4)]
for _ in range(3):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    paths[a].append(b)
    paths[b].append(a)

start = 0
for i in range(4):
    if len(paths[i]) == 1:
        start = i
        break

visited = {start}
def dfs(n):
    if len(paths[n]) >= 3:
        print('NO')
        exit()
    for p in paths[n]:
        if p in visited:
            continue
        visited.add(p)
        dfs(p)

dfs(start)

if len(visited) == 4:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 38256
import os
from collections import Counter

import sys
import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))

A = np.array(A, dtype=int)
B = (A + np.arange(1, N + 1)).tolist()
C = (A - np.arange(1, N + 1)).tolist()

c_cnt = Counter(C)
ans = 0
for k, b in Counter(B).items():
    ans += c_cnt[-k] * b
print(ans)


Measured memory_bytes: 75292
program abc060c
  use,intrinsic :: iso_fortran_env
  implicit none
  integer(int64) :: n, t
  integer(int64),dimension(:),allocatable :: a
  read *, n, t
  allocate(a(n))
  read *, a
  a = [a, 0_8] - [0_8, a]
  a = a(2:)
  a(n) = t
  print *, sum(merge(a, t, a < t))
end program abc060c


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

using namespace std;

int main(){
 int  n;
  cin >> n;
 
  
long t=1,a=1;
   
 for(int i=0;i<n;i++){
    long c,d;
    cin >> c >> d;
    long n=max((t-1)/c+1,(a-1)/d+1);
     t=n*c;
     a=n*d;
    
  }
  
  cout << t+a << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;int n,a[5000];int main(){int i,j,t,s;while(cin>>n,n){s=0;t=-100001;for(i=0;i<n;i++){cin>>a[i];}for(i=0;i<n;i++){s+=a[i];if(t<s)t=s;for(j=i+1;j<n;j++){s+=a[j];if(t<s)t=s;}s=0;}cout<<t<<endl;}return 0;}

Measured memory_bytes: 0
macro_rules! get_char {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().chars().collect::<Vec<_>>()
        }
    };
}

fn main() {
    let s = get_char!();

    for bit in 0..(1 << s.len() - 1) {
        let mut total = 0;
        let mut res = "".to_string();

        res.push(s[0]);
        total += s[0].to_digit(10).unwrap() as i32;

        for (i, c) in s.iter().skip(1).enumerate() {
            let x = c.to_digit(10).unwrap() as i32;
            if bit & (1 << i) != 0 {
                total += x;
                res.push('+');
            } else {
                total -= x;
                res.push('-');
            }
            res.push(*c);
        }
        if total == 7 {
            println!("{}=7", res);
            std::process::exit(0);
        }
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

template<int MOD>
struct ModInt {
  ll x;
  ModInt():x(0){}
  ModInt(ll x):x((x%MOD+MOD)%MOD){}
  int getMod() { return MOD; }
  ModInt operator-() const { return ModInt(0) - *this;}
  ModInt& operator+=(const ModInt& a){ if((x+=a.x)>=MOD) x-=MOD; return *this;}
  ModInt& operator-=(const ModInt& a){ if((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
  ModInt& operator*=(const ModInt& a){ (x*=a.x)%=MOD; return *this;}
  ModInt operator+(const ModInt& a)const{ return ModInt(*this) += a;}
  ModInt operator-(const ModInt& a)const{ return ModInt(*this) -= a;}
  ModInt operator*(const ModInt& a)const{ return ModInt(*this) *= a;}
  bool operator<(const ModInt& a)const{ return x < a.x;}
  bool operator==(const ModInt& a)const{ return x == a.x;}
  ModInt pow(ll t) const {
    if (!t) return 1;
    ModInt a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  friend istream & operator >> (istream & in, ModInt & v) {
    ll x;
    in >> x;
    v.x = x;
    return in;
  }
  friend ostream & operator << (ostream & out, ModInt<MOD> const & v) {
    out << v.x;
    return out;
  }
};
const int MOD = 1000000007;
using mint = ModInt<MOD>;

typedef pair<ll, ll> P;

P rev(P p) {
  swap(p.first, p.second);
  if (p.first == 0 or p.second == 0) return p;

  p.first *= -1;
  if (p.second < 0) p.first *= -1, p.second *= -1;
  return p;
}

int main() {
  int n; cin >> n;
  map<P, int> M;
  int zero2 = 0, a_zero = 0, b_zero = 0;
  loop(i,0,n) {
    ll a, b; cin >> a >> b;
    if (a == 0 and b == 0) M[P(0, 0)]++;
    else if (a == 0) M[P(0, 1)]++;
    else if (b == 0) M[P(1, 0)]++;
    else {
      ll gc = __gcd(abs(a), abs(b));
      a /= gc, b /= gc;
      if (b < 0) a *= -1, b *= -1;
      M[P(a, b)]++;
    }
  }

  auto aa = [&](const P p1) {
    return mint(2).pow(M[p1]);
  };

  auto ab = [&](const P p1, const P p2) {
    // それぞれのグループ独立に1個以上選ぶ.
    // さらに両グループから1つも選ばない場合で+1
    return (mint(2).pow(M[p1]) - 1) + (mint(2).pow(M[p2]) - 1) + 1;
  };

  mint ans = 1;
  set<P> S;
  for (auto &&m: M) {
    if (m.first.first == 0 and m.first.second == 0) continue;
    if (S.count(m.first)) continue;
    ll count = m.second;
    P p = rev(m.first);
    if (M[p] > 0) {
      ans *= ab(p, m.first);
    } else {
      ans *= aa(m.first);
    }
    S.insert(p);
  }

  // 各有理数rグループから1つも選ばないのもカウントしてるので-1
  ans -= 1;

  // (0, 0)の場合はそれ１つを選ぶしかない.
  ans += M[P(0, 0)];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 41104
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-03-08 20:41:44
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

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

  string s; cin >> s;
  int n = s.size();

  s += '$';

  for (int i = 0; i < n; i += 2) {
    if (s.substr(i, 2) != "hi") {
      cout << "No" << endl; return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 2000000

int H,A[MAX+1];

void maxHeapify(int i){
  int l,r,Lst,cd;
  
  l = 2*i; r = 2*i+1;
  
  if(l <= H && A[l] > A[i]){
    Lst = l;
  }else Lst = i;
  if(r <= H && A[r] > A[Lst]){
    Lst = r;
  }

  if(Lst != i){
    cd = A[Lst];
    A[Lst] = A[i];
    A[i] = cd;
    maxHeapify(Lst);
  }
}

int main(){
  int i;
  scanf("%d",&H);
  for(i=1;i<=H;i++) scanf("%d",&A[i]);
  for(i=H/2;i>=1;i--) maxHeapify(i);
  for(i=1;i<=H;i++) printf(" %d",A[i]);
  printf("\n");
  
  return 0;
}



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

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  int x,n;cin>>x>>n;
  set<int> st;
  for(int i=-200;i<=200;i++){
    st.insert(i);
  }
  for(int i=0;i<n;i++){
    int t;cin>>t;st.erase(t);
  }
  int ans=-200;
  for(auto v : st){
    if(abs(v-x)<abs(ans-x)){
      ans=v;
    }
  }
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define pback push_back
#define mpair make_pair
#define MODN 1000000007

using namespace std;

int main(){

    int n;
    cin >> n;

    vector<int> a;
    vector<int> b;

    rep(i,n + 1){
        int tmp;
        cin >> tmp;
        a.pback(tmp);
    }

    rep(i,n){
        int tmp;
        cin >> tmp;
        b.pback(tmp);
    }

    ll sum = 0;

    rep(i,n){

        int remain = b[i];

        if(a[i] > remain){
            sum = sum + remain;
        }else{
            sum = sum + a[i];
            remain = remain - a[i];

            if(a[i + 1] > remain){
                sum = sum + remain;
                a[i + 1] = a[i + 1] - remain;
            }else{
                sum = sum + a[i + 1];
                a[i + 1] = 0;

            }

        }

    }

    cout << sum << endl;

    return 0;
}

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

using namespace std;

const int N = 1E5 + 5;
int a[N];
int par[N];
int size[N];
vector<pair<int, int> > v[N];

void init(int n) {
	for(int i = 1; i <= n; i++) {
		par[i] = i;
		size[i] = 1;
	}
}

int root(int i) {
	while(par[i] != i) {
		par[i] = par[par[i]];
		i = par[i];
	}
	return i;
}

void weighted_union(int a, int b) {
	int root_a = root(a);
	int root_b = root(b);
	if(root_a == root_b)
		return;
	if(size[root_a] < size[root_b]) {
		par[root_a] = par[root_b];
		size[root_b] += size[root_a];
	} 
	else {
		par[root_b] = par[root_a];
		size[root_a] += size[root_b];
	}
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i ++)
        cin >> a[i];
    init(n);
    int x, y;
    while(m --) {
        cin >> x >> y;
        weighted_union(x, y);
    }
    for(int i = 1; i <= n; i ++)
        v[root(a[i])].push_back({a[i], i});
    int res = 0;
    for(int i = 1; i <= n; i ++) {
        if(v[i].size()) {
            unordered_map<int, bool> umap;
            for(int j = 0; j < (int) v[i].size(); j ++)
                umap[v[i][j].second] = true;
            for(int j = 0; j < (int) v[i].size(); j ++)
                if(umap[v[i][j].first])
                    res ++;
        }
    }
    cout << res << '\n';
    return 0;
}

Measured memory_bytes: 8948
#include <bits/stdc++.h>
#define ll long long int
#define K 1000000007
using namespace std;

int main() {
	/*ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    */
    int x;
    cin>>x;
    
    cout<<(x+1)%2<<endl;
	return 0;
}


Measured memory_bytes: 3620
import sys
from string import ascii_lowercase as AL

input = sys.stdin.readline


def main():
    H, W = map(int, input().split())

    alpha = {}
    for al in AL:
        alpha[al] = 0
    for i in range(H):
        a = input().rstrip()
        for s in a:
            alpha[s] += 1

    values = list(alpha.values())

    q_h, r_h, = divmod(H, 2)
    q_w, r_w, = divmod(W, 2)
    g_4 = q_h * q_w
    g_2 = q_h * r_w + q_w * r_h
    g_1 = r_h * r_w

    for i in range(len(values)):
        while g_4 > 0:
            if values[i] >= 4:
                g_4 -= 1
                values[i] -= 4
            else:
                break
    for i in range(len(values)):
        while g_2 > 0:
            if values[i] >= 2:
                g_2 -= 1
                values[i] -= 2
            else:
                break
    for i in range(len(values)):
        while g_1 > 0:
            if values[i] == 1:
                g_1 -= 1
                values[i] = 0
            else:
                break

    if g_4 == g_2 == g_1 == 0:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
	int h,w;cin >> h >> w;
	int cost[10][10];
	rep(i,10)rep(j,10)cin >> cost[i][j];
	rep(i,10)rep(j,10)rep(k,10)cost[j][k] = min(cost[j][k],cost[j][i] + cost[i][k]);
	int ret = 0;
	rep(i,h)rep(j,w){
		int a;cin >> a;
		if(a == -1)continue;
		ret += cost[a][1];
	}
	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 3604
import java.util.*

fun main(args: Array<String>) {
    val (N, K) = readLine()!!.split(" ").map {it.toInt()}

    if (K > (N - 1) * (N - 2) / 2) {
        println(-1)
        return
    }

    val edges = ArrayList<Pair<Int, Int>>()

    for (i in 2 .. N) {
        edges.add(Pair(1, i))
    }

    var k = (N - 1) * (N - 2) / 2

    for (i in 2 .. N) {
        for (j in i + 1 .. N) {
            if (k > K) {
                edges.add(Pair(i, j))
                k--
            }
        }
    }

    println(edges.size)

    for (e in edges) {
        println("${e.first} ${e.second}")
    }
}


Measured memory_bytes: 38636
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

void printb(ll n) {
    rep(i, 32) {
        if (n & 1ll<<31) cout<<1;
        else cout<<0;
        n = n<<1;
    }
    cout<<endl;
}

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

    ll m, n;
    cin>>m>>n;
    printb(m&n);
    printb(m|n);
    printb(m^n);
}


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

typedef long long ll;


int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);
 
    long long H, W;
 
    cin >> H >> W;

    long long x = H * W;

    if(H == 1 || W == 1) {
        cout << 1 << endl;
      	return 0;
    }
 
    if(x % 2) {
        cout << x / 2LL + 1LL << endl;
    } else {
        cout << x / 2LL << endl;
    }
}

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

int main(){
    int n,k;
    cin >> n >> k;
    vector<vector<int>> adj(n);
    for(int i=0; i<n-1; i++){
        int a,b;
        cin >> a >> b;
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    vector<int> parent(n, -1);
    // 部分木のサイズ
    vector<int> dp_subtree(n, 0);
    // 親方向にカットエッジが伸びてる場合の部分木のサイズK以上の連結成分の個数
    vector<int> dp_cut_top(n, 0);
    auto dfs = [&](auto dfs, int v, int par) -> void {
        parent[v] = par;
        dp_subtree[v] = 1;
        for(int cld: adj[v]){
            if(cld == par) continue;
            dfs(dfs, cld, v);
            dp_subtree[v] += dp_subtree[cld];
        }
        int tmpnum = 0;
        for(int cld: adj[v]){
            if(cld == par) continue;
            if(dp_subtree[cld] >= k) tmpnum++;
        }
        dp_cut_top[v] = tmpnum;
        for(int cld: adj[v]){
            if(cld == par) continue;
            int loss = (dp_subtree[cld]>=k)? 1: 0;
            int gain = dp_cut_top[cld];
            dp_cut_top[v] = max(dp_cut_top[v], tmpnum -loss +gain);
        }
    };
    dfs(dfs, 0, -1);
    int ans = 0;
    for(int i=0; i<n; i++){
        // 頂点iを取り除いた時のK連結成分数
        int sub = 0;
        if(n-dp_subtree[i] >= k) sub++;
        // 子方向にエッジを伸ばしたときの増減
        vector<int> gain;
        for(int cld: adj[i]){
            if(cld == parent[i]) continue;
            int subtree_ok = (dp_subtree[cld]>=k)? 1: 0;
            if(subtree_ok == 1) sub++;
            gain.push_back(dp_cut_top[cld] -subtree_ok);
        }
        sort(gain.begin(), gain.end(), greater<int>());
        if(gain.empty()) continue; // 相異なる2点を選ぶ、に違反
        if(gain.size() >= 1u){
            ans = max(ans, sub+gain[0]);
        }
        if(gain.size() >= 2u){
            ans = max(ans, sub+gain[0]+gain[1]);
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 14596
n = int(input())
cnt = 0
queue = []
last = {}
for _ in range(n):
    p = int(input())
    if p-1 not in last.keys():
        last[p] = len(queue)
        queue.append([p])
        if cnt < 1:
            cnt = 1
    else:
        queue[last[p-1]].append(p)
        last[p] = last[p-1]
        if cnt < len(queue[last[p-1]]):
            cnt = len(queue[last[p-1]])

print(n-cnt)


Measured memory_bytes: 50384
while True:
    H,W = map(int,input().split())
    if H == W == 0: break
    l = ['#.','.#']
    flg = True
    result = ''
    for i in range(H):
        flg = ~flg
        ret = l[flg] * (W//2)
        if W%2 == 1: ret = (ret + l[flg])[:W]
        result += ret + '\n'
    print(result)

Measured memory_bytes: 7580
from collections import Counter
n=int(input())
strings=[]
for _ in range(n):
    s=input()
    s=sorted(s)
    s="".join(s)
    strings.append(s)
c=Counter(strings)
ans=0
for i,v in c.items():
    ans+=int(v*(v-1)*0.5)
print(ans)


Measured memory_bytes: 19764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	long long int n,a[100],dp[101][21];
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<=20;i++){
		if(i==a[0])dp[0][i]=1;
		else dp[0][i]=0;
	}
	for(int i=1;i<n-1;i++){
		for(int j=0;j<21;j++){
			dp[i][j]=0;
			if(j+a[i]<=20)dp[i][j]+=dp[i-1][j+a[i]];
			if(j-a[i]>=0)dp[i][j]+=dp[i-1][j-a[i]];
		}
	}
/*	for(int i=0;i<n-1;i++){
		for(int j=0;j<21;j++){
			cout<<dp[i][j]<<" ";
		}cout<<endl;
	}*/
	cout<<dp[n-2][a[n-1]]<<endl;
}

Measured memory_bytes: 1172
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <climits>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)
#define rep1(i, n) for(int i = 1; i <= (int) n; i++)
#define all(v) v.begin(),v.end()

int main() {
    int n,m;
    cin >> n >> m;
    rep(i,m) {
        int a;
        cin >> a;
        n -= a;
    }
    cout << max(-1,n) << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>
int main(void)
{
	int i, n;
	char t[4];
	int c[4];
	for (i=0; i<4; ++i) c[i]=0;
	while (scanf("%d,%s", &n, t) != EOF) {
		switch (t[0]) {
			case 'A': if (t[1]=='B') c[2]++; else c[0]++; break;
			case 'B': c[1]++; break;
			case 'O': c[3]++; break;
		}
	}
	if (c[1] < 6) return 1;
	for (i=0; i<4; ++i) printf("%d\n", c[i]);
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String[] t = sc.nextLine().split(" ");
		long a = Long.parseLong(t[0]);
		long b = Long.parseLong(t[1]);
		long c = Long.parseLong(t[2]);
		long d = Long.parseLong(t[3]);

		long ans = a * c;
		ans = Math.max(ans, a * d);
		ans = Math.max(ans, b * d);
		ans = Math.max(ans, b * c);

		if((a <= 0 && b >= 0 )|| (c <= 0 && d >= 0)) {
			ans = Math.max(ans, 0);
		}


		System.out.println(ans);
	}
}

Measured memory_bytes: 35652
n, m = map(int, input().split())
V = n + m
par = [i for i in range(0, V)]
sizes = [1] * V


def find(x):
    if x == par[x]:
        return x
    par[x] = find(par[x])
    return par[x]


def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    if sizes[x] < sizes[y]:
        x, y = y, x
    par[y] = x
    sizes[x] += sizes[y]


for i in range(0, n):
    for l in [int(k)for k in input().split()][1:]:
        unite(i, l - 1 + n)
r = "YES"
for i in range(0, n):
    if find(i) != find(0):
        r = "NO"
print(r)


Measured memory_bytes: 12592
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long ll;
const int mod= 1e+9+7;

int main() {
    string S; cin>>S;
    ll K; cin>>K;
    ll b=S.size();
    ll a=min(b,K);
    for(int i=0;i<a;i++){
        if(S[i]>'1'){
             cout<<S[i]<<endl;
        return 0;
        }
    }
    cout<<1<<endl;
}


Measured memory_bytes: 256
L,R = map(int,input().split())
ans = 2020
if R - L + 1 >= 2019 :  
  ans = 0
else:
  for i in range(L, R+1):
    for j in range(i+1, R+1):
      if i*j % 2019 < ans:
        ans = i*j % 2019
print(ans)

Measured memory_bytes: 40556