akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1e9; 

int main() {
  ll n, k, s;
  cin >> n >> k >>s;
  ll temp=(s+1)%mod;
  for(int i=0;i<n;i++) {
    if(i<k) {
      cout << s;
    }
    else {
      cout << temp;
    }
    if(i!=n) {
      cout << " ";
    }
  }
  cout << endl;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
 
#define INF (1<<29)
 
int G[100][100], n;
 
int prim(){
  int p[100], d[100], c[100];
  int u;
 
  for(int i = 0; i < n; i++){
    d[i] = INF;
    p[i] = -1;
    c[i] = 0;
  }
 
  d[0] = 0;
 
  while(1){
    int minv = INF;
    u = -1;
    for(int i = 0; i < n; i++){
      if(minv > d[i] && c[i] != 2){
        u = i;
        // cout << u << endl;
        minv = d[i];
      }
    }
 
    if(u == -1) break;
    c[u] = 2;
    for(int v = 0; v < n; v++){
      if(c[v] != 2 && G[u][v] != INF){
        if(d[v] > G[u][v]){
          d[v] = G[u][v];
          p[v] = u;
          c[v] = 1;
        }
      }
    }
  }
 
  int sum = 0;
  for(int i = 0; i < n; i++){
    if(p[i] != -1) sum+=G[i][p[i]];
    // cout << p[i] << endl;
  }
  return sum;
}
 
 
  int main(){
 
    cin >> n;
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        int v;
        cin >> v;
        G[i][j] = v;
        if(v == -1) G[i][j] = INF;
      }
      // cout << endl;
    }
 
    cout << prim() << endl;
 
  }

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

using namespace std;

int main() {
  char a[100][101];
  int h, w;
  cin >> h >> w;
  vector<bool> col(w, false);
  vector<bool> row(h, false);
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      char c;
      cin >> c;
      row[i] = row[i] || c == '#';
      col[j] = col[j] || c == '#';
      a[i][j] = c;
    }
  }
  for (int i = 0; i < h; ++i) {
    if (!row[i]) continue;
    for (int j = 0; j < w; ++j) {
      if (!col[j]) continue;
      cout << a[i][j];
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>

using namespace std;

typedef long long ll;

#ifdef ONPC
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

bool can(int x, int y)
{
  return __builtin_popcount(x ^ y) % 2;
}

vector <int> solve(int n, int x, int y)
{
  if ((x >> (n + 1)) & 1) x -= (1 << (n + 1));
  if ((y >> (n + 1)) & 1) y -= (1 << (n + 1));
  if (n == 0)
  {
    return {x, y};
  }
  if (((x >> n) & 1) != ((y >> n) & 1))
  {
    for (int i = 0; i < (1 << (n + 1)); i++)
    {
      if (((i >> n) & 1) != ((x >> n) & 1)) continue;
      if (can(x, i) && can(i ^ (1 << n), y))
      {
        auto l = solve(n - 1, x, i);
        auto r = solve(n - 1, i ^ (1 << n), y);
        vector <int> ret;
        for (int a : l) ret.push_back(a + (x & (1 << n)));
        for (int a : r) ret.push_back(a + (y & (1 << n)));
        for (int i = 1; i < (int) ret.size(); i++)
        {
          assert(__builtin_popcount(ret[i] ^ ret[i - 1]) == 1);
        }
        return ret;
      }
    }
    assert(0);
  }
  else
  {
    auto b = solve(n - 1, x, y);
    auto ret = solve(n - 1, x, b[1]);
    vector <int> ans;
    ans.push_back(x);
    ans.push_back(x ^ (1 << n));
    ret.erase(ret.begin());
    for (int t : ret)
    {
      int sw = ((1 << n) & (x ^ (1 << n)));
      ans.push_back(t + sw);
    }
    b.erase(b.begin());
    for (int t : b)
    {
      int sw = ((1 << n) & x);
      ans.push_back(t + sw);
    }
    return ans;
  }
}

int main()
{
#ifdef ONPC
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  {
    int n = rnd() % 17 + 1, a = rnd() % (1 << n), b = rnd() % (1 << n);
    cin >> n >> a >> b;
    if (__builtin_popcount(a ^ b) % 2)
    {
      cout << "YES\n";
      auto x = solve(n - 1, a, b);
      for (int y : x)
      {
        cout << y << ' ';
      }
      cout << '\n';
    }
    else
    {
      cout << "NO\n";
    }
  }
}


Measured memory_bytes: 1756
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#define pb push_back
using namespace std;

const int N = 1e5+10;
int n,m;
vector <int> G[N], G2[N], V;
int Deg[N];
int DP[N];
queue <int> Q;


int main(){
  scanf("%d%d",&n,&m);
  int x,y;
  for(int i=1; i<=m; i++){
    scanf("%d%d",&x,&y);
    G[x].pb(y);
    G2[y].pb(x);
    Deg[y]++;
  }
  for(int i=1; i<=n; i++)if(Deg[i] == 0)Q.push(i);
  while(!Q.empty()){
    int v = Q.front();
    Q.pop();
    V.pb(v);
    for(auto u : G[v]){
      Deg[u]--;
      if(Deg[u]==0)Q.push(u);
    }
  }
  for(int i = V.size()-1; i>=0; i--){
    int v = V[i];
    for(auto u : G2[v]){
      DP[u] = max(DP[u], DP[v]+1);
    }
  }
  int res = 0;
  for(int i=1; i<=n; i++){
    res = max(res, DP[i]);
  }
  printf("%d\n",res);


  return 0;
}


Measured memory_bytes: 12412
import java.util.*;
 
class Main{
    Scanner sc = new Scanner(System.in);
 
    Main(){
    int a=sc.nextInt();
    int b=sc.nextInt();
    System.out.print( (a/b)+" "+(a%b)+" " );
    System.out.printf("%.8f\n", (double)a/b );
    }
 
    public static void main(String[] args){
    new Main();
    }
}


Measured memory_bytes: 26488
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int x = in.nextInt();

        int[] kyu = {600, 800, 1000, 1200, 1400, 1600, 1800, 2000};
        for (int i = 0; i < kyu.length; i++) {
            if (x < kyu[i]) {
                System.out.println(8 - i);
                break;
            }
        }
    }
}

