akhauriyash/Code-Regression huggingface dataset:
object Main extends App {
  val sc = new FastScanner(System.in)
  val n, q = sc.nextInt()
  val c = List.fill(n)(sc.nextInt()-1)
  val lr = List.fill(q)((sc.nextInt()-1, sc.nextInt()-1))

  val pre = Array.fill(n)(-1)
  val ps = Array.fill(n)(List[Int]())
  for ((r, idx) <- c.zipWithIndex) {
    val l = pre(r)
    if (l != -1) {
      ps(l) ::= idx
    }
    pre(r) = idx
  }

  val qs = Array.fill(n)(List[(Int, Int)]())
  for (((l, r), idx) <- lr.zipWithIndex) {
    qs(l) ::= (r, idx)
  }

  val ans = Array.fill(q)(0)
  val bit = new BinaryIndexedTree(n)

  for (x <- n-1 to 0 by -1) {
    for (y <- ps(x)) {
      bit.add(y, 1)
    }
    for ((y, idx) <- qs(x)) {
      ans(idx) = y-x+1 - bit.query(y+1)
    }
  }

  val pw = new java.io.PrintWriter(Console.out)
  ans.foreach(pw.println)
  pw.flush()
}

class BinaryIndexedTree(n: Int) {
  private val tree = Array.fill(n+1)(0)

  def query(r: Int): Int = {
    var res = 0
    var i = r
    while (i > 0) {
      res += tree(i)
      i -= i & -i
    }
    res
  }

  def add(idx: Int, a: Int): Unit = {
    var i = idx+1
    while (i <= n) {
      tree(i) += a
      i += i & -i
    }
  }
}

class FastScanner(source: java.io.InputStream) {
  val buf = new Array[Byte](1024)
  var now, end = 0

  def isPrintable(b: Byte): Boolean = 33 <= b && b <= 126
  def isNum(b: Byte): Boolean = 48 <= b && b <= 57

  def hasNextByte: Boolean = {
    if (now < end) {
      true
    } else {
      now = 0
      end = source.read(buf)
      end > 0
    }
  }

  def nextByte(): Byte = {
    if (hasNextByte) {
      val b = buf(now)
      now += 1
      b
    } else {
      -1
    }
  }

  def hasNext: Boolean = {
    while (hasNextByte && !isPrintable(buf(now))) {
      now += 1
    }
    hasNextByte
  }

  def next(): String = {
    if (hasNext) {
      val sb = new StringBuilder()
      var b = nextByte()
      while (isPrintable(b)) {
        sb += b.toChar
        b = nextByte()
      }
      sb.toString
    } else {
      throw new NoSuchElementException()
    }
  }

  def nextInt(): Int = {
    nextLong().toInt
  }

  def nextLong(): Long = {
    if (hasNext) {
      var b = nextByte()
      var sign = 1
      var n = 0L
      if (b == '-') {
        sign = -1
        b = nextByte()
      }
      while (isNum(b)) {
        n = n * 10 + (b - 48)
        b = nextByte()
      }
      sign * n
    } else {
      throw new NoSuchElementException()
    }
  }

  def nextDouble(): Double = next().toDouble
}


Measured memory_bytes: 271452
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int h = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        double jikakudo = (double)h*30+(double)m/2.0;
        double hunkakudo = 6.0 * (double)m;
        double kakudo = 0;
        if(sa(jikakudo, hunkakudo) >= 180) kakudo = 360 - sa(jikakudo, hunkakudo);
        else kakudo = sa(jikakudo, hunkakudo);
        double ans = a*a + b*b - 2*a*b*Math.cos(Math.toRadians(kakudo));
        System.out.println(Math.sqrt(ans));
    }
    static double sa(double a, double c) {
        if(a <= c) return c-a;
        else return a-c;
    }
}

Measured memory_bytes: 35904
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
// #define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const ll INF = (1LL<<60);
#else
const int INF = (1LL<<30);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

