akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import deque


def solve():
    N, M = map(int, input().split())
    edges = [set() for _ in range(N+1)]
    for a, b in (map(int, line.split()) for line in sys.stdin):
        edges[a].add(b)

    # 答えが見つかるまで、スタート地点は全て試します
    for start in range(1, N+1):
        visited = [0]*(N+1)

        dq = deque([(start, {start})])
        visited[start] = 1

        while dq:
            # 点と、これまで通ってきた頂点を取り出す
            v, route = dq.popleft()
            # これまで通ってきた頂点集合と、行き先の頂点集合の積集合をとる
            s = route & edges[v]
            # s=={start}でなければuとおr sが空集合でも通る。sが何やらいろいろあると、通れない。
            if not (not s or s == {start}):
                continue
            for dest in edges[v]:
                # startに戻ってきたら出力して終了
                if dest == start:
                    print(len(route))
                    print(*route, sep='\n')
                    exit()
                # 訪問済みであれば、スルー
                if visited[dest]:
                    continue
                visited[dest] = 1
                # destを始点として、通ってきた頂点にdestを追加したもの
                dq.append((dest, route | {dest}))

    print(-1)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 9688
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<'\n';}}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
ll N=1;
vvi segsum;
void update(int w,int i,ll x){
    i+=N-1;
    segsum[w][i]=x;
    while(i>0){
        i=(i-1)/2;
        segsum[w][i]=segsum[w][i*2+1]|segsum[w][i*2+2];
    }
}
ll getsum(int w,int a,int b,int k,int l,int r){
    if(a<=l&&r<=b)return segsum[w][k];
    if(r<=a||b<=l)return 0;
    ll c1=getsum(w,a,b,k*2+1,l,(l+r)/2);
    ll c2=getsum(w,a,b,k*2+2,(l+r)/2,r);
    return c1|c2;
}
int main(){
    ll n;cin>>n;
    string s;cin>>s;
    while(N<n)N*=2;
    segsum=vvi(26,vi(N*2-1));
    rep(w,26){
        rep(i,N){
            if(i<n)segsum[w][i+N-1]=(int)((int)(s[i]-'a')==w);
        }
        for(int i=N-2;i>=0;i--)segsum[w][i]=segsum[w][i*2+1]|segsum[w][i*2+2];
    }
    ll q;cin>>q;
    rep(i,q){
        int a;cin>>a;a--;
        if(a){
            int l,r;cin>>l>>r;l--;r--;
            ll ans=0;
            rep(j,26)ans+=getsum(j,l,r+1,0,0,N);
            out(ans);
        }
        else{
            int a;cin>>a;
            char c;cin>>c;
            update((int)(s[a-1]-'a'),a-1,0);
            update((int)(c-'a'),a-1,1);
            s[a-1]=c;
        }
    }
}

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

// infty
#define ULLINF (ULLONG_MAX)
#define LLINF  (LLONG_MAX)
#define IINF   (INT_MAX)
#define INF    (1<<29)

// math
#define Sq(x) ((x)*(x))

// container utility
#define ALL(x) (x).begin(), (x).end()
#define MP make_pair
#define PB push_back
#define EACH(it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();it++)

// rep
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;

typedef long long ll;

// pair util
#define FST first
#define SND second

// range validator
#define CK(n,a,b) (a<=n && n<b)

// conversion
template<class T> inline string toStr(T a) { ostringstream oss_; oss_ << a; return oss_.str(); }
inline int toInt(string s) { return atoi(s.c_str()); }

// prime
bool isPrime(int a) { for(int i=2; i*i <=a; i++) if(a%i == 0) return false; return true; }

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

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


int main() {
  int N;
  bool blank = 0;
  while(cin >> N && N) {
    if(blank) cout << endl;
    blank = 1;
    vector<pair<PII, string> > vec;
    for(int i=0; i<N; i++) {
      string s; cin >> s;
      int a, b, c;
      cin >> a >> b >> c;
      vec.push_back(MP(MP(-a*3-c*1, i), s));
    }
    sort(ALL(vec));
    
    EACH(it, vec) {
      cout << it->second << "," << -it->first.first << endl;
    }
  }
  
  
  return 0;
}

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