Measured memory_bytes: 35648
#include <iostream>
#include <string>
#include <deque>
#include <algorithm>
#include <cctype>
using namespace std;

int main(){
	int n, m;
	for(cin >> n; n--; ){
		string cmd, msgstr;
		cin >> cmd >> msgstr;
		
		deque<char> msg(msgstr.begin(), msgstr.end());
		deque<char>::iterator it1, it2;
		
		for(int i = cmd.size() - 1; i >= 0; --i){
			switch(cmd[i]){
				case 'J':
					msg.push_front( msg.back() );
					msg.pop_back();
					break;
				case 'C':
					msg.push_back( msg.front() );
					msg.pop_front();
					break;
				case 'E':
					m = msg.size() / 2;
					it1 = msg.begin();
					it2 = msg.end() - m;
					while( m-- ){
						swap( *it1++, *it2++ );
					}
					break;
				case 'A':
					reverse(msg.begin(), msg.end());
					break;
				case 'P':
					for(it1 = msg.begin(); it1 != msg.end(); ++it1){
						if( isdigit(*it1) ){
							*it1 = (*it1 == '0' ? '9' : *it1 - 1);
						}
					}
					break;
				case 'M':
					for(it1 = msg.begin(); it1 != msg.end(); ++it1){
						if( isdigit(*it1) ){
							*it1 = (*it1 == '9' ? '0' : *it1 + 1);
						}
					}
					break;
			}
		}
		
		cout << string(msg.begin(), msg.end()) << '\n';
	}
}

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

const int MAX_N = 2e5;

void solve(long long N, long long K, long long A[MAX_N]) {
    map<long long , long long> m;
    long long a, b;
    long long current = 0;
    m[0] = 0;
    for (int i = 1; i < N; i++) {
        current = A[current] - 1;
        if (m.count(current)) {
            a = m[current];
            b = i;
            break;
        }
        m[current] = i;
        if (i == K) {
            cout << current + 1 << endl;
            return;
        }
    }
    long long rest = (K - a) % (b - a);
    while (rest) {
        current = A[current] - 1;
        rest--;
    }
    cout << current + 1 << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N, K, A[MAX_N];
    scanf("%lld %lld", &N, &K);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
    }

    solve(N, K, A);

    return 0;
}


Measured memory_bytes: 15128
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;



struct SegmentTree{
	int n;
	vector<int>dat;
	int f(int a,int b){return a + b;}
	SegmentTree(){};
	void init(int n_){
		n = 1;
		while(n < n_)n <<= 1;
		dat.assign(n << 1,0ll);
	}
	void set_val(int k,int x){
		dat[k += n] = x;
		while(k >>= 1){
			dat[k] = f(dat[k<<1|0],dat[k<<1|1]);
		}
	}
	int query(int L,int R){
		int vl = 0ll,vr = 0ll;
		for(int l = L + n,r = R + n;l < r;l >>= 1,r >>= 1){
			if(l & 1)vl = f(vl,dat[l++]);
			if(r & 1)vr = f(dat[--r],vr);
		}
		return f(vl,vr);
	}
};
signed main(){
	int N,Q;cin >> N >> Q;
	SegmentTree seg;
	seg.init(N);
	REP(i,Q){
		int com;cin >> com;
		if(com){
			int x,y;cin >> x >> y;
			--x;
			cout << seg.query(x,y) << endl;
		}else{
			int x,y;cin >> x >> y;
			--x;
			seg.set_val(x,seg.query(x,x + 1) + y);
		}
	}
}


Measured memory_bytes: 4908
import math

N, K = map(int, input().split())

A = list(map(int, input().split()))
F = list(map(int, input().split()))

A.sort(reverse=True)
F.sort()

def check(x):
  k = K
  for i in range(N):
    k -= max(0,math.ceil((A[i]*F[i]-x)/F[i]))

  return k >= 0



left = 0
right = 10**12

if check(left):
  print(0)
  exit()

while left + 1 < right:
  mid = (left + right)//2
  if check(mid):
    right = mid
  else:
    left = mid


print(right)


Measured memory_bytes: 119500
def main():

  n,k=map(int,input().split())
  r,s,p=map(int,input().split())
  t=list(input())

  point=dict()
  point["p"]=s  #s wins p
  point["s"]=r  #r wins s
  point["r"]=p  #p wins r
  point["checked"]=0

  ans=0
  for i in range(n):
    tmp=i-k
    if tmp>=0 and t[tmp]==t[i]:
      ans+=0
      t[i]="checked"
    else:
      ans+=point[t[i]]
  print(ans)

main()

Measured memory_bytes: 4084
#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>

using namespace std;
using lli = long long int;
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

const lli BLOCK = 500;
lli n, h[200001], a[200001], dp[200002], sq[1000];

void update(lli i, lli x) {
  dp[i] = x;
  sq[i/BLOCK] = max(x, sq[i/BLOCK]);
}

lli get(lli r) {
  lli y = 0, i = 0;
  for (; i<r/BLOCK; ++i) {
    y = max(y, sq[i]);
  }
  for (lli j=BLOCK*i; j<=r; ++j) {
    y = max(y, dp[j]);
  }
  return y;
}

int main() {
  cin >> n;
  read_n(h, n);
  read_n(a, n);

  for (lli i=0; i<n; ++i) {
    update(h[i], a[i] + get(h[i] - 1));
  }

  cout << get(n) << endl;
  return 0;
}


