akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int N, W, w, v;
long long dp[100100], ret;

int main() {
	scanf("%d%d", &N, &W);
	
	for(int j = 0; j < N; j++) {
		scanf("%d%d", &w, &v);
		for(int i = W; i >= w; i--) {
			dp[i] = max(dp[i - w] + v, dp[i]);
			ret = max(ret, dp[i]);
		}
	}
	
	printf("%lld", ret);
}


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

int main () {
  int N;
  cin >> N;
  vector<double> x(N),y(N);
  for (int i=0; i<N; i++) {
    cin >> x[i] >> y[i];
  }
  double ans = 0;
  double num = 0;
  for (int i=0; i<N-1; i++) {
    for (int j=i+1; j<N; j++) {
      ans += sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
      num++;
    }
  }
  ans *= N-1;
  ans /= num;
  cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
/**
 *     author: qodjf
 *     created: 05.01.2020 01:00:38
 */
#include <bits/stdc++.h>
using namespace std;

string to_string(string s) { return '"' + s + '"'; }

string to_string(const char *s) { return to_string((string)s); }

string to_string(bool b) { return (b ? "true" : "false"); }

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define dbg(...) 42
#endif

#define mst(x, a) memset(x, a, sizeof(x))

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr ll LLINF = 0x3f3f3f3f3f3f3f3f;
constexpr ll MOD = 1e9 + 7;

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

int N, M;
ll L;

void floyd(int n, vector<vector<ll>> &d) {
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

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

  cin >> N >> M >> L;
  vector<vector<ll>> d(N, vector<ll>(N, LLINF));
  for (int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    d[a][b] = c;
    d[b][a] = c;
  }

  floyd(N, d);

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      d[i][j] = d[i][j] <= L ? 1 : LLINF;
    }
  }

  floyd(N, d);

  int Q;
  cin >> Q;
  while (Q--) {
    int s, t;
    cin >> s >> t;

    ll ans = d[s - 1][t - 1];
    cout << (ans < LLINF ? ans - 1 : -1) << endl;
  }
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl 
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl 
#define no cout<<"no"<<endl
#define vec(a,y,x)  vector<vector<char>> a (y,vector<char>(x))
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};



bool check(vector<vector<int>> &G,vector<int> permu,int n,int v){
  int a,b;
  if(v==n-1) return true;
  if(v==0) a=0;
  else a=permu.at(v-1);
  b=permu.at(v);
  if(find(all(G.at(a)),b)==G.at(a).end()) return false;
  if(!check(G,permu,n,v+1)) return false; 
  return true;
}

int main(){
  int n,m;
  int ans=0;
  cin>>n>>m;
  vector<vector<int>> G(n);
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--;b--;
    G.at(a).push_back(b);
    G.at(b).push_back(a);
  }
  vector<int> permu={};
  rep(i,n-1)
    permu.push_back(i+1);
  do{
    if(check(G,permu,n,0))
      ans++;
  }while(next_permutation(all(permu)));
  cout<<ans<<endl;  
}

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

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

template<class T, class U> void chmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> void chmin(T &a, U b) { if (b < a) a = b; }

using ll = long long;
using ld = long double;
using namespace std;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  int a, b; cin >> a >> b;

  if (a > 8 || b > 8) cout << ":(\n";
  else cout << "Yay!\n";
  
  return (0);
}

Measured memory_bytes: 3668
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int[] m = new int[n];
		int sum = 0;
		for(int i = 0; i < n; i++) {
			m[i] = sc.nextInt();
			sum += m[i];
		}
		Arrays.sort(m);
		System.out.println(n + (x - sum) / m[0]);
	}
}

Measured memory_bytes: 21844
/*
C language 162bytes

char s[1<<20];m[1<<20],n,t;main(){for(gets(s);s[n];m[++n]=--t)for(;t&&s[~t]-s[n];t=m[~t]);t-=~n;n=!printf(t*2<n?"Love %.*s!\n":"mitomerarenaiWA\n",t*=n/3/t+1,s);}
*/


#include <stdio.h>
#include <string.h>

char s[1000010];
int mp[1000010];

int main(){
	int i, n, t, p, q = 0;

	fgets(s, sizeof(s), stdin);
	n = strlen(s) - 1;

	mp[0] = -1;
	t = -1;
	for(i = 0; i < n; ++i){
		while(t >= 0 && s[t] != s[i]){
			t = mp[t];
		}
		mp[i + 1] = ++t;
	}
	
	p = n - mp[n];
	if(p > 0){
		q = p * (n / (3 * p) + 1);
		if(q * 2 >= n){
			q = 0;
		}
	}

	if(q != 0){
		printf("Love %.*s!\n", q, s);
	}
	else{
		puts("mitomerarenaiWA");
	}

	return 0;
}

