akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define MAXNUM 50

int main(int argc, char* argv[]){
	int N, K, i, j, tmp;
	int l[MAXNUM] = {0};
	int ans = 0;

	scanf("%d %d", &N, &K);
	scanf("%d", &l[0]);
	for(i=1; i<N; i++){
		scanf(" %d", &l[i]);
	}

	for(i=0; i<N; i++){
		for(j=0; j<N; j++){
			if(l[i] > l[j]){
				tmp = l[i];
				l[i] = l[j];
				l[j] = tmp; 
			}
		}
	}

	for(i=0; i<K; i++){
		ans += l[i];
	}

	printf("%d", ans);

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define     ll           long long
ll a[200009],b[200009];
map<ll,ll>mp;
map<ll,ll>mp1;
int main()
{
    cin.sync_with_stdio(false);
    ll i,j,k,l,c,v,n,m,r,t;
    ll x1,x2,y1,y2,x3,x4,x5,x6;
    string s,s1,s2,s3;
    ll ttt;
    while(cin>>n)
    {
        cout<<(pow(n,2)*n);
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
 
// #define DEBUG 100
 
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll >;
 
const ll oo = 1e18 + 7;
const ll mod = 1e9 + 7,maxn = 1e5 + 100, maxm = 1e5+100;
const double PI = acos(-1);

int main (){
    ios_base::sync_with_stdio(false);
    int n;
    bool can = false;
    cin >> n;

    vector<int> vs(n);

    for (int i=0; i<n; i++){
        int a, b;
        cin >> a >> b;
        if (a == b) vs[i] = 1;
        else vs[i] = 0;

        if (i >= 2 and vs[i-2] and vs[i-1] and vs[i]) {
            can = true;
        }
    }

    if (can){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3680
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(int i = 0; i < (n); ++i)

int MAXN = 200005;
vector<ll> dp(
  MAXN);    // free time when Mr.Kizahashi finished i-th job
int main(void) {
  int n;
  cin >> n;
  vector<P> job(n);
  rep(i, n) {
    ll a, b;
    cin >> a >> b;
    job[i] = make_pair(b, a);
  }
  sort(job.begin(), job.end());
  dp[0] = job[0].first - job[0].second;
  if(dp[0] < 0) {
    cout << "No" << endl;
    return 0;
  }
  for(int i = 1; i < n; i++) {
    dp[i] = dp[i - 1] + (job[i].first - job[i - 1].first)
            - job[i].second;
    if(dp[i] < 0) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;
lli gcd(lli a, lli b){
    if(b == 0) return a;
    return gcd(b, a%b);
}

struct Clock60{
    lli H,d;
    lli h,m,sn,sd;
    lli harg,marg,sarg;
    Clock60(lli H, lli h, lli m, lli sn, lli sd):H(H),h(h),m(m),sn(sn),sd(sd){
        calcArgs();
    }
    void addSeconds(lli n, lli d){
        sn = d*sn + sd*n;
        sd = sd*d;
        lli g = gcd(sn, sd);
        sn /= g;
        sd /= g;
        m += sn/(60*sd);
        sn %= (60*sd);
        h += m/60;
        m %= 60;
        h %= H;
        calcArgs();
    }
    void calcArgs(){
        d = 120*H*sd;
        sarg = d*sn/sd;
        marg = d*m + sarg/60;
        harg = d*h*60/H + marg/H;
    }
    bool isValid(){
        return harg != marg and ((harg+marg)/2 -sarg)%(30*d) == 0;
    }
};
int main(){
    while(1){
        lli H,h,m,s;
        cin >> H >> h >> m >> s;
        if(H == 0) break;

        Clock60 ini(H, h, m, s, 1);
        lli midarg = (ini.marg + ini.harg) / 2;
        lli diff = abs(ini.sarg - midarg) %(30*ini.d);
        lli cand[4] = {diff, 30*ini.d + diff, 30*ini.d - diff, 60*ini.d - diff};
        sort(cand, cand+4);
        for(int i=0; i<4; i++){
            Clock60 a = ini;
            a.addSeconds(cand[i], 119*H - 1);
            if(a.isValid()){
                cout << a.h << " " << a.m << " " << a.sn << " " << a.sd << endl;
                break;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3152
def solve(Q, H, S, D, N):
    return min(
        N * Q * 4,
        N * H * 2,
        N * S,
        (N // 2) * D + min(S * (N % 2), H * 2 * (N % 2), Q * 4 * (N % 2))
    )

if __name__ == "__main__":
    Q, H, S, D = tuple(map(int, input().split(" ")))
    N = int(input())
    print(solve(Q, H, S, D, N))


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigDecimal;
class Main {
    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int n = Integer.parseInt(line);
        for(int i=0; i<n;i++){
        	BigDecimal bd1 = new BigDecimal(br.readLine());
        	BigDecimal bd2 = new BigDecimal(br.readLine());
        	if(bd1.precision()>80 || bd2.precision() > 80 || bd1.add(bd2).precision()>80 ){
        		System.out.println("overflow");
        	}else{
        		System.out.println(bd1.add(bd2));
        	}
        }
    }
}

Measured memory_bytes: 24564
#include<stdio.h>
main(){

  int a[10],i,j,tmp;

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

  for(i=0 ; i<9 ; i++){
    for(j=9 ; j>i ; j--){
      if(a[j] > a[j-1]){
	tmp=a[j];
	a[j]=a[j-1];
	a[j-1]=tmp;
      }
    }
  }

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

  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ll long long
#define mod 1000000007
using namespace std;

/*vector<pair<int,int> >op;
string s,t;
int isprime(ll n){
    if(n==2 || n==3) return 1;
    for(int i=2;i*i<=n;i++){
        if(n%i==0) return 0;
    }
    return 1;
}*/

void solve(){
    ll m,n,k=1;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++){
        if(a[i]==k) k++;
    }
    m = n-k+1;
    if(k==1) m=-1;
    cout<<m;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int q;
    //cin>>q;
    //while(q--){
        solve();
    //}
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const long long INF=INT_MAX/4;
const long long MOD=998244353;
const double EPS=1e-14;
const bool DEBUG=false;

const string YES = "YES";
const string NO = "NO";
const string Yes = "Yes";
const string No = "No";

template<class T>
void debug(T head){
    if(DEBUG){
        cout<<head<<endl;
    }
}

template <class Head, class... Body>
void debug(Head head, Body... body){
    if(DEBUG){
        cout<<head<<" ";
        debug(body...);
    }
}

/////
void answer(ll sx, ll sy, ll tx, ll ty){
    for(int i=sy; i<ty; ++i){
        cout<<"U";
    }
    for(int i=sx; i<tx; ++i){
        cout<<"R";
    }
    for(int i=sy; i<ty; ++i){
        cout<<"D";
    }
    for(int i=sx; i<tx; ++i){
        cout<<"L";
    }

    cout<<"L";
    for(int i=sy; i<ty+1; ++i){
        cout<<"U";
    }
    for(int i=sx; i<tx+1; ++i){
        cout<<"R";
    }
    cout<<"D";

    cout<<"R";
    for(int i=sy; i<ty+1; ++i){
        cout<<"D";
    }
    for(int i=sx; i<tx+1; ++i){
        cout<<"L";
    }
    cout<<"U";
    cout<<endl;

    return;
}

/////

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

    ll sx, sy, tx, ty;
    cin>>sx>>sy>>tx>>ty;
    answer(sx, sy, tx, ty);

    return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<map>
#include<sstream>
#include<set>
#include<stack>
#include<iterator>
#include<cctype>
#include<cmath>
#include<cassert>
using namespace std;
const int maxn=1000+10;
int n,maxd,a[maxn]={1};
int h(int d){
	int maxc=0;
	for(int i=0;i<=d;i++) maxc=max(maxc,a[i]);
	return maxc;
}
bool dfs(int d){
	//cout<<a[d]<<endl;
	if(a[d]==n) return true;
	if(d==maxd) return false;
	if(h(d)<<(maxd-d) <n) return false;
	for(int i=d;i>=0;i--){
		a[d+1]=a[d]+a[i];
		if(dfs(d+1))return true;
		if(a[d]>a[i]){
			a[d+1]=a[d]-a[i];
	    	if(dfs(d+1))return true;
		}
	}
	return false;
}
int main(){
	while(scanf("%d",&n)&&n){
		if(n==1) cout<<"0"<<endl;
		else{
			for(maxd=1;maxd<=13;maxd++){
				if(dfs(0)){
					cout<<maxd<<endl;
					break;
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3132
# ABC083b
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n, a, b = map(int, input().split())

ans = 0
for i in range(n+1):
    su = sum(list(map(int, list(str(i)))))
    # print(su)
    if (a <= su <= b):
        ans += i
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<cmath>

using namespace std;

int main(){
    int N,K;
    cin >> N >> K;
    int mindex = 0;
    int min = 100001;
    for(int i= 0;i<N;i++){
        int tmp;
        cin >> tmp;
        if(tmp<min){
            mindex = i;
            min = tmp;
        }
    }
    if(K==N){
        cout << 1 << endl;
        return 0;
    }
    int leftindex = 1;
    int leftsum = 0;
    if(mindex == 0 || mindex == 1){
        leftindex = K-1;
        leftsum = 1;
    }
    else{
        while(leftindex < mindex){
            leftindex += (K-1);
            leftsum += 1;
        }
        leftindex -= 1;
    }
    int leftresult =  ceil((N-1-leftindex)/float(K-1)) + leftsum;
    int rightindex = 1;
    int rightsum = 0;
    if(N-1-mindex == 0 || N-1-mindex == 1){
        rightindex = K-1;
        rightsum = 1;
    }
    else{
        while(rightindex < N-1-mindex){
            rightindex += (K-1);
            rightsum += 1;
        }
        rightindex -= 1;
    }    
    int rightresult =  ceil((N-1-rightindex)/float(K-1)) + rightsum;
    if(leftresult > rightresult){
        cout << rightresult <<endl;
    }
    else {
        cout << leftresult << endl;
    }
    return 0;

}

Measured memory_bytes: 256
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = []
for i in range(n):
    a.append(list(map(int, input().split())))
    
dp = [[0]*pow(2,n) for _ in range(n+1)]
dp[0][0] = 1
M = 10**9+7
from itertools import combinations
for i in range(1,n+1):
    for c in combinations(range(n), i):
        b = 0
        for item in c:
            b += 1<<item
        for item in c:
            if a[i-1][item]:
                dp[i][b] += dp[i-1][b-(1<<item)]
                dp[i][b] %= M
print(dp[n][pow(2,n)-1])

Measured memory_bytes: 434660
#include <bits/stdc++.h>
using namespace std;
unsigned long long gcd(unsigned long long int u, unsigned long long int v) {
    while ( v != 0) {
        unsigned long long int r = u % v;
        u = v;
        v = r;
    }
    return u;
}

int main(void){
    // Your code here!
    int n;cin>>n;
    vector<unsigned long long int> v;
    for(int i=0;i<n;i++)
    {
        unsigned long long int t;cin>>t;
        v.push_back(t);
    }
    unsigned long long int temp=0;
    for(auto x:v)
    {
        //cout << x << ":";
        if(temp==0)
        {
            temp=x;continue;
        }
        
        temp = ((temp)/gcd(temp,x))*x;
        //cout<<temp<<"\n";
        continue;
    }
    
    cout<<temp;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

// bellman_ford
template<typename Edge>
struct bellman_ford {
  using Graph = std::vector<std::vector<Edge>>;
  using T = typename Edge::cost_type;

  Graph& G;
  int N;
  std::vector<T> d;
  std::vector<bool> neg;
  T INF;
  bellman_ford(Graph& Graph, T inf):
    G(Graph), N(Graph.size()), INF(inf) {}

  bool search(int s) {
    d.assign(N, INF);
    neg.assign(N, false);
    d[s] = 0;
    bool has_nl = false;
    for(int i = 0; i < N; ++i) {
      for(int j = 0; j < N; ++j) for(auto const& e: G[j]) {
        T newd = d[j] + e.cost;
        if(d[e.to] > newd) {
          d[e.to] = newd;
          if(i == N-1) has_nl = neg[e.to] = true;
        }
      }
    }
    for(int i = 0; i < N-1; ++i) {
      for(int j = 0; j < N; ++j) if(neg[j]) for(auto const& e: G[j]) {
        neg[e.to] = true;
      }
    }
    return has_nl;
  }
};

struct edge {
  typedef int64_t cost_type;
  cost_type cost;
  int to;
  edge(cost_type c, int t): cost(c), to(t) {}
};

int64_t const INF = 1e18;

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int N, M; std::cin >> N >> M;
  std::vector<std::vector<edge>> G(N);
  for(int i = 0; i < M; ++i) {
    int a, b, c; std::cin >> a >> b >> c; --a; --b;
    G[a].emplace_back(-c, b);
  }
  bellman_ford<edge> bf(G, INF);
  bf.search(0);
  if(bf.neg[N-1]) fin("inf");
  fin(-bf.d[N-1]);
  return 0;
}


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

using ll = long long;
constexpr ll inf = static_cast<ll>(1e15);
constexpr ll mod = static_cast<ll>(1e9 + 7);

char b;
int main()
{
	std::cin >> b;

	if (b == 'A')
		std::cout << 'T' << std::endl;
	else if (b == 'T')
		std::cout << 'A' << std::endl;
	else if (b == 'C')
		std::cout << 'G' << std::endl;
	else
		std::cout << 'C' << std::endl;
	return 0;
}


Measured memory_bytes: 256
/* @ by batr (T) */
#include <bits/stdc++.h>
 
#define ll long long
#define pb push_back
#define mp make_pair
#define all(X) (X).begin(), (X).end()
 
#define cmp_all(X) (X).begin(), (X).end(), cmp
 
#define B begin()
#define E end()
#define sz size()
#define skip continue
 
#define ppi pair<pair<int, int>, int>
#define pii pair<int, int> 
#define pli pair<ll, int>
#define pcc pair<char, char>
 
#define F first
#define S second
 
using namespace std;
 
const int maxn = 1e7 + 17;
const int MAXN = maxn * 4;
const int darr = 1e3 + 17;
const ll INF = 1e17 + 5;
const int mod = 1e9 + 7;
 
void Need_For_Speed () {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

int n;
int a[maxn];
int sum;

int main () {
	Need_For_Speed();
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	if (sum % 2 == 0) {
		cout << "YES";
	}
	else {
		cout << "NO";
	}
	return 0;
}

Measured memory_bytes: 640
let rec check2 lst n = List.for_all (fun l -> List.mem n l) lst
let rec check lst n =
  if n = 0 then 0
  else if check2 lst n then 1 + check lst (n-1)
  else check lst (n-1)
let () =
  let (n, m) = Scanf.scanf "%d %d\n" (fun x y -> (x, y)) in
  let lst = Array.to_list (Array.init n (fun _ -> Scanf.scanf "%d " (fun k -> Array.to_list (Array.init k (fun _ -> Scanf.scanf "%d " (fun x -> x)))))) in
  Printf.printf "%d\n" (check lst m)

Measured memory_bytes: 640
#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 ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)
const ll nax = 3e6;
ll fact[nax + 1];
ll mod = 1e9 + 7;
ll power(ll x, ll y) {
	ll ans = 1;
	while(y) {
		if(y & 1) {
			ans = (ans * x) % mod;
		}
		y /= 2;
		x = (x * x) % mod;
	}
	return ans;
}
ll modinverse(ll x) {
	return power(x, mod - 2);
}
ll combi(ll n, ll r) {
	return (fact[n] * modinverse((fact[r] * fact[n - r])%mod))%mod;
}
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll k, i;
    string s;
    cin >> k >> s;
    fact[0] = 1;
    for(i = 1; i < nax + 1; i++) {
    	fact[i] = (fact[i-1] * i) % mod;
    }
    ll tot = power(26, k + s.length());
    for(i = 0; i < s.length(); i++) {
    	tot = ((tot - combi(k + s.length(), i) * power(25, k + s.length() - i))%mod + mod)%mod;
    }
    cout << tot << "\n";
}

Measured memory_bytes: 27740
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cstring>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout << #x << ": " << x << endl
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

ll a,b,c,cnt=0;
string s;

int main(){
    cin>>s;
    for(int i=0; i<s.size(); i++){
        if(s[i]=='1')cnt++;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main()
{
int n,a,b;
cin>>n>>a>>b;
cout<<min(n*a,b)<<endl;
}

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

int main(){
  int W, H, x, y, r;
  cin>>W>>H>>x>>y>>r;
  if(x>=r and x<=W-r and y>=r and y<=H-r){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}



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

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

template<class T=ll> ll LIS(std::vector<T> v, T inf=1LL<<62, bool is_strong=true){ // LongestIncreasingSubsequence 最長増加部分列 O(nlogn)
    std::vector<T> dp(v.size(), inf);  // 1indexed, dp[i]:長さiの増加部分列の最後尾の要素の最小値
    for(ll i=0; i<v.size(); i++){
        if(is_strong) *std::lower_bound(dp.begin(), dp.end(), v[i]) = v[i];
        else *std::upper_bound(dp.begin(), dp.end(), v[i]) = v[i];
    }
    return std::lower_bound(dp.begin(),dp.end(), inf) - dp.begin();
}

int main(){
    ll n,a;
    vector<ll> v; v.clear();
    cin>>n;
    REP(i,n){
        cin>>a;
        v.push_back(a);
    }
    cout << LIS(v) << endl;
    return 0;
}


Measured memory_bytes: 5252
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {          
                string input = Console.ReadLine();
                int n = int.Parse(input);

                for (int i = 3; i <= n; i++)
                {
                    if (i % 3 == 0 || i.ToString().IndexOf("3") >= 0)
                    {
                        Console.Write(string.Format(" {0}",i));
                    }          
                }
                Console.WriteLine();
        }
    }
}

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

using namespace std;

int n, ans;
long long m, x[105];

int main() {
	scanf("%d%lld", &n, &m);
	for (int i = 0; i < n; i++)
		scanf("%lld", x + i);
	sort(x, x + n);
	for (int i = 0; i < n; i++)
		if (x[i] > m)
			break;
		else {
			m -= x[i];
			ans++;
		}
	if (ans == n && m)
		ans--;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll N;
    cin >> N;
    string S;
    cin >> S;
    ll pointer=0;
    ll left_counter=0;
    for(int i=0; i<S.size(); i++){
        if(S[i]=='(') pointer++;
        else{
            if(pointer==0) left_counter++;
            else pointer--; 
        }
    }
    ll right_counter=pointer;

    string res="";
    for(int i=0; i<left_counter; i++){
        res+='(';
    }
    res+=S;
    for(int i=0;i<right_counter; i++){
        res+=')';
    }
    cout << res << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define debug(x) std::cerr<<#x<<":"<<(x)<<std::endl;
#define INIT ios::sync_with_stdio(false);cin.tie(0);

int n,m;
vector<int> e[1010], ev[1010];
bool canVisit[1010][1010];

void bfs(int fr){
  queue<int> q;
  for(int i=0;i<e[fr].size();++i){
    int to = e[fr][i];
    canVisit[fr][to] = true;
    q.push(to);
  }

  while(!q.empty()) {
    int frm = q.front();q.pop();
    for(int i=0;i<e[frm].size();++i){
      int to = e[frm][i];
      if(canVisit[fr][to]) continue;
      canVisit[fr][to] = true;
      q.push(to);
    }
  }
}

int restore(int p, int q, int dg){
  sort(e[p].begin(), e[p].end());
  if(!binary_search(e[p].begin(), e[p].end(), q)) {
    swap(p,q);
  }

  sort(e[p].begin(), e[p].end());
  if(!binary_search(e[p].begin(), e[p].end(), q)) {
    return 0;
  }

  vector<int> ans;
  vector<int> dist(n,1e9+1);
  queue<int> qq;
  qq.push(q);
  dist[q] = 0;

  while(!qq.empty()) {
    int fr = qq.front(); qq.pop();
    if (fr == p) break;
    
    for(int i=0;i<e[fr].size();++i){
      int to = e[fr][i];
      if(dist[to] <= dist[fr] + 1) continue;
      dist[to] = dist[fr] + 1;
      qq.push(to);
    }
  }
  
  int st = p;
  ans.emplace_back(st);
  //debug(st);
  //// debug(dist[st]);
  if (dg==1) {
    return dist[st];
  }
  for(int i=0;i<n;++i){
    for(int j=0;j<ev[st].size();++j){
      int to = ev[st][j];
      if (dist[to] == dist[st] - 1) {
        st = to;
        ans.emplace_back(to);
        break;
      }
    }
  }
  
  
  reverse(ans.begin(), ans.end());
  cout<<ans.size()<<endl;
  for(int i=0;i<ans.size();++i){
    cout<<ans[i]+1<<endl;
  }
  
  return 1;
}

signed main() {
  INIT;
  cin>>n>>m;
  for(int i=0;i<m;++i){
    int p,q;cin>>p>>q;
    --p;--q;
    e[p].emplace_back(q);
    ev[q].emplace_back(p);
  }

  memset(canVisit, false, sizeof(canVisit));

  for(int i=0;i<n;++i) bfs(i); 

  int mn = 1e9+1, idf=-1, idt= -1;
  for(int i=0;i<n-1;++i){
    for(int j=i+1;j<n;++j){
      if(canVisit[i][j] && canVisit[j][i]) {
        int tmp = restore(i,j,1);
        if(tmp==0) continue;
        if(tmp<mn){
          // debug(tmp);
          mn = tmp;
          idf = i;idt = j;
        }
      }
    }
  }
  if(idf>=0 && idt>=0) {
    // debug(idf);
    // debug(idt);
    restore(idf,idt,0);
  }
  else {
  
  cout<<-1<<endl;
  }
  return 0;
}


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

int main(void){
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if(s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios::sync_with_stdio(false);
    ll a,b,c,d,n;
    cin >> a >> b >> c >> d >> n;
    n*=4;
    b=min(b,a*2);
    c=min(c,b*2);
    d=min(d,c*2);
    cout << (n/8*d+c*(n&4)/4+(n&2)/2*b+(n&1)*a) << '\n';
}

Measured memory_bytes: 764
n = int(input());

a = list(map(int, input().split()));

ok = True;
ans = 1;
a.sort();
for val in a:
    ans *= val;
    if(ans > 1e18):
        ok = False;
        break;
    elif(ans == 0):
        break;

if(ok):
    print(ans);
else:
    print(-1);


Measured memory_bytes: 21696
N,M=[ int(it) for it in input().split() ]

if ( N>=2 and M>=2 ):
  print ( (N-2)*(M-2) )
elif ( min(N,M) == 1 and max(N,M)>1 ):
  print ( max(N,M)-2 )
else:
  print ( 1 )

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

bool is_prime(int n){
    for (int i = 2; i * i <= n; i++) {
        if(n % i == 0) return false;
    }
    return true;
}

int main(void)
{
    int N;
    cin >> N;
    while(!is_prime(N)){
        N++;
    }
    pr(N);
}

Measured memory_bytes: 256
import math
x = int(input())

for i in range(x,10**100+1):
    flag = 1
    max = math.floor(math.sqrt(x))

    for j in range(2,max+1):
        if i % j == 0:
            flag = 0
    
    if flag == 1:
        num = i
        break

print(num)

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++i ) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

LL comb(int n, int k) {
    if( n < k ) return 0;
    if( n < 0 || k < 0 ) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

int bfs(int h, int w);

int mp[25][25];

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

    int h, w;
    cin >> h >> w;
    int mx = 0;

    for( int i = 0; i < 25; ++i ) {
        for( int j = 0; j < 25; ++j ) {
            mp[i][j] = -1;
        }
    }

    for( int i = 1; i <= h; ++i ) {
        for( int j = 1; j <= w; ++j ) {
            char c;
            cin >> c;
            if( c == '.' ) mp[i][j] = 0;

        }
    }

    for( int i = 1; i <= h; ++i ) {
        for( int j = 1; j <= w; ++j ) {
            if( mp[i][j] == -1 ) continue;
            int tmp = bfs(i, j);
            mx = max(tmp, mx);

        }
    }
    cout << mx << endl;

    return 0;
}


int bfs(int h, int w) {
    queue< pair< P, int > > q;
    q.push(MP(MP(h, w), 0) );
    bool vi[25][25] = {};
    int cst[25][25] = {};
    vi[h][w] = true;
    while( !q.empty() ) {
        pair< P, int > p = q.front(); q.pop();

        for( int i = 0; i < 4; ++i ) {
            if( mp[p.F.F + dx[i]][p.F.S + dy[i]] == -1 ) continue;
            if( !vi[p.F.F + dx[i]][p.F.S + dy[i]] ) {
                q.push(MP(MP(p.F.F + dx[i], p.F.S + dy[i]), p.S + 1));
                cst[p.F.F + dx[i]][p.F.S + dy[i]] = p.S + 1;
                vi[p.F.F + dx[i]][p.F.S + dy[i]] = true;

            }
        }
    }

    int mx = 0;
    for( int i = 0; i < 25; ++i ) {
        for( int j = 0; j < 25; ++j ) {
            mx = max(mx, cst[i][j]);

        }
    }

    return mx;
}


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

vector< int > adj[10];
int digit[1000];

void solve(int pos, int tot, int &k){
    if(pos == tot){
        k--;
        
        if(k == 0){
            for(int i = 0 ; i < tot ; i++){
                printf("%d", digit[i]);
            }
            
            printf("\n");
        }
    }else{
        for(int u: adj[digit[pos - 1]]){
            digit[pos] = u;
            solve(pos + 1, tot, k);
            
            if(k == 0){
                break;
            }
        }
    }
}

int main() {
    for(int i = 0 ; i < 9 ; i++){
        adj[i].push_back(i + 1);
        adj[i + 1].push_back(i);
    }
    
    for(int i = 0 ; i <= 9 ; i++){
        adj[i].push_back(i);
        sort(adj[i].begin(), adj[i].end());
    }
    
    int k;
    
    scanf("%d", &k);
    
    for(int i = 1 ; i <= 20 ; i++){
        for(int f = 1 ; f <= 9 ; f++){
            digit[0] = f;
            solve(1, i, k);    
            
            if(k == 0){
                return 0;
            }
        }
    }
    
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
  int n;
  scanf("%d", &n);
  long long int arr[n], maximum = 1e18, prod = 1, flags = 0, zero = 0;
  
  for (int i = 0; i < n; i++) {
    scanf("%lld", &arr[i]);
    flags = arr[i] > maximum ? 1 : flags;
    prod *= arr[i];
    arr[i] ? maximum/= arr[i] : zero = 1;
  }

  (zero) ? puts("0") : ((flags) ? puts("-1") : printf("%lld\n", prod));
  return 0;
}

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


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;


int main(){
    int a, b;
    cin >> a >> b;
    if(a >= 10 || b >= 10){
        cout << -1 << endl;
    }
    else{
        cout << a * b << endl;
    }

    return 0;
}


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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    string s; cin >> s;

    string ans;

    ans += s[0];

    int t = s.size() - 2;

    ans += to_string(t);

    int x = s.size() - 1;
    ans += s[x];

    cout << ans << endl;
}

Measured memory_bytes: 256
use std::collections::HashMap;

use proconio::fastout;
use whiteread::parse_line;

#[fastout]
fn main() {
    let s: String = parse_line().unwrap();
    let mut m: HashMap<u8, usize> = HashMap::new();
    for u in s.into_bytes() {
        let e = m.entry(u).or_insert(0);
        *e += 1;
    }

    for v in m.values() {
        if v % 2 != 0 {
            println!("No");
            return;
        }
    }
    println!("Yes");
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;

int main(){
  int n; cin >> n;
  for(int i = 1; i <= 50000; i++){
    int now = i * 1.08;
    if(now == n){
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define ii pair<int,int>
#define vii vector<ii>
#define vi vector<int>

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
 

void solve(){
	double n,k, ans = 0; cin >> n >> k;
	FOR(i,1,n+1){
		int flips = 0;
		int temp = i;
		while(temp < k){
			temp *= 2;
			++flips;
		}
		ans += pow(0.5,flips);
	}
	cout << fixed << setprecision(10) << ans/n;
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	solve();
	return 0;
}
 


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

using namespace std;

using ll = long long;

const long long MOD = 1e9 + 7;
const int INF = 1e9 + 7;

int dfs(const auto& graph, int v, auto is_visit) {
    is_visit[v] = true;
    bool ok = true;
    for (bool b : is_visit) ok &= b;
    if (ok) return 1;
    
    int res = 0;
    for (int u : graph[v]) {
        if (is_visit[u]) continue;
        res += dfs(graph, u, is_visit);
        is_visit[u] = false;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<vector<int>> graph(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    vector<bool> is_visit(N, false);
    cout << dfs(graph, 0, is_visit) << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main() {
  char s[100000];
  cin >> s;

  int N = 0;
  for (int i=0;i<ARRAY_LENGTH(s);i++) {
    if (s[i] == '\0')
      break;
    N++;
  }
  int p_me = N/2; // 自分が出せるパーの最大値
  
  int p_ot = 0;
  for (int i=0;i<N;i++) {
    if (s[i] == 'p') {
      p_ot++;
    }
  }
  int res = p_me - p_ot;
  cout << res << endl;
}

Measured memory_bytes: 384
n,k = map(int, input().split())
a = [0] * n
for i in range(k):
  d = int(input())
  b = list(map(int, input().split()))
  for j in range(len(b)):
    a[b[j]-1] = 1
res = 0
for i in range(n):
  if a[i] == 0:
    res += 1
print(res)

Measured memory_bytes: 9188
#include<bits/stdc++.h>
#define tmp(x) std::cout<<"& "<<(x)<<" &\n"
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
typedef long long ll;

using namespace std;
const int maxn=1e6+100;
	ll t,ans=0;
ll cnt[maxn];
int main(){
//	freopen("in.txt","r",stdin);
   	scanf("%lld",&t);
   	cnt[1]=7%t;
   	for(int i=2;i<=1000001;++i){
   		cnt[i]=(10*cnt[i-1])%t;
	   }
	   
	   ll tt=0;
	for(int i=1;i<=1000000;++i){
		tt+=cnt[i];
		if(tt%t==0){
			ans=i;break;
		}
		else tt%=t;
	}
	
   	if(ans==0)printf("-1");
   	else printf("%d",ans);
    
 
 
 
    return 0;
}

Measured memory_bytes: 11632
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-12 13:11:13
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rev(x) greater<x>()
#define MOD 1000000007
#define INF 1000000000

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod)
{
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod)
{
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod)
{
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

int gcd(int k, int l)
{
    if (l > 0) return gcd(l, k%l);
    else return k;
}

struct UnionFind
{
    vector<int> par;

    UnionFind(int n) : par(n) {
        for (int i = 0; i < n; i++) par[i] = i;
    }

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

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

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

int main()
{
    int h, w;
    cin >> h >> w;
    char coor[h][w];
    for (int i = 0; i < h; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < w; j++) {
            coor[i][j] = s[j];
        }
    }

    int v[8][2] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}, {1, 1}};
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (coor[i][j] == '.') {
                int cnt = 0;
                for (int k = 0; k < 8; k++) {
                    int x, y;
                    x = i+v[k][0]; y = j+v[k][1];
                    if (x >= 0 && x <= h-1 && y >= 0 && y <= w-1) {
                        if (coor[x][y] == '#') cnt++;
                    }
                }

                coor[i][j] = cnt + '0';
            }
        }
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cout << coor[i][j];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


int main(){
    int n;
    cin >> n;
    int p[n];
    rep(i, n) {
        int q;
        cin >> q;
        p[q-1] = i;
    }


    int tmp = 1;
    int ans = 0;
    rep(i, n - 1){
        if (p[i] < p[i+1]) tmp++;
        else {
            ans = max(ans, tmp);
            tmp = 1;
        }
    }
    
    ans = max(ans, tmp);
    
    cout << n - ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define sz size()
int main() {
	string s;
	cin >> s;
	int n = s.sz;
	int n1 = (n - 1) / 2;
	string h = s;
	reverse(h.begin(), h.end());
	bool ch1 = (h == s);
	h = "";
	for(int i = 0; i < n1; ++i) h += s[i];
	string k = h;
	//cout << h << ' ';
	reverse(k.begin(), k.end());
	bool ch2 = (k == h);
	h = "";
	n1 = (n + 3) / 2;
	for(int i = n1 - 1; i < n; ++i) h += s[i];
	k = h;
	reverse(k.begin(), k.end());
	if(ch1 && ch2 && k == h)cout << "Yes";else cout<<"No";
    return 0;
}


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

int D, G, p[10], c[10];

signed main() {
  cin >> D >> G; G/=100;
  for(int i=0; i<D; i++) cin >> p[i] >> c[i];
  for(int i=0; i<D; i++) c[i]/=100;

  int ans = 2e9;
  for (int bit = 0; bit < (1<<D); ++bit) {
    int score = 0;
    int problems = 0;
    for (int i = 0; i < D; ++i) if (bit & (1<<i)) {
      score += p[i] * (i+1) + c[i];
      problems += p[i];
    }
    if (score >= G) {
      ans = min(ans, problems);
      continue;
    }
    int res = G - score;
    for (int i = 0; i < D; ++i) if (!(bit & (1<<i))) {
      int r = (res + i) / (i+1);
      if(r > p[i]) continue;
      ans = min(ans, problems + r);
    }
  }
  cout << ans << endl;
}


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

Measured memory_bytes: 4724
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

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

using G = vector<vector<int>>;

void dfs(const int s, int c, const G& g, vector<int>& d)
{
    d[s] = c;

    for(const auto& t : g[s]) {
        if (d[t] == -1) {
            dfs(t, c + 1, g, d);
        }
    }
}

int main()
{
    int n;
    cin >> n;

    G g(n);

    for (int i = 0; i < n-1; ++i) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;

        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }

    vector<int> d1(n, -1);
    vector<int> dn(n, -1);

    dfs(0, 0, g, d1);
    dfs(n-1, 0, g, dn);

    int f = 0;
    int s = 0;

    for (int i = 0; i < n; ++i) {
        if (d1[i] <= dn[i]) {
            ++f;
        } else {
            ++s;
        }
    }

    if (f > s) {
        cout << "Fennec" << endl;
    } else {
        cout << "Snuke" << endl;
    }

    return 0;
}


Measured memory_bytes: 11136
/**
  *  Worg
  */
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>

int main() {
	std::string s, t; std::cin >> s >> t;
	int n = (int)s.size(), m = (int)t.size();
	s.resize(n + 1); t.resize(m + 1);
	for (int i = n; i >= 1; i--) {
		s[i] = s[i - 1];
	}
	for (int j = m; j >= 1; j--) {
		t[j] = t[j - 1];
	}

	std::vector<std::vector<int>> dp(n + 1, std::vector<int>(m + 1, 0));
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			dp[i][j] = std::max(dp[i - 1][j], dp[i][j - 1]);

			int x = dp[i - 1][j - 1] + (s[i] == t[j]);
			dp[i][j] = std::max(dp[i][j], x);
		}
	}

	std::string result;
	int i = n, j = m;
	while (i > 0 && j > 0) {
		int x = dp[i - 1][j - 1] + (s[i] == t[j]);
		if (dp[i - 1][j] >= dp[i][j - 1] && dp[i - 1][j] >= x) {
			i -= 1;
		} else if (dp[i][j - 1] >= dp[i - 1][j] && dp[i][j - 1] >= x) {
			j -= 1;
		} else {
			if (s[i] == t[j]) {
				result += s[i];
			}
			i -= 1; j -= 1;
		}
	}

	std::reverse(result.begin(), result.end());
	std::cout << result << '\n';
	return 0;
}

Measured memory_bytes: 35584
#include <cstdio>
#include <algorithm>
using namespace std;
#define gc getchar()

int read()
{
	int x=0;char c=gc;
	for(;c<48||c>57;c=gc);
	for(;c>47&&c<58;c=gc)
		x*=10,x+=c-48;
	return x;
}

const int maxn=100050;
int n,a[maxn],in[maxn],out[maxn];
int st[maxn],pv[maxn],p1[maxn],tot;

inline void side(int u,int v)
{
	pv[++tot]=v;
	p1[tot]=st[u];
	st[u]=tot;
	++in[u];++out[u];
}

void init()
{
	n=read();
	for(int i=2;i<=n;++i)
	{
		a[i]=read();
		side(a[i],i);
	}
}

int q[maxn],l=1,r,ans;
int b[maxn],d[maxn],m;

bool cmp(int a,int b){return a>b;}

void getchild(int x)
{
	m=1;
	for(int i=st[x];i;i=p1[i])
		b[m++]=d[pv[i]];
	sort(b+1,b+m,cmp);
}

void upd(int x)
{
	if(!--out[x])
	{
		getchild(x);
		for(int i=1;i<m;++i)
			d[x]=max(d[x],b[i]+i);
	}
}

void solve()
{
	for(int i=1;i<=n;++i)
		if(!in[i])
		{
			q[++r]=i;
			upd(a[i]);
		}
	while(l<=r)
	{
		int x=q[l++];
		ans=max(ans,d[x]);
		if(!--in[a[x]])
		{
			q[++r]=a[x];
			upd(a[a[x]]);
		}
	}
	printf("%d\n",ans);
}

int main()
{
	init();
	solve();
	return 0;
}

Measured memory_bytes: 3328
from collections import Counter
N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

D = Counter(D)
flag = True
for t in T:
    if D[t]>0:
        D[t] -= 1
    else:
        flag = False
        break
if flag:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 41700
import Text.Printf
main=do
  s<-getLine
  putStrLn $ solve $ map (read :: String ->Int) $ words s

solve::[Int]-> String
solve [a,b] =
  (show (a `div`b)) ++ " " ++ (show (a `mod` b)) ++ " " ++ s
  where c=(fromIntegral(a)/ fromIntegral(b)) :: Double
        s = printf "%.5f" c ::String

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

using namespace std;

bool check(int n){
    int a = n % 10;
    n /= 10;

    while(n){
        int b = n % 10;
        if ( a != b){
            return false;
        }
        n = n / 10;
    }
    return true;
}

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

    int n;
    cin >> n;

    for (int i = n; i < 1000; i++){
        if (check(i)) {
            cout << i;
            break;
        }
    }
    return 0;
}



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

int main() {
  int n,m;
  cin>>n>>m;
  int p[m];
  string s[m];
  for(int i=0;i<m;i++) cin>>p[i]>>s[i];
  int b[100010]={0};
  bool c[100010]={false};
  for(int i=0;i<m;i++){
    if(s[i]=="AC") c[p[i]]=true;
    else{
      if(!c[p[i]]) b[p[i]]++;
    }
  }
  int res1=0,res2=0;
  for(int i=1;i<=n;i++) {
    if(c[i])res1+=b[i];
    if(c[i]) res2++;
  }
  cout<<res2<<' '<<res1<<endl;
  return 0;
}


Measured memory_bytes: 6656
N = int(input())

lst = []

for _ in range(N):
    a, b = map(int, input().split())
    lst.append([a, b])

lst = sorted(lst, key=lambda x: x[1], reverse=False)

s = 0
for a, b in lst:
    s += a

    if s > b:
        print('No')
        exit()

print('Yes')

Measured memory_bytes: 39700
#include <stdio.h> 

int main(void){
    int a,b,x;
	char op;	
	
	while(1){
	scanf("%d %c %d\n",&a,&op,&b);
		
		if(op =='+'){
			x=a+b;
			printf("%d\n",x);
		}else if(op =='-'){
			x=a-b;
			printf("%d\n",x);
		}else if(op =='/'){
			x=a/b;
			printf("%d\n",x);
		}else if(op =='*'){
			x=a*b;
			printf("%d\n",x);
		}else if(op =='?'){
			break;
		}
	}

    return 0;
}


Measured memory_bytes: 2108
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN];
int head, tail, n;

void enqueue(P x){
  Q[tail]=x;
  tail=(tail+1)%LEN;
}

P dequeue(void){
  P x=Q[head];
  head=(head+1)%LEN;
  return x;
}
int min(int a,int b){
  return a<b?a:b;
}

int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head=1;
  tail=n+1;
  
  while(head!=tail){
    u=dequeue();
    c=min(q,u.t);
    u.t-=c;
    elaps+=c;
    if(u.t>0) enqueue(u);
    else printf("%s %d\n",u.name,elaps);
  }

  return 0;
}



Measured memory_bytes: 11844