char s[100002];
int main() {
    scanf("%s", s);
    int n = strlen(s);
    int ans = n;
    for (int i = 1; i < n; i++) {
        if (s[i] - s[i-1]) {
            ans = min(ans, max(i, n-i));
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 384
import sys

def main():
    input = sys.stdin.readline
    N, C = map(int, input().split())
    P = [list(map(int, input().split())) for _ in range(N)]
    P = sorted(P, key=lambda x: x[0])

    V = []
    for p in P:
        flag = True
        for i in range(len(V)):
            if V[i][0] < p[0]:
                V[i] = [p[1], p[2]]
                flag = False
                break
            elif V[i][0] == p[0] and V[i][1] == p[2]:
                V[i] = [p[1], p[2]]
                flag = False
                break
            else:
                continue

        if flag:
            V.append([p[1], p[2]])

    print(len(V))


if __name__ == '__main__':
    main()


Measured memory_bytes: 29944
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

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

    if (!(a % 2 && b % 2 && c % 2) && a == b && b == c) {
        cout << "-1\n";
        return 0;
    }

    int ans = 0;
    while (!(a % 2 || b % 2 || c % 2)) {
        int A = (b + c) / 2;
        int B = (a + c) / 2;
        int C = (a + b) / 2;
        tie(a, b, c) = tie(A, B, C);
        ans++;
    }

    cout << ans << "\n";
}

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

int main(int argc, const char * argv[]) {
    
    int n,m;
    string s[110],t[110];
    string word;
    int answer=0;
    int point=0;
    
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> s[i];
    }
    cin >> m;
    for(int i=0;i<m;i++){
        cin >> t[i];
    }
    
    for(int i=0;i<n;i++){
        point=0;
        word=s[i];
        
        for(int j=0;j<n;j++){
            if(word==s[j]) point++;
        }
        for(int j=0;j<m;j++){
            if(word==t[j]) point--;
        }
        
        answer=max(answer,point);
    }
    
    cout << answer << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl

class mint {
    long long x;
public:
    mint(long long 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 {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=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 {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};
/* -- template -- */
int main() {
    int N; cin >> N;
    map<char, int> m;
    rep(i, N) {
        string S; cin >> S;
        map<char, int> tmp;
        rep(j, S.size()) {
            if(i == 0)m[S[j]]++;
            tmp[S[j]]++;
        }
        for(char j = 'a'; j <= 'z';++j) {
            m[j] = min(tmp[j], m[j]);
        }
    }
    for(auto itr = m.begin(); itr != m.end(); ++itr) {
        rep(i, itr->second)
            cout << itr->first;
    }
}


Measured memory_bytes: 384
import sys
from collections import defaultdict

# ----------

sys.setrecursionlimit(10 ** 7)
INF = float("inf")
MOD = 10 ** 9 + 7


def combination(n, k):
    if k > n - k:
        return combination(n, n - k)
    return fact[n] * ifact[k] * ifact[n - k]


def permitation(n, k):
    # nPk = nCk * k!
    if n < 0:
        return 0
    res = combination(n, k) * fact[k]
    return res % MOD


N, K = map(int, input().split())
to = defaultdict(list)
for i in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)

# nまでの階乗を前処理
n = 200005
fact = defaultdict(int)
fact[0] = 1
for i in range(1, n + 1):
    fact[i] = fact[i - 1] * i
    fact[i] %= MOD
# nまでの階乗の逆元を前処理
ifact = defaultdict(int)
ifact[n] = pow(fact[n], MOD - 2, MOD)
for i in reversed(range(1, n + 1)):
    ifact[i - 1] = ifact[i] * i
    ifact[i - 1] %= MOD


def dfs(v, p=-1):
    global ans
    for u in to[v]:
        if u == p:
            continue
        dfs(u, v)
    if p == -1:
        nk = K
        c = len(to[v]) + 1
    else:
        nk = K - 2
        c = len(to[v]) - 1
    ans *= permitation(nk, c)
    ans %= MOD


ans = 1
dfs(0)
print(ans)


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

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
 
const int N=3e5+5,MAX=3e7,MOD=1e9+7;
 
using namespace std;


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

    	std::vector<int> a(n);

    	for(int i=0;i<n;i++)scanf("%d",&a[i]);

    	 int max = 1, len = 1; 
      
  
    for (int i=1; i<n; i++) 
    { 
        
        if (a[i] <= a[i-1]) 
            len++; 
        else
        { 
            
            if (max < len)     
                max = len; 
                 
            len = 1;     
        }     
    } 
      
  
    if (max < len) 
        max = len; 
      
    printf("%d\n",max-1 );



}	


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
    int N;
    cin >> N;
    int count;
    double prob;

    for(int i=1;i<=N;i++){
        if(i%2 == 1){
            count++;
        }
    }
    prob=double(count)/double(N);
    cout << prob << endl;

    return 0;
}

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

using namespace std;

main()
{
    int N;
    cin >> N;
    vector<pair<int, bool>> testimony_is_honest[N]; // 0: who, 1: whom
    for (int i = 0; i < N; i++)
    {
        int a;
        cin >> a;
        for (int j = 0; j < a; j++)
        {
            int x, y;
            cin >> x >> y;
            testimony_is_honest[i].emplace_back(x - 1, y == 1);
        }
    }
    int ans = 0;
    stack<pair<int /*index*/, vector<int> /*honest_nums*/>> s;
    s.emplace(0, vector<int>(0));
    while (!s.empty())
    {
        auto t = s.top();
        s.pop();
        int index = t.first;
        vector<int> honest_nums = t.second;
        if (index >= N)
        {
            vector<bool> is_honest(N, false);
            for (auto h : honest_nums)
            {
                is_honest[h] = true;
            }
            bool ok = true;
            for (int i = 0; i < N; i++)
            {
                if (!is_honest[i])
                    continue;
                for (auto tes : testimony_is_honest[i])
                {
                    if (tes.second != is_honest[tes.first])
                        ok = false;
                }
            }
            if (ok)
            {
                ans = max(ans, (int)honest_nums.size());
            }
        }
        else
        {
            s.emplace(index + 1, honest_nums);
            honest_nums.push_back(index);
            s.emplace(index + 1, honest_nums);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
ll n, q, a, b, glb;

struct segtree {
	ll val[888888], lim;
	void init () {
		for(lim=1;lim<=n;lim<<=1);
		for(ll i=2*lim;--i;) val[i] = inf;
	}
	void upd (ll P, ll V) {
		P += lim;
		while(P) {val[P] = min(val[P], V); P >>= 1;}
	}
	ll get (ll S, ll E) {
		S += lim; E += lim;
		ll ret = inf;
		while(S<=E) {
			if(S%2==1) {ret = min(val[S], ret); S++;}
			if(E%2==0) {ret = min(val[E], ret); E--;}
			S>>=1; E>>=1;
		}
		return ret;
	}
} l, r;

int main()
{
	scanf("%lld%lld%lld%lld",&n,&q,&a,&b);
	ll P;
	scanf("%lld",&P);
	l.init(); r.init();
	l.upd(a, abs(b-P) - a); r.upd(a, abs(b-P) + a);
	l.upd(b, abs(a-P) - b); r.upd(b, abs(a-P) + b);
	for(ll i=2;i<=q;i++) {
		ll C, V = inf;
		scanf("%lld",&C);
		V = min(V, l.get(1, C) + C);
		V = min(V, r.get(C, n) - C);
		glb += abs(P - C);
		l.upd(P, V - P - abs(P-C));
		r.upd(P, V + P - abs(P-C));
		P = C;
	}
	ll ans = inf;
	for(ll i=1;i<=n;i++) {
		ans = min(ans, l.get(i, i) + i + glb);
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 12544
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}

int main(){
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  rep(i,m){
    int a, b;
    cin >> a >> b;
    mp[a]++;
    mp[b]++;
  }
  REP(i,n+1){
    cout << mp[i] << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    long long A, B, K;
    cin >> A >> B >> K;
    printf("%lld %lld\n", max(0LL, A-K), max(0LL, B-max(0LL, K-A)));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp setprecision(12)<<fixed
#define ss second
#define fori(v) for(ll i=0; i<v; i++)
#define forj(v) for(ll j=0; j<v; j++)
#define fork(v) for(ll k=0; k<v; k++)
#define forl(v) for(ll l=0; l<v; l++)
#define fort(v) for(ll t=0; t<v; t++)
#define forz(v) for(ll z=0; z<v; z++)
#define forx(v) for(ll x=0; x<v; x++)
#define ll long long
#define double long double
#define MAX (int)(2*pow(10,5) + 10)
#define N 100000
#define pb(a) push_back(a)
// #define cout out
// #define cin in
ll inf = pow(10,9);
ll modulo = inf;
double eps = 1e-10;
ifstream in;
ofstream out;

void deal(){
	ll n ;
	cin>>n;
	vector<pair<ll,ll> > arr(n);
	fori(n)
		cin>>arr[i].ff>>arr[i].ss;
	ll mn = n;
	fori(n){
		for(ll j = i+1; j<n; j++){
			if(i==j)
				continue;
			ll dx = arr[j].ff - arr[i].ff;
			ll dy = arr[j].ss - arr[i].ss;
			vector<bool> vis(n,0);
			ll sy = 0;
			fork(n){
				if(!vis[k]){
					vector<ll> bfs(1,k);
					++sy;
					fori(bfs.size()){
						ll hd = bfs[i];
						forj(n){
							if(vis[j])
								continue;
							if( (arr[j].ss - arr[hd].ss == dy && arr[j].ff - arr[hd].ff == dx) || (arr[j].ss - arr[hd].ss == -dy && arr[j].ff - arr[hd].ff == -dx) ){
								vis[j] = 1;
								bfs.pb(j);
							} 
						}
					}
					
				}
			}
			mn = min(mn,sy);
			
		}
	}
	cout<<mn;
}


int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	deal();
}


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

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

    int v[N], w[N];
    for (int i = 0; i < N; i++) {
        cin >> v[i] >> w[i];
    }

    vector<vector<int>> dp(N+1, vector<int>(W+1, 0));

    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= W; j++) {
            if (j < w[i]) {
                dp[i+1][j] = dp[i][j];
            }
            else {
                dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i]);
            }
        }
    }

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

    return 0;
}


Measured memory_bytes: 6808
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#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 INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k,q;cin >> n >> k >> q;
  vector<ll> a(n,k);
  rep(i,q){
      ll tmp; cin >> tmp;
      tmp--;
      a[tmp]++;
  }
  rep(i,n){
      if(a[i]-q>0){
          cout << "Yes"<<endl;
      }else{
          cout <<"No" << endl;
      }
  }
}

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


signed main() {
    int N, R;
    cin >> N >> R;
    if (N > 9) cout << R << endl;
    else cout << R + ((10 -N) * 100) << endl;

}


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

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		List<Integer> list = new ArrayList<Integer>();


		int min = Math.min(A, B);

		int K = sc.nextInt();
		for (int i = 1; i <= min; i++) {

			if (A % i == 0 && B % i == 0) {

				list.add(i);
			}

		}
		Collections.sort(list, Comparator.reverseOrder());
		System.out.println(list.get(K-1));

	}

}