Measured memory_bytes: 5428
#include <cstdio>
#include <iostream>
#define P 1000000007
using namespace std;
int n;
char s1[100],s2[100];
int main(){
	scanf("%d",&n);
	scanf("%s",s1);
	scanf("%s",s2);
	long long ans=s1[0]==s2[0] ? 3:6;
	for(int i=1;i<n;++i){
		if(s1[i-1]==s2[i-1])ans=ans*2%P;
		if(s1[i]!=s2[i] && s1[i-1]!=s2[i-1] && s1[i]!=s1[i-1] && s2[i]!=s2[i-1])ans=ans*3%P;
	}
	printf("%d",ans);
}

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

using namespace std;

int main(void) {
    int N;
    cin >> N;
    map<int,int> mp;
    while(N--) {
        int A;
        cin >> A;
        ++mp[A];
    }

    int ans = 0;
    for(auto itr=mp.begin(); itr!=mp.end(); itr++) {
        if(itr->second%2) {
            ++ans;
        }
    }

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


Measured memory_bytes: 4992
#include<iostream>
using namespace std;
int main()
{
  long K;
  cin >> K;
  long sum=0;
  for(int a=1;a<K+1;a++){
    for(int b=1;b<K+1;b++){
  		for(int c=1;c<K+1;c++){
          int gcd = 0;
          for(int i=1;i<a+1 && i<b+1 && i<c+1;i++){
  			if(a%i==0 && b%i==0 && c%i==0){
  			gcd = i;
  			}
  		}
    sum =sum+gcd;
    }
  }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int X=0;
int C[3]={0};
int ans=0;
int N;

void dfs(int d){
  // cerr<<X<<" "<<C[0]<<endl;
  if(C[0]*C[1]*C[2]>0 and X<=N)ans++;
  if(d>8){
    return;
  }
  else {
    X*=10;
    X+=3;
    C[0]++;
    dfs(d+1);
    X-=3;
    C[0]--;
    C[1]++;
    X+=5;
    dfs(d+1);
    X-=5;
    C[1]--;
    C[2]++;
    X+=7;
    dfs(d+1);
    X-=7;
    C[2]--;
    X/=10;
  }

}
int main(){
  cin>>N;
  dfs(0);
  cout<<ans<<endl;
  return 0;
}


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

int main(){
  
  int N;
  long long W;
  cin >>N>>W;
  vector<long long> w(N);
  vector<int> v(N);
  for(int i=0;i<N;i++){
    long long x,y;
    cin >>x>>y;
    w[i] = x;
    v[i] = y;
  }
  
  long long maxv = 0;
  long long maxw = 0;
  for(int i=0;i<N;i++){
    maxv += v[i];
    maxw += w[i];
  }
  
  vector<vector<long long>> dp(N+1,vector<long long>(maxv+1,maxw));
  
  for(int i=1;i<N+1;i++){
    for(int j=0;j<maxv+1;j++){
      long long res1 = dp[i-1][j]; //①直前の品物までの最善手
      long long res2 = 0; //②初期値
      if (j<=v[i-1]) res2 = w[i-1]; //必要な価値が少なければとりあえずそれを積めばいい
      else{
        res2 = dp[i-1][j-v[i-1]] + w[i-1];
        //達成価値が大きければ、「品物の価値を減じた状態の最善手」からプラス
      }
      dp[i][j] = min(res1,res2); //①と②の軽い方を比較する最善手
    }
  }
  
  //for(int i=0;i<N+1;i++){
  //  for(int j=85;j<95;j++){
  //    cout << dp[i][j] << " ";
  //  }
  //  cout << endl;
  //}
  
  for(int i=0;i<maxv+1;i++){
    if(dp[N][i] > W){
      cout << i-1 << endl;
      break;
    }
    if(i==maxv) cout << i << endl;
  }
}

Measured memory_bytes: 80256
//#pragma warning(disable:4996)
//#pragma comment(linker, "/STACK:336777216")
//#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))
#define sz(x) (int)(x.size())
#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
const int N=200005;
int spf[1000005];int mx[1000005];
void solve()
{
    
    for(int i=1;i<=1000004;i++)
        spf[i]=i;
    for(int i=2;i<=sqrt(1000000);i++)
        if(spf[i]==i)
            for(int j=2*i;j<=1000004;j+=i)
                if(spf[j]==j)
                    spf[j]=i;
    
    int n;
    cin>>n;
    int a[n],pr=1,g;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        //g=gcd(pr,a[i]);
        //pr=(pr*a[i])%hell;
        int x=a[i];
        while(x>1)
        {
            int sp=spf[x];int cnt=0;
            while(!(x%sp))
            {
                x=x/sp;
                cnt++;
            }
            mx[sp]=max(mx[sp],cnt);
        }
    }
    int lc=1;
    for(int i=2;i<=1000000;i++)
        if(spf[i]==i&&mx[i])
        {
            lc=(lc*power(i,mx[i],hell))%hell;
        }
     int inv,sm=0;
    for(int i=0;i<n;i++)
    {
        inv=power(a[i],hell-2,hell);
        sm=(sm+inv)%hell;
    }
    lc=(lc%hell*sm%hell)%hell;
    cout<<lc<<endl;
}

int32_t main()
{
    IOS;
    int t;
    t=1;
    // cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 15744
from sys import stdin

def score(mid, fin, re):
    if mid == -1 or fin == -1:
        return "F"
    elif (mid+fin) >= 80:
        return "A"
    elif (mid+fin) >= 65:
        return "B"
    elif (mid+fin) >= 50:
        return "C"
    elif (mid+fin) >= 30:
        if re >= 50:
            return "C"
        else:
            return "D"
    else:
        return "F"

while True:
    m, f, r = [int(x) for x in stdin.readline().rstrip().split()]
    if m == -1 and f == -1 and r == -1:
        break
    else:
        print(score(m, f, r))


Measured memory_bytes: 5608
N, Q = map(int, input().split())
S = input()
l = [0] * Q
r = [0] * Q
for i in range(Q):
    l[i], r[i] = map(int, input().split())

dp = [0] * N
tmp = ''
for i in range(N):
    if i == 0:
        dp[i] = 0
        tmp = S[i]
    else:
        if tmp == 'A' and S[i] == 'C':
            tmp = S[i]
            dp[i] = dp[i-1] + 1
        else:
            tmp = S[i]
            dp[i] = dp[i-1]

for i in range(Q):
    ans = dp[r[i]-1] - dp[l[i]-1]
    print(ans)

Measured memory_bytes: 14156
using System;
using System.Linq;

namespace arc092_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] redx = new int[n]; int[] redy = new int[n];
            for (int i = 0; i < n; i++)
            {
                int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
                redx[i] = x[0]; redy[i] = x[1];
            }
            int[] bluex = new int[n]; int[] bluey = new int[n];
            for (int i = 0; i < n; i++)
            {
                int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
                bluex[i] = x[0]; bluey[i] = x[1];
            }
            Array.Sort(redx,redy); Array.Reverse(redx); Array.Reverse(redy);
            Array.Sort(bluex,bluey);
            bool[] used = new bool[n]; int ret = 0;
            for (int i = 0; i < n; i++)
            {
                int wheremin = -1; int minbluey = int.MaxValue;
                for (int j = 0; j < n; j++)
                {
                    if (!used[j] && redx[i] < bluex[j] && redy[i] < bluey[j])
                    {
                        if (minbluey > bluey[j])
                        {
                            wheremin = j;
                            minbluey = bluey[j];
                        }
                    }
                }
                if (wheremin >= 0)
                {
                    used[wheremin] = true; ret++;
                }
            }
            Console.WriteLine(ret);
        }
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N;
    cin >> N;
    vector<ll> A(N);
    vector<ll> sum(N);
    for(size_t i=0;i<N; i++)
    {
        cin >> A[i];
    }
    for(ll i=N-2;i>=0;i--)
    {
        sum[i] = (sum[i+1] + A[i+1]) % DIV;
        //cerr << sum[i] << endl;
    }

    ll total = 0;
    for(size_t i=0;i<N-1; i++)
    {
        //sum -= A[i];
        total += (A[i] * sum[i]) %DIV;
        total %= DIV;
        /*
        for(size_t j=i+1;j<N; j++)
        {
            ll mul = (A[i]*A[j]) % DIV;
            sum += mul;
            sum %= DIV;
        }
        */
    }
    cout << total << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 6356
import java.util.Scanner;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A=sc.nextInt();
    int B=sc.nextInt();
    int C=sc.nextInt();
    int K=sc.nextInt();
    int X=K-A-B;
    if(A+B>=K) {
    	if(A>=K) {
    		System.out.println(K);
    	}else {
    		System.out.println(A);
    	}
    }else {
    	System.out.println(A-X);
    }
    	}
    }

