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

int main() {
  int N;
  cin >> N;
  priority_queue<int, vector<int>, greater<int>> P;
  int count = 0;
  
  for (int i = 0; i < N; i++) {
    int p = 0;
    cin >> p;
    P.push(p);
    int m = P.top();
    if (p == m) {
      count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 1400
#include <stdio.h>

int main(void)
{
	int n, m, a[100][100] = { 0 }, b[100] = { 0 }, c[100] = { 0 }, i, t;

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

	for (i = 0; i < n ; i++)
	{
		for (t = 0; t < m ; t++)
		{
			scanf("%d", &a[i][t]);
		}
	}

	for (t = 0; t < m; t++)
	{
		scanf("%d", &b[t]);
	}

	for (i = 0; i < n; i++)
	{
		for (t = 0; t < m; t++)
		{
			c[i] = c[i] + a[i][t] * b[t];
		}
	}

	for ( i = 0; i < n; i++)
	{
		printf("%d\n", c[i]);
	}
	return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define vi vector<int>
#define vs vector<string>
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
using namespace std;

int main(){
  int n,m;
  cin>>n;
  vi t(n);
  rep(i,n)cin>>t[i];
  cin>>m;
  vi p(m), x(m);
  rep(i,m)cin>>p[i]>>x[i];
  int s;
  rep(i,m){
    s = 0;
    rep(j,n){
      s += (p[i]-1==j?x[i]:t[j]);
    }
    cout<<s<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
#define _GLIBCXX_DEBUG

int mei(vector<string> &S, int H, int W, int x, int y) {
  vector<vector<int>> n(H, vector<int>(W, 100000));
  n[x][y] = 0;
  queue<vector<int>> q;
  q.push({x, y, 0});
  
  while(!q.empty()) {
    vector<int> v = q.front();
    int h = v[0], w = v[1], m = v[2];
    q.pop();
    if(h > 0 && S[h-1][w] == '.' && n[h-1][w] > 10000) {
      n[h-1][w] = m+1;
      q.push({h-1, w, m+1});
    }
    if(h < H-1 && S[h+1][w] == '.' && n[h+1][w] > 10000) {
      n[h+1][w] = m+1;
      q.push({h+1, w, m+1});
    }
    if(w > 0 && S[h][w-1] == '.' && n[h][w-1] > 10000) {
      n[h][w-1] = m+1;
      q.push({h, w-1, m+1});
    }
    if(w < W-1 && S[h][w+1] == '.' && n[h][w+1] > 10000) {
      n[h][w+1] = m+1;
      q.push({h, w+1, m+1});
    }
  }
  
  int ans = 0;
  rep(h, H) rep(w, W) if(S[h][w] == '.') ans = max(ans, n[h][w]);
  
  return ans;
}

signed main() {
  int H, W; cin >> H >> W;
  vector<string> S(H);
  rep(i, H) cin >> S[i];

  int ans = 0;
  rep(h, H) rep(w, W) if(S[h][w] == '.') ans = max(ans, mei(S, H, W, h, w));
  
  cout << ans << endl;


}


Measured memory_bytes: 3600
from collections import Counter


def solve(nums):
    counts = [pair for pair in Counter(nums).items() if pair[1] >= 2]
    counts.sort()
    counts.reverse()

    if len(counts) == 0:
        return 0
    elif len(counts) == 1:
        (val, cnt) = counts[0]
        return 0 if cnt < 4 else val * val
    else:
        (val1, cnt1) = counts[0]
        (val2, cnt2) = counts[1]
        return val1 * val2 if cnt1 < 4 else val1 * val1


if __name__ == '__main__':
    n = input()
    a = [int(i) for i in input().split()]
    print(solve(a))

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

using namespace std;

int main() {
  long long a, b, c, x, y, z, ans;
  scanf("%ld %ld %ld %ld %ld", &a, &b, &c, &x, &y);
  z = max(x, y);
  ans = (long long)9e9;
  for (int i = 0; i <= z; i++) {
    ans = min(ans, a * max(0LL, (x - i)) + b * max(0LL, (y - i)) + 2 * c * i);
  }
  printf("%ld", ans);
  return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputReader cin = new InputReader(System.in);
        PrintWriter cout = new PrintWriter(System.out);

        TaskA taskA = new TaskA();
        taskA.run(cin, cout);

        cout.close();
    }
}

class TaskA {
    void run(InputReader cin, PrintWriter cout) {
        int a = cin.nextInt();
        int b = cin.nextInt();

        String result;
        final String ZERO = "Zero";
        final String POS = "Positive";
        final String NEG = "Negative";

        if (a == 0 || b == 0) {
            result = ZERO;
        } else if (a < 0 && 0 < b) {
            result = ZERO;
        } else if (a < 0 && b < 0) {
            if ((b - a) % 2 == 0) {
                result = NEG;
            } else {
                result = POS;
            }
        } else { // 0 < a && 0 < b
            result = POS;
        }

        cout.println(result);
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

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

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

Measured memory_bytes: 21460
#include <iostream>
#include <string>
#include <vector>
#define _GLIBCXX_DEBUG
using namespace std;

int main() {
    int H,W;
    cin >> H >> W;
    for(int i=0;i<W+2;i++) {
        cout << "#";
    }
    cout << endl;
    for(int i=0;i<H;i++) {
        string s;
        cin >> s;
        cout << "#" << s << "#" << endl;
    }
    for(int i=0;i<W+2;i++) {
        cout << "#";
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N;
	while(cin>>N) {
		VI V(N), C(N);
		REP(i, N) cin>>V[i];
		REP(i, N) cin>>C[i];
		ll ans = 0;
		REP(bi, 1<<N) {
			ll lans = 0;
			REP(i, N) {
				if(bi>>i&1) lans += V[i]-C[i];
			}
			maxUpdate(ans, lans);
		}
		
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define prArr(Arr,n) for(int _=0;_<n;_++)   cout<<(Arr)[_]<<" ";
using namespace std;
const int INF=(int)1e9+10;
const int MOD=(int)1e9+7;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,flag=0,ctr=1;
    cin>>n;
    int ans=n-1;
    vector<int> v(n);
    for(int i=0;i<n&&cin>>v[i];i++)
        flag|=(v[i]==1);
    if(!flag)
        return cout<<"-1",0;
    for(int i=0;i<n;i++)
        if(v[i]==ctr)
            ans=min(ans,n-ctr),ctr++;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<functional>
#include<cstring>

using namespace std;

#define MOD 1000000007

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

	long long n;
	long long a[4] = { 10,9,8 };
	long long b[4] = { 10,9,8 };

	scanf("%lld", &n);

	for (long long i = 1; i < n; i++)
	{
		for (int j = 0; j < 4; j++)
		{
			a[j] = a[j] * b[j] % MOD;
		}
	}

	printf("%lld\n", ((a[0] - a[1] * 2 % MOD + MOD) % MOD + a[2]) % MOD);

	return 0;
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int   //used int to avoid mle
#define ulli unsigned long long int 
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define spl set<pll>
#define msl multiset <lli>
#define msp multiset <pll>
#define pll pair<lli, lli>
#define mll map<lli, lli>              //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x)
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define fbo find_by_order //returns iterator
#define fok order_of_key //return index
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
lli mod=998244353;
//string s=bitset<32>(n).to_string();
typedef tree<lli,null_type,less<lli>,rb_tree_tag, // change both to lli if set is req insted of multiset
tree_order_statistics_node_update> indexed_set;
int main()
{
	lli n;
	cin>>n;
	bool ani=false;
	while(n){
		if(n%10==7)ani=true;
		n=n/10;
	}
	if(ani)cout<<"Yes";else cout<<"No";
	
	
	
	
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
const int INF = numeric_limits<int>::max();

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

int main()
{
    char c;
    cin >> c;
    if (c >= 'a' && c <= 'z')
        cout << "a" << endl;
    else
        cout << "A" << endl;
    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#include <chrono>
#include <ctime>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;
const ll SIZE = 1e5 + 10, INF = 1e9, K = 300;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<vector<ll>> g;

bool used[SIZE];

ll dfs(int v) {
    used[v] = 1;

    ll cur = 0;
    for (auto to : g[v]) {
        if (!used[to]) {
            
            cur ^= (dfs(to) + 1);
        }
    }

    return cur;
}
int main() {
    fastInp;

    ll n;
    cin >> n;

    g.resize(n);

    for (int i = 0; i < n - 1; i++) {
        ll u, v;
        cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    
    if (dfs(0)) {
        cout << "Alice";
    }
    else {
        cout << "Bob";
    }
    return 0;
}

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

const int _ = 5003 , P = 1e9 + 7;
int poww(long long a , int b){int tms = 1; while(b){if(b & 1) tms = tms * a % P; a =a  * a % P; b >>= 1;} return tms;}
int fa[_] , sz[_]; bool flg[_];
int find(int x){return fa[x] == x ? x : (fa[x] = find(fa[x]));}

int main(){
	int N; cin >> N; for(int i = 1 ; i <= N ; ++i){fa[i] = i; sz[i] = 1;}
	for(int i = 1 ; i <= N ; ++i){
		int P; cin >> P; if(P == -1) flg[i] = 1; else{sz[find(P)] += sz[find(i)]; fa[find(i)] = find(P);}
	}
	int cnt = 0; vector < int > pot; for(int i = 1 ; i <= N ; ++i) if(fa[i] == i){pot.push_back(i); cnt += flg[i];}
	static int dp[5003]; int ans = 1ll * poww(N - 1 , cnt) * (N - pot.size() + cnt) % P;
	dp[0] = 1; for(auto t : pot) if(flg[t]) for(int i = cnt ; i ; --i) dp[i] = (dp[i] + 1ll * dp[i - 1] * sz[t]) % P;
	static int fac[5003]; fac[0] = 1; for(int i = 1 ; i <= cnt ; ++i) fac[i] = 1ll * fac[i - 1] * i % P;
	for(int i = 1 ; i <= cnt ; ++i) ans = (ans - 1ll * (dp[i] - (i == 1 ? cnt : 0)) * fac[i - 1] % P * poww(N - 1 , cnt - i)) % P;
	cout << (ans + P) % P; return 0;
}


Measured memory_bytes: 3732
n = int(input())
value = list(map(int, input().split()))
cost = list(map(int, input().split()))
cnt = 0

dif = [value[x] - cost[x] for x in range(n)]

for i in range(n):
    if dif[i] > 0:
        cnt += dif[i]

print(cnt)

Measured memory_bytes: 3060
n, x, y = map(int, input().split())
x -= 1
y -= 1

ans = [0 for _ in range(n)]
for i in range(n-1):
    for j in range(i+1, n):
        distance = min(j - i, abs(x - i) + 1 + abs(j - y), abs(y - i) + 1 + abs(j - x))
        ans[distance] += 1

for i in range(1, n):
    print(ans[i])

Measured memory_bytes: 48092
n,m,c = map(int,input().split())
B = list(map(int,input().split()))
li2=[input() for i in range(n)]
A = []
for i in range(n):
    A.append( [int(x.strip()) for x in li2[i].split()])

ans = 0

for i in range(n):
    var = c
    for j in range(m):
        var += A[i][j]*B[j]
    if var > 0:
       ans += 1
       
print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  int N,M,Q;
  cin >> N >> M >> Q;
  int L[M],R[M];
  for(int i=0;i<M;i++) cin >> L[i] >> R[i];
  int p[Q],q[Q];
  for(int i=0;i<Q;i++) cin >> p[i] >> q[i];

  //二次元累積和
  int sum[N+1][N+1];
  fill(sum[0],sum[N+1],0);
  for(int i=0;i<M;i++){
    sum[L[i]][R[i]]++;
  }
  for(int i=1;i<=N;i++){
    for(int j=1;j<=N;j++){
      sum[i][j] += sum[i-1][j];
      sum[i][j] += sum[i][j-1];
      sum[i][j] -= sum[i-1][j-1];
    }
  }

  //クエリ
  for(int k=0;k<Q;k++){
    int ans = 0;
    ans += sum[q[k]][q[k]];
    ans -= sum[q[k]][p[k]-1];
    ans -= sum[p[k]-1][q[k]];
    ans += sum[p[k]-1][p[k]-1];
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 4224
# -*- coding: utf-8 -*-

# input
N = int(input())
v = list(map(int, input().split()))

# solve
v.sort()
first = sum(v[0:2]) / 2
if N != 2:
    tmp = first
    for i in range(2, N):
        ans = (tmp + v[i]) / 2
        tmp = ans
else:
    ans = first

# output
print(ans)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

int h, w, s;

const int MAX_N = 40;
//const int MAX_P = MAX_N * MAX_N;

pair<int, int> dp[MAX_N][MAX_N][MAX_N][MAX_N];


void cumulativeSum(int s[MAX_N][MAX_N], int h, int w){
    //?????????????´????(1,1)
    rep(i,h + 1) rep(j,w + 1) s[i][j + 1] += s[i][j];
    rep(i,h + 1) rep(j,w + 1) s[i + 1][j] += s[i][j];
}

//(i,j)????????????(k,l)???????????¨??????????????¢
int sum(int j, int i, int l, int k, int s[MAX_N][MAX_N]){
    return s[k][l] - s[i - 1][l] - s[k][j - 1] + s[i - 1][j - 1];
}

pair<int, int> dfs(int lx, int ly, int rx, int ry, int g[MAX_N][MAX_N]){
    if(dp[ly][lx][ry][rx].first != -1) return dp[ly][lx][ry][rx];

    int total = sum(1,1,w,h,g);
    pair<int, int> res = make_pair(1, s - (total - sum(lx,ly,rx,ry,g)));

    range(i,ly, ry){
        if(total - sum(lx,ly,rx,i,g) > s || total - sum(lx,i + 1,rx,ry,g) > s) continue;
        pair<int, int> a = dfs(lx,ly,rx,i,g);
        pair<int, int> b = dfs(lx,i + 1,rx,ry,g);
        pair<int, int> cal = make_pair(a.first + b.first, min(a.second, b.second));
        res = max(res, cal);
    }

    range(i,lx, rx){
        if(total - sum(lx,ly,i,ry,g) > s || total - sum(i + 1,ly,rx,ry,g) > s) continue;
        pair<int, int> a = dfs(lx,ly,i,ry,g);
        pair<int, int> b = dfs(i + 1,ly,rx,ry,g);
        pair<int, int> cal = make_pair(a.first + b.first, min(a.second, b.second));
        res = max(res, cal);
    }
    return dp[ly][lx][ry][rx] = res;
}

int main(){
    while(cin >> h >> w >> s, h||w){

        int g[MAX_N][MAX_N] = {0};
        rep(i,h){
            rep(j,w){
                cin >> g[i + 1][j + 1];
            }
        }

        rep(i,MAX_N) rep(j,MAX_N) rep(k,MAX_N) rep(l,MAX_N) dp[i][j][k][l] = make_pair(-1,-1);
        cumulativeSum(g,h,w);
        //rep(i,h + 1){ rep(j,w + 1){ cout << g[i][j] << ' ' ; } cout << endl; }
        //    rep(ry,h - 1){
        //        rep(rx,w - 1){
        //            range(ly,ry + 1,h){
        //                range(lx,rx + 1,w){
        //                    dp[
        //                }
        //            }
        //        }
        //    }
        pair<int, int> p = dfs(1,1,w,h,g);
        cout << p.first << ' ' << p.second << endl;
    }
}

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

struct edge { int to, cost; };
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VECINT;
typedef vector<ll> VECLL;

struct UnionFind {
  vector<int> par,ranc;

  UnionFind(int N) : par(N),ranc(N) { REP(i,N) par[i]=i,ranc[i]=0; }

  int root(int s) {
    if (par[s]==s) return s;
    else return root(par[s]);
  }

  bool same(int x, int y) { return root(x)==root(y); }

  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x==y) return;
    if (ranc[x]>ranc[y]) {
      par[y] = x;
    } else {
      par[x] = y;
      if (ranc[x]==ranc[y]) ranc[y]++;
    }
  }
};

int main() {
  int N,K,L;cin>>N>>K>>L;
  UnionFind uf1(N),uf2(N);
  REP(i,K) {
    int p,q;cin>>p>>q;
    p--;
    q--;
    uf1.unite(p,q);
  }
  REP(i,L) {
    int r,s;cin>>r>>s;
    r--;
    s--;
    uf2.unite(r,s);
  }
  map<P,int> res;
  REP(i,N) {
    res[{uf1.root(i),uf2.root(i)}]++;
  }
  REP(i,N) {
    cout << res[{uf1.root(i),uf2.root(i)}] << ' ';
  }

  return 0;
}

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

// @@ !! LIM(binsearch f:intDiv)
// --> binsearch f:intDiv
// ---- inserted library file binsearch.cc

template<typename T>
T binsearch(auto check, T yes, T no, T err = (T)1) {
  while (abs(yes - no) > err) {
    T mid = (yes + no) / (T)2;
    if (check(mid)) yes = mid;
    else            no  = mid;
  }
  return yes;
}

// ---- end binsearch.cc
// ---- inserted function intDiv from util.cc
// Integer Division; regardless pos/neg
ll divFloor(ll x, ll y) {
  if (x > 0) {
    if (y > 0) return x / y;
    else       return (x - y - 1) / y;
  }else {
    if (y > 0) return (x - y + 1) / y;
    else       return x / y;
  }
}

ll divCeil(ll x, ll y) {
  if (x > 0) {
    if (y > 0) return (x + y - 1) / y;
    else       return x / y;
  }else {
    if (y > 0) return x / y;
    else       return (x + y + 1) / y;
  }
}
// ---- end intDiv
// @@ !! LIM  -- end mark --

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll big = 2e9;

  ll N, K; cin >> N >> K;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++) cin >> A.at(i);

  auto check = [&](ll len) -> bool {
    ll cnt = 0;
    for (ll i = 0; i < N; i++) {
      ll t = divCeil(A.at(i), len);
      cnt += t - 1;
    }
    return cnt <= K;
  };

  ll x = binsearch<ll>(check, big, 0);
  cout << x << endl;

  return 0;
}



Measured memory_bytes: 4688
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
using namespace std;
int main () { 
	long long x,y = 1;
	cin >> x;
	for(int i = 1; i <= x; i++){
			y = y * i % (1000000007);
		}
	cout << y << endl;
} 			


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

using namespace std;

int main()
{
    string w;
    cin >> w;
    map<char, int> m;
    for(auto c : w) m[c]++;
    for(auto c : m) {
        if(c.second % 2 == 1) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 764
'''
chapter2_3
ALDS1_1_D Maximum Profit
'''
N = int(input())
R = [int(input()) for i in range(N)]
minr = R[0]
maxr = -10**9
for i in range(1,N):
    maxr = max(maxr, R[i]-minr)
    minr = min(minr,R[i])
print(maxr)



Measured memory_bytes: 13600
#include "bits/stdc++.h"
using namespace std;
#define all(x) x.begin(), x.end()

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int N, M; cin >> N >> M;
    vector<string> w(N), s(M), S, RS;
    for (auto &wi: w) cin >> wi, S.push_back(wi), RS.push_back(string(wi.rbegin(), wi.rend()));
    sort(all(S)), sort(all(RS));
    auto f1 = [&](string s) {
        s.pop_back();
        return int(lower_bound(all(S), s + '~') - lower_bound(all(S), s));
    };
    auto f2 = [&](string s) {
        s.pop_back();
        return int(lower_bound(all(RS), s + '~') - lower_bound(all(RS), s));
    };
    auto f3 = [&](string s) {
        return (binary_search(all(S), s) ? 1 : 0);
    };
    auto slv = [&](string s) {
        if (s.back() == '*') {
            return f1(s);
        } else if (s[0] == '*') {
            return f2(string(s.rbegin(), s.rend()));
        } else {
            return f3(s);
        }
    };
    for (auto &si: s) {
        cin >> si;
        int pos;
        if ((pos = si.find('?')) == string::npos) {
            cout << slv(si) << "\n";
        } else {
            int res = 0;
            for (int i = 0; i < 26; ++i) {
                si[pos] = char('a' + i);
                res += slv(si);
            }
            cout << res << "\n";
        }
    }
}



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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

vector<ll> create(ll N) {
    vector<ll> tabel;
    tabel.reserve(N + 1);
    tabel.push_back(0);
    for(ll i = 1; i <= N; i++) {
        tabel.push_back(tabel.back() + i);
    }
    return tabel;
}

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

    ll N;
    std::cin >> N;

    map<string, ll> map;
    REP(i, N) {
        string S;
        std::cin >> S;
        SORT(S);
        auto itr = map.find(S);
        if(itr != map.end()) {
            itr->second++;
        }
        else {
            map.emplace(S, 1);
        }
    }

    auto table = create(N);

    ll ans = 0;
    for(const auto& v : map) {
        if(1 < v.second) {
            ans += table[v.second - 1];
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 12032
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

int main(){
    string x;
    cin >> x;
    for (int i=0;i<x.size();++i){
        if (x[i]=='A' && x[i+1]=='C'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 384
n=int(input())
a=list(map(int,input().split()))
l=[]
for i in range(len(a)+2):
  l.append(0)
  
for i in a:
  if(l[i]==0):
  	l[i]=1
  else:
    l[i] += 1

for i in range(1,len(l)):
    print(l[i])          
            

Measured memory_bytes: 32224
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

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;
}
int main() {
    int N;
    cin >> N;
    vi a(N+1);
    a[0] = 0;
    rep(i, 1, N+1) {
        cin >> a[i];
    }

    int res = 0;
    rep(i, 1, N+1) {
        if (a[i] == i) {
            swap(a[i], a[i+1]);
            ++res;
        };
    }
    cout << res << endl;
    return 0;
}

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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define REPC(var, start, end) for(int var = start; var <= (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cerr << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;
#define DBG(x) cerr << x << endl;

/*
	
*/
int n;
VI A;
map<int, int> cnt;
LL solve()
{
	for(auto i : A) ++cnt[i];

	LL ret = 0, fs = -1, se = -1;
	for(auto it = cnt.rbegin(); it != cnt.rend(); ++it)
	{
		LL len = it->first, c = it->second;
		if(c >= 2)
		{
			if(c >= 4)
				ret = max(ret, len * len);
			if(fs == -1) fs = len;
			else if(se == -1) se = len;
			else {
				ret = max(ret, fs * se);
			}
		}
	}
	if(fs > 0 && se > 0)
		ret = max(ret, fs * se);
	return ret;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	///freopen("tmp.in", "r", stdin);
	//freopen("tmp.out", "w", stderr);
#endif
	cin >> n;

	A.resize(n);
	REP(i, 0, n) cin >> A[i];

	cout << solve() << endl;

	return 0;
}

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

int main()
{
  int i,n;
  int w[100];
  int sum[100];
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &w[i]);
  }
  int diff1,diff2;
  sum[0]=w[0];
  for (i = 1; i < n; i++) {
    sum[i]=sum[i-1]+w[i];
  }
  i=0;
  while(sum[i]<sum[n-1]/2) {
    i++;
  }
  diff1=abs((sum[n-1]-sum[i])-sum[i]);
  diff2=abs((sum[n-1]-sum[i-1])-sum[i-1]);
  if(diff2<diff1) diff1=diff2;
  printf("%d\n", diff1);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
using namespace std;
const int inf = 1e18 + 7;
const int N = 1e6 + 7;
const int md = 1e9 + 7;
void sol() {
  int f = 0;
  int m1, m2, d1, d2;
  cin >> m1 >> d1;
  cin >> m2 >> d2;
  if(d2 == 1) f = 1;
  cout << f;
}

int32_t main() 
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  //cin >> T; while(T--) 
  sol();
  return 0;
}


Measured memory_bytes: 256
from collections import Counter as D, defaultdict as dd
from math import factorial as ft, ceil as aron
from fractions import gcd as pg 
from bisect import insort as ins, bisect_left as bl, bisect_right as br
import sys

#sys.stdin=open("./testfile1.py","r")
raw_input=sys.stdin.readline

f1=lambda : map(int,raw_input().split())
f2=lambda : map(int,list(raw_input()))
f3=lambda : int(raw_input())
f4=lambda : raw_input().rstrip()
def main():
	
	s=f4()
	n1=0
	ans=0
	i=0
	while i<len(s)-1:
		if s[i]=="A":
			n1+=1
		elif s[i:i+2]=="BC":
			ans+=n1
			i+=1
		else:
			n1=0
		i+=1
	print ans

if __name__ == '__main__':
	main()


Measured memory_bytes: 34920
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		int ans = 0;
		boolean canDiv = false;

		long search = (long)Math.sqrt(N);

		for (long i = 1; i <= search; i++) {
			if(N%i == 0) {
				canDiv = true;
				ans = countDigits(N/i);
			}
		}

		System.out.println(ans);
	}

	public static int countDigits(long n) {
		int cnt = 0;
		while (n > 0) {
			cnt++;
			n /=10;
		}
		return cnt;
	}
}


Measured memory_bytes: 21844
n = int(input())

hyo = [[[1]]]

for i in range(n-1):
    n_hyo = []
    for arr in hyo[i]:
        for j in range(max(arr)+1):
            n_arr = arr[:]
            n_arr.append(j+1)
            n_hyo.append(n_arr)
    hyo.append(n_hyo)

alp = ['a','b','c','d','e','f','g','h','i','j']

for i in hyo[n-1]:
    ans = ''
    for j in i:
        ans += alp[j-1]
    print(ans)

    


Measured memory_bytes: 34380
//##MohK
//16/2/2020 .....2,46
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    if(a==b&&a!=c){
        cout<<"Yes"<<endl;
    }
    else if(a==c&&a!=b){
        cout<<"Yes"<<endl;
    }
    else if(b==c&&b!=a){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;

   return 0;
}





Measured memory_bytes: 764
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

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

    ll A,B;
    cin >> A >> B;
    if(A % 3 == 0 || B % 3 == 0 || (A+B) % 3 == 0) print("Possible");
    else print("Impossible");

    return 0;
}

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

#define vec              vector<int>
#define vecll            vector<ll>
#define vecd             vector<double>
#define vecst            vector<string>
#define vecb             vector<bool>
#define v2(v,n,m,init)   vector<vector<int>>  v(n, vector<int>(m, init))
#define vb2(v,n,m,init)  vector<vector<bool>> v(n, vector<bool>(m, init))
#define vll2(v,n,m,init) vector<vector<ll>>   v(n, vector<ll>(m, init))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
template <typename T>
bool chmax(T &a, const T& b){if(a<b){a=b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a>b){a=b; return true;} return false;}
//----------------------------------------------------------------

int main(void) {
  int n;
  cin >> n;
  vll2(a, n, n, 0);
  rep(i,n){
    rep(j,n){
      cin >> a[i][j];
    }
  }

  vector<vector<ll>> b=a;
  rep(k,n){
    rep(i,n){
      rep(j,n){
        chmin(b[i][j], b[i][k]+b[k][j]);
      }
    }
  }

  rep(i,n){
    rep(j,n){
      if(b[i][j]<a[i][j]){
        prt(-1);
        return 0;
      }
    }
  }

  ll ans=0;
  rep(i,n){
    REP(j,i,n){
      bool ok=true;
      rep(k,n){
        if(i!=k && j!=k && b[i][j]==b[i][k]+b[k][j]){
          ok=false;
        }
      }
      if(ok) ans+=b[i][j];
    }
  }

  prt(ans);

}


Measured memory_bytes: 5080
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    char b;
    cin>>b;
    map<char,char> ans;
    ans['A']='T';
    ans['T']='A';
    ans['C']='G';
    ans['G']='C';
    cout<<ans[b]<<endl;
}

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

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



int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    ll res = 0;
    int left = 0;
    int right = 0;
    int sum = 0;
    for (left = 0;left < n;left++){
        while(right < n && (sum ^ v[right]) == (sum + v[right])){
            sum += v[right];
            right++;
        }
        res += right-left;
        if (left == right) right++;
        else {
            sum -= v[left];
        }
    }
    
    cout << res << endl;

    return 0;

}


Measured memory_bytes: 1024
#include <array>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

const int MAX_N = 1120;
const int MAX_K = 14;

vector<int> sieve(int n) {
	vector<int> res(1, 2);
	vector<bool> prime(n, true);
	for(int i = 3; i < n; i += 2) {
		if(prime[i]) {
			res.push_back(i);
			for(long long j = static_cast<long long>(i) * i; j < n; j += i * 2)
				prime[j] = false;
		}
	}

	return res;
}

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	const auto primes = sieve(MAX_N + 1);
	const int num = primes.size();

	array<array<int, MAX_K + 1>, MAX_N + 1> dp{};
	dp[0][0] = 1;

	for(int i = 0; i < num; ++i) {
		for(int j = MAX_N - primes[i]; j >= 0; --j) {
			for(int l = MAX_K - 1; l >= 0; --l) {
				dp[j + primes[i]][l + 1] += dp[j][l];
			}
		}
	}

	for(int n, k; cin >> n >> k && n;) {
		cout << dp[n][k] << endl;
	}

	return EXIT_SUCCESS;
}

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

long long A,B,C,K;
int main(){
    cin >> A >> B >> C >> K;
    if(K<=A) cout << K << endl;
    else if(A<K && K<=A+B) cout << A << endl;
    else if(A+B<K && K<=A+B+C) cout << A-(K-A-B) << endl;
    return 0;

}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define INF 1e9

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef vector < pair<int, int> > vii;
typedef long double ld;
typedef tree<pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;


ll dp[51][2501];
ll n, a, x, ans;

int main()
{
	dp[0][0]=1;
	cin >> n >> a;
	for(int i = 1; i <= n; i++){
		cin >> x;
		for(int j = i; j >= 1; j--){
			for(int k = x; k <= 2500; k++){
				dp[j][k]+=dp[j-1][k-x];
			} 
		}
	}
	for(int i = 1; i*a <= 2500 && i <= n; i++){
		ans+=dp[i][i*a];
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 1280
# ABC131 Megalomania

import sys

N = int(input())
AB = [list(int(a) for a in input().split()) for a in range(N)]

AB.sort(key=lambda x:x[1])

jikan = 0
for i, j in AB:
    jikan += i
    if jikan > j:
        print("No")
        sys.exit()
print("Yes")

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

ll powll(ll a,ll n){
  if(n==0)
  {
    return 1;
  }
  return powll(a,n-1)*a;
}

ll a[5000];
int main() {
   ll i,j,k;
   ll n,m,sum=0;
   cin >>n>>m;
   for(i=0; i<n; i++)
   {
     cin >>a[i];
     sum+=a[i];
   } 
   sort(a+0,a+n);
   reverse(a+0,a+n);
   if(sum%(4*m)==0)
   {
     sum/=(4*m);
   }else
   {
     sum=sum/(4*m)+1;
   }
   
   if(a[m-1]<sum)
   {
     cout<< "No" <<endl;
   }else
   {
     cout<< "Yes" <<endl;
   }
   
   
}

Measured memory_bytes: 256
local N = io.read("*n")
local A = {}
for i = 1, N do
    A[i] = io.read("*n")
end

local biggest, smallest = 0, 1000000000
for i = 1, N do
    if biggest < A[i] then
        biggest = A[i]
    end
    if smallest > A[i] then
        smallest = A[i]
    end
end
print(biggest - smallest)

Measured memory_bytes: 256
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())

    min = 10 ** 15

    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            j = n // i
            if min > i + j - 2:
                min = i + j - 2

    print(min)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 38768
#include<iostream>
using namespace std;
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#define int long long int
#define mod 1000000007
int prime[1000001];
void sieve()
{
	int j;
	for(j=1;j<=1000000;j++)
	{
		prime[j]=j;
	}
	for(j=2;j<=1000;j++)
	{
		if(prime[j]==j)
		{
			for(int k=2;j*k<=1000000;k++)
			{
				prime[j*k]=j;
			}
		}
	}
}
int32_t main()
{
	sieve();
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	int answer=0;
	int c;
	for(c=1;c<n;c++)
	{
		int x=n-c;
		int here=1;
		while(x!=1)
		{
			int val=prime[x];
			int count=0;
			while(x!=1&&prime[x]==val)
			{
				x/=prime[x];
				count++;
			}
			here*=(count+1);
		}
		answer+=here;
	}
	cout<<answer<<endl;
}


Measured memory_bytes: 11468
#include <iostream>
#include <string>

using namespace std;

int main(void){
    string str;
    string ans = "yes";
    cin >> str;
    for(int i;i<str.size() - 1;i++){
        size_t out = str.find(str[i],i+1);
        if(out != -1)
            ans = "no";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream> 
#include<algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
const int mod=1e9+7;
long long v[2005][2005];
int main(){
	long long n,k;
	cin>>n>>k;
	v[0][0]=1;
	for(int i=1;i<=n;i++){
		v[i][0]=1;
		for(int j=1;j<=i;j++){
			v[i][j]=(v[i-1][j-1]+v[i-1][j])%mod;
		}
	}	
	for(int i=1;i<=k;i++){
		cout<<(v[n-k+1][i]*v[k-1][i-1]%mod)<<endl;
	}
	return 0;
}

Measured memory_bytes: 30208
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int> > gpq; //逆順priority_queue
typedef priority_queue<int> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

ll gcd(ll x,ll y){
    ll b=max(x,y),s=min(x,y);
    if(s<=0)return b;
    return gcd(s,b%s);
}


int main(){    
    int N,M;
    vi A(M);
    cin>>N>>M;
    ll total=0;
    for(int i=0;i<M;i++){
        cin>>A[i];
        total+=A[i];
    }
    if(N-total>=0){
        cout<<N-total<<endl;
    }else{
        cout<<-1<<endl;
    }

}


Measured memory_bytes: 3752
import fractions
a,b,k=map(int,input().split())
g=fractions.gcd(a,b)
A=[]
for i in range(1,int(g**0.5+1)):
    if g%i==0:
        A.append(i)
        if g//i!=i:
            A.append(g//i)
A.sort()
print(A[-k])

Measured memory_bytes: 5048
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)x.size())
using namespace std;
typedef long long ll;

char s[64];int n;

int main(){
	scanf("%s",s);n=strlen(s);
	s[n-8]=0;
	puts(s);
	return 0;
}

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

int main(){
  
  string s;
  cin>>s;
  
  for(int i=0;i<s.length()-1;i++){
    if(s[i]==s[i+1]){
      cout<<"Bad";return 0;}
  }
  cout<<"Good";
  
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
#define srep(i, j, k) for (int i = j; i < k; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using ull = unsigned long long;

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; }

//�G���g�X�e�l�X���
vector<int> estora(vector<int> num) {
    int sel = 0;
    while (sel < num.size()) {
        int d = num[sel];
        for (int i = 0; i < num.size(); i++) {
            if (num[i] % d == 0 && num[i] != d && d != 1) {
                num.erase(num.begin() + i);
                i--;
            }
        }
        sel++;
    }
    return num;
}
/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/*�f��������*/
//���색�C�u����
//i����ɑf���ɂ��Ă����Ȃ��Ƃ��܂��ł��Ȃ�&&�v�Z�ʃ��o�C
//�G�X�g���l�X��⿂őf����U����Ă����K�v�������肻��
vector<ll> fac(ll n, vector<ll> num) {
    ll kazu = n;
    for (int i = 2; i <= n; i++) {
        while (1) {
            if (kazu % i != 0) break;

            kazu /= i;
            num[i]++;
        }
    }
    if (kazu == n && n != 1)
        num[n]++;
    return num;
    int ans = 0;
    if (kazu != 1) ans++;
    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = 1; j <= num[i]; j++) {
            num[i] -= j;
            ans++;
        }
    }
    return num;
}
const int INF = 1001001001;

//mint�p�̒萔 (10��9�� + 7)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

int main() {
    int n, m;
    cin >> n >> m;
    int ans = 0;
    ans += n * (n - 1) / 2;
    ans += m * (m - 1) / 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  cin >> A >> B;
  if((A+B)%3==0 || A%3==0 || B%3==0){
    cout << "Possible" << endl;}
  else{
    cout << "Impossible" << endl;}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
using ll = long long;
using namespace std;
ll v[100];
vector<ll> st;
int main(){
	ll n,k,q=0,r=0,x=0;
	cin>>n>>k;
	rep(i,0,n)cin>>v[i];
	rep(in,1,min(k,n)+1){
		rep(div,0,in+1){
		x=k-in;
		rep(j,0,div) st.push_back(v[j]);
		rep(k,n-in+div,n)st.push_back(v[k]);
		sort(st.begin(),st.end());
		rep(i,0,st.size())if(st[i]>=0||i+1>x){x=i;break;}
        rep(i,x,st.size())r+=st[i];
		q=max(q,r),r=0,st.clear();
		}
	}
	cout<<q;
}

Measured memory_bytes: 256