Measured memory_bytes: 21844
# include<iostream>
# include<queue>
using namespace std;
struct P{
	int x;
	int y;
	P(int x,int y):x(x),y(y){
	}
};

char maze[100][100];
int a[100][100];
int H,W;
int dx[4]={0,0,-1,1};
int dy[4]={1,-1,0,0};
int MAX=0;
void init()
{
	for(int i=0;i<H;i++)
	{
		for(int j=0;j<W;j++)
		{
			a[i][j]= -1;
		}
	}
}
void bfs(int i,int j)
{
	queue<P> que;
	que.push(P(i,j));
    a[i][j]=0;
	while(!que.empty())
	{
		P p = que.front();
		que.pop();
		for(int i=0;i<4;i++)
		{
			 int nx = p.x+dx[i];
			 int ny = p.y+dy[i];
			 if(nx>=0&&nx<H&&ny>=0&&ny<W&&maze[nx][ny]=='.'&&a[nx][ny]==-1)
			 {
			 	a[nx][ny]= a[p.x][p.y]+1;
			 	MAX = max(MAX,a[nx][ny]);
			 	que.push(P(nx,ny));
			 }
		}
	}
}

int main ()
{

	 cin>>H>>W;

	 for(int i=0;i<H;i++)
	 {
	 	 for(int j=0;j<W;j++)
	 	 {
	 	 	 cin>>maze[i][j]; 	 	
		  }
	 }
	 
	 for(int i=0;i<H;i++)
	 {
	 	 for(int j=0;j<W;j++)
	 	 {
	 	 	  if(maze[i][j]=='.')
			 {
			      init();
				 
				  bfs(i,j);
				 
			 }	 	
		  }
	 }	
	  cout<<MAX<<endl;
	
}