Measured memory_bytes: 35664
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
#include <unordered_set>

using namespace std;
typedef long long ll;

int main(){
    // int N;cin>>N;
    // for(int s = 0; s < (1<<N); s++){//for(int i = 0; i < N; i++)
    //     vector<int> ans;
    //     for(int i = 0; i<N; i++){
    //         //要素iを使うかどうか
    //         if(s &(1<<i))ans.push_back(i);
    //         // cout<<s<<endl;
    //     }
    //     cout<<"{";
    //     for (int i = 0; i < ans.size(); i++)
    //     {
    //         cout<<ans[i];
    //         //途中なら,を出力
    //         if(i < ans.size() - 1) cout<<",";
    //     }
    //     cout<<"}"<<endl;
        
    // }
    int N;cin>>N;
    vector<int> D(N);
    for(int i = 0; i < N; i++){
        cin>>D[i];
    }

    ll ans = 0;
    for(int i  = 0; i < N; i++){
        for(int j = i+1; j < N ; j++){
            ans += D[i]*D[j];
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
using System;

namespace B
{
    class Program
    {
        static int[] ToInt(string[] str)
        {
            int len = str.Length;
            int[] intAry = new int[len];
            for(int i = 0; i < len; i++)
            {
                intAry[i] = int.Parse(str[i]);
            }
            return intAry;
        }
        static void Main(string[] args)
        {
            int[] IntAry = ToInt(Console.ReadLine().Split(' '));
            double X = (IntAry[0]-1) / IntAry[3];
            double Y = (IntAry[2]-1) / IntAry[1];

            if( Y <= X)
            {
                Console.WriteLine("Yes");
            }else{
                Console.WriteLine("No");
            }
            

        }
    }
}

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

typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vp;
const int inf = 1e9;
const ll INF = 1e18;
const db eps = 1e-10;

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define ep emplace
#define mem(a) memset(a, 0, sizeof(a))
#define copy(a, b) memcpy(a, b, sizeof(b))
#define PA cout << "pass\n"
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define TM cout << db(clock()) / CLOCKS_PER_SEC << '\n'

const int mod = 998244353;
const int maxn = 1e7 + 233;
int fac[maxn], inv[maxn];

int pow_mod(int q, int w){
    int ret = 1;
    while(w){
        if(w & 1) ret = 1ll * ret * q % mod;
        q = 1ll * q * q % mod;
        w >>= 1;
    }
    return ret % mod;
}

int n;
int po[maxn];

int C(int x, int y){
    if(x < y) return 0;
    return 1ll * fac[x] * inv[y] % mod * inv[x - y] % mod;
}

int main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    po[0] = fac[0] = inv[0] = 1;
    for(int i = 1; i <= n; i++) fac[i] = 1ll * fac[i - 1] * i % mod, po[i] = (po[i - 1] + po[i - 1]) % mod;
    inv[n] = pow_mod(fac[n], mod - 2);
    for(int i = n - 1; i; i--) inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;
    int res = 0;
    for(int i = n / 2 + 1; i <= n; i++) res = (res + 2ll * C(n, i) * po[n - i]) % mod;
    cout << (pow_mod(3, n) + mod - res) % mod << '\n';
    return 0;
}

Measured memory_bytes: 117504
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
int main(){
  int n,maxx=0;
  cin>>n;
  map<string,int> s;
  rep(i,n){
  string ss;
    cin>>ss;
    s[ss]++;
    maxx =max(maxx,s[ss]);
  }
  for(auto y: s){
  if(y.second==maxx)cout<<y.first<<endl;
  }
}

Measured memory_bytes: 25216
S = gets.chomp.chars

def count(list, first_color)
  color = first_color
  count = 0
  list.each do |c|
    count += 1 if c != color
    color = color == '0' ? '1' : '0'
  end
  count
end

ans = [count(S, '0'), count(S, '1')].min
puts ans


Measured memory_bytes: 9596
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
#include<unordered_set>
#include<unordered_map>
using namespace std;
 
 
 
int n;
#define MAX 100002
 
vector<int> v[MAX];
int gr[MAX];
 
inline void dfs(int b,int pr=-1) {
	if (v[b].size() == 1 && pr != -1) {
		gr[b] = 0;
		return;
	}
	for (int i = 0; i < v[b].size(); i++) {
		int go = v[b][i];
		if (go != pr) {
			dfs(go,b);
			gr[b] ^= (gr[go] + 1);
		}
	}
}
 
int main() {
	cin >> n;
	for (int i = 1; i < n; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		a--;
		b--;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	dfs(0);
	if (gr[0]) {
		puts("Alice");
	}
	else {
		puts("Bob");
	}
	return 0;
}

Measured memory_bytes: 10496
/*---------------------------------

 @Author:   Dicer
 @DateTime: 2019-05-12 11:45:41

---------------------------------*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
inline ll qpow(ll a,ll b,ll mod){ll res=1;while(b){if(b&1)res = (res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int MAXN = 2e5 + 7;

int a[MAXN];
ll dp[MAXN][2][2];
int main(int argc, char const *argv[])
{
	int n;
	cin >> n;
	for(int i = 1; i <= n; ++i)	cin >> a[i];
	for(int i = 1; i <= n; ++i){
		dp[i][0][0] = dp[i][0][1] = dp[i][1][0] = dp[i][1][1] = -INF; 
	}
	dp[1][0][0] = a[1]; dp[1][0][1] = -a[1];
	// dp[1][1][0] = -a[1]; dp[1][1][1] = a[1];
	for(int i = 2; i < n; ++i){
		dp[i][0][1] = max(dp[i-1][1][0], dp[i-1][0][0]) - a[i];
		dp[i][0][0] = max(dp[i-1][1][0], dp[i-1][0][0]) + a[i];
		dp[i][1][1] = max(dp[i-1][1][1], dp[i-1][0][1]) + a[i];
		dp[i][1][0] = max(dp[i-1][1][1], dp[i-1][0][1]) - a[i];
	}
	dp[n][1][0] = max(dp[n-1][0][1], dp[n-1][1][1]) - a[n];
	dp[n][0][0] = max(dp[n-1][0][0], dp[n-1][1][0]) + a[n];
	cout << max(dp[n][1][0], dp[n][0][0]) << endl;
	// for(int i = 1; i <= n; ++i){
		// cout << max(max(dp[i][1][0], dp[i][0][0]), max(dp[i][1][1], dp[i][0][1])) << endl;
	// }
	return 0;
}

Measured memory_bytes: 4736
#include <iostream>
#include <string>
#include <cstring>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#define int long long
using namespace std;
signed main(){
    int n;
    cin>>n;
    vector<int> a(n);
    vector<int> s(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        if(i==0)s[i]=a[i];
        else s[i]=s[i-1]+a[i];
    }
    int ans=100000;
    for(int i=0;i<n;i++){
        ans=min(ans,abs((s[n-1]-s[i])-s[i]));
    }
    cout<<ans<<endl;
    return 0;
}


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

#define sim template < class c
#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 {
#ifndef LOCAL
~debug() { cerr << endl; }
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__) << "] "

int main() {
	float d, t, s;
	cin >> d >> t >> s;
	if (d / s <= t) {
		cout << "Yes\n";
	}
	else cout << "No\n";
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
#define rep(x, y) for(int x = 0; x < (y); x++)
#define REP(x, z, y) for(int x = (z); x < (y); x++)
#define all(x) x.begin(), x.end()
#define len(x) (sizeof(x) / sizeof(x[0]))
#define split_str(str, sp_word) istringstream stream(str); string res; for(int cnt = 0; getline(stream,res,sp_word); cnt++)
#define scanln(x) fgets(x, sizeof x, stdin)
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
#define i_str(x) atoi(x.c_str())
#define digit(x) ((int)log10((double)(x)) + 1)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
using namespace std;
const int MOD = 1000000007; 
typedef long long ll;
typedef string str;
 
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  cout << (a + b == c || a + c == b || b + c == a ? "Yes" : "No");
  return 0;
}

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }

int main()
{
  int a;
  string s;
  cin >> a >> s;

  if (a >= 3200)
    cout << s << endl;
  else
    cout << "red" << endl;

  return 0;
}


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

using namespace std;
typedef long long int lli;

lli A,B,X;
double M;
double c;
double theta = 0.0;
string huka = "-1";
bool counter = false;


int main(void){
    cin >> A >> B >> X;
 //   cout << A <<" " <<B <<" " << X << endl;
    
    M = (double)X / (double)A;
    
    double temp = B * 0.5 * A;
    
    //cout << M << " " << temp << endl;
    
    if(M > temp){
        c = 2.0*M/(double)A - B;
        theta = M_PI/2.0 - atan((double)A/(B-c));
   //     cout << 1 << endl;
    }else if(M == temp){
        theta = M_PI*0.5 - atan((double)A/B);
    //   cout << 2 << endl;
    }else{
        theta = atan( (B*(double)B)/(2.0*M) );
        //cout << 3 << endl;
    }
    
    theta = theta * (180.0/M_PI);
    cout <<setprecision(11)<<theta<< endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
// using namespace __gnu_pbds;
using namespace std;
 
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;
typedef pair <long long,long long> ii;
// typedef complex<long double> point;

struct abc{
    ll a,b,c;
};

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin >> n >> k;
    set <ll> arr;
    vector <ll> arr1(n);
    ll s = 0;
    ll s1 = 0;
    for (int z=0;z<n;z++){
        arr.insert(k+z);
        s += k+z;
    }
    for (int z=n;z<2*n;z++){
        s += k+z;
    }
    ll i = 0;
    for (int z=2*n;z<3*n;z++,i++){
        arr1[i] = k+z;
        s1 += arr1[i];
    }
    if (s1 < s){
        cout << -1 << endl;
    } else {
        ll i = n-1;
        for (int z=2*n-1;z>=n;z-=2){
            auto it = arr.lower_bound(arr1[i]-(z+k));
            if (it == arr.end()) it--;
            cout << z+k << " "  << *it << " " << arr1[i] << endl;
            i--;
            arr.erase(it);
        }
        for (int z=2*n-2;z>=n;z-=2){
            auto it = arr.lower_bound(arr1[i]-(z+k));
            if (it == arr.end()) it--;
            cout << z+k << " " << *it << " " << arr1[i] << endl;
            i--;
            arr.erase(it);
        }
    }
}

Measured memory_bytes: 7680
#include <bits/stdc++.h>
 
 
#define se second
#define sz(x) (int)(x.size())
#define ll long long
#define rep(i,x,y) for(int i = x; i <= y; ++i)
#define repr(i,x,y) for(int i = x; i >= y; --i)
#define pb push_back
#define mp make_pair
#define fi first
#define ull unsigned ll
 
#define pi 3.14159265358979
 
 
using namespace std;
 
const int N = (int)(1e6) + 322;
const ll INF = 2e18 + 17;
const int inf = 2e9;
const int mod = 1000000007;
const double eps = 1e-9;
 
int gcd(int a, int b) { return b ? gcd (b, a % b) : a; }
 
int nbr_bits(int a){
    return log2(a)+1;
}
 
 
ll fastpow(int a, int n, int mod) {
    if(n==0)
        return 1;
    if(n%2==0){
        ll res = fastpow(a,n/2,mod);
        res*=res;
        res%=mod;
        return res;
    }
    ll res = (fastpow(a,n-1,mod)*a)%mod;
    return res;
    
}
 
// ----------------------------------------------------

map<int,pair<string,int> > occ;
int n;

bool comp(int a, int b){
    if(occ[a].first==occ[b].first) return occ[a].second > occ[b].second ;
    return occ[a].first < occ[b].first;
}
 
 
int main()
{
     ios_base::sync_with_stdio(false);
//      cin >> t ;
//      while(t--){
//      
     cin >> n ;
     int ans =  n % 1000 ;
	  if(ans == 0) cout << 0 << endl;
	  else  cout << 1000 - ans << endl;
	   
     return 0;
}

Measured memory_bytes: 3704
#include <stdio.h>

int main()
{
  int a, b, c, d, maxv, minv, time;

  scanf("%d %d %d %d", &a, &b, &c, &d);
  maxv = a > c ? a : c;
  minv = b < d ? b : d;
  time = minv > maxv ? minv - maxv : 0;
  printf("%d\n", time);
  
  return 0;
}

Measured memory_bytes: 128
/*input
1
0
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}


int d[maxn];
int b[maxn];
int main()
{
	//IOS;
	int n;
	cin>>n;
	REP(i,n) cin>>d[i];

	if(n>=12){
		sort(d,d+n);
		if(d[0]==0){
			cout<<0;
			return 0;
		}
		REP(i,n-2) if(d[i]==d[i+1]&&d[i]==d[i+2]){
			cout<<0;
			return 0;
		}
		REP(i,n-1) if(d[i]==d[i+1]&&d[i]==12){
			cout<<0;
			return 0;
		}
		cout<<1;
		return 0;
	}
	int ans=0;
	REP(i,(1<<n)){
		REP(j,n){
			if(i&(1<<j)) b[j]=24-d[j];
			else b[j]=d[j];
		}
		b[n]=0;
		int meow=24;
		REP(k,n+1) for(int j=k+1;j<=n;j++){
			meow=min({meow,abs(b[k]-b[j]),24-abs(b[k]-b[j])});
		}
		ans=max(ans,meow);
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
/*
 * count.cpp
 *
 *  Created on: 2019/05/17
 *      Author: MEIP-users
 */

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <cstdlib>
#include <cctype>
#include <cstdio>
#include <ctype.h>
#include <bits/stdc++.h>

using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1e9+10)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))