Measured memory_bytes: 4992
#define y1 askjdkasldjlkasd
#include <bits/stdc++.h>
#undef y1

using namespace std;

#define pb push_back
#define mp make_pair
#define fi(a, b) for(int i=a; i<=b; i++)
#define fj(a, b) for(int j=a; j<=b; j++)
#define fo(a, b) for(int o=a; o<=b; o++)
#define fdi(a, b) for(int i=a; i>=b; i--)
#define fdj(a, b) for(int j=a; j>=b; j--)
#define fdo(a, b) for(int o=a; o>=b; o--)
#define clr(x) memset(x, 0, sizeof(x))
#define cpy(x,y) memcpy(x, y, sizeof(y))
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;

#ifdef _DEBUG
#define LOCAL
#endif

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while (0)
#endif

double START_TIME;

void exit() {
#ifdef LOCAL	
	cerr << "TIME: " << setprecision(5) << fixed << (clock() - START_TIME) / CLOCKS_PER_SEC << endl;
#endif	
	exit(0);
}

template<typename A, typename B>
ostream& operator<<(ostream& os, pair<A, B> p) {
	os << "(" << p.first << ", " << p.second << ")";
	return os;
}

template<typename T>
ostream& operator<<(ostream& os, vector<T> v) {
	fi(0, sz(v) - 1) {
		os << v[i] << " ";
	}
	return os;
}

template<typename T>
ostream& operator<<(ostream& os, set<T> t) {
	for (auto z : t) {
		os << z << " ";
	}
	return os;
}

template<typename T1, typename T2>
ostream& operator<<(ostream& os, map<T1, T2> t) {
	cerr << endl;
	for (auto z : t) {
		os << "\t" << z.first << " -> " << z.second << endl;
	}
	return os;
}

#ifdef LOCAL
#define dbg(x) {cerr << __LINE__ << "\t" << #x << ": " << x << endl;}
#define dbg0(x, n) {cerr << __LINE__ << "\t" << #x << ": "; for (int ABC = 0; ABC < n; ABC++) cerr << x[ABC] << ' '; cerr << endl;}
#define dbg1(x, n) {cerr << __LINE__ << "\t" << #x << ": "; for (int ABC = 1; ABC <= n; ABC++) cerr << x[ABC] << ' '; cerr << endl;}
#else
#define dbg(x) while(0){}
#define dbg0(x, n) while(0){}
#define dbg1(x, n) while(0){}
#endif

#ifdef LOCAL
#define ass(x) if (!(x)) { cerr << __LINE__ << "\tassertion failed: " << #x << endl, abort(); }
#else
#define ass(x) assert(x)
#endif

///////////////////////////////////////////////////

int deg[41];