Measured memory_bytes: 256
let pn = 1000003

let pow x n =
  let rec doit i acc =
    if i = n then acc
    else doit (i + 1) (acc*x)
  in doit 0 1

let str_fold_left f init s =
  let n = String.length s in
  let rec doit i acc =
    if i = n then acc
    else doit (i + 1) (f acc s.[i])
  in doit 0 init

let () =
  let p = read_line () in
  let t = read_line () in
  let n = String.length p in
  let m = String.length t in
  let h = Array.make (n + 1) 0 in
  String.iteri (fun i c -> h.(i+1) <- h.(i)*pn + Char.code c) p;
  let ht = str_fold_left (fun acc c -> acc*pn + Char.code c) 0 t in
  let x = pow pn m in
  let rec doit i =
    if i <= n then begin
      if h.(i) - h.(i-m)*x = ht then Printf.printf "%d\n" (i - m);
      doit (i + 1)
    end in
  doit m

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

int main() {
  string S;
  cin >> S;
  for (int i = 0; i < (1 << 3); i++) {
    string f = S[0] + string();
    int t = S[0] - '0';
    for (int j = 0; j < 3; j++) {
      if (i & (1 << j)) {
        t += S[j+1] - '0';
        f += "+";
        f += S[j+1];
      }
      else {
        t -= S[j+1] - '0';
        f += "-";
        f += S[j+1];
      }
    }
    if (t == 7) {
      cout << f + "=7" << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int s[300005];

void print_s(int n){
	for(int i=0;i<n;i++){
		if(s[i]==0){
			n=i;
			break;
		}
	}
	for(int i=0;i<n;i++){
		cout<<s[i]<<(i!=n-1?' ':'\n');
	}
}

int main(){
	int n,m;
	int i,j,k;
	cin>>m>>n;
	if(m==1){
		for(i=0;i<(n+1)/2;i++)s[i]=1;
		print_s(n);
		return 0;
	}
	if(m%2==0){
		s[0]=m/2;
		for(i=1;i<n;i++)s[i]=m;
		print_s(n);
		return 0;
	}
	for(i=0;i<n;i++)s[i]=m/2+1;
	for(i=0;i<n/2;i++){
		if(s[n-1]!=0)s[n-1]--;
		else{
			for(j=n-2;j>=0;j--){
				if(s[j]!=0){
					s[j]--;
					break;
				}
			}
			if(s[j]!=0)for(++j;j<n;j++)s[j]=m;
		}
	}
	print_s(n);
	return 0;
}


Measured memory_bytes: 3456
#include<stdio.h>

int insertionSort(int a[], int n, int g)
{
    int i;
    int cnt = 0;
        for (i = g; i < n; i++){
            int v = a[i];
            int j = i - g;
            while (j >= 0 && a[j] > v){
                a[j+g] = a[j];
                j = j - g;
                cnt++;
            }
            a[j+g] = v;
        }
    return cnt;
}

int shellSort(int a[], int n)
{
    int m = 0;
    int cnt = 0;
    int g = 1;
    while (g <= n){
        g = g*3+1;
        m++;
    }
    printf("%d\n", m);

    int G[m];
    for(int i = 0; i < m; i++){
        G[i] = (g = g/3);
        if (i != 0)
            printf(" ");
        printf("%d", G[i]);
    }
    printf("\n");

    for (int i = 0; i < m; i++)
         cnt += insertionSort(a, n, G[i]);

    return cnt;
}     

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

    int a[n], i;
    for (i = 0; i < n; i++)
        scanf(" %d", &a[i]);
    
    printf("%d\n", shellSort(a, n));



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

    return 0;
}


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

using namespace std;

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

int main() {
    int n;
    cin >> n;
    vector<int> s(n);
    REP(i, n) cin >> s[i];
    VSORT(s);

    int q;
    cin >> q;
    int ans = 0;
    REP(i, q) {
        int t;
        cin >> t;
        if (binary_search(ALL(s), t)) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3172
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner c = new Scanner(System.in);
        double a = c.nextInt();
        double b = c.nextInt();
        double h = c.nextInt();
        double m = c.nextInt();
        double angle = ((h*60+m)/(12*60))*2*Math.PI-m/30*Math.PI;
        System.out.println(Math.sqrt(Math.pow(a,2)+Math.pow(b,2)-2*a*b*Math.cos(angle)));
    }
}


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

int h, w;
char tile[100][100];
int dx[4] = { 0, 1, 0, -1 }, dy[4] = { -1, 0, 1, 0 };
std::string arrows = "^>v<";

int main()
{
	while( std::cin >> h >> w, h | w )
	{
		for( int i = 0; i != h; ++i )
			for( int j = 0; j != w; ++j )
				std::cin >> tile[i][j];

		int x = 0, y = 0;
		while( true )
		{
			if( tile[y][x] == '-' )
			{
				std::cout << "LOOP" << std::endl;
				break;
			}
			else if( tile[y][x] != '.' )
			{
				int i = arrows.find( tile[y][x] );
				tile[y][x] = '-';
				x += dx[i]; y += dy[i];
			}
			else
			{
				std::cout << x << " " << y << std::endl;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	int a, b, c;
	cin >> a >> b >> c;
	int ans = 0;
	ans = max({ a * 10 + b + c,b * 10 + a + c,c * 10 + a + b });
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;

int main(){
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	int x1 = abs(tx - sx);
	int y1 = abs(ty - sy);
	for(int i = 0; i < y1; i++){
		cout << "U";
	}
	for(int i = 0; i < x1; i++){
		cout << "R";
	}
	for(int i = 0; i < y1; i++){
		cout << "D";
	}
	for(int i = 0; i < x1; i++){
		cout << "L";
	}
	cout << "L";
	for(int i = 0; i < y1 + 1; i++){
		cout << "U";
	}
	for(int i = 0; i < x1 + 1; i++){
		cout << "R";
	}
	cout << "D";
	cout << "R";
	for(int i = 0; i < y1 + 1; i++){
		cout << "D";
	}
	for(int i = 0; i < x1 + 1; i++){
		cout << "L";
	}
	cout << "U" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;

int keta_Sum(int num){
    
    int sum = 0;
    
    // 各桁の計算
    while(num != 0){
        sum += num % 10;
        num /= 10;
    }
    
    return sum;
}


int main(){
    
    int N, A, B;
    cin >> N >> A >> B;
    
    int ans = 0;
    for(int i = 1; i <= N; i++){
        int sum = keta_Sum(i);
        if(sum >= A && sum <= B) ans += i;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 3156
#include<bits/stdc++.h>
using namespace std;
void File(){
    freopen("ARC92F.in","r",stdin);
    freopen("ARC92F.out","w",stdout);
}
#define REP(i,a,b) for(register int i=a;i<=b;++i)
#define DREP(i,a,b) for(register int i=a;i>=b;--i)
#define mem(a) memset(a,0,sizeof(a))
const int maxn=1000+10;
const int maxm=200000+10;
vector<int>E[maxn];
int n,m,beg[maxn],len,num[maxn][maxn];
bool can[maxn][maxn],vis[maxn],can1[maxn][maxn];
int vis1[maxn],vis2[maxn],from[maxm],to[maxm];
void dfs(int u,int rt){
    vis[u]=1;
    can[rt][u]=1;
    int size=E[u].size()-1;
    REP(i,0,size){
        int v=E[u][i];
        if(vis[v])continue;
        dfs(v,rt);
    }
}
void dfs1(int u){
    vis[u]=1;
    int size=E[u].size()-1;
    REP(i,0,size){
        int v=E[u][i];
        if(vis[v])continue;
        vis1[v]=num[u][v];
        dfs1(v);
    }
}
void dfs2(int u){
    vis[u]=1;
    int size=E[u].size()-1;
    DREP(i,size,0){
        int v=E[u][i];
        if(vis[v])continue;
        vis2[v]=num[u][v];
        dfs2(v);
    }
}
int main(){
    //File();
    scanf("%d%d",&n,&m);
    REP(i,1,m){
        int u,v;
        scanf("%d%d",&u,&v);
        E[u].push_back(v);
        num[u][v]=++len;
        from[len]=u;
        to[len]=v;
    }
    REP(i,1,n){
        dfs(i,i);
        mem(vis);
    }
    REP(i,1,n){
        dfs1(i);
        mem(vis);
        dfs2(i);
        mem(vis);
        int size=E[i].size()-1;
        REP(j,0,size){
            int v=E[i][j];
            if(vis1[v]!=num[i][v] || vis2[v]!=num[i][v])
                can1[i][v]=1;
        }
        mem(vis1);
        mem(vis2);
    }
    REP(i,1,m){
        int u=from[i],v=to[i];
        if((can[v][u]^can1[u][v])==0)
            puts("same");
        else puts("diff");
    }
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n, k; cin>>n>>k;
    int ans=0;
    rep(i, n){
        int h; cin>>h;
        if (h>=k) ans++;
    }
    cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 256
S = input()
str_list = ['dream','dreamer','erase','eraser']
fl = True
while fl:
    if S[-5:] in str_list:
        S = S[0:-5]
    elif S[-6:] in str_list:
        S = S[0:-6]
    elif S[-7:] in str_list:
        S = S[0:-7]
    elif S=="":
        fl = False
    else:
        print('NO')
        exit()
print('YES')

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

int main() {
  int a,b,c,d;
  int left,right;
  cin >> a >> b >> c >> d;
  
  left = a + b;
  right = c + d;
  
  if ( left > right ) {
  	cout << "Left" << endl;
  } else if ( left < right ) {
  	cout << "Right" << endl;
  } else {
  	cout << "Balanced" << endl;
  }
}

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

#define x first
#define y second
#define y1 Y1
#define y2 Y2
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;

template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; }

inline void proc_status()
{
	ifstream t ("/proc/self/status");
	cerr << string (istreambuf_iterator <char> (t), istreambuf_iterator <char> ()) <<endl;
}

template <typename T> T read ()
{
	T sum = 0, fl = 1; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
	return sum * fl;
}

const int Maxn = 100 + 10, Maxv = 1e3 + 100;

int N, M;
LL Dp[Maxv * Maxn];
pii A[Maxn];

inline void Solve ()
{
	memset(Dp, 0x3f, sizeof Dp);
	int MAX = N * 1000;
	Dp[0] = 0;
	for (int i = 1; i <= N; ++i)
		for (int j = MAX; j >= A[i].y; --j)
			Chkmin(Dp[j], Dp[j - A[i].y] + A[i].x);
	for (int i = MAX; i >= 0; --i)
		if (Dp[i] <= M)
		{
			printf("%d\n", i);
			return ;
		}
}

inline void Input ()
{
	N = read<int>(), M = read<int>();
	for (int i = 1; i <= N; ++i) A[i].x = read<int>(), A[i].y = read<int>();
}

int main()
{
#ifdef hk_cnyali
	freopen("E.in", "r", stdin);
	freopen("E.out", "w", stdout);
#endif
	Input();
	Solve();
	return 0;
}


Measured memory_bytes: 1152
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {//233
	int n,x;
	cin>>n>>x;
	vi l(n);
	for(int &i:l)cin>>i;
	int ld = 0;
	int b = 1;
	REP(i,0,n-1) {
		ld+=l[i];
		if(ld>x){break;}
		b++;
	}
	cout<<b;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3648
package main

import "fmt"

func main() {
	var a, b, c string
	fmt.Scanf("%s %s %s", &a, &b, &c)
	if a[len(a)-1] == b[0] && b[len(b)-1] == c[0] {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 512
// Package main provides
//
// File:  a.go
// Author: ymiyamoto
//
// Created on Wed Jan  9 00:30:57 2019
//
package main

import (
	"fmt"
	"sort"
)

func max(slice ...int) int {
	sort.Ints(slice)
	return slice[len(slice)-1]
}

func main() {
	var X, t int
	fmt.Scan(&X, &t)

	fmt.Println(max(X-t, 0))
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
    double a, b; cin >> a >> b;
    double x; cin >> x; x /= (a*a);
    if(x<=(b/2)){
        double y = 2*a*x / b;
        double res = acos(y/(sqrt(b*b+y*y)));
        res = res*180/M_PI;
        cout << fixed << setprecision(15) << res << endl;
    }
    else{
        double y = 2*x - b;
        double res = acos(a/sqrt(a*a+(b-y)*(b-y)));
        res = res*180/M_PI;
        cout << fixed << setprecision(15) << res << endl;
    }
    return 0;
}

Measured memory_bytes: 3972
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <stdlib.h>
#include <tuple>
#include <iomanip>
#include <iterator>
#include <stdio.h>
#include <fstream>
#include <time.h>
using namespace std;
const double PI = 3.14159265358979323846;
const long long int MOD = 1000000000 + 7;

struct UnionFind {
    vector<int> parent;

    UnionFind(int N) : parent(N) {
        for (int i = 0; i < N; i++) {
            parent[i] = -1;
        }
    }

    int root(int i) {
        if (parent[i] < 0) {
            return i;
        }
        return (parent[i] = root(parent[i]));
    }

    bool unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx != ry) {
            parent[ry] += parent[rx];
            parent[rx] = ry;

            return true;
        }
        else {
            return false;
        }
    }

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

    int treeSize(int x) {
        

        return -parent[root(x)];
    }
};

long long int modpow(long long int base, long long int pow, long long int mod) {
    if (pow == 1) {
        return base;
    }
    else if (pow == 0) {
        return 1;
    }

    if (pow % 2 == 0) {
        auto temp = modpow(base, pow / 2, mod);
        return (temp * temp) % mod;
    }
    else {
        return base * modpow(base, pow - 1, mod) % mod;
    }
}

long long int moddiv(long long int X, long long int Y, long long int mod) {
    auto fermatDiv = modpow(Y, mod - 2, mod);

    return (X * fermatDiv) % mod;
}

long long modCombination(long long left, long long right, long long int mod) {
    long long answer = 1;
    for (long long i = 0; i < right; i++) {
        answer = (answer * (left - i)) % mod;
        answer = moddiv(answer, (i + 1), mod);
    }

    return answer;
}

bool IsPrime(long long N) {
    if (N == 1) {
        return false;
    }
    for (long long i = 2; i * i <= N; i++) {
        if (N % i == 0) {
            return false;
        }
    }

    return true;
}



vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({ a, ex });
    }

    // 最後に残った数について
    if (N != 1) res.push_back({ N, 1 });
    return res;
}

long long euclid(long long a, long long b) {
    if (a > b) {
        long long temp = b;
        b = a;
        a = temp;
    }
    if (b % a == 0) {
        return a;
    }
    else {
        return euclid(a, b - a);
    }
}

int main() {
    long long N;
    cin >> N;

    cout << N * (N + 1) / 2 - N << endl;

    return 0;
}

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

using namespace std;


void solve() {
    int n; cin >> n;
    vector<double> a(n);
    double tot = 1.0;
    for (auto& x: a) {
        cin >> x;
        tot*=x;
    }
    double res = 0;
    for (auto& x: a) {
        res += tot/x;
    }
    res = tot/res;
    cout << fixed << setprecision(10) << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/


int main(){
    vector<int> a(5);
    for(int i=0; i<5; i++) cin >> a[i];

    int k; cin >> k;
    if(a[4]-a[0] <= k) cout << "Yay!" << endl;
    else cout << ":(" << endl;


}

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

int main() {
  int N, X;
  cin >> N >> X;
  int L[N];
  for (int i=0; i < N; i++) cin >> L[i];
  int BoundCount = 1, position = 0;
  for (int i=0; i < N; i++) {
    position += L[i];
    if (position > X) break;
    else BoundCount++;
  } 
  cout << BoundCount << endl;
}
  

Measured memory_bytes: 764
N, M = gets.split.map(&:to_i)
ab = N.times.map { gets.split.map(&:to_i) }

A = 0
B = 1

ab.sort_by! { |ab| ab[A] }

m = M
ans = 0
ab.each do |ab|
  buy = [m, ab[B]].min
  ans += buy * ab[A]
  m -= buy
  if buy <= 0
    break
  end
end

puts ans


Measured memory_bytes: 12664
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;

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

            int a = N % 10;

            if (a == 3)
            {
                Console.WriteLine ("bon");
            }
            else if (a == 0 || a == 1 || a == 6 || a == 8)
            {
                Console.WriteLine ("pon");
            }
            else
            {
                Console.WriteLine ("hon");
            }

        }
    }

    class MyLibrary
    {

        // 自作の関数
        public static int MyFunction (int n)
        {
            return 0;
        }
    }
}

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

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

    int k = (int)sqrt(n);
    cout << k * k << endl;

    return 0;
}

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

int main(){
  int n, m;
  string s;
  cin >> n >> m >> s;
  vector<bool> bo(n+1);
  for(int i=0; i<=n; ++i){
    if(s[i]-'0') bo[i] = true;
    else bo[i] = false;
  }
  vector<int> ans(0);
  int posi = n;
  while(posi > 0){
    bool ansis = false;
    for(int i = max(0,posi-m); i<posi; ++i){
      //cout << posi << " " << i << ':' << bo[i] << endl;
      if(!bo[i]){
        ansis = true;
        ans.push_back(posi-i);
        posi = i;
        break;
      }
    }
    if(!ansis){
      cout << -1 << endl;
      return 0;
    }
  }
  for(int i=ans.size()-1; i>=0; --i){
    if(i==0) printf("%d\n",ans[i]);
    else printf("%d ",ans[i]);
  }
}

Measured memory_bytes: 4008
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <tuple>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define DECIM8  fixed<<setprecision(8) 
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

using namespace std;
string itor(int i)
{
  stringstream roman;
  if(i/1000>=2) roman << i/1000;
  if(i/1000) roman << 'm';
  i%=1000;
  if(i/100>=2) roman << i/100;
  if(i/100) roman << 'c';
  i%=100;
  if(i/10>=2) roman << i/10;
  if(i/10) roman << 'x';
  i%=10;
  if(i>=2) roman << i;
  if(i) roman << 'i';
  return roman.str();
}
int main(void)
{
  map<string,int> rimap;
  REP(i,10000){
    rimap[itor(i)]=i;
  }
  int n;
  cin >> n;
  REP(i,n){
    string a,b;
    cin >> a >> b;
    cout << itor(rimap[a]+rimap[b]) << endl;
  }
  return 0;
}

Measured memory_bytes: 2328
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007
#define INF 800000000
#define MAX 1000

vector<vector<int>> graph;
vector<int> depth,parent;
vector<int> deepest;

int solve_depth(int v){
  for(auto nv:graph.at(v)){
    if(depth.at(nv)!=-1){
      continue;
    }
    parent.at(nv)=v;
    depth.at(nv)=depth.at(v)+1;
    int k=solve_depth(nv);
    deepest.at(v)=max(deepest.at(v),k);
  }
  return deepest.at(v)=max(deepest.at(v),depth.at(v));
}

int main(){
  int N,u,v;
  cin>>N>>u>>v;
  u--;v--;
  graph.resize(N);
  for(int i=0;i<N-1;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    graph.at(a).push_back(b);
    graph.at(b).push_back(a);
  }

  depth.resize(N,-1);
  deepest.resize(N,0);
  parent.resize(N,-1);
  depth.at(v)=0;
  parent.at(v)=v;
  solve_depth(v);

  int x=u;
  int ans=0;
  for(int i=0;i<(depth.at(u)-1)/2+1;i++){
    ans=max(ans,deepest.at(x)-1);
    x=parent.at(x);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 12032
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define per(i, a, b) for(int i = (b) - 1; i >= (a); --i)
#define de(x) cout << #x << " = " << x << endl
#define dd(x) cout << #x << " = " << x << " "
#define endl '\n'
#define pw(x) (1ll<<(x))
#define all(x) x.begin(), x.end()
#define sz(x) (int)x. size()
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;

int n;
const int N=2e5+1;
vi e[N];
queue<int>que[3];
int c[N],ans[N];
int cnt[2];

void dfs(int p,int pre)
{
    for(auto v:e[p])
    {
        if(v==pre)continue;
        c[v]=c[p]^1;
        cnt[c[v]]++;
        dfs(v,p);
    }
}

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

    while(cin>>n)
    {
        rep(i,1,n+1)
        {
            e[i].clear();
            que[i%3].push(i);
        }
        rep(i,1,n)
        {
            int x,y;
            cin>>x>>y;
            e[x].pb(y);
            e[y].pb(x);
        }
        cnt[0]=1;
        cnt[1]=0;
        c[1]=0;
        dfs(1,-1);
        if(cnt[0]>cnt[1])
        {
            swap(cnt[0],cnt[1]);
            rep(i,1,n+1)c[i]^=1;
        }
        rep(i,1,n+1)
        {
            if(cnt[0]<=n/3)
            {
                if(c[i]==0)
                {
                    ans[i]=que[0].front();
                    que[0].pop();
                }
                else
                {
                    per(j,0,3)
                    {
                        if(!que[j].empty())
                        {
                            ans[i]=que[j].front();
                            que[j].pop();
                            break;
                        }
                    }
                }
            }
            else
            {
                if(!que[c[i]+1].empty())
                {
                    ans[i]=que[c[i]+1].front();
                    que[c[i]+1].pop();
                }
                else
                {
                    ans[i]=que[0].front();
                    que[0].pop();
                }
            }
        }
        rep(i,1,n)cout<<ans[i]<<" ";
        cout<<ans[n]<<endl;
    }

    return 0;
}


Measured memory_bytes: 19712
S=input()

l=0
for i in range(len(S)):
  for j in range(i+1,len(S)+1):
    s = set(S[i:j])
    if s <= {'A','C','G','T'} and len(S[i:j])>l:
      l = len(S[i:j])
      
print(l)

Measured memory_bytes: 9044