int main(){

	int n,m;
	cin>>n>>m;
	int mi=0;
	int ma=n;
	rep(i,m){
		int l,r;
		cin>>l>>r;
		mi = max(mi,l);
		ma = min(ma,r);
	}
	int count = ma - mi+1;
	if(count<0){
		count=0;
	}
	cout<<count<<endl;

	return 0;

}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


int main()
{
	vector<int> a(3);

	for (int i = 0; i < 3; i++)
	{
		cin >> a[i];
	}

	sort(all(a));

	println(a.front() << " " << a.back());
}



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

using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
char a[1000][1001];
ll dp[1000][1000];
int main() {
	int H, W;
	cin >> H >> W;
	for (int i = 0; i < H; i++) cin >> a[i];
	dp[0][0] = 1;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (j + 1 < W && a[i][j + 1] != '#') (dp[i][j + 1] += dp[i][j]) %= MOD;
			if (i + 1 < H && a[i + 1][j] != '#') (dp[i + 1][j] += dp[i][j]) %= MOD;
		}
	}
	cout << dp[H - 1][W - 1] << endl;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

const ll MOD = 1e9 + 7;

int main(){
    int n;
    cin >> n;
    int p[n];
    rep(i, n) cin >> p[i];
    int ans = 0;
    rep(i, n-2) {
        if ((p[i] > p[i+1] && p[i+2] < p[i+1]) || (p[i] < p[i+1] && p[i+2] > p[i+1])) ans++;
    }
    cout << ans << endl;
}

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