void solve() {
	int maxi = 0;
	fi(1, 4) maxi = max(maxi, deg[i]);
	if (maxi == 3) {
		printf("NO\n");
	} else {
		printf("YES\n");
	}
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	START_TIME = (double)clock();
#endif
	
	fi(1, 3) {
		int x, y;
		scanf("%d %d", &x, &y);
		deg[x]++;
		deg[y]++;
	}
	solve();

	exit();
	return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<string> ves;
typedef vector<vector<int>> ve_vei;
#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 rep2(i,n) for(int i=2;i<(int)(n);i++)
#define fs first
#define sc second
#define all(a) a.begin(),a.end()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
 
int main() {
	//cout.precision(10);
	cin.tie(0);
	ios::sync_with_stdio(false);

    int N,K; cin >> N >> K;
    int x = 1;
    rep(i,N) {
        if(K >= x) x *= 2;
        else x += K;
    }
    cout << x << endl;
}

Measured memory_bytes: 256
import sys

inf = 1<<30
ans = 0

def solve():
    n = int(sys.stdin.readline().rstrip())
    a = list(map(int, sys.stdin.readline().split()))

    MergeSort(a)

    print(ans)

def MergeSort(a):
    if len(a) == 1:
        return a

    apre = MergeSort(a[:len(a)//2])
    asuf = MergeSort(a[len(a)//2:])

    res = merge(apre, asuf)

    return res

def merge(a, b):
    global ans
    na = len(a)
    nb = len(b)

    a.append(inf)
    b.append(inf)

    la = 0
    lb = 0

    res = []

    for i in range(na + nb):
        if a[la] > b[lb]:
            ans += na - la
            res.append(b[lb])
            lb += 1
        else:
            res.append(a[la])
            la += 1

    return res

if __name__ == '__main__':
    solve()

Measured memory_bytes: 30076
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <sstream>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <map>
#include <climits>
#include <bitset>
using namespace std;
#define MATH_PI 3.14159265358979323846
int main(){
	ios::sync_with_stdio(false);
	int iLeft1, iLeft2, iRight1, iRight2;
	cin >> iLeft1 >> iLeft2 >> iRight1 >> iRight2;
	if (iLeft1 + iLeft2 > iRight1 + iRight2)
		cout << "Left\n";
	else if (iLeft1 + iLeft2 == iRight1 + iRight2)
		cout << "Balanced\n";
	else
		cout << "Right\n";
endapp:
	////system("pause > nul");
	return 0;
}

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

max_diff=-1
diff=-1
for i in range(len(arr)):
    if i==0:
        diff= k-arr[-1]+arr[0]
    else:
        diff= arr[i]-arr[i-1]
    if diff>max_diff:
        max_diff=diff
print(k-max_diff)

Measured memory_bytes: 26444
#include <stdio.h>

int main()
{
    int a, b, min =10000000000, max = -10000000000;
    long long sum = 0;

    scanf("%d", &a);
    for (int i = 0; i < a; i++)
    {
        scanf("%d", &b);
        sum = sum + b;
        if (b < min)
            min = b;
        if (b > max)
            max = b;
    }
    printf("%d %d %lli\n", min, max, sum);

    return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}
const int INF = 1<<30;
const int MOD = 1000000007;
int dx[4] = {0,0,-1,1};
int dy[4] = {-1,1,0,0};

int main(){

  int n; cin >> n;
  vector<int> a(n),idx(n);
  rep(i,n) cin >> a[i],a[i]--;
  rep(i,n) idx[a[i]] = i;
  set<int> s = {-1,n};//番兵を入れる。
  
  ll ans = 0;
  rep(i,n){
    s.insert(idx[i]); //数字iの位置をsetに入れる
    auto itr = s.find(idx[i]); //iの位置を示したイテレータを取得
    int l,r;
    //右にある小さい数。iが右端の数字(indexがn-1)が入った時は番兵のお陰でrが1になる。
    itr++;
    r = *itr - idx[i];
    
    //左にある小さい数。iが左端の数字(indexが0)が入った時は、番兵のお陰でlが1になる。
    itr = s.find(idx[i]);
    itr--;
    l = idx[i] - *itr;
    
    ans += (ll)l*r*(i+1);
    //printf("r=%d,l=%d,ans=%d\n",r,l,ans);
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 11136
import sys


# import math
# import bisect

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
# INF = sys.maxsize
# MOD = 10 ** 9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

# ===CODE===
def main():
    class UnionFind():
        def __init__(self, n):
            self.n = n
            self.parents = [-1] * n

        def find(self, x):
            if self.parents[x] < 0:
                return x
            else:
                self.parents[x] = self.find(self.parents[x])
                return self.parents[x]

        def union(self, x, y):
            x = self.find(x)
            y = self.find(y)

            if x == y:
                return

            if self.parents[x] > self.parents[y]:
                x, y = y, x

            self.parents[x] += self.parents[y]
            self.parents[y] = x

        def size(self, x):
            return -self.parents[self.find(x)]

        def same(self, x, y):
            return self.find(x) == self.find(y)

        def members(self, x):
            root = self.find(x)
            return [i for i in range(self.n) if self.find(i) == root]

        def roots(self):
            return [i for i, x in enumerate(self.parents) if x < 0]

        def group_count(self):
            return len(self.roots())

        def all_group_members(self):
            return {r: self.members(r) for r in self.roots()}

        def __str__(self):
            return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

    n,m = map(int,input().split())

    ans = 0
    d = []
    for i in range(m):
        a,b = map(int,input().split())
        a-=1
        b-=1
        d.append((a,b))

    ans = 0
    for i in range(m):
        que = UnionFind(n)
        for j in range(m):
            if i!=j:
                que.union(d[j][0], d[j][1])

        if que.group_count() != 1:
            ans+=1

    print(ans)





if __name__ == '__main__':
    main()


Measured memory_bytes: 40944
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n=Integer.parseInt(sc.next());
int m=Integer.parseInt(sc.next());
int[][] a=new int[n][m]; 
for(int i=0;i<n;i++){for(int j=0;j<m;j++){a[i][j]=Integer.parseInt(sc.next());}}
int[] b=new int[m];
for(int i=0;i<m;i++){b[i]=Integer.parseInt(sc.next());}
int[] c=new int[n];
for(int i=0;i<n;i++){for(int j=0;j<m;j++){c[i]+=a[i][j]*b[j];}}
for(int i:c){System.out.println(i);}
}
}


Measured memory_bytes: 37852
#include<stdio.h>
typedef struct{
  int parent;
  int left;
  int right;
} Tree;
Tree tree[10000];
//int s=0,t=0;
#define NIL -1
int getheight(int);
int main()
{
  int i,id,j,n,k,depth=0,num,l,r,degree=0,height=0;
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    tree[i].parent=NIL;
  }
 
  for(i=0;i<n;i++){
    scanf("%d%d%d",&id,&l,&r);
    tree[id].left=l;
    tree[id].right=r;
    if(l!=NIL && r!=NIL){
      tree[l].parent=id;
      tree[r].parent=id;
    }
    else if(l!=NIL && r==NIL){
      tree[l].parent=id;
    }
    else if(l==NIL && r!=NIL){
      tree[r].parent=id;
    }
  }
   
  for(i=0;i<n;i++){
    printf("node %d: parent = %d, ",i,tree[i].parent);
    if(tree[i].parent==NIL){
      printf("sibling = -1, ");
    }
    else if(tree[tree[i].parent].left==i){
      printf("sibling = %d, ",tree[tree[i].parent].right);
    }
    else{
      printf("sibling = %d, ",tree[tree[i].parent].left);
    }
    printf("degree = ");
    if(tree[i].left!=NIL && tree[i].right!=NIL){
      printf("2, ");
    }
    else if(tree[i].left==NIL && tree[i].right==NIL){
      printf("0, ");   }
    else printf("1, ");
 
    num=i;
    while(tree[num].parent!=NIL){
      depth++;
      num=tree[num].parent;
    }
    printf("depth = %d, ",depth);
    depth=0;
 
    printf("height = ");
    height=getheight(i);
    printf("%d,",height);
    //s=0;t=0;
     
    if(tree[i].parent==NIL){
      printf(" root\n");
    }
    else if(tree[i].left==NIL && tree[i].right==NIL){
      printf(" leaf\n");
    }
    else {
      printf(" internal node\n");
      }
  }
  return 0;
}

int getheight(int i)
{
  int s=0,t=0;
  if(tree[i].left==NIL && tree[i].right==NIL)return 0;

  if(tree[i].left!=NIL){
  s=getheight(tree[i].left)+1;
  }
  if(tree[i].right!=NIL){
  t=getheight(tree[i].right)+1;
  }
  if(s>t){
    
    return s;
  }
  else{
    return t;
  }
}



Measured memory_bytes: 2148
#include <stdio.h>

int main(void)
{
	char str[20];
	int i;
	
	if(scanf("%s", str) == 1) {
		for(i = 0; i < 20; i++) {
			if(str[i] == ',') {
				str[i] = ' ';
			}
		}
	}
	printf("%s", str);
	return 0;
}

Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

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

	void run() {
		Scanner sc = new Scanner(System.in);

		int N=sc.nextInt();

		//もとの入力
		int[] X=new int[N];
		//ソートした文字列を扱うための配列
		List<Integer> Y=new ArrayList<Integer>();


		for (int i = 0; i < N; i++) {
			int buf=sc.nextInt();

			X[i]=buf;
			Y.add(buf);
		}

		Collections.sort(Y);

		for (int i = 0; i < N; i++) {
			int buf=X[i];

			int locate=Y.get((N-1)/2);

			if(buf<=locate) {
				System.out.println(Y.get((N+1)/2));
			}else {
				System.out.println(Y.get((N-1)/2));
			}
		}


	}



	//以下テンプレート

	public static int[] extgcd(int a, int b) {

		int x0 = 1;
		int x1 = 0;

		int y0 = 0;
		int y1 = 1;

		while (b != 0) {
			int q = a / b;
			int r = a % b;

			int x2 = x0 - q * x1;
			int y2 = y0 - q * y1;

			a = b;
			b = r;

			x0 = x1;
			x1 = x2;

			y0 = y1;
			y1 = y2;
		}

		return new int[] { a, x0, y0 };

	}

	static int gcd(int a, int b) {

		if (b == 0)
			return a;

		if (a < b) {
			int t = a;
			a = b;
			b = t;
		}

		return gcd(b, a % b);

	}

	static int lcm(int a, int b) {
		return a * b / gcd(a, b);
	}

	static void swap(int[] a) {
		int t;

		t = a[0];
		a[0] = a[1];
		a[1] = t;

		return;
	}

	static <T> void output(List<T> list) {

		for (int i = 0; i < list.size(); i++) {
			System.out.print(list.get(i));

			if (i != list.size() - 1) {
				System.out.print(" ");
			} else {
				nl();
			}
		}

	}

	static void output(String[][] str) {

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				print(str[i][j]);
			}

			nl();
		}

	}

	static void output(boolean flg, String Yes, String No) {

		if (flg) {
			pln(Yes);
		} else {
			pln(No);
		}

	}

	static void output(String[][] str, int digit) {

		String dig = "%" + String.valueOf(digit) + "s";

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				System.out.printf(dig, str[i][j]);
			}
			nl();
		}

	}

	static void pln(String str) {
		System.out.println(str);
	}

	static void pln(int x) {
		System.out.println(x);
	}

	static void print(String str) {
		System.out.print(str);
	}

	static void print(int x) {
		System.out.print(x);
	}

	static void print(String str, int times) {
		for (int i = 0; i < times; i++) {
			print(str);
		}
	}

	static void print(int x, int times) {
		for (int i = 0; i < times; i++) {
			print(x);
		}
	}

	static void nl() {
		System.out.println();
	}

}