signed main(void)
{
  string s;
  cin >> s;
  string t = s;
  reverse(ALL(t));
  if(s == t) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

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

int main(){
    int n,m;
    cin >> n >> m;
    int table[30] = {0};//

    int k,tmp;

    rep(i,n){
        cin >> k;
        rep(j,k){
            cin >> tmp;
            tmp--;
            table[tmp]++;
        }
    }
    int ans = 0;

    // rep(i,m){
    //     cout << table[i] << endl;
    // }

    rep(i,m){
        if(table[i] == n)ans++;
    }

cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
from math import cos, radians, sqrt

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

a, b, h, m = MAP()

hm = h*60 + m

heach = hm / 720
meach = m / 60
hdig = heach * 360
mdig = meach * 360
dig = min(abs(hdig-mdig), 360 - abs(hdig-mdig))

ans = sqrt(a**2 + b**2 -(2*a*b*cos(radians(dig))))
print(ans)


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> a(n + 1), b(n);
  for (int i = 0; i < n + 1; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans += min(a[i], b[i]);
    b[i] -= min(a[i], b[i]);
    ans += min(a[i + 1], b[i]);
    a[i + 1] -= min(a[i + 1], b[i]);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
#define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define ll long long
 
#define vi vector<int>
#define vl vector<long>
#define vll vector<long long>
 
#define infi INT_MAX
#define infl LONG_LONG_MAX
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=(b-1);i>=a;i--)
#define F first
#define S second
#define G(a,b) get<a>(b)
#define MP make_pair
#define MT make_tuple
#define pll pair<ll,ll> 
#define endl "\n"
#define ALL(v) v.begin(),v.end()
#define nl cout<<"\n";
#define pr(x) cout<<x;
#define pr1(x) cout<<x<<" ";
#define pr2(x,y) cout<<x<<" "<<y;
#define deb printf("***************************************************************************************\n");

inline ll ceil(ll a,ll b)
{
  return (a+b-1)/b;
}



void func()
{ 
  ll x;
  cin>>x;
  ll y=x/500;
  ll ans=1000*y;
  x%=500;
  ll z=x/5;
  ans+=(5*z);
  cout<<ans<<endl;
} 

int main() 
{
    //fast
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif // ONLINE_JUDGE*/
    
    ll ntc=1;
    //cin>>ntc;

    f(i,1,ntc+1)
    {
      //cout<<"Case #"<<i<<": ";
      func();
    }
 
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
    int n;
    while(cin>>n)
    {
        if(n==0)break;
        int a,b;
        int as=0,bs=0;
        for(int kk=0;kk<n;kk++)
        {
            cin>>a>>b;
            if(a>b)as+=a+b;
            else if(a<b)bs+=a+b;
            else if(a==b)
            {
                as+=a;
                bs+=b;
            }
        }
            cout<<as<<" "<<bs<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;

const ll INF = 1LL << 32;

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

int main() {
  ll n;

  cin >> n;

  ll ans = 0;

  ll cur = 1;
  for (ll i = 0; i < n; i++) {
    ll tmp;
    cin >> tmp;
    if (tmp != cur) ans++;
    else {
      cur++;
    }
  }

  if(cur == 1){
    puts("-1");
    return 0;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
N, M, C = (int(x) for x in input().split())
B = list(map(int, input().split()))
ct = 0
for i in range(N):
  ans = 0
  A = list(map(int, input().split()))
  for j in range(M):
    ans += A[j] * B[j]
  if ans + C > 0:
    ct += 1
print(ct)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main()
{
    int n,a,b,x,y,z;
    cin>>n>>a>>b;
    x=max(a,b);
    y=min(a,b);
    z=x-y;

    if(z%2==0)
    {
        cout<<"Alice"<<endl;
    }
    else
        cout<<"Borys"<<endl;
        return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
vector<bool> used;
int main(){
	int n, m;
	cin>>n>>m;
	int d0 = 0, d1 = 1, d2;
	int i = 1;
	for(int j = 0; j <= m; ++j){
		int i1;
		if(j < m)cin>>i1;
		else i1 = n + 1;
		for(; i < i1 ;++i){
			d2 = d0 + d1;
			if(d2 >= MOD)d2 -= MOD;
			d0 = d1; d1 = d2;
		}
		d0 = d1;
		d1 = 0;
		i++;
	}
	cout<<d0<<endl;	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long int     ll;
typedef  vector<int>       vi;
typedef  pair<int,int>     pii;
#define  int               ll
#define  F                 first
#define  S                 second
#define  pb                push_back
#define  mp                make_pair 
#define  si(x)             (int)x.size()
#define  all(x)            x.begin(),x.end()
#define  minv(m,n)         *min_element(m,n)      
#define  maxv(m,n)         *max_element(m,n)
#define  mem(a,x)          memset(a,x,sizeof(a))
#define  deb(x)            cout<<#x<<" = "<<x<<endl
#define  rep(i,n)          for(int i=0; i<n;i++)
#define  prs(x)            fixed <<setprecision(x)
#define  w(ttz)            int ttz;cin>>ttz;while(ttz--)
#define  show(a)           for(auto x:a){cout<<x<<" ";}cout<<endl;
        void iosbase(void);

// bool string
int32_t main() 
{   
  iosbase();
  int  n , l;
  cin>>n>>l;
  string st[n];
  rep( i , n)
  cin>>st[i];
  sort(st , st+n  );
  rep( i , n)
  cout<<st[i];


}


void iosbase(void){
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif 
}

Measured memory_bytes: 3652
INF = 10 ** 9
MOD = 10 ** 9 + 7
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  copy import deepcopy
from bisect import bisect_left

def main():
    n = int(input())
    C = [int(input()) for _ in range(n)]

    dic = {i:0 for i in set(C)}
    dp = [0] * (n + 1)
    dp[0] = 1
    for i in range(n):
        if i > 0 and C[i] == C[i - 1]:
            dp[i + 1] = dp[i]
            continue
        else:
            dp[i + 1] = (dp[i] + dic[C[i]])%MOD
            dic[C[i]] += dp[i]
            dic[C[i]] %= MOD
    print(dp[-1]%MOD)
    
if __name__ == '__main__':
    main() 

Measured memory_bytes: 44164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC targett("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(ll i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 4e18
#define five 100005;
#define six 1000005;
#define prllclock cerr<<"Time"<<1000*(ld)clock()(ld)CLOCKS_PER_SEC<<"ms\n";
//_______________________________________________________________________________
int main()
{
       int n;
       cin>>n;

       int x[n];
       memset(x,0,sizeof x);
       fri(i,1,n)
       {
              int xx;
              cin>>xx;
              --xx;
              x[xx]++;
       }
       fri(i,0,n)
       {
              cout<<x[i]<<endl;
       }
}


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

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, m;
	cin >> n >> m;
	int T;
	cin >> T;
	vector<int> x(m);
	vector<int> y(m);
	for(int i = 0; i < m; i++){
		cin >> x[i] >> y[i];
		x[i]--; y[i]--;
	}
	if(T == 1){
		using B = bitset<50000>;
		vector<B> cur(n);
		for(int i = 0; i < n; i++){
			cur[i][i].flip();
		}
		for(int i = 0; i < m; i++){
			cur[x[i]] |= cur[y[i]];
			cur[y[i]] |= cur[x[i]];
		}
		for(int i = 0; i < n; i++){
			if((int)cur[i].count() == n){
				vector<int> where(n, 0);
				where[i] = 1;
				string st(m, '.');
				for(int j = m-1; j >= 0; j--){
					st[j] = "^v"[where[x[j]] < where[y[j]]];
					where[x[j]] |= where[y[j]];
					where[y[j]] |= where[x[j]];
				}
				cout << st << '\n';
				return 0;
			}
		}
		cout << -1 << '\n';
	} else if(T == 2){
		if(n == 2){
			cout << -1 << '\n';
			return 0;
		}
		string st(m, '^');
		vector<int> reach(3, 1);
		int last = -1;
		for(int i = 0; i < m; i++){
			if(y[i] >= 3) continue;
			int other = 3 - x[i] - y[i];
			if(!reach[other]){
				assert(last >= 0);
				st[last] ^= ('^' ^ 'v');
				reach[other] = true;
			}
			st[i] = '^';
			reach[x[i]] = true;
			reach[y[i]] = false;
			last = i;
		}
		cout << st << '\n';
	}
}

Measured memory_bytes: 306944
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
string s;
int a[101010],b[101010],c[101010],n,mx,now;
void change1()
{
	memset(b,0,sizeof(b));
	now=0;
	char lt='R';
	for(int i=0;i<n;i++)
	{
		if(s[i]==lt)
		{
			now++;
		}
		else
		{
			if(lt=='R')
			{
				b[i-1]+=now;
			}
			else
			{
				b[i-now]+=now;
			}
			lt=s[i];
			now=1;
		}
	}
	b[n-now]+=now;
	for(int i=0;i<n;i++)
	{
		if(b[i])
		{
			if((mx-max(b[i]-1,b[i+1]-1)%2+(b[i]>b[i+1]))%2==0)
			{
				int t=b[i]+b[i+1];
				b[i]=t/2;
				b[i+1]=t/2+t%2;
			}
			else
			{
				int t=b[i]+b[i+1];
				b[i+1]=t/2;
				b[i]=t/2+t%2;
			}
			i++;
		}
	}
	for(int i=0;i<n;i++)
	{
		a[i]=b[i];
	}
}
void change2()
{
	memset(b,0,sizeof(b));
	for(int i=0;i<n;i++)
	{
		if(s[i]=='R')
		{
			b[i+1]+=a[i];
		}
		else
		{
			b[i-1]+=a[i];
		}
	}
	for(int i=0;i<n;i++)
	{
		a[i]=b[i];
	}
}
int main()
{
	cin>>s;
	n=s.size();
	char lt='R';
	for(int i=0;i<n;i++)
	{
		a[i]=1;
	}
	for(int i=0;i<n;i++)
	{
		if(s[i]==lt)
		{
			now++;
		}
		else
		{
			lt=s[i];
			mx=max(mx,now);
			now=1;
		}
	}
	mx=max(mx,now);
	change1();
	mx%=2;
	if(mx%2==1)
	{
		change2();
	}
	for(int i=0;i<n;i++)
	{
		cout<<a[i]<<' ';
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1408
import java.util.*;
class Main{
    Scanner sc=new Scanner(System.in);
    void main(){
	int a=sc.nextInt();
	int b=sc.nextInt();
	System.out.println(a*b+" "+((a+b)*2));
    }
    public static void main(String[]ag){
	new Main().main();
    }
}

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

int main(){
    int n;
    cin>>n;
    vector<int>a;
    int sum=0;
    a.push_back(0);
    rep(i,n){
        int x; cin>>x;
        a.push_back(x);
    }
    a.push_back(0);
    rep(i,n+1){
        sum+=abs(a[i]-a[i+1]);
    }
    for(int i=1; i<=n; ++i){
        if((a[i-1]<a[i]&&a[i]>a[i+1])||(a[i-1]>a[i]&&a[i]<a[i+1])){
            cout<<sum-min(abs(a[i-1]-a[i]),abs(a[i]-a[i+1]))*2<<endl;
        }
        else cout<<sum<<endl;
    }
}

Measured memory_bytes: 1784
fun main(args: Array<String>){

    val n = readLine()!!.toInt()

    val a = n % 10
    val s = when(a){
        2,4,5,7,9 -> "hon"
        0,1,6,8 -> "pon"
        3 -> "bon"
        else -> "hon"
    }

    println("$s")


}



Measured memory_bytes: 34364
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back


int main()
{
   ll n,m,k,i,j,x;
   string s;
   cin>>s;

   for(i=1;i<4;i++)
   {
      if(s[i]==s[i-1])
      {
         cout<<"Bad";
         return 0;
      }
   }

   cout<<"Good";
}


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

using namespace std;

typedef long long LL;

const int MX=4005,N=MX/2,MXV=200005,md=1000000007,iv2=(md+1)/2;
int n,m,ch,ff,ans;
int a[MXV],b[MXV];
int s[MX][MX],C[MX][MX];

int main(){
	int i,j;
	cin>>n;
	for(i=1;i<=n;i++)cin>>a[i]>>b[i];
	for(i=1;i<=n;i++)s[N-a[i]][N-b[i]]++;
	for(i=1;i<MX;i++)C[i][0]=C[0][i]=1;
	for(i=1;i<MX;i++)
		for (j=1;j<MX;j++) {
			if (i>0) (s[i][j]+=s[i-1][j])%=md;
			if (j>0) (s[i][j]+=s[i][j-1])%=md;
			C[i][j]=(C[i-1][j]+C[i][j-1])%md;
		}
	for(i=1;i<=n;i++)ans=(ans+s[N+a[i]][N+b[i]])%md;
	for(i=1;i<=n;i++)ans=(ans+md-C[a[i]*2][b[i]*2])%md;
	ans=(LL)ans*iv2%md;
	cout<<ans<<endl;
	return 0;
}


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

int main(){
    int N, M, V, P;
    cin >> N >> M >> V >> P;
    int *A = new int[N];
    long *SUM = new long[N];
    long sum=0;
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    sort(A, A+N);
    for(int i=0;i<N;i++){
    	sum += A[i];
      	SUM[i] = sum;
    }

    int boder = A[N-P];
    int ans = N;
    for(int i=N-P-1;i>=0;i--){
        if(A[i]==boder||A[i+1]==A[i]){
            continue;
        }else{
            int you = A[i] + M;
            if(you<boder){
                ans = N - i - 1;
                break;
            }
            if(i+P>=V){
                continue;
            }else{
                int rest = N - i - P;
                long enemy = static_cast<long>(you) * static_cast<long>(rest) - static_cast<long>(SUM[i+rest] - SUM[i]);
                if(enemy < static_cast<long>(M)*static_cast<long>(V-i-P)){
                    ans = N - i - 1;
                    break;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int main(){
  int n,k;
  cin>>n>>k;
  vector<int>cnt(n);
  rep(i,k){
    int d;
    cin>>d;
    rep(i,d){
      int a;
      cin>>a;
      cnt[a-1]++;
    }
  }
  int ans=0;
  rep(i,n){
    if(cnt[i]==0)ans++;
  }
  cout<<ans<<endl;
  return(0);
}


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


using namespace std;





#define ll                  long long int


#define endl                '\n'


#define rep(i,a,b)          for(ll i=a;i<b;i++)





void solve()


{


    ll n;


    cin>>n;


    ll a[n+1];


    rep(i,1,n+1) cin >> a[i];


    ll ps[n+1],dp[n+1];


    dp[0] = 0;dp[1] = 0;


    ps[1] = a[1];


    for(ll i=3;i<=n;i+=2) ps[i] = ps[i-2] + a[i];


    rep(i,2,n+1){


        if (i&1){


            dp[i] = max(dp[i-1],a[i]+dp[i-2]);


        }


        else{


            dp[i] = max(dp[i-2] + a[i],ps[i-1]);


        }


    }


    cout << dp[n] << endl;




}




int32_t main(){


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


    solve();


    return 0;


}

Measured memory_bytes: 8324
# original_author prd_xxx

N,M = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(M)]
P = list(map(int,input().split()))

ans = 0
# bin N 左シフトを1からNまで行う。
for b in range(1<<N):
    for i in range(M):
        c = 0
        for s in src[i][1:]:
            # 解答bitflagとand計算でスイッチのonoffを定義
            if b&(1<<(s-1)):
                c += 1
        # 最後に条件スイッチの条件と合致しているか検証
        # 合わなければelseに飛ばずbの次を検証しに行く
        if c%2 != P[i]: break
    else:
        ans += 1
print(ans)


Measured memory_bytes: 3064
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define dbg(x) { cerr<<"> "<<#x<<": "<<x<< endl; }
#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int inf = INT_MAX;
const double eps = 0.0000001;
const double PI = acos(-1.0);
const int MOD = 1e9+7;
const int N  = 105;

int w[N], v[N], dp[N][100005];

int solve (int i, int j) {
	if (j == 0) return 0;
	if (j < 0) return -inf;
	if (i == 0) return 0;
	if (dp[i][j]) return dp[i][j];
	dp[i][j] = max(v[i] + solve(i-1, j-w[i]), solve(i-1, j));
	return dp[i][j];
}

signed main(){
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif  
    IOS;

    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    	cin >> w[i] >> v[i];
    cout << solve(n, k);
    return 0;
}

Measured memory_bytes: 79360
#include<stdio.h>
int main()
{
    long long int k,s,x,y,z,i,j,p,count=0;
    scanf("%lld%lld",&k,&s);
    for(i=0; i<=k; i++)
    {
        x=i;
        for(j=0;j<=k;j++)
        {
            y=j;
            z=s-x-y;
                if(x+y+z==s&&z>=0&&z<=k)
                {
                   count++;
                }

        }
    }
    printf("%lld\n",count);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int Find_LCM(ll a,ll b)
{
    return a*b/__gcd(a,b);
}
int main()
{

    ll a,b;
    cin>>a>>b;

    ll x=Find_LCM(a,b);

    ll y=a*b;


    if(x%a==0 && x%b==0){
      cout<<x<<endl;
    }else{
    cout<<a*b<<endl;
    }

    /*

    cout<<__gcd(a,b)<<endl;

    if(a>=b)cout<<a*b<<endl;
    else{
    ll x=Find_LCM(a,b);
    cout<<x<<endl;
    }

*/


    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys

def main():
	K, S = map(int, input().split(" "))
	
	ans = 0
	for X in range(K+1):
		for Y in range(K+1):
			Z = S - X - Y
			if 0 > Z or K < Z:
				continue
			ans += 1
			
	print(ans)
	
if __name__ == "__main__":
	main()
	

Measured memory_bytes: 2940
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
// in fenwick always use size as 1000010
#define int long long
#define ll long long
#define pp pair<int,int>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
int max(int x, int y)
{
    return x>y ? x : y;
}
int min(int x, int y)
{
    return x<y ? x : y;
}
void _(int&a , int b)
{
    a=(a%mod+b%mod)%mod;
    a=(a+mod)%mod;
}
ll cl(ll a,ll b)
{
    return (a/b)+(!(!(a%b)));
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s,t;
    cin >> s>> t;
    ll ans=0;
    for (int i = 0; i < s.size(); ++i)
    {
    	ans+=(s[i]!=t[i]);
    }
    cout << ans;
    }

Measured memory_bytes: 3740
package main

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

func main() {

	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	in := sc.Text()
	stack := Stack{}
	stack2 := Stack2{}
	total := 0
	for i, v := range []rune(in) {
		val := string(v)
		// fmt.Print(val)

		switch val {
		case "\\":
			stack.push(i)
		case "/":
			b := stack.pop()
			if b == -1 {
				continue
			}

			area := i - b
			total = total + area

			// fmt.Print(" ")
			// for _, v := range stack2.stack {
			// 	fmt.Print(v.area)
			// 	fmt.Print(" ")
			// }

			// if !stack2.empty() {
			// 	fmt.Println()
			// }

			// for _, v := range stack2.stack {
			// 	fmt.Print(v.index)
			// 	fmt.Print(" ")
			// }

			// if !stack2.empty() {
			// 	fmt.Println()
			// }
			if !stack2.empty() {
				// fmt.Printf("b:%v index:%v", b, stack2.top().index)
				if stack2.top().index < b {
					stack2.push(Tuple{b, area})

				} else {
					s := stack2.pop()
					newArea := area

					for s.index > b {
						newArea = newArea + s.area
						s = stack2.pop()
					}
					stack2.push(s)
					stack2.push(Tuple{b, newArea})

				}
			} else {
				stack2.push(Tuple{b, area})

			}

		case "_":
		}
	}

	fmt.Println(total)

	result := []string{}
	for _, v := range stack2.stack {
		if v.area == 0 {
			continue
		}

		result = append(result, strconv.Itoa(v.area))
	}

	if len(result) != 0 {
		fmt.Print(len(result))
		fmt.Print(" ")

		fmt.Println(strings.Join(result, " "))

	} else {
		fmt.Println(len(result))

	}

}

type Stack struct {
	stack []int
}

func (stack *Stack) push(val int) {
	stack.stack = append(stack.stack, val)
}

func (stack *Stack) pop() int {
	if len(stack.stack) == 0 {
		return -1
	}

	val := stack.stack[len(stack.stack)-1]
	stack.stack = stack.stack[0 : len(stack.stack)-1]
	return val
}

func (stack *Stack) empty() bool {
	if len(stack.stack) == 0 {
		return true
	}
	return false
}

type Stack2 struct {
	stack []Tuple
}

type Tuple struct {
	index int
	area  int
}

func (stack *Stack2) push(val Tuple) {
	stack.stack = append(stack.stack, val)
}

func (stack *Stack2) pop() Tuple {
	if len(stack.stack) == 0 {
		return Tuple{-1, 0}
	}

	val := stack.stack[len(stack.stack)-1]
	stack.stack = stack.stack[0 : len(stack.stack)-1]
	return val
}

func (stack *Stack2) top() Tuple {
	if len(stack.stack) == 0 {
		return Tuple{-1, 0}
	}

	val := stack.stack[len(stack.stack)-1]
	return val
}

func (stack *Stack2) empty() bool {
	if len(stack.stack) == 0 {
		return true
	}
	return false
}



Measured memory_bytes: 2112
#include<stdio.h>

#define MAX  100
#define INFTY  (1<<21)
#define WHITE  0
#define GRAY  1
#define BLACK  2

int n, M[MAX][MAX];

int prim(){
  int i, v, sum = 0, u, minv;
  int d[MAX], p[MAX], color[MAX];

  for(i = 0 ; i < n ; i++){
    d[i] = INFTY;
    p[i] = -1;
    color[i] = WHITE;
  }

  d[0] = 0;

  while(1){
    minv = INFTY;
    u = -1;
    for(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(v = 0 ; v < n ; v++){
      if(color[v] != BLACK && M[u][v] != INFTY){
	if(d[v] > M[u][v]){
	  d[v] = M[u][v];
	  p[v] = u;
	  color[v] = GRAY;
	}
      }
    }
  }

  for(i = 0 ; i < n ; i++){
    if(p[i] != -1) sum += M[i][p[i]];
  }

  return sum;
}

int main(){
  int e, i, j;
  
  scanf("%d",&n);

  for(i = 0 ; i < n ; i++){
    for(j = 0 ; j < n ; j++){
      scanf("%d",&e);
      M[i][j] = (e == -1) ? INFTY : e;
    }
  }

  printf("%d\n",prim());

  return 0;
}

Measured memory_bytes: 632
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    int i,j,cnt=0;
    cin>>s>>t;
    for(i=0;i<3;i++)
    {
        if(s[i]==t[i])
            cnt++;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return int(i)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	var (
		s string
		t string
	)
	fmt.Scan(&s, &t)

	n := len(s)

	start := make([]int, 0, 26)
	goal := make([]int, 0, 26)
	for i := 0; i < 26; i++ {
		start = append(start, -1)
		goal = append(goal, -1)
	}

	for i := 0; i < n; i++ {
		a := int(s[i] - 'a')
		b := int(t[i] - 'a')

		// 何かしら変換が行われている]
		if start[a] != -1 {
			if start[a] != b {
				fmt.Println("No")
				return
			}
		} else {
			start[a] = b
		}

		if goal[b] != -1 {
			if goal[b] != a {
				fmt.Println("No")
				return
			}
		} else {
			goal[b] = a
		}
	}

	fmt.Println("Yes")
}


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

//50 
typedef long long ll;

int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>> v(m);
	for (int i = 0; i < m; ++i) {
		int x;
		cin >> x;
		for (int j = 0; j < x; ++j) {
			int p;
			cin >> p;
			p--;
			v[i].push_back(p);
		}
	}
	vector<int> p(m);
	for (int i = 0; i < m; ++i) {
		cin >> p[i];
	}
	int cnt = 0;
	for (int i = 0; i < pow(2,n); ++i) {
		vector<int> s(n);
		for (int j = 0; j < n; ++j) {
			if ((i >> j) & 1) {
				s[j] = 1;
			}
		}
		bool d = 1;
		for (int k = 0; k < m; ++k) {
			int cp = 0;
			for (int w = 0; w < (int)v[k].size(); ++w) {
				if (s[v[k][w]]) {
					cp++;
				}
			}
			if (cp % 2 != p[k]) d = 0;  
		}
		if (d) {
			cnt++;
		}
	}
	cout << cnt;
}
	


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

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)


/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;


/* constant */
const int inf = 10001000100;
const int mod = 1e9 + 7;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};


/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}


/* general_method */
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


/* main */

int n, k;
vi arr;

int first = 0;
int second = 1;

int dp[2][100010];


int dfs(int turn, int rest){ //winner

    if(rest < 0){
        if(turn == first){
            return first;
        }else{
            return second;
        }
    }

    if(dp[turn][rest] > -1) return dp[turn][rest];



    bool win = false;

    rep(i,0,n) if(dfs(turn ^ 1, rest - arr[i]) == turn) win = true;

    if(win){
        return dp[turn][rest] = turn;
    }else{
        return dp[turn][rest] = turn ^ 1;
    }



}


signed main(){


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

    cin >> n >> k;
    rep(i,0,n) arr.push_back(input());

    memset(dp, -1, sizeof(dp));

    if(dfs(first, k) == first){
        print("First");
    }else{
        print("Second");
    }






	



	
	


	




	




    



	








    



    





    


    

}



Measured memory_bytes: 8064
a, b = map(int, input().split())
if a == b:
    for _ in range (a):
        print (a,end="")
    exit (0)
else:
    if a < b:
        for _ in range(b):
            print (a,end="")
    else:
        for _ in range(a):
            print (b,end="")

Measured memory_bytes: 3060
@1=map$-=$_-2,@0=1..<>+2;--$0[-1];$p=$_,map$\+=$p*($$_[$N=$$_[$i=$_[$p]]]-($$_[$P=${1-$_}[$i]]=$N))*($i-$P),0,1for map$_[$_]=++$i,glob<>;print

Measured memory_bytes: 43172
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const int dig=60;
#define N 233
inline ll read(){
	ll x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int T,n;
ll a[N];
char s[N];
struct Basis{
	ll d[64];
	void clear(){
		memset(d,0,sizeof(d));
	}
	void Insert(ll x){
		for(int i=dig;i>=0;--i){
			if((x>>i)&1){
				if(d[i]){
					x^=d[i];
				}
				else{
					d[i]=x;
					return;
				}
			}
		}
	}
	bool check(ll x){
		for(int i=dig;i>=0;--i){
			if((x>>i)&1){
				if(!d[i])return false;
				x^=d[i];
			}
		}
		return true;
	}
}B;
int Solve(){
	n=read();
	for(int i=1;i<=n;++i){
		a[i]=read();
	}
	scanf("%s",s+1);
	B.clear();
	for(int i=n;i>=1;--i){
		if(s[i]=='0'){
			B.Insert(a[i]);
		}
		else{
			if(!B.check(a[i]))return 1;
		}
	}
	return 0;
}
int main(){
	T=read();
	while(T--){
		printf("%d\n",Solve());
	}
	return 0;
}



Measured memory_bytes: 3732
M=8**7
m,f,g,i=M*476+1,[j:=1],[k:=1]*M,1
while i<M:f+=f[-1]*i%m,;i+=1
g+=pow(M*f[-1],m-2,m),
while i:g[i-1]=g[i]*i%m;i-=1
A,B=map(int,input().split())
if A<B:A,B=B,A
while j<=B:i+=k*f[A+B-j]*g[B-j];k=k*2%m;j+=1
print((i*f[B]*g[A+B]+A)%m)

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

int pazzle[3][3];
int tmp[3][3];
int test_x[4] = {0,1,0,-1};
int test_y[4] = {1,0,-1,0};

int main() {
    int i,j,l,sign,x,y;
        
    for(i=0; i<3; i++){
        for(j=0; j<3; j++) scanf("%d",&pazzle[i][j]);
    }
         
    emp(&x,&y);
    for(l=0; l<100; l++){
        for(i=0; i<3; i++){
            for(j=0; j<3; j++) tmp[i][j] = pazzle[i][j];
        }
            
        sign = dfs(x,y,-1,0,l);
        if(sign!=-1){
            printf("%d\n",sign);
            break;
        }
            
        for(i=0; i<3; i++){
            for(j=0; j<3; j++) pazzle[i][j] = tmp[i][j];
        }
            
        sign = -1;
        if(l==99) printf("%d\n",sign);
    }
        
    return 0;
}

void emp(int *x,int *y) {
  int i,j;
  for(i=0; i<3; i++) {
    for(j=0; j<3; j++) {
      if(!pazzle[i][j]) {
    *x = j;
    *y = i;
      }
    }
  }
}
void swap(int *s,int *v){
  int tmp;
  tmp = *s;
  *s = *v;
  *v = tmp;
}   
int calc(){
  int i,a,sum=0; 
  for(i=0; i<9; i++){
    a = pazzle[i/3][i%3];
    if(a){
      a--;
      sum += abs(i/3 - a/3) + abs(i%3 - a%3);
    }
  }    
  return sum;
}
int dfs(int x,int y,int p,int d,const int lim){
    int i,h,x2,y2,res;   
    h = calc();
    if(h==0) {
        return d;
    }
    if(d+h>lim) {
        return -1;
    }
    for(i=0; i<4; i++){
        x2 = x+test_x[i];
        y2 = y+test_y[i];      
        if(~p && i==(p+2)%4) continue;
        if(!(0<=x2 && x2<3 && 0<=y2 && y2<3)) continue;    
        swap(&pazzle[y][x],&pazzle[y2][x2]);
        res = dfs(x2,y2,i,d+1,lim);
        if(~res) {
            return res;
        }
        swap(&pazzle[y][x],&pazzle[y2][x2]);
    }   
    return -1;
}    



Measured memory_bytes: 2112
n = input()
a,b = 0,0
if int(n[:2]) <= 12 and int(n[:2]) != 0:
    a = 1
if int(n[2:]) <= 12 and int(n[2:]) != 0:
    b = 1
if a == 0 and b == 0:
    print("NA")
if a == 0 and b == 1:
    print("YYMM")
if a == 1 and b == 0:
    print("MMYY")
if a == 1 and b == 1:
    print("AMBIGUOUS")

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

#define ll long long
#define INF INT_MAX

using namespace std;

int main() {
    int ww;
    int index = 1;
    while(scanf("%d",&ww) && ww){
        int n;
        cin >> n;
        int v[n],w[n];
        int dp[n+1][2000];
        bool go[n+1][2000];
        memset(dp,0,sizeof(dp));
        memset(go,false,sizeof(go));
        for(int i = 0;i < n;i++){
            scanf("%d,%d",&v[i],&w[i]);
        }
        for(int i = n-1;i >= 0;i--){
            for(int j = 0;j <= ww;j++){
                if(j < w[i]){
                    dp[i][j] = dp[i+1][j];
                    go[i][j] = false;
                }else{
                    if(dp[i+1][j] < dp[i+1][j-w[i]]+v[i]){
                        dp[i][j] = dp[i+1][j-w[i]]+v[i];
                        go[i][j] = true;
                    }else{
                        dp[i][j] = dp[i+1][j];
                        go[i][j] = false;
                    }
                }
            }
        }
        cout << "Case " << index++ << ":" << endl;
        cout << dp[0][ww] << endl;
        int sumweight = 0;
        for(int i = 0;i < n;i++){
            if(go[i][ww]){
                sumweight += w[i];
                ww -= w[i];
            }
        }
        cout << sumweight << endl;
 
        // for(int j = 0;j <= n;j++){
        //     for(int i = 0;i <= ww ;i++){
        //         printf("%3d ",dp[j][i]);
        //     }
        //     cout << endl;
        // }
    }
	return 0;
}        

Measured memory_bytes: 12948
class Unionfind:
    def __init__(self, n):
        self.d = []
        for _ in range(n):
            self.d.append(-1)
    
    def find(self, x):
        if self.d[x] < 0:
            return x
        else:
            self.d[x] = self.find(self.d[x])
            return self.d[x]
        
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.d[x] > self.d[y]:
            x, y = y, x
        self.d[x] = self.d[x] + self.d[y]
        self.d[y] = x
        return True
    
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def size(self, x):
        return -self.d[self.find(x)]

n, m, k = map(int, input().split())
dame = [set() for _ in range(n)]
uf = Unionfind(n)

for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    dame[a].add(b)
    dame[b].add(a)
    uf.unite(a, b)

for _ in range(k):
    c, d = map(int, input().split())
    c -= 1
    d -= 1
    if not uf.same(c, d):
        continue
    dame[c].add(d)
    dame[d].add(c)

for i in range(n):
    mem = uf.size(i) - 1
    mem -= len(dame[i])
    print(mem, end= " ")
print()


Measured memory_bytes: 127136
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using lli = long long int;
using i64 = int64_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n, a[5];
int main() {
  cin >> n; read_n(a, 5);
  i64 x = *min_element(&a[0], &a[5]);
  i64 ans = 4 + (n + x - 1) / x;
  cout << ans << '\n';
  return 0;
}


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

int main(){
    string S,T;
    int ans=0;
    cin >> S;
    cin >> T;
    rep(i,3) if(S[i]==T[i]) ans++;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main()
{
	int n, m, d;
	map<int, int> a;
	vector<int> b;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> d;
		
		if (a.find(d) != a.end())
			a[d]++;
		else
			a[d] = 1;
	}

	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> d;
		b.push_back(d);
	}

	int c = 0;
	for (const auto& e : b) {
		if (a.find(e) != a.end()) {
			if (a[e] != 0) {
				c++;
				a[e]--;
			}
		}
	}

	c == m ? cout << "YES\n" : cout << "NO\n";

	return 0;
}


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

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

Measured memory_bytes: 3620
n = int(input())
a = []
c = []
for i in range(n):
  b = input().split()
  b[1] = int(b[1])
  a.append(b)
  c.append(b)

s = sorted(a, key=lambda a:a[1], reverse=True)
m = sorted(s, key=lambda s:s[0])

for i in range(n):
  for j in range(n):
    if m[i] == c[j]:
      print(j+1)

Measured memory_bytes: 3064
#ifndef LOCAL
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
int n ;
vector<int> v ;
int dp[3001][3001] ;
int dfs(int x, int y){
    if ( x > y ) {
        return 0 ;
    }
    if ( x >= n ) {
        return 0 ;
    }
    if ( y < 0 ) {
        return 0 ;
    }
    if ( dp[x][y] != -INF ) return dp[x][y] ;
    int ans = max(v[x] - dfs(x + 1, y), v[y] - dfs(x, y - 1)) ;
    return dp[x][y] = ans ;
}
signed main(){
    fastio
    for(int i = 0; i < 3001; i++){
        for(int j = 0; j < 3001; j++){
            dp[i][j] = -INF ;
        }
    }
    cin >> n ;
    v = vector<int>(n) ;
    for(int i = 0; i < n; i++){
        cin >> v[i] ;
    }
    int ans = dfs(0, n - 1) ;
    cout << ans << endl;
    return 0; 
}

Measured memory_bytes: 74164
N,D=map(int,input().split())
ans=0
for i in range(N):
    X,Y=map(int,input().split())
    if (X**2+Y**2)**(1/2)<=D:
        ans+=1
print(ans)





        

    









    

        




    















    



    





    






        






    
















        


























            
    


    


    
    














    


    














Measured memory_bytes: 9624
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
using namespace std;
 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef stack<int> SI;
typedef queue<int> QI;
typedef pair<int,int> PII;
typedef long long LL;
 
#define d(x)  cout<<#x<<" = "<<(x)<<endl;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define EMP empty()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).rbegin()) i=(c).rbegin(); i!=(c).rend(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c,n) sort(c,c+n)
#define VSORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define DFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define DREP(i,n) DFOR(i,n,0)
#define INF 1000000000
 
const double EPS = 1e-10;
const double PI  = acos(-1.0);
////////////////////////////////////////////////
static const int MAX=10000;
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;
 
int n;
vector<PII> adj[MAX];
void dijkstra()
{
    priority_queue<PII> PQ;
    int color[MAX];
    int d[MAX];
    REP(i,n)
    {
        d[i]=INF;
        color[i]=WHITE;
    }
     
    d[0]=0;
    PQ.push(MP(0,0));
    color[0]=GRAY;
     
    while(!PQ.EMP)
    {
        PII f=PQ.top();
        PQ.pop();
        int u=f.second;
        color[u]=BLACK;
         
        if(d[u]<f.first*(-1))continue;
         
        REP(j,SZ(adj[u]))
        {
            int v=adj[u][j].first;
            if(color[v]==BLACK)continue;
            if(d[v]>d[u]+adj[u][j].second)
            {
                d[v]=d[u]+adj[u][j].second;
                PQ.push(MP(d[v]*(-1),v));
                color[v]=GRAY;
            }
        }
    }
    REP(i,n)
    {
        cout<<i<<" "<<(d[i]==INF?-1:d[i])<<endl;
    }
}
 
int main()
{
    int k,u,c,v;
    cin>>n;
    REP(i,n)
    {
        cin>>u>>k;
        REP(j,k)
        {
            cin>>v>>c;
            adj[u].PB(MP(v,c));
        }
    }
     
    dijkstra();
     
    return 0;
}

Measured memory_bytes: 8096
a = input()
al = a.split()

ial = []
for i in range(len(al)):
    ial.append(int(al[i]))


for i in range(len(ial)):
  if ial[i] == 0:
    try:
        print(ial[i+1]-1)
    except IndexError:
        print(ial[i-1]+1)

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

int main(){
    int A, B, C;
    cin >> A >> B >> C;

    int answer = A * C;

    if(answer > B){
        cout << B / A << endl;
    }
    else if(answer < B || answer == B){
        cout << C << endl;
    }
}

Measured memory_bytes: 256