akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main () {
  string s;
  cin >> s;
  deque<char> data;
  for(int i = 0; i < s.size(); i++) {
    if(s.at(i) == 'B' && !data.empty())data.pop_back();
    else if(s.at(i) == '0' || s.at(i) == '1')data.push_back(s.at(i));
  }
  while(!data.empty()) {
    cout << data.front();
    data.pop_front();
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	int n;
	LL m;
	scanf("%d%lld", &n, &m);
	vector<LL> as(n);
	for(int i = 0; i < n; ++i){
		scanf("%lld", &as[i]);
	}
	sort(ALL(as));
	vector<LL> psum(n + 1);
	partial_sum(ALL(as), psum.begin() + 1);

	LL ok = 0, ng = 1LL << 60;
	while(abs(ok - ng) > 1){
		LL mid = (ok + ng) >> 1;
		LL cnt = 0;
		for(LL b : as){
			cnt += as.end() - lower_bound(ALL(as), mid - b);
		}
		if(cnt >= m){ ok = mid; }
		else{ ng = mid; }
	}

	LL ans = 0;
	LL rest = m;
	for(int i = n - 1; i >= 0 && rest > 0; --i){
		LL b = as[i];
		LL k = lower_bound(ALL(as), ng - b) - as.begin();
		LL t = min(n - k, rest);
		ans += b * t;
		ans += psum[n] - psum[n - t];
		rest -= t;
	}
	ans += ok * rest;
	printf("%lld\n", ans);
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){
	throw;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld long double
int main(){
	/*
	#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
	#endif*/
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int a,b;
	cin>>a>>b;
	vector<int> v;
	for(int i=a;i<=b && i<=a+2020;i++){
		v.push_back(i%2019);
	}
	int ans=1000000;
	for(int i=0;i<v.size();i++){
		for(int j=i+1;j<v.size();j++){
			ans=min(ans, (v[i]*v[j])%2019 );
		}
	}
	cout<<ans;
}


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

typedef long long int ll;

string s;
ll dp[100005][2];
ll mod = (1e9)+7;
ll solve(ll id,ll x)
{
    if(id>s.size())return 0;
    //cout<<id<<" "<<x<<endl;
    if(id==s.size())
    {
        if(x==0)
        return 1;
        else
            return 0;
    }

    if(dp[id][x]==-1)
    {
        ll val =0;

        if(s[id]=='0'){
            val = (solve(id+1,x) + 2*solve(id+1,1))%mod;
        }
        else{
            val = (solve(id+1,0)+2*solve(id+1,x)%mod);
        }
        dp[id][x] = val%mod;
    }
   // cout<<id<<" "<<x<<" "<<dp[id][x]<<endl;
    return dp[id][x]%mod;


}

int main()
{
    cin>>s;
    reverse(s.begin(),s.end());
    memset(dp,-1,sizeof(dp));
    cout<<solve(0,0)%mod<<endl;
}


Measured memory_bytes: 6656
import java.util.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for(i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sc.next());
		}
		sc.close();
		Arrays.sort(a);
		System.out.println(a[a.length-1]-a[0]);
	}
}


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