Measured memory_bytes: 97372
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<ctime>
#include<cstdlib>
#include<cmath>
using namespace std;
int main()
{
    string ss;
    cin>>ss;
    if(ss=="AAA"||ss=="BBB") puts("No");
    else puts("Yes");
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<utility>
#include<queue>
#include<tuple>
#include<stdio.h>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	string s;
	cin>>s;
	if(s=="AAA" || s=="BBB")
		cout<<"No"<<endl;
	else
		cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
k = int(input())
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

s = l[k-1]

print (s)


Measured memory_bytes: 2940
#!/usr/bin/env python3
import sys
INF = float("inf")

MOD = 1000000007  # type: int


def solve(n: int, m: int, x: "List[int]", y: "List[int]"):

    xtot = 0
    for i in range(n-1):
        xtot += (x[i+1]-x[i])*(i+1)*(n-i-1) % MOD
    ytot = 0
    for i in range(m-1):
        ytot += (y[i+1]-y[i])*(i+1)*(m-i-1) % MOD

    print(xtot*ytot % MOD)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    m = int(next(tokens))  # type: int
    x = [int(next(tokens)) for _ in range(n)]  # type: "List[int]"
    y = [int(next(tokens)) for _ in range(m)]  # type: "List[int]"
    solve(n, m, x, y)


if __name__ == '__main__':
    main()


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


#define int long long 


struct DSU{
	vector <int> p, sz;
	DSU(int n) {
		p.resize(n + 1); sz.resize(n + 1, 1);
		for(int i = 1; i <= n; i++) {
			p[i] = i;
		}
	}
	int find(int x) {
		return p[x] = (p[x] == x) ? p[x] : find(p[x]);
	}
	int merge(int x, int y) {
		x = find(x);
		y = find(y);
		if(x == y) {
			return 0;
		}
		p[x] = y;
		sz[y] += sz[x];
		return 1;
	}
};


int32_t main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, m, ans = 1; cin >> n >> m; DSU d(n);
	for(int i = 1; i <= m; i++) {
		int u, v; cin >> u >> v;
		d.merge(u, v);
		ans = max(ans, d.sz[d.find(u)]);
	}
	cout << ans << endl;
}

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

int main() {
  char s;
  cin >> s;

  if (s == 'a' || s == 'i' || s == 'u' || s == 'e' || s == 'o') {
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}

ll fac[510000], finv[510000], inv[510000];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < 510000; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}
/*
int main() {
    // 前処理
    COMinit();

    // 計算例
    cout << COM(100000, 50000) << endl;
}*/