using namespace std;

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
    int n;cin >> n;
    if(n == 3 || n == 5 || n == 7)return cout << "YES",0;
    cout << "NO";
    return 0;
}


Measured memory_bytes: 256
# N = gets.to_i
# A = gets.split(" ").map(&:to_i)
# S = gets.chomp

N = gets.to_i
A = gets.to_i
B = gets.to_i
C = gets.to_i
D = gets.to_i
E = gets.to_i

min = [A, B, C, D, E].min

n = (1.0 * N / min).ceil
puts n + 4


Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    int N,X,ans=0,minD=INT32_MAX;
    cin>>N>>X;
    REP(i,N){
        int m;cin>>m;
        minD=min(m,minD);
        ans++;
        X-=m;
    }
    ans+=(X/minD);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
require("fs").readFileSync("/dev/stdin","utf8").split('\n').map(function(i){for(t=26;t--;)for(s=26;s--;)r=i.replace(/[\w]/g,function(j){return String.fromCharCode((j.charCodeAt(0)*t+s)%26+97)}),r.match(/th(is|at)/)?console.log(r):0})

Measured memory_bytes: 10460
#include <iostream>
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7;

ll dp[10000000][2];

//1:L未満
//0:Lと一致

int main(){
    string s;
    ll i,j,k;
    cin >> s;
    ll ss=s.size();
    ll tcnt=0,ret=0;
    dp[0][0]=1;
    for(i=0;i<ss;i++){
        if(s[i]=='1'){
            dp[i+1][0]=dp[i][0]*2;              //Lと一致しているときは1をどちらに振り分けるかの2通り
            dp[i+1][1]=dp[i][1]*3 + dp[i][0];   //L未満が確定しているなら1を振り分ける+振り分けない+i桁目を0にする
        }else{
            dp[i+1][0]=dp[i][0];                //Lと一致しているならどうしようもない
            dp[i+1][1]=dp[i][1]*3;              //Lと一致してないなら3通り
        }
        
        dp[i+1][0]%=MOD;
        dp[i+1][1]%=MOD;
    }
    ret=dp[ss][0]+dp[ss][1];
    ret%=MOD;
    cout << ret << endl;
}