int main () {
	int n;
	int hist[6];
	fill(hist, hist + 6, 0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		double h;
		cin >> h;
		if (h < 165.0) hist[0]++;
		else if (h < 170.0) hist[1]++;
		else if (h < 175.0) hist[2]++;
		else if (h < 180.0) hist[3]++;
		else if (h < 185.0) hist[4]++;
		else hist[5]++;
	}
	for (int i = 0; i < 6; i++) {
		cout << i + 1 << ':';
		for (int j = 0; j < hist[i]; j++) {
			cout << '*';
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
using namespace std;
#define ll long long

int main() {
	ll d, n, ans = 1;
	cin >> d >> n;
	for (int i = 0; i < d; i++) {
		ans *= 100;
	}
	if (n != 100) ans *= n;
	else ans *= 101;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import Counter

n = int(input())
v = list(map(int, input().split()))

a = Counter(v[::2])
b = Counter(v[1::2])
a = a.most_common()
b = b.most_common()

if n % 2 == 0:
    al = n // 2
    bl = al
else:
    al = n // 2 + 1
    bl = n // 2

if len(a) == 1 and len(b) == 1:
    if a[0][0] == b[0][0]:
        print(min(a[0][1], b[0][1]))
    else:
        print(0)
elif len(a) == 1 or len(b) == 1:
    if len(a) == 1:
        if a[0][0] == b[0][0]:
            print(bl - b[1][1])
        else:
            print(bl - b[0][1])
    if len(b) == 1:
        if a[0][0] == b[0][0]:
            print(al - a[1][1])
        else:
            print(al - a[0][1])
else:
     if a[0][0] == b[0][0]:
         print(min(n - a[0][1] - b[1][1], n - a[1][1] - b[0][1])) 
     else:
         print(n - a[0][1] - b[0][1])


Measured memory_bytes: 18656
def main():
    import sys
    from bisect import bisect_right
    input = sys.stdin.readline
    N, M, K = [int(x) for x in input().strip().split()]
    A = [int(x) for x in input().strip().split()]
    B = [int(x) for x in input().strip().split()]
    Ac = [0] * N
    t = 0
    for i, a in enumerate(A):
        t += a
        Ac[i] = t
    Bc = [0] * M
    t = 0
    for i, b in enumerate(B):
        t += b
        Bc[i] = t

    ans = bisect_right(Bc, K)

    for i, ac in enumerate(Ac):
        if ac > K:
            break
        ans = max(ans, i+1+bisect_right(Bc, K-ac))

    print(ans)

if __name__ == '__main__':
    main()

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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

const ll P = 1000000007;

int main()
{
    ll N,K;
    cin >> N >> K;

    ll total = 0;

    for(ll i=K;i<=N+1;i++)
    {
        total += (i * (N - i + 1) + 1);
        total %= P;
    }

    cout << total << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
    using namespace std;
    
    int main(){
        long  p , q, r;
        cin >> p >> q >> r;
        
        long ans;
        ans = min(p + r , q + r);
        ans = min(ans , p + q);
        cout << ans << endl;
        
        return 0;
    }

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

map<pair<int,int>,int> m;
set<pair<int,int>> st;

int main(void){
	int H,W,N;
	cin >> H >> W >> N;
	for(int i=0;i<N;i++){
		int x,y;
		cin >> x >> y;
		for(int a=0;a<3;a++){
			for(int b=0;b<3;b++){
				int nx = x-a;
				int ny = y-b;
				if(nx<1||ny<1||nx>H-2||ny>W-2)continue;
				st.insert(pair<int,int>(nx,ny));
				m[pair<int,int>(nx,ny)]++;
			}
		}
	}
	for(int i=0;i<10;i++){
		ll ans = 0;
		for(auto x:st){
			if(m[x]==i)ans++;
		}
		if(i==0){
			ans = (ll)(H-2)*(W-2) - st.size();
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 98688
import numpy as np
N, K = map(int, input().split())
A = np.array(sorted(list(map(int, input().split()))))
F = np.array(sorted(list(map(int, input().split())), reverse=True))
s = A.sum()
l = -1
r = 10**12+2
# 全てのa*fが答えとなる数以下にできるかを10**12から二分探索
while l+1 < r:
    m = (l+r) // 2 # こここそが二分探索の肝で、ありえん小さい数とありえん大きい数から始めて半分にして狭めていく
    # 全てのA、Fにつき、Aとm//Fで小さい方の合計がK以下
    # m//Fは修行したあとの消化コスト
    # mが大きすぎてnp.minimum(A, m//F)がすべてAを選ぶならその合計は0なのでK以下が成り立つ
    # その場合、r=mとしてrを減らして再計算
    # K以下は修行に余力を残した状態か、修行できてないか。それより上のmはありえないのでr = mとする
    if s - np.minimum(A, m//F).sum() <= K:
        r = m
    # 修行ポイント以上に修行してしまった場合、それ未満のmはありえないのでl = mとする
    else:
        l = m
print(r)


Measured memory_bytes: 37264
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, b) for (int i = 0; i < (b); i++ )

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

const int INF = 100000000;
const double PI=acos(-1);

int main () {
    int N,M;
    cin >> N;
    int D[N];
    rep(i,N) {
        cin >> D[i];
    }

    cin >> M;

    map<int,int64_t> T;

    rep(i,M) {
        int tmp; cin >> tmp;
        if(!T.count(tmp)) {
            T[tmp] = 1;
        }
        else {
            T[tmp]++;
        }
    }
    string ans = "YES";
    rep(i,N){
        if (T.count(D[i])) {
            T[D[i]]--;
        }
    }
    for (auto p: T) {
        auto key = p.first;
        auto value = p.second;
        if (value >0) {
            ans = "NO";
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 13568
#include <iostream>
#include <cstdio>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());


int main(){
	int n;
	cin>>n;
	vector<ll> v(n,1);
	rep(i,n) cin>>v[i];
	ll tt=v[0];
	rep(i,n){
		tt=min(v[i],tt);
	}
	// cout<<tt<<endl;
	rep(i,tt){
		bool f=true;
		rep(j,n){
			if(v[j]%(i+1)==0) continue;
			else{
				f=false;
				break;
			}
		}
		if(f) cout<<i+1<<endl;
	}
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (int i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define fi first
#define se second
#define int long long
using namespace std;
using ll = long long;
using II = pair<int, int>; using VII = vector<II>; using VVII = vector<VII>;
using VI = vector<int>; using VVI = vector<VI>; using VVVI = vector<VVI>;
template <class T = int> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T = int> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <class T> ostream& operator<<(ostream &s, const vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream &s, const vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream &s, const pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, const map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
constexpr int MOD = 1e9 + 7;

signed main() {
  int n, k; cin >> n >> k;
  VI h(n + k);
  REP (i, n) cin >> h[i];
  VI dp(n + k, 1e15);
  dp[0] = 0;
  REP (i, n) {
    REPI (j, 1, k + 1) {
      dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
    }
  }
  cout << dp[n - 1] << endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,N) for(ll i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll a,b,c,d;

int main(){
    cin >> a >> b >> c >> d;
    cout << min(a,b)+min(c,d) << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
class disjoint_set {
  public:
    vector<int> rank, p;
    disjoint_set(){};
    disjoint_set (int size) {
      rank.resize(size, 0);
      p.resize(size, 0);
      for (int i = 0; i < size; i++) {
        makeSet(i);
      }
    }
    void makeSet (int x) {
      p[x] = x;
      rank[x] = 0;
    }
    bool same (int x, int y) {
      return find_set(x) == find_set(y);
    }
    void unite (int x, int y) {
      link(find_set(x), find_set(y));
    }
    void link (int x, int y) {
      if (rank[x] > rank[y]) {
        p[y] = x;
      } else {
        p[x] = y;
        if (rank[x] == rank[y]) {
          rank[y]++;
        }
      }
    }
    int find_set (int x) {
      if (x != p[x]) {
        p[x] = find_set(p[x]);
      }
      return p[x];
    }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  disjoint_set ds(n);
  vector<pair<int, int>> x(n);
  vector<pair<int, int>> y(n);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    x[i] = {a, i};
    y[i] = {b, i};
  }
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>>> pq;
  for (int i = 1; i < n; i++) {
    {
      int u, v, d;
      d = x[i].first - x[i - 1].first;
      u = x[i - 1].second;
      v = x[i].second;
      pq.push({d, {u, v}});
    }
    {
      int u, v, d;
      d = y[i].first - y[i - 1].first;
      u = y[i - 1].second;
      v = y[i].second;
      pq.push({d, {u, v}});
    }
  }
  int cnt = 0;
  int ans = 0;
  while (!pq.empty()) {
    auto e = pq.top();
    pq.pop();
    int dst = e.first;
    int one = e.second.first;
    int ant = e.second.second;
    if (ds.same(one, ant)) {
      continue;
    }
    ds.unite(one, ant);
    ans += dst;
  }
  cout << ans << '\n';
  return 0;
}

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

void CountingSort(int*, int*, int);
int n;
main() {
  int i,*A,*B;
  scanf("%d",&n);
  A = (int *)malloc(sizeof(int) * n+1);
  B = (int *)malloc(sizeof(int) * n+1);
  if(A == NULL) {
    printf("メモリが確保できません\n");
    exit(EXIT_FAILURE);
  }
  if(B == NULL) {
    printf("メモリが確保できません\n");
    exit(EXIT_FAILURE);
  }

  for(i = 1; i <= n; i++) {
    scanf("%d",&A[i]);
  }

  CountingSort(A, B,10000);

  for(i = 1; i <= n; i++) {
    if(i > 1) printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");
  free(A);
  free(B);

  return 0;
}

void CountingSort(int *A,int *B, int k) {
  int i,j;
  int *C;
  C = (int*)malloc(sizeof(int) * 10001);
  for(i = 0; i < k; i++) {
    C[i] = 0;
  }

/* C[i]にiの出現数を記録する。 */
  for(j = 1; j < n+1; j++) {
    C[A[j]]++;
  }

/* C[i]にi以下の数の出現数を記録する */
  for(i = 1; i < k; i++) {
    C[i] = C[i] + C[i-1];
  }

  for(j = n; j > 0; j--) {
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  free(C);
}

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

using namespace std;

int main ()
{
    int n , m;
    cin >> n >> m ;
    int ara[10000];

    for(int i = 1 ; i <= m ; i++)
    {
        cin >> ara[i];
    }
    int sum = 0 ;
    for(int i = 1 ; i <= m ; i++)
    {
        sum= sum + ara[i];
    }
    if(n>=sum)
        cout << n-sum << endl ;
    else
        cout << "-1" << endl ;

    return 0 ;


}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using edges = vector<int>;
using graph = vector<unordered_map<int, edges>>;
 
const int INF = 1e9;
//
graph G;
vector<int> d;
vector<unordered_set<int>> used;
queue<int> q;
void dfs(int i, int c, int dist) {
  used[i].insert(c);
  if (d[i] == -1) {
    d[i] = dist;
    q.push(i);
  }
  for (auto&& j : G[i][c]) {
    if (used[j].count(c)) continue;
    if (d[j] != -1 && d[j] < dist) continue;
    dfs(j, c, dist);
  }
}
void dijkstra(int s) {
  int N = G.size();
  d.assign(N, -1); d[s] = 0;
  used.resize(N);
  q.push(s);
  while (!q.empty()) {
    int i = q.front(); q.pop();
    for (auto&& itr : G[i]) {
      int c = itr.first;
      if (!used[i].count(c)) dfs(i, c, d[i] + 1);
    }
  }
}
 
int main() {
  int N, M; cin >> N >> M;
  G.resize(N);
  for (int i = 0; i < M; ++i) {
    int p, q, c; cin >> p >> q >> c;
    --p; --q;
    G[p][c].push_back(q);
    G[q][c].push_back(p);
  }
  dijkstra(0);
  cout << d[N - 1] << endl;
  return 0;
}

Measured memory_bytes: 67840
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdint.h>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout << #x << ": " << x << endl

int v;
int e;

//グラフの隣接リスト
vector<ll> g[100010];
//頂点の入次数を管理
int h[100010];

vector<ll> topological_sort() {
  //入次数が0の頂点の集合
  stack<int> st;

  //入次数が0の頂点であればstに追加
  REP(i, v) if (h[i] == 0) st.push(i);

  //ソートされた後のグラフ
  vector<ll> ans;
  // stがなくなるまでループ
  while (st.size()) {
    // stの集合のから一つ取り出す
    int i = st.top();
    st.pop();
    ans.push_back(i);
    for (auto &j : g[i]) {
      //隣接する頂点の入次数をマイナス1
      h[j]--;
      //これによって入次数が0になればstに追加
      if (h[j] == 0)
        st.push(j);
    }
  }
  return ans;
}

map<ll, ll> node_to_order;

bool comp(const pair<ll, ll> &l, const pair<ll, ll> &r) {
  if (l.second < r.second) {
    return true;
  } else if (l.second > r.second) {
    return false;
  } else {
    return node_to_order[l.first] > node_to_order[r.first];
  }
}

void solve(long long N, long long M, std::vector<long long> A,
           std::vector<long long> B) {
  v = N;
  e = N - 1 + M;
  REP(i, A.size()) {
    g[A[i] - 1].push_back(B[i] - 1);
    h[B[i] - 1]++;
  }
  auto ans = topological_sort();
  for (int i : ans) {
    node_to_order[ans[i]] = i;
  }
  vector<pair<ll, ll>> C(A.size());
  REP(i, A.size()) {
    C[i].first = A[i] - 1;
    C[i].second = B[i] - 1;
  }
  sort(ALL(C), comp);
  vector<ll> parent(N, 0);
  ll prev = -1;
  REP(i, C.size()) {
    if (prev == C[i].second) {
      C[i].first = -1;
    } else {
      parent[C[i].second] = C[i].first + 1;
    }
    prev = C[i].second;
  }
  REP(i, N) {
    std::cout << parent[i] << std::endl;
  }
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> A(N - 1 + M);
  std::vector<long long> B(N - 1 + M);
  for (int i = 0; i < N - 1 + M; i++) {
    scanf("%lld", &A[i]);
    scanf("%lld", &B[i]);
  }
  solve(N, M, std::move(A), std::move(B));
  return 0;
}


Measured memory_bytes: 17652
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.TokioMarine_2020
{
    class B
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            long[] av = ReadLongs();
            long[] bw = ReadLongs();
            long a = av[0];
            long v = av[1];
            long b = bw[0];
            long w = bw[1];
            long t = ReadLong();
            long delta = v - w;
            if (delta * t >= Abs(a - b))
            {
                WriteLine("YES");
            }
            else
            {
                WriteLine("NO");
            }
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 27540
#include<iostream>
#include<queue>
#include<memory>
#include<map>
#include<set>
#include<unordered_map>
#include<array>
#include<vector>
#include<algorithm>
#include<list>
#include<limits>
#include<stdio.h>
#include<math.h>
#include<string>
#include<thread>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;

const ll MOD = 1000000007;

int main()
{
	int K, X;
	cin >> K >> X;

	for (int i = X - K + 1; i < K + X; ++i)
	{
		cout << i << " ";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
import java.text.DecimalFormat;
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        double h = sc.nextDouble();
        double a = sc.nextDouble();

        System.out.println((new DecimalFormat("###########")).format(Math.ceil(h/a)));
    }
}

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

using namespace std;

using int64 = long long;

int main() {
  int64 N, X[1000], Y[1000];
  cin >> N;
  int type = -1;
  for(int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;

    int t = (x + y) % 2 == 0 ? 0 : 1;
    if(type == -1) type = t;
    if(type != t) {
      cout << -1 << endl;
      return 0;
    }

    X[i] = x - y;
    Y[i] = x + y;
  }

  vector< int64 > use;
  int64 sum = 0;
  for(int64 i = 31; i >= 0; i--) {
    use.emplace_back(1LL << i);
    sum += 1LL << i;
  }

  cout << use.size() + (type == 0) << endl;
  for(int i = 0; i < use.size(); i++) {
    cout << use[i] << " ";
  }

  if(type == 0) {
    cout << 1;
    for(int j = 0; j < N; j++) {
      X[j]--;
      Y[j]--;
    }
  }
  cout << endl;


  for(int i = 0; i < N; i++) {
    int64 latte = (X[i] + sum) / 2;
    int64 malta = (Y[i] + sum) / 2;
    for(int64 j = 31; j >= 0; j--) {
      int t1 = (latte >> j) & 1;
      int t2 = (malta >> j) & 1;
      if(t1 == 0 && t2 == 0) cout << "L";
      else if(t1 == 1 && t2 == 1) cout << "R";
      else if(t1 == 1 && t2 == 0) cout << "D";
      else cout << "U";
    }
    if(type == 0) cout << "R";
    cout << endl;
  }

}

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

using namespace std;

int main() {
	string s1,s2;
	cin >> s1 >> s2;
	int n=s1.length();
	int m=s2.length();
	int dp[n+1][m+1];
	for(int i=0;i<=n;i++)
	{
        for(int j=0;j<=m;j++)
        {
            if(i == 0 || j==0)
            {
               dp[i][j] = 0;
            }
            else if(s1[i-1] == s2[j-1])
            {
                dp[i][j] = 1 + dp[i-1][j-1];
            }
            else{
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
	char ans[dp[n][m]];
	string t="";
	int idx=dp[n][m]-1;
	int i=n;
	int j=m;
	while (i > 0 && j > 0) 
    {
      if (s1[i-1] == s2[j-1]) 
      { 
          ans[idx] = s1[i-1]; 
          t+=s1[i-1];
          i--;
          j--; 
          idx--;
      } 
      else if (dp[i-1][j] > dp[i][j-1]) 
         i--; 
      else
         j--; 
   } 
   reverse(t.begin(),t.end());
	cout<<t<<endl;

return 0;
}

Measured memory_bytes: 35456
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

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

        if x == y:
            return

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

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

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

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

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

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

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

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

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

N, M = map(int, input().split())
f_uf = UnionFind(N)
for _ in range(M):
  a, b = map(int, input().split())
  f_uf.union(a-1, b-1)
answer = 1
for i in range(N):
  answer = max(answer, f_uf.size(i))
print(answer)


Measured memory_bytes: 79304
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <math.h>
const long long mod = 1000000007;
//const long long mod = 998244353;
int main() {
	int N,M;
	scanf("%d", &N);
	scanf("%d", &M);
	int a = N < M ? N : M;
	int b = N >= M ? N : M;
	for (int i = 0; i < b; i++)printf("%d", a);
	return 0;
}

Measured memory_bytes: 128
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		if(N%500 <= A) System.out.println("Yes");
		else System.out.println("No");
		return;
	}
}

Measured memory_bytes: 23252
import sys
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def gcd(a,b):
    if a==0:
        return b
    else:
        return gcd(b%a,a)
def all_factors(n):
    small, large = [], []
    for i in range(1, int(n**0.5) + 1, 2 if n & 1 else 1):
        if not n % i:
            small.append(i)
            large.append(n // i)
    if small[-1] == large[-1]:
        large.pop()
    large.reverse()
    small.extend(large)
    return small
def is_prime(n):
    if n < 5 or n & 1 == 0 or n % 3 == 0:
        return 2 <= n <= 3
    s = ((n - 1) & (1 - n)).bit_length() - 1
    d = n >> s
    for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
        p = pow(a, d, n)
        if p == 1 or p == n - 1 or a % n == 0:
            continue
        for _ in range(s):
            p = (p * p) % n
            if p == n - 1:
                break
        else:
            return False
    return True

a,b=get_ints()
g=gcd(a,b)
lst=all_factors(g)
count=1
for i in lst:
    if is_prime(i):
        count+=1
print(count)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;
string s;
int P;
vector<vector<int>>data[2];
int dp(int ind,int rem,bool lim){
      if(ind==s.length()){
            if(rem==0)return 1;
            else return 0;
      }
      int cnt=0;
      if(lim){
            for(int i=0;i<s[ind]-'0';i++){
                  if(data[0][ind+1][(rem+i)%P]==-1)data[0][ind+1][(rem+i)%P]=dp(ind+1,(rem+i)%P,false);
                  cnt=(cnt+data[0][ind+1][(rem+i)%P])%modulo;
            }
            if(data[lim][ind+1][(rem+s[ind]-'0')%P]==-1)data[lim][ind+1][(rem+s[ind]-'0')%P]=dp(ind+1,(rem+s[ind]-'0')%P,true);
            cnt=(cnt+data[lim][ind+1][(rem+s[ind]-'0')%P])%modulo;
      }
      else{
            for(int i=0;i<=9;i++){
                  if(data[0][ind+1][(rem+i)%P]==-1)data[0][ind+1][(rem+i)%P]=dp(ind+1,(rem+i)%P,false);
                  cnt=(cnt+data[0][ind+1][(rem+i)%P])%modulo;
            }
      }
      return cnt;
}
int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
   //   freopen("q.gir","r",stdin);
   //   freopen("q.cik","w",stdout);
      cin>>s;
      cin>>P;
      data[0].resize(s.length()+1,vector<int>(P,-1));
      data[1].resize(s.length()+1,vector<int>(P,-1));
      cout<<(dp(0,0,true)-1+modulo)%modulo;
}


Measured memory_bytes: 17664
#include <bits/stdc++.h>
#define int long long
#define N 100010
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
int h,w,cx,cy;

bool in(int x,int y){return 0<=x && x<w && 0<=y && y<h;}

int calc2(int x1,int y1,int x2,int y2){
  if(x1 > x2) swap(x1, x2), swap(y1, y2);  
  if(x1 >= w) return 0;

  if(x1 < 0){
    if(y1 - y2 < 0) y1 += abs(x1) ,x1 = 0;
    if(y1 - y2 > 0) y1 -= abs(x1) ,x1 = 0;
  }

  if(x2 >= w){
    if(y1 - y2 < 0) y2 -= abs(x2-(w-1)) ,x2 = w-1;
    if(y1 - y2 > 0) y2 += abs(x2-(w-1)) ,x2 = w-1;
  }
  if(y1 > y2) swap(x1, x2), swap(y1, y2);
  if(y1 >= h) return 0;

  if(y1 < 0){
    if(x1 - x2 < 0) x1 += abs(y1) ,y1 = 0;
    if(x1 - x2 > 0) x1 -= abs(y1) ,y1 = 0;
  }

  if(y2 >= h){
    if(x1 - x2 < 0) x2 -= abs(y2-(h-1)) ,y2 = h-1;
    if(x1 - x2 > 0) x2 += abs(y2-(h-1)) ,y2 = h-1;
  }
  
  if(!in(x1,y1) || !in(x2,y2)) return 0;
  return abs(x2 - x1)+1;
}

int calc(int d){
  if(d == 0) return 1;
  return 
    calc2(cx,cy+d,cx+d,cy) + 
    calc2(cx+d,cy,cx,cy-d) +
    calc2(cx,cy-d,cx-d,cy) +
    calc2(cx-d,cy,cx,cy+d) -
    (in(cx,cy+d) + in(cx+d,cy) + in(cx,cy-d) + in(cx-d,cy));
}


template< class T >
void printVec(T a,char ch = ' '){
  for(int i=0;i<a.size();i++){
    if(i)cout<<ch;
    cout<<a[i];
  }
  cout<<endl;
}

signed main(){

  int X,Y,Z,A,B,C,n;
  cin>>X>>Y>>Z>>A>>B>>C>>n;
  w = X;
  h = Y;
  cx = A;
  cy = B;
  int D[N]={};
  for(int i=0;i<=X+Y;i++){
    D[i%n] += calc(i);
  }

  //for(int i=0;i<n;i++) cout<<D[i]<<" ";cout<<endl;  


  int ans = 0;
  int L1 = 0, R1= 0;
  int L2 = n-1, R2= 0;
  for(int i=0;i<Z-C;i++){
    int c = i%n;
    ans += D[(n-c)%n];
    R1 = (n - c)%n;
    if(i==0)L1=R1;
  }

  for(int i=1;i<=C;i++){
    int c = i%n;
    ans += D[(n-c)%n];
    R2 = (n - c)%n;
  }
  
  vector<int> Ans(1,ans);
  
  //swap(L1,R1);
  //swap(L2,R2);
  for(int i=1;i<n;i++){
    //cout<<"i="<<i<<endl;
    //cout<<L1<<" "<<R1<<endl;
    //cout<<L2<<" "<<R2<<endl;
    /*
      ans -= D[L1];
    L1++;L1%=n;

    R1++;R1%=n; 
    ans += D[R1];
    
    
    ans -= D[L2];
    L2++;L2%=n;

    R2++;R2%=n; 
    ans += D[R2];
    */

    ans -= D[L1];
    L1+=n-1;L1%=n;
    
    R1+=n-1;R1%=n;     
    ans += D[R1];
    
    ans -= D[L2];    
    L2+=n-1;L2%=n;
    
    R2+=n-1;R2%=n; 
    ans += D[R2];

    
    Ans.push_back(ans);
  }

  reverse(Ans.begin()+1,Ans.end());
  printVec(Ans);
  return 0;
}

Measured memory_bytes: 3952
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int a,b,c;
cin >> a;
cout << 3*a*a << endl;
return 0;
}


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

using namespace std;

int main()
{
  int res = 0;
  int over = 0;
  int a, b;
  for (int i = 0; i < 5; i++)
  {
    cin >> a;
    res += a;
    b = ceil(a / 10.0) * 10 - a;
    res += b;
    if (b > over)
    {
      over = b;
    }
  }

  cout << res - over << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i, a, n) for ( i = a; i < (n); i++)
#define fill(a,v)                    memset(a, v, sizeof a)
#define sz(a)                       ((int)(a.size()))
#define x first
#define y second
#define mp make_pair
#define pb push_back
using namespace std;

int main(){
	fast;
	ll i,j,k,tc,q,n,flag;	
	cin>>n;
	vector<ll> a(n),dp(n+1,0);
	rep(i,0,n){
		cin>>a[i];
	}
	dp[1]=abs(a[1]-a[0]);
	rep(i,2,n){
		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	}

	cout<<dp[n-1]<<endl;


	return 0;
}


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

using namespace std;

int solve (string const& s, int h) {
  int n = s.size();
  vector<pair<int, int>> dp(n + 1, {0, h});
  for (int i = n - 1, par = -1; i >= 0; i--) {
    if (par != -1) par ^= 1;
    if (s[i] == '1') {
      dp[i] = {dp[i + 1].first - 1, dp[i + 1].second - 1};
    } else if (s[i] == '0') {
      dp[i] = {dp[i + 1].first + 1, dp[i + 1].second + 1};
    } else {
      if (dp[i + 1].first == dp[i + 1].second && par == -1) {
        par = (dp[i + 1].first + 1) & 1;
      }
      dp[i] = {dp[i + 1].first - 1, dp[i + 1].second + 1};
    }
    dp[i].first = max(dp[i].first, 0);
    dp[i].second = min(dp[i].second, h);
    if ((dp[i].first > h) || (dp[i].second < 0) || (par != -1 && dp[i].first == dp[i].second && (dp[i].first & 1) != par)) {
      return 0;
    }
  }
  return 1;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n = s.size();
  int l = 1, r = n;
  while (l != r) {
    int mid = (l + r) / 2;
    int ok = solve(s, mid);
    if (ok) {
      r = mid;
    } else l = mid + 1;
  }
  cout << l << '\n';
  return 0;
}

Measured memory_bytes: 12204
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

ll dp[110][100010];
ll accum[100010];

int main(void){
    ll n,k;
    cin>>n>>k;
    vector<ll>a(n);
    for(ll i=0;i<n;i++)cin>>a[i];
    dp[0][0]=1;
    for(ll i=0;i<n;i++){
        accum[0]=0;
        for(ll j=0;j<=k;j++)accum[j+1]=(accum[j]+dp[i][j])%N;
        for(ll j=0;j<=k;j++)dp[i+1][j]=(accum[j+1]-accum[max((ll)0,j-a[i])]+N)%N;
    }
    cout<<dp[n][k]<<endl;
    return 0;
}


Measured memory_bytes: 79360
#include <iostream>
#include <algorithm>
#include <string>
#include <ctype.h>

using namespace std;


int ctoi(char c) {
  return isdigit(c) ? c - '0' : c;
}

char itoc(int i) {
  return i + '0';
}

string add(string a, string b) {
  int max_leng, t, ap, bp;
  bool over = false;

  string ret = "";
  max_leng = (a.length() > b.length()) ? a.length() : b.length();
  if (max_leng > 80)
    return "overflow";

  ap = a.length() - 1;
  bp = b.length() - 1;
  for (int i = 0; i < max_leng; i++) {
    if (ap >= 0 && bp >= 0)
      t = ctoi(a.at(ap)) + ctoi(b.at(bp));
    if (ap >= 0 && bp < 0)
      t = ctoi(a.at(ap));
    if (ap < 0 && bp >= 0)
      t = ctoi(b.at(bp));
    if (over) t++; // increase in digit
    ret += itoc(t % 10);
    if (t > 9) over = true;
    else over = false;
    ap--; bp--;
  }
  if (over) ret += '1';
  reverse(ret.begin(), ret.end());
  if (ret.length() > 80) return "overflow";
  else return ret;
}

int main() {
  int n;
  string number1, number2;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> number1;
    cin >> number2;
    cout << add(number1, number2) << endl;
  }
  return 0;
}

Measured memory_bytes: 0
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const int NINF = -1*INF;
const long long LLINF = 1ll << 60;
const long long LLNINF = -1*LLINF;

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<pi> vpi;
typedef vector<vector<int>> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef vector<vld> vvld;
 
#define mp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()
#define revAll(x) x.rbegin(), x.rend()
#define gcd(a, b) __gcd(a, b)
#define popcount(x) __builtin_popcount(x)
#define isize(x) (int)(x.size())
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define umap unordered_map

const ll MOD = 1e9 + 7;

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	int n; cin >> n;
	int mw = 0, ms = 0;
	vvi A = vvi();
	rep(i, n){
		int w, s, v; cin >> w >> s >> v;
		A.pb({w, s, v});
		mw = max(mw, w);
		ms = max(ms, s);
	}
	sort(
		all(A),
		[](vi a, vi b){return (a[0] + a[1] < b[0] + b[1]);}
		);
	ll lim = mw + ms + 100;
	vll dp = vll(lim + 1);
	ll ans = 0;
	for(const auto& item : A){
		int w = item[0], s = item[1], v = item[2];
		for(int i = lim; i >= 0; i--){
			if (i - w < 0) continue;
			if (i - w > s) continue;
			dp[i] = max(dp[i], dp[i-w] + v);
			ans = max(ans, dp[i]);
		}
	}
	cout << ans;
}

Measured memory_bytes: 3772
#include <iostream>
using namespace std;
int main()
{
    int x;
    bool ok=false;
    cin >> x;
    for (int i=1;i<=9;i++)
    {
        if (x%i==0 && x/i<=9)
        {
            ok=true;
            break;
        }
    }
    if (ok) cout << "Yes";
    else cout << "No";
}


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

int main(){
	int A, B; cin >> A >> B;

	if(A <= 8 && B <= 8){
		cout << "Yay!";
	}
	else{
		cout << ":(";
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>

#define Emax 2000
#define Vmax 1000
#define Dmax (10000)
#define INF (1000000)

using namespace std;

typedef unsigned int uint;
typedef long long int llint_t;

struct Edge {
  int from, to, cost;
};

Edge edges[Emax];
static llint_t d[Vmax];
static int Vnum, Enum, r;

void bellman_ford() {
  fill_n(d, Vnum, INF);
  d[r] = 0;
  for (int i = 0; i < Vnum - 1; i++) {
    for (int j = 0; j < Enum; j++) {
      auto uv = edges[j];
      auto u = uv.from;
      auto v = uv.to;
      if (d[u] == INF) continue;
      d[v] = min(d[v], d[u] + uv.cost);
    }
  }
  for (int i = 0; i < Enum; i++) {
    auto uv = edges[i];
    if (d[uv.from] == INF) continue;
    if (d[uv.from] + uv.cost < d[uv.to]) {
      puts("NEGATIVE CYCLE");
      exit(0);
    }
  }
}

int main(int ac, char **av) {
  scanf("%d %d %d", &Vnum, &Enum, &r);

  for (int i = 0; i < Enum; i++) {
    int s, t, d;
    scanf("%d %d %d", &s, &t, &d);
    Edge e;
    e.from = s;
    e.to = t;
    e.cost = d;
    edges[i] = e;
  }

  bellman_ford();

  for (int i = 0; i < Vnum; i++) {
    if (d[i] == INF) {
      printf("INF\n");
    } else {
      printf("%d\n", d[i]);
    }
  }
  return 0;
}


Measured memory_bytes: 2768
n,q = map(int,input().split())
s = input()
A = [0 for _ in range(n)]
C = [0 for _ in range(n)]
memo1 = [0 for _ in range(n)]
memo2 = [0 for _ in range(n)]

for i in range(n):
    if s[i]=="A":
        A[i] = 1
    elif s[i] =="C":
        C[i] = 1
    if i == 0:
        continue
    if A[i-1] and C[i]:
        memo1[i] = memo1[i-1] + 1
    else:
        memo1[i] = memo1[i-1]
for i in range(n-2,-1,-1):
    if A[i] and C[i+1]:
        memo2[i] = memo2[i+1] + 1
    else:
        memo2[i] = memo2[i+1]
total = memo2[0]
for _ in range(q):
    l,r = map(lambda x:int(x)-1,input().split())
    ans = total
    if l >0:
        ans -= memo1[l-1]
        if A[l-1] and C[l]:
            ans -=1
    if r<n-1:
        ans -= memo2[r+1]
        if A[r] and C[r+1]:
            ans -= 1
    print(ans)

Measured memory_bytes: 10212
import java.io.PrintWriter;
import java.util.*;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = sc.nextInt();
        long k = sc.nextLong();

        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt() - 1;
        }

        boolean[] visited = new boolean[n + 1];
        int[] tele = new int[n + 1];
        int current = 0;
        int index = 0;
        int loopStart;
        while (true) {
            if (visited[current]) {
                loopStart = current;
                break;
            }
            visited[current] = true;
//            debug(visited, current);
            index++;
            current = arr[current];
            tele[index] = current;
        }

//        debug(loopStart, index);

        int loopStartIdx = 0;
        for (int i = 0; i < n; i++) {
            if (tele[i] == loopStart) {
                loopStartIdx = i;
                break;
            }
        }

        int loopCount = index - loopStartIdx;
        int noLoopCount = loopStartIdx;
//        debug(loopCount, noLoopCount);
//        debug(tele);
        long j = k > noLoopCount ? noLoopCount + (k - noLoopCount) % loopCount : k;
        System.out.println(tele[(int)j] + 1);







        // out.println("Hello World");
        out.flush();    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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


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

int main(void){
    string a,b;
    cin >> a >> b;
    int n = stoi(a+b);
    for(int i=1; i<=sqrt(n); i++){
        if(i*i == n){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = list(input())
for i in range(N-K):
    if T[i] == T[i+K]:
        T[i+K] = "@"
dic1 = {"r":P,"s":R,"p":S,"@":0}
points = 0
for i in range(N):
    points += dic1[T[i]]
print(points)

Measured memory_bytes: 4084
package main

import (
	"fmt"
	"strings"
)

func main() {
	var (
		a, b int
		s    string
	)

	fmt.Scan(&a, &b, &s)

	parts := strings.Split(s, "-")

	if len(parts) < 2 {
		fmt.Println("No")
		return
	}

	if len(parts[0]) == a && len(parts[1]) == b {
		fmt.Println("Yes")
		return
	}

	fmt.Println("No")
}


Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define sort(s) sort(s.begin(),s.end())
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define Pll pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0)return a;
	return gcd(b, a % b);
}

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
int c(int a, int b, int m) {
	int ans = 1;
	for (int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}
	int size(int a) {
		return par[root(a)];
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int b_s(vector<int>& a, int key) {
	int left = -1;
	int right = a.size();
	while (right - left > 1) {
		int mid = left + (right - left) / 2;
		if (a[mid] >= key)right = mid;
		else left = mid;
	}
	return left;
}

int main() {
	int n;
	cin >> n;
	rep(i, 1, n+1) {
		int ans = 0;
		rep(j, 1, 101) {
			rep(k, 1, 101) {
				int x = j * j + k * k + j * k;
				if (x >= i)break;
				for (int l=1;; l++) {
					if (x + l * (l + k + j) == i)ans++;
					if (x + l * (l + k + j) > i)break;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3636
import numpy as np

a,b,x = map(float,input().split())

s = a*a
y1 = 2.0*(s*b-x)/a/a
t1 = y1 / a
y2 = 2.0*x/a/b
t2 = 1.0/(y2 / b)
theta1 = np.rad2deg(np.arctan(t1))
theta2 = np.rad2deg(np.arctan(t2))
if(y1 <= b):print(theta1)
else:print(theta2)

Measured memory_bytes: 12488
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
  int n;
  cin >> n;
  int ab = 0;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  rep(i,n){
    rep(j,n){
      ab = max(ab,abs(a[i] - a[j]));
    }
  }
  cout << ab << endl;
}

Measured memory_bytes: 3616
N = int(input())
A = [int(input()) for i in range(N)]
MOD = 998244353

S = sum(A)

dp = [[0]*(S+1) for _ in range(N+1)]
dp[0][0] = 1

dp2 = [[0]*(S+1) for _ in range(N+1)]
dp2[0][0] = 1

for i in range(N):
    a = A[i]
    x = 0
    while x <= S:
        if x + a <= S:
            dp[i+1][x+a] += dp[i][x] % MOD
            dp2[i+1][x+a] += dp2[i][x] % MOD
        dp[i+1][x] += dp[i][x] * 2 % MOD
        dp2[i+1][x] += dp2[i][x] % MOD
        x += 1


if S % 2 == 0:
    ans = 3 ** N - sum(dp[N][S//2:]) * 3
    ans += 3 * dp2[N][S//2]
else:
    ans = 3 ** N - sum(dp[N][S//2 + 1:]) * 3

print(ans % MOD)


Measured memory_bytes: 460168