//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
*/
const ll MAX = 100000;
ll par[MAX];
ll ran[MAX];
void init(ll n){
    rep(i,n){
        par[i] = i;
        ran[i] = 0;
    }
}
ll find(ll x){
    if(x == par[x])return x;
    else return par[x] = find(par[x]);
}
void unite(ll x,ll y){
    x = find(x);
    y = find(y);
    if(x == y)return;
    if(ran[x] < ran[y]){
        par[x] = y;
    }
    else{
        par[y] = x;
        if(ran[x] == ran[y])ran[x]++;
    }
}
bool same(ll x,ll y){
    return find(x) == find(y);
}
int main(){
    ll N,M;
    cin >> N>>M;
    init(N);
    ll x,y,z;
    rep(i,M){
        cin >> x >> y >> z;
        unite(x - 1,y - 1);
    }
    map<ll,ll> num;
    rep(i,N){
        num[find(i)]++;
    }
    ll ans = 0;
    for(auto x : num){
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 11340
import math

def euclid_dis(c,d,a=0.0,b=0.0):
    return math.sqrt((c-a)**2.0+(d-b)**2.0)

def heron(a,b,c):
    z=(a+b+c)/2.0
    return math.sqrt(z*(z-a)*(z-b)*(z-c))

ans=0
xy=[]
while 1:
    try:
        xy.append(map(float,raw_input().split(",")))
    except:
        break

n=len(xy)

for i in xrange(2,n):
    a=euclid_dis(xy[(i-1)%n][0],xy[(i-1)%n][1],xy[0][0],xy[0][1])
    b=euclid_dis(xy[i%n][0],xy[i%n][1],xy[0][0],xy[0][1])
    c=euclid_dis(xy[i%n][0],xy[i%n][1],xy[(i-1)%n][0],xy[(i-1)%n][1])   
    ans+=heron(a,b,c)
print ans

Measured memory_bytes: 6584
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
const int INFTY =2147483647;


int main(){
    int n,k,c;
    string s;
    int A[200005]={},B[200005]={};
    cin>>n>>k>>c>>s;
    int i=0,cnt=1;
    while(cnt<=k && i<n){
        if(s[i]-'o'==0){
            A[i]=cnt;
            cnt++;
            i+=c;
        }
        i++;
    }
    i=n-1;
    int cnt2=k;
    while(i>=0&&cnt2>0){
        if(s[i]-'o'==0){
            B[i]=cnt2;
            cnt2--;
            i-=c;
        }
        i--;
    }
    REP(i,n){
        if(A[i]!=0&&A[i]==B[i]) cout<<i+1<<endl;
    }
    
}

Measured memory_bytes: 3332
N=int(input())
S=input()

import collections
tw=S.count('W')
te=S.count('E')

ans=float('inf')
cw=[0,0]
ce=[tw,te]
#print(cw,ce)
for i in S:
    if i=='W':
        ce[0]-=1
        ans=min(ans,cw[0]+ce[1])
        #print(cw,ce,cw[0]+ce[1])
        cw[0]+=1
    else:
        ce[1]-=1
        ans=min(ans,cw[0]+ce[1])
        #print(cw,ce,cw[0]+ce[1])
        cw[1]+=1
    
print(ans)

Measured memory_bytes: 9780
#include <algorithm>
#include <iostream>
#include <vector>
#include <utility>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl

using namespace std;
using ll = long long;

struct UnionFind {
    int n;
    vector<int> parent;
    UnionFind(int _n=0): n(_n), parent(_n, -1) {}
    int root(int x) {
        if (parent[x] < 0) return x;
        return parent[x] = root(parent[x]);
    }
    bool connect(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (size(x) < size(y)) swap(x, y);
        parent[x] += parent[y];
        parent[y] = x;
        return true;
    }
    int group() {
        int res = 0;
        for (int i=0;i<n;++i) if (root(i) == i) res++;
        return res; 
    }
    bool same(int x, int y) { return root(x) == root(y); }
    int size(int x) { return -parent[root(x)]; }
};


int main() {
    int n, m; cin >> n >> m;
    UnionFind tree(n);

    vector<vector<int>> ab(n);
    rep(i, m) {
        int a, b; cin >> a >> b;
        a--;
        b--;
        ab[a].push_back(b);
        ab[b].push_back(a);
    }

    vector<int> bad_num;
    for (int i = 0; i < n - 1; ++i) {
        bool broken = false;
        for (int e: ab[i]) {
            bad_num.push_back(e);
        }
        for (auto e: bad_num) {
            if ((i + 1) == e) {
                broken = true;
                break;
            }
        }
        if (broken) {
            bad_num = {};
            continue;
        }
        tree.connect(i, i + 1);
    }

    cout << (tree.group() - 1) << endl;
}

Measured memory_bytes: 6656
/*  -*- coding: utf-8 -*-
 *
 * a.cc: C: Flip,Flip, and Flip......
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  if (n ==1 && m == 1) puts("1");
  else if (n == 1) printf("%d\n", m - 2);
  else if (m == 1) printf("%d\n", n - 2);
  else 
    printf("%lld\n", (ll)(n - 2) * (m - 2));
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from itertools import permutations

def warshall_floyd():
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k]+d[k][j])

N, M, R = map(int, input().split())
r = list(map(int, input().split()))
d = [[10**18]*N for _ in range(N)]

for i in range(N):
    d[i][i] = 0

for _ in range(M):
    A, B, C = map(int, input().split())
    d[A-1][B-1] = C
    d[B-1][A-1] = C

warshall_floyd()
ans = 10**18

for p in permutations(r):
    now = p[0]-1
    cand = 0

    for i in range(1, R):
        cand += d[now][p[i]-1]
        now = p[i]-1

    ans = min(ans, cand)

print(ans)

Measured memory_bytes: 74372
"use strict";
function main(input) {
    const args = input.split('\n');

    const tiles = args[0].split('');
    const tiles_len = tiles.length;

    let zero_ans = 0;
    let one_ans = 0;

    // ゼロから始まる
    for (let i = 0; i < tiles_len; i++) {
        if (i % 2 == 0 && tiles[i] == 0) {
        } else if (i % 2 == 1 && tiles[i] == 1) {
        } else {
            zero_ans++;
        }
    }

    // 株式会社いちから
    for (let i = 0; i < tiles_len; i++) {
        if (i % 2 == 0 && tiles[i] == 1) {
        } else if (i % 2 == 1 && tiles[i] == 0) {
        } else {
            one_ans++;
        }
    }

    let sin_ans = zero_ans < one_ans ? zero_ans : one_ans;

    console.log(sin_ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 9400
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
using namespace std;

long long digit_sum(long long num){
  long long sum=0,dig;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

int main()
{
  long long N,ans;
  cin>>N;
  ans=digit_sum(N);
  if(ans==1)ans=10;
  cout<< ans <<endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back 
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin >> s;
	for(int i = 0; i < s.length(); i++){
		if(s[i] == '7'){
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";

}

Measured memory_bytes: 3652
import sys
from bisect import bisect

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    n=int(input())
    aa=list(map(int, input().split()))
    cs=[aa[0]]
    for i in range(1,n):
        cs.append(cs[i-1]+aa[i])
    #print(cs)
    mid=cs[-1]/2
    mi=bisect(cs,mid)
    ans=min(mid-cs[mi-1],cs[mi]-mid)
    print(int(ans*2))

main()

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

int main() {
  
  int k,x,y;
  cin >> k >> x;
  
  y=k*500;
  if(y>=x){
   cout << "Yes" <<endl;
  }
  
  else{
   cout << "No" <<endl;
  }
  
}
  
    
  




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

using namespace std;

typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli>> mat;

lli n,k,x,y;

int main(){
  cin >> n >> k >> x >> y;
  if(n <= k) cout << n*x << endl;
  else cout << k*x + (n-k)*y << endl;
  return 0;
}


Measured memory_bytes: 256
N, M, Q = map(int, input().split())

t = [[0] * (N + 1) for _ in range(N + 1)]
for _ in range(M):
    L, R = map(int, input().split())
    t[L][R] += 1

for i in range(N + 1):
    for j in range(N):
        t[i][j + 1] += t[i][j]

for i in range(N):
    for j in range(N + 1):
        t[i + 1][j] += t[i][j]

result = []
for _ in range(Q):
    p, q = map(int, input().split())
    result.append(t[q][q] + t[p - 1][p - 1] - t[p - 1][q] - t[q][p - 1])
print('\n'.join(str(v) for v in result))


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


int a[1000050];
map<long long,int>mp;
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",a+i);
    long long ans=0,sum=0;
    mp[0]++;
    for(int i=1;i<=n;i++)
    {
        sum+=a[i];
        ans+=mp[sum];
        mp[sum]++;
    }
    printf("%lld\n",ans);
	return 0;
}



Measured memory_bytes: 13568
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
int compare(const void *a,const void *b){
    if(*(long long *)a>*(long long *)b)return -1;
     return 1;
}
int comp(const void *a,const void *b){
    if(*(long long *)a>*(long long *)b)return 1;
     return -1;
}
int main()
{   int i=0,n;
    scanf("%d",&n);
    long long a[n],b[n],d[n],husoku=0,m=0,stock=0,o[n];
    for(i=0;i<n;i++){
        scanf("%lld",&a[i]);
        
    }
    for(i=0;i<n;i++){
        scanf("%lld",&b[i]);
        if(a[i]<b[i]){
            husoku+=b[i]-a[i];
            m++;
            d[i]=a[i]-b[i];
        }else{
            stock+=a[i]-b[i];
            d[i]=a[i]-b[i];
        }
        o[i]=d[i];
    }
    if(stock<husoku){
        printf("-1");
        return 0;
    }
    if(husoku==0){
        printf("0");
        return 0;
    }
    int ans=m,k=0;
    qsort(d,n,sizeof(long long),compare);
    for(i=0;i<n;i++){
        if(husoku>0){
            ans++;
            husoku-=d[i];
        }
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 4092
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;

int main(){
	int x[220],a,b,c = 0,n;
	scanf("%d %d",&a,&b);
	for(int i = 0;i < a;i++){
		scanf("%d",&x[i]);
	}
	sort(x,x + a);
	for(int i = a - 1;i > a - 1 - b;i--){
		c += x[i];
	}
	printf("%d\n",c);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	double a, min = 10000000, max=-1;
	while (cin >> a){
		if (a < min){
			min = a;
		}
		if (a>max){
			max = a;
		}
	}
	cout << max - min << endl;
	return 0;
}


Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
int main(){
int A,B,C,X,Y;
  cin>>A>>B>>C>>X>>Y;
  if(A+B<=2*C){
  cout<<A*X+B*Y<<endl;
  }else{
  if(X<=Y){
    if(B<=2*C)
    cout<<2*C*X+(Y-X)*B<<endl;
    else
      cout<<2*C*Y<<endl;
  }
    else{
      if(A<=2*C)
      cout<<2*C*Y+(X-Y)*A<<endl;
      else
        cout<<2*C*X<<endl;
    }
  }
  
   return 0;
}

Measured memory_bytes: 256
import itertools

N = int(input())
A = []
x = []
y = []
for i in range(N):
    A.append(int(input()))
    x.append([])
    y.append([])
    for j in range(A[i]):
        e1,e2 = map(int, input().split())
        x[i].append(e1-1)
        y[i].append(e2)

# B[i]=1: 人iは正直者，0: 不親切
# すべての取りうる状態について
ans = []
for e in itertools.product("01",repeat=N):
    # tmp = "".join(e)
    B = [int(a) for a in e]

    flag = True
    # この状態が矛盾しないことをチェックする
    # つまり，
    # i=正直者かつi「jは正直者」=> j=不親切
    # i=正直者かつi「jは不親切」=> j=正直者
    # の場合，矛盾
    for i in range(N):
        # iが正直者ならば
        if B[i] == 1:
            # iのすべての証言について
            for j in range(A[i]):
                # 「x[i][j]は正直者」と証言した場合
                if y[i][j] == 1:
                    # x[i][j]が正直者であることを確認
                    if B[x[i][j]] == 0: flag = False
                else:
                    # x[i][j]が不親切であることを確認
                    if B[x[i][j]] == 1: flag = False

    if flag:
        # 正直者の数
        ans.append([e == 1 for e in B].count(True))

# 矛盾しない状態の中で，正直者の数が最大になるもの
print(max(ans))

Measured memory_bytes: 3444
#include<stdio.h>

int main() {
    int a,b,c; //変数の宣言
    
    //入力
    scanf("%d %d %d", &a, &b, &c);
    
    //出力
    if (a < b) {
        if (b < c) {
            printf("Yes\n");
        }else{
            printf("No\n");
        }
    }else{
        printf("No\n");
    }
    
    return 0;
}



Measured memory_bytes: 2048
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 2000100;

//Convert int to string
template <typename T>
string to_str(T str)
{
    stringstream stream;
    stream << str;
    return stream.str();
}

//Convert string to int
template <typename T>
int to_int(T num)
{
    int val;
    stringstream stream;
    stream << num;
    stream >> val;
    return val;
}

int main(){
        _
        int a, b; cin >> a >> b;
        int cnt = 0;
        for(int i = a; i<=b; i++){
            string s = to_str(i);
            string t = s;
            reverse(all(t));
            if(s==t)cnt++;
        }
        cout<<cnt<<endl;


return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] heights = new int[n];

      int minHeight = Integer.MAX_VALUE;
      for(int i = 0; i < n; i++) {
        heights[i] = sc.nextInt();
        if(heights[i] > 0)
          minHeight = Math.min(minHeight, heights[i]);
      }

      int cnt = 0;

      while(minHeight != Integer.MAX_VALUE) {
        
        int nextMinHeight = Integer.MAX_VALUE;
        int i = 0;
        int seg = 1;
        for(; i < n; i++) {
          if(heights[i] != 0) {
            i++;
            break;
          }
        }
        for(; i < n; i++) {
          if(heights[i-1] == 0 && heights[i] != 0)
            seg++;
        }
        cnt += minHeight * seg;
        for(i = 0; i < n; i++) {
          if(heights[i] == 0)  continue;
          heights[i] -= minHeight;
          nextMinHeight = Math.min(nextMinHeight, heights[i]);
        }
        minHeight = nextMinHeight;
      }
      System.out.println(cnt);
  }
}

Measured memory_bytes: 23120
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#include<vector>
using namespace std;
const long long mod = 1e9+7;

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

    vector<int>a(N+1,1);// 要素数N+1, trueで初期化
    for(int i =0; i<M; i++){
        // 指定された階段だけ計算しないようにする。
        int b;cin >> b;
        a[b] = 0;
    }

    vector<long long int>dp(N+1);
    dp[0]=1;//1階まで行く通り

    // 値少ない順から計算。動的計画法
    for(int i=0;i<N;i++){

        // i+1,i+2の2階分だけ回して、1階先・2階先に今の値を入れておく。
        for(int next=i+1;next<=min(N,i+2);next++){
            // 指定した壊れた階段は計算しない。
            // 隣同士の階が壊れていた場合は以降0になる。
            if(a[next]){
                dp[next] += dp[i];
                dp[next] %= mod;
            }
        }

    }
    cout << dp[N] <<endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;

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

int gFlg = 0;

string parse( string s ) {
	if(s[0] == '-') {
		s = s.substr(1, s.length()-1);
		s = parse(s);
		if(s[0]=='T')      s = 'F';
		else if(s[0]=='F') s = 'T';
	}
	else if(s[0] == '(') {
		int cl = 1, op=1;
		int cntClos = 0;
		while(!(cntClos==0 && s[cl]==')')) {
			if( s[cl] == '(' ) cntClos++;
			else if( s[cl] == ')' ) cntClos--;
			cl++;
		}
		while(!(cntClos==0 && (s[op]=='*' || s[op]=='+' || s[op]=='>'))) {
			if( s[op] == '(' ) cntClos++;
			else if( s[op] == ')' ) cntClos--;
			op++;
		}
		string s1=s, s2=s;
		if( s[op] == '>' )  s1 = s1.substr( 1, op-2 );
		else                s1 = s1.substr( 1, op-1 );
		s2 = s2.substr( op+1, cl-op-1 );
		s1 = parse(s1);
		s2 = parse(s2);
		if( s[op] == '+' ) {
			if(s1[0]=='F' && s2[0]=='F') s = 'F';
			else s = 'T';
		}
		else if( s[op] == '*' ) {
			if(s1[0]=='T' && s2[0]=='T') s = 'T';
			else s = 'F';
		}
		else {
			if(s1[0]=='T' && s2[0]=='F') s = 'F';
			else s = 'T';
		}
	}
	else if( 'a'<=s[0] && s[0]<='k' ) {
		bool tf = gFlg & (1<<(s[0]-'a'));
		s = tf ? 'T' : 'F';
	}
	return s;
}

int main() {
	string in;
	while( cin >> in, in[0]!='#' ) {
		bool ok = true;
		for(int flg=0; flg<(1<<11); flg++) {
			gFlg = flg;
			string s1=in, s2=in;
			int posEq = 0;
			while(in[posEq] != '=') posEq++;
			s1 = s1.substr( 0, posEq );
			s2 = s2.substr( posEq+1, s2.length()-posEq-1 );
			s1 = parse(s1);
			s2 = parse(s2);
			if( s1 != s2 ) {
				ok = false;
				break;
			}
		}
		if(ok) cout << "YES" << endl;
		else   cout << "NO"  << endl;
	}
	return 0;
}

Measured memory_bytes: 1976