Measured memory_bytes: 2048
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset(a,0,sizeof(a));
#define MEM_1(a) memset(a,-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 998244353;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 };
int ddx[] = { 0,0,1,1,1,-1,-1,-1 }, ddy[] = { 1,-1,1,0,-1,1,0,-1 };

int deg[100001];
int main() {
	ll x,y;
	scanf("%lld%lld",&x,&y);
	puts((ll)abs(x-y)<=1?"Brown":"Alice");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    vector<int> d;
    int sa = 0, sb = 0;
    rep(i, 0, n){
        cin >> a[i];
        sa += a[i];
    }    
    rep(i, 0, n){
        cin >> b[i];
        sb += b[i];
    }
    if(sa < sb){
        cout << -1 << endl;
        return 0;
    }
    int ans = 0, sum = 0;
    rep(i, 0, n){
        int tmp = a[i] - b[i];
        if(tmp >= 0){
            d.push_back(tmp);
        }else{
            sum -= tmp;
            ans++;
        }
    }
    sort(d.rbegin(), d.rend());
    int i = 0;
    while(sum > 0){
        ans++;
        sum -= d[i];
        i++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2936
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		int A = sc.nextInt();
      	int B = sc.nextInt();
		String U = sc.next();
      	if(U.equals(S))
        {
			System.out.println( (A-1) + " " + B);
        }
      	else if(U.equals(T))
        {
          	System.out.println( A + " " + (B-1));
        }
	}
}

Measured memory_bytes: 21844
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define ff first
#define pii pair<int, int>
#define vii vector< pair<int,int> >
#define vi vector<int>
#define vvi vector< vector< int> >
#define ss second
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define int long long
#define all(a) a.begin(), a.end()
#define inf (1LL<<61)
#define ull unsigned long long
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace4(x, y, z, d)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#d<<": "<<d<<endl

#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define debug1(x) cerr << #x << ": " << x <<'\n'
#define debug2(x, y) cerr << #x << ": " << x << '\t' << #y << ": " << y <<'\n'
#define debug3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z <<'\n'
using namespace std;
int dx[]={1,0,-1, 0};int dy[]={0,1,0, -1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
bool compare(const pair<int,int> &a,
             const pair<int,int> &b)
{
    if(a.ff == b.ff) {
        return (b.ss < a.ss);
    }
    return (a.ff<b.ff);
}
bool prime[1000001];
void SieveOfEratosthenes(int n) 
{
    // Create a boolean array "prime[0..n]" and initialize
    // all entries it as true. A value in prime[i] will
    // finally be false if i is Not a prime, else true.

    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
}
int32_t main()
{
    IOS;
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    /********************* From here ***********************/
    int n,m;
    cin >> n >> m;
    string s;
    cin >> s ;
    
    int ind[n+1]  = {0};
    ind[1] = 0;
    rep(i, 2, n+1){
        if(s[i-1]=='C' && s[i-2]=='A'){
            ind[i] = ind[i-1]+1;
        }
        else{
            ind[i] = ind[i-1];
        }
    }
    
    rep(i, 0, m){
        int l,r;
        cin >> l >> r;
        cout << ind[r] - ind[l] << endl;
    }
}



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


int main(){
  
  int N, K;
  long long c;
  cin >> N >> K;
  
  c = K;
  
  for(int i=1; i < N; i++){
    c = c * (K - 1);
  }
  
  cout << c << endl;
  
}


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

#define ll long long
#define ld long double

using namespace std;

const long long LINF = LLONG_MAX;
const int INF = INT_MAX;
const int MOD = 1000000007;

const ld PI = 3.14159265358979323;

const int N = 2e2 + 111;

int n, a[N];

int main() {
    #ifdef Vova
        freopen("input", "r", stdin);
    #else
        ios::sync_with_stdio(false);
        cin.tie(0);
    #endif
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a+n);
    int ans = 0;
    for (int i = 0; i < n; i++){
        for (int j = upper_bound(a, a+n, a[i]) - a; j < n; j++){
            ans += lower_bound(a, a+n, a[i] + a[j]) - upper_bound(a, a+n, a[j]);
        }
    }
    cout << ans;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
 
int main(){
    string s; cin >> s;
    
    int l = 0, r = s.length() - 1;

    int i = 0;
 	while(1){
        if(s[i] == 'A'){
            l = i;
            break;
        }
        i++;
    }

    i = s.length() - 1;
 	while(1){
        if(s[i] == 'Z'){
            r = i;
            break;
        }
        i--;
    }
  	cout << r-l+1;
}

Measured memory_bytes: 640
n = int(input())
a = list(map(int, input().split()))

c = [0] * n
for i in range(n):
    c[i] = a[i] - (i+1)

c.sort()
b = c[n//2]
ans = 0
for j in range(n):
    ans += abs(c[j] - b)

print(ans)


Measured memory_bytes: 26708
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

int main() {
		int N;
		cin >> N;
		ll A[N];
		for (int i = 0; i < N; i++) {
				cin >> A[i];
				A[i] -= (i+1);
		}

		sort(A, A+N);
		ll x = A[N/2];

		ll ans = 0;
		for (int i = 0; i < N; i++) {
				ans += abs(x - A[i]);
		}

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


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int n,k,i,mini = 1,maxi = 1e9;
vector<int> A;

bool check(int tar)
{
    int j, cur = 0;
    for(j=0;j<n;j++)
    {
        cur += (A[j]-1)/tar;
    }
    if(cur > k)
        return false;
    else
        return true;
}

int main()
{
    cin>>n>>k;
    for(i=0;i<n;i++)
    {
        int a;
        cin>>a;
        A.push_back(a);
    }
    while(mini < maxi)
    {
        int mid = mini + maxi >> 1;
        if(mini == mid)
        {
            if(!check(mini))
                mini = maxi;
            else
                maxi = mini;
        }
        else
        {
            if(check(mid))
                maxi = mid;
            else
                mini = mid+1;
        }
    }
    cout<<mini;
    return 0;
}


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

using namespace std;

const int MAXN = 1e5 + 10;

int n, Q;
vector<long long> vec;
long long a[MAXN], b[MAXN];
long long answer[MAXN];

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> Q;
	vec.push_back(n);
	for (int i = 1; i <= Q; i++)
	{
		long long q;
		cin >> q;
		while (vec.size() && vec.back() >= q)
			vec.pop_back();
		vec.push_back(q);
	}
	int z = vec.size();
	a[z - 1] = 1;
	for (int i = z - 1; ~i; i--)
	{
		long long local = vec[i];
		while (true)
		{
			int id = lower_bound(vec.begin(), vec.begin() + i, local) - vec.begin();
			if (id == 0)
			{
				b[local] += a[i];
				break;
			}
			a[id - 1] += a[i] * (local / vec[id - 1]);
			local %= vec[id - 1];
		}
	}
	for (int i = n; i; i--)
	{
		b[i] += b[i + 1];
	}
	for (int i = 1; i <= n; i++)
		cout << b[i] << '\n';
	return 0;
}

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

int main(){
    char moji[][6] = {
        {'.',',','!','?',' '},
        {'a','b','c',},
        {'d','e','f',},
        {'g','h','i',},
        {'j','k','l',},
        {'m','n','o',},
        {'p','q','r','s',},
        {'t','u','v',},
        {'w','x','y','z',}
    };

    int jo[9] = {5,3,3,3,3,3,4,3,4};

    int n; cin>>n;

    for(int i=0; i<n; i++){
        string s; cin>>s;
        int count =-1;
        int v;

        for(int j=0; j<s.size(); j++){ 
            if(s[j] != '0'){
                v = s[j] - '0';
                v--;
                count++;
            }

            else{
                if(count == -1) continue;
                cout<<moji[v][count % jo[v]];
                count = -1;
            }
        }

        cout<<endl;
    }

    return 0;
}


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

using namespace std;
typedef long long LL;

const int MAXN = 2E5 + 5;
const int MOD = 998244353;

int n, k;
int l[20], r[20];
LL dp[MAXN], sum[MAXN];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >> k;
    for (int i = 1; i <= k; i++) cin >> l[i] >> r[i];
    dp[1] = 1;
    sum[1] = 1;
    for (int i = 2; i <= n; i++)
        for (int j = 1; j <= k; j++) {
            if (i - l[j] >= 0) {
                dp[i] += sum[i - l[j]] - sum[max(0, i - r[j] - 1)];
                dp[i] = (dp[i] % MOD + MOD) % MOD;
            }
            sum[i] = (sum[i - 1] + dp[i]) % MOD;
        }
    cout << dp[n];
    return 0;
}


Measured memory_bytes: 6772
import java.io.*;

public class Main {
    public static void main(String[] args){
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        try{

        int S = Integer.parseInt(reader.readLine());

        System.out.printf("%d:%d:%d\n",S/3600,(S%3600)/60,S%60);
        

        }catch(IOException e){
            System.out.println(e);
        }
        }

    }


Measured memory_bytes: 24632