akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const ll INF = 1LL << 58;
const ll MOD = 1000000007;
typedef vector<pii> vpii;
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;
}

int ans = 0;

int N, M, Q;
int mem[51][4];
void solve(int i, vi v)
{
    if (v.size() == N)
    {
        int tmp = 0;
        REP(i, Q)
        {
            if (v[mem[i][1] - 1] - v[mem[i][0] - 1] == mem[i][2])
            {
                tmp += mem[i][3];
            }
        }
        ans = max(ans, tmp);
        return;
    }
    if (i == M + 1)
        return;
    solve(i + 1, v);
    v.push_back(i);
    solve(i, v);
    solve(i + 1, v);
}

signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    cin >> N >> M >> Q;
    REP(i, Q)
    {
        cin >> mem[i][0] >> mem[i][1] >> mem[i][2] >> mem[i][3];
    }

    vi v;
    solve(1, v);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<map>
#include<vector>
#include<cstdio>
#include<cstring>
using namespace std;

int main()
{
	map<int, pair<int,bool> >num;
	int a,b,count;
	string s;
	while(getline(cin ,s) , s != "")
	{
		sscanf(s.c_str(),"%d,%d",&a ,&b);

		if(!num.count(a))
		{
			num.insert(make_pair(a, make_pair(1,false)));
		}
		else
		{
			num[a].first++;
		}
	}
	while(getline(cin ,s) , s != "")
	{
		sscanf(s.c_str(),"%d,%d",&a ,&b);

		if(num.count(a))
		{
			num[a].first++;
			num[a].second = true;
		}
	}
	map<int, pair<int,bool> >::iterator it;
	for(it = num.begin(); it != num.end(); it++)
	{
		if((*it).second.second)
		printf("%d %d\n",(*it).first, (*it).second.first);
	}
}

Measured memory_bytes: 1248
import java.util.*;

public class Main {
  public static void main (String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    
    String[] Weather = {"Sunny","Cloudy","Rainy"};
    
    for(int i = 0; i < 3 ; i++) {
      if(Weather[i].equals(s)){
        if(i < 2 ){
          System.out.println(Weather[i + 1]);
        }else{
          System.out.println(Weather[0]);
        }
      }
    }
  }
}




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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const ll MAX_NUM = (ll)(3e3 + 500);

ll m;

tuple<ll, ll, ll> solve() {
  for (ll h = 1; h <= MAX_NUM; ++h) {
    for (ll n = 1; n <= MAX_NUM; ++n) {
      ll top = m * h * n;
      ll bottom = 4 * h * n - m * n - m * h;

      // printf("h: %d, n: %d, top: %d, bottom: %d\n", h, n, top, bottom);

      if (bottom == 0) continue;
      if (top < 1) continue;

      if (top % bottom != 0) continue;

      ll w = top / bottom;

      if (w < 1) continue;

      return make_tuple(h, n, top / bottom);
    }
  }

  return make_tuple(-1LL, -1LL, -1LL);
}

int main(void) {
  // Here your code !
  scanf("%lld", &m);

  auto ans = solve();

  printf("%lld %lld %lld\n", get<0>(ans), get<1>(ans), get<2>(ans));

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
const long long M = 998244353;

long long c[5001][5001];
long long ch(int n, int k) {
    if (0 > n || k > n) return 0;
    if (k < 0) return 0;
    return c[n][k];
}

int main() {
    int k, n; cin >> k >> n;
    for (int a = 0; a <= 5000; a++) {
        c[a][0] = 1; c[a][a] = 1;
        for (int b = 1; b < a; b++) {
            c[a][b] = (c[a-1][b] + c[a-1][b-1])%M;
        }
    }
    
    for (int i0 = 2; i0 <= 2*k; i0++) {
        int i = (i0 > k+1) ? 2*k - i0 + 2 : i0;
        long long ans = 0;
        int u = min(k, i/2), l = max(1, i-k);
        for (int m = 0; m <= u - l + 1; m++) {
            ans += (ch(u-l+1, m) * ch(n+k-1-2*m, n-2*m) * (m%2 == 0 ? 1 : -1)) % M;
            ans %= M;
        }
        cout << (ans%M + M) % M << endl;
    }
}


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

int main() {
	int N;
	cin >> N;
	vector<long long> left(N), right(N);
	for (int i = 0; i < N; ++i) cin >> left[i] >> right[i];
	sort(left.begin(), left.end(), greater<long long>());
	sort(right.begin(), right.end());
	long long res = 0, tmp = 0;

	// left スタート
	tmp = 0;
	for (int i = 0; i < N; ++i) {
		tmp += left[i]; res = max(res, tmp);
		tmp -= right[i]; res = max(res, tmp);
	}

	// right スタート
	tmp = 0;
	for (int i = 0; i < N; ++i) {
		tmp -= right[i]; res = max(res, tmp);
		tmp += left[i]; res = max(res, tmp);
	}

	cout << res * 2 << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;

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

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

    for(int i=0;i<n;i++){
        for(int j=0;j<9;j++){
            if(b[i] == a[j]){
                a[j] = 0;
            }
        }
    }

    if(a[0] + a[1] + a[2] == 0 || a[3] + a[4] + a[5] == 0 || a[6] + a[7] + a[8] == 0 || a[0] + a[3] + a[6] == 0 || a[1] + a[4] + a[7] == 0 || a[2] + a[5] + a[8] == 0 || a[0] + a[4] + a[8] == 0 || a[2] + a[4] + a[6] == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}

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

int main() {
    int N=0, K=0;
    cin >> N >> K;

    vector<int> h(N, -1);
    rep(i, N) cin >> h.at(i);

    int cnt = 0;
    rep(i, N){
        if(h.at(i) >= K) cnt++;
    }

    cout << cnt << endl;
}


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

int main()
{
    int n;
    cin >> n;
    char a[n+1], b[n+1], c[n+1];
    for (int i=0; i<n; i++){
        cin >> a[i];
    }
    for (int i=0; i<n; i++){
        cin >> b[i];
    }
    for (int i=0; i<n; i++){
        cin >> c[i];
    }
    int sum=0;
    for (int i=0; i<n; i++){
        if (a[i]==b[i] && a[i]==c[i]){
            continue;
        }else if(a[i]==b[i] || a[i]==c[i] || b[i]==c[i]){
            sum++;
        }else{
            sum+=2;
        }
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = input()
B = A.split()
total = 0
for i in range(N) :
    mini = int(i)
    for j in range(i, N) :
        if int(B[j]) < int(B[mini]) :
            mini = int(j)
    if mini != int(i) :
        B[i], B[mini] = B[mini], B[i]
        total += 1
print(" ".join(B))
print(total)


Measured memory_bytes: 5600
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;

ll a[100000];
ll dif[100000];

int main()
{
	int n;
	int odd;
	ll ab;
	ll mint=9999999999;
	int index=0;
	ll num1,num2;
	
	cin>>n;
	if(n%2==0)
		odd=0;
	else
		odd=1;
	
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	reverse(a,a+n);

	num1 = a[0];
	ab = num1/2;

	for(int i=1;i<n;i++)
	{
		dif[i] = abs(ab-a[i]);
		if(ab<a[i])
			dif[i]-=odd;
		
		if(dif[i]<mint)
		{
			mint=dif[i];
			index=i;
		}
	}
	num2=a[index];
	
	cout<<num1<<" "<<num2<<endl;
	return 0;
}

Measured memory_bytes: 1792
(* O(n log n) *)
let n = Scanf.scanf " %d" @@ (+) 0
let bas = Array.init n @@ fun i -> Scanf.scanf " %d %d" @@ fun a b -> b, a
let _ =
  Array.sort compare bas;
  Array.fold_left (fun t (b, a) -> if a + t > b then (print_endline "No"; exit 0) else a + t) 0 bas |> ignore;
  print_endline "Yes"

Measured memory_bytes: 9600
#%%
H, W = [int(i) for i in input().split()]
maze = [[] for _ in range(H)]

num_black = 0
for i in range(H):
    temp = input()
    for j in temp:
        maze[i].append(j)
        if j == "#":
            num_black += 1
            
#%%
import copy, collections

maze_copy = copy.deepcopy(maze)
color = [["W"] * W for _ in range(H)]


X, Y = 0, 0
vec = [[1, 0], [-1, 0], [0, 1], [0, -1]]
color[Y][X] = "G"
que = collections.deque()
maze_copy[Y][X] = 1
que.append([Y, X])

while len(que) != 0:
    u = que.popleft()
    for y, x in vec:
        temp_x = u[1] + x
        temp_y = u[0] + y
        if (0 <= temp_x < W and 0 <= temp_y < H
                and maze_copy[temp_y][temp_x] == "." and color[temp_y][temp_x] == "W"):
            color[temp_y][temp_x] = "G"
            maze_copy[temp_y][temp_x] = maze_copy[u[0]][u[1]] + 1
            que.append([temp_y, temp_x])
    
if maze_copy[-1][-1] == ".":
    print(-1)
else:
    print(W * H - num_black - maze_copy[-1][-1])



Measured memory_bytes: 9676
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int sx,sy,tx,ty;
string ans;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>sx>>sy>>tx>>ty;
    rep(i,tx-sx) cout<<'R';
    rep(i,ty-sy) cout<<'U';
    rep(i,tx-sx) cout<<'L';
    rep(i,ty-sy) cout<<'D';
    cout<<'D';
    rep(i,tx-sx+1) cout<<'R';
    rep(i,ty-sy+1) cout<<'U';
    cout<<'L';
    cout<<'U';
    rep(i,tx-sx+1) cout<<'L';
    rep(i,ty-sy+1) cout<<'D';
    cout<<'R'<<endl;
}

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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;
const ll INF = 1LL << 60;

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



// Main Code



int main()
{
  int n;
  ll h;
  cin>>n>>h;
  vector<ll> a(n), b(n);
  ll amax = 0;
  rep(i, 0, n)
  {
    cin>>a[i]>>b[i];
    amax = max(amax, a[i]);
  }
  sort(b.begin(), b.end(), greater<ll>());
  //cout<<b[0]<<endl;
  ll cnt = 0;
  rep(i, 0, n)
  {
    if (b[i] <= amax) break;
    h -= b[i];
    cnt++;
    if (h <= 0) break;
  }
  if(h > 0)
    cnt += ((h + amax -1) / amax);
  cout<<cnt<<endl;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int maxCount = 0;
        Map<String, Integer> m = new HashMap<>();
        for (int i = 0; i < n; i++) {
            String s = sc.next();
            Integer c = m.get(s);
            Integer newCount = c == null ? 1 : c + 1;
            if (maxCount < newCount) maxCount = newCount;
            m.put(s, newCount);
        }


        final int mc = maxCount;
        m.entrySet().stream()
                .filter(x -> x.getValue() == mc)
                .sorted(Map.Entry.comparingByKey())
                .forEach(x -> System.out.println(x.getKey()));

    }
}

Measured memory_bytes: 87672
#include <stdio.h>

typedef struct {
	long long key;
	int id;
} data;

void merge_sort(data x[], int n)
{
	static data y[200001] = {};
	if (n == 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p].key < x[q].key)? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int main()
{
	int i, N;
	long long D, A, X[200001], H[200001];
	scanf("%d %lld %lld", &N, &D, &A);
	for (i = 1; i <= N; i++) scanf("%lld %lld", &(X[i]), &(H[i]));
	
	data d[200001];
	for (i = 0; i < N; i++) {
		d[i].key = X[i+1];
		d[i].id = i + 1;
	}
	merge_sort(d, N);
	
	int j, k, l, r, b[200001][2] = {}, head, tail, tmp;
	long long ans = 0;
	for (i = 0, head = 0, tail = 0, tmp = 0; i < N; i++) {
		for (; head < tail && b[head][0] < i; head++) tmp -= b[head][1];
		if (H[d[i].id] <= tmp) continue;

		ans += (H[d[i].id] - tmp + A - 1) / A;
		for (l = i, r = N - 1; l < r; ) {
			if (d[(l+r+1)/2].key > d[i].key + D * 2) r = (l + r - 1) / 2;
			else l = (l + r + 1) / 2;
		}
		b[tail][0] = l;
		b[tail][1] = ((H[d[i].id] - tmp + A - 1) / A) * A;
		tmp += b[tail++][1];
	}
	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 12668
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main()
{
	int a[3];
	char cang1, cang2;
	a[0] = 1;

	while (scanf("%c,%c", &cang1, &cang2) != EOF){
		for (int i = 0; i < 3; i++){
		 if (cang1 == 'A' + i){
			 for (int j = 0; j < 3; j++){
				 if (cang2 == 'A' + j) swap(a[i], a[j]);
			 }
		 }
		}
	}
	for (int i = 0; i < 3; i++){
		if (a[i] == 1) printf("%c\n", 'A' + i);
	}
	return (0);
}

Measured memory_bytes: 1140
import sys
n=int(input())
a=list(map(int,sys.stdin.read().split()))
check_a=[False for _ in range(n)]
c=0
i=0
while True:
  if i == 1:
    print(c)
    exit()
  nex=a[i]-1
  if check_a[i]:
    break
  check_a[i]=True
  i=nex
  c+=1
print(-1)

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

int main(){
	long long int A, B, C, ans;
	cin >> A >> B >> C;
	ans = B;				//B食べる
	if(B<=C){
		C -= B;		ans += B;	//Cの分
		if(A<=C){
			ans += A;		//C食べる
			if(C-A>0)	ans++;	//C一枚あったら食べる
		}
		else{
			ans += C;

		}
	}
	else{
		ans += C;
		//cout << ans << endl;
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
typedef long long ll;
using namespace std;
int main(){
    int R, G, B, N; cin >> R >> G >> B >> N;
    ll cnt = 0;
    for(int i=0; i<=N; i++)for(int j=0; j<=N-i; j++)if((N - i*R - j*G) % B == 0 && i*R + j*G <= N) cnt++;
    cout << cnt << endl;
    return 0;
}

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

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N);
    map<ll, ll> mp;
    mp[0]++;
    ll sum = 0;
    ll res = 0;
    rep(i, N) {
        cin >> A[i];
        sum += A[i];
        //if(A[i]%M == 0) res++;
        mp[sum%M]++;
    }

    
    for(auto& p: mp) {
        ll n = p.second;
        res += (n*(n-1))/2;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 200100
//#define NIL -1

int main() {
    int n;
    cin >> n;
    vector<LL> t(n, 0);
    vector<LL> c(n-1);
    vector<LL> s(n-1);
    vector<LL> f(n-1);

    for(int i=0; i<n-1; i++){
        cin >> c[i] >> s[i] >> f[i];
    }

    for(int i=0; i<n-1; i++){
        for(int j=0; j<=i; j++){
            if(s[i]>t[j]){
                t[j]=s[i];
            }else{
                if(t[j]%f[i]!=0){
                    t[j]+=(f[i]-t[j]%f[i]);
                }
            }
            t[j]+=c[i];
        }
        //for(int j=0; j<n; j++){
        //    cout << t[j] << endl;
        //}
    }

    for(int i=0; i<n; i++){
        cout << t[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<double,double> pdd;
#define SQ(i) ((i)*(i))
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) int(i.size())
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define TIME(i) Timer i(#i)
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define TIME(i)
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif
class Timer {
private:
    string scope_name;
    chrono::high_resolution_clock::time_point start_time;
public:
    Timer (string name) : scope_name(name) {
        start_time = chrono::high_resolution_clock::now();
    }
    ~Timer () {
        auto stop_time = chrono::high_resolution_clock::now();
        auto length = chrono::duration_cast<chrono::microseconds>(stop_time - start_time).count();
        double mlength = double(length) * 0.001;
        debug(scope_name, mlength);
    }
};

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
const ll K = 320000;


ll calc (ll n, ll b) {
    ll sum = 0;
    while (n) {
        sum += n % b;
        n /= b;
    }
    return sum;
}
/********** Good Luck :) **********/
int main()
{
    TIME(main);
    IOS();

    ll n, s;
    cin >> n >> s;
    ll ans = (n == s ? s + 1 : INF);
    REP (i, K) {
        if (i > 1 && calc(n, i) == s) {
            ans = min(ans, ll(i));
        }
    }

    REP1 (i, min(s, K)) {
        ll b = (n + i - s) / i;
        if (b > 1 && calc(n, b) == s) {
            ans = min(ans, b);
        }
    }

    cout << (ans == INF ? -1 : ans) << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import deque

def main():
    RoomNum,PathNum=map(int,input().split())

    G=[[] for _ in range(RoomNum)]

    for _ in range(PathNum):
        a,b=map(int,input().split())
        G[a-1].append(b-1)
        G[b-1].append(a-1)

    dist=[-1]*RoomNum
    que=deque([])
    dist[0]=0
    que.append(0)

    while len(que)>0:
        v=que.popleft()

        for i in G[v]: #vからつながっている頂点をすべて調べる
            if dist[i]!=-1: #すでに発見済み（キューに追加済み）は無視
                continue
            dist[i]=v #発見したら深さを更新するが今回は看板の数字
            que.append(i)

    if (-1 in dist): #未発見のものが残っているとき
        print("No")
    else:
        print("Yes")
        for i in dist[1:]:
            print(i+1)

if __name__=="__main__":
    main()







Measured memory_bytes: 34972
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
#define MXN 200005
int main(){
    int x,y;
    scanf("%d %d",&x,&y);
    if(x>=0&&y>=0){
        if(y>x){
            printf("%d\n",y-x);
        }
        else{
            printf("%d\n",x-y+1+(y!=0));
        }
    }
    else if(x<0&&y<0){
        if(y>x){
            printf("%d\n",y-x);
        }
        else{
            printf("%d\n",x-y+2);
        }
    }
    else if(x<0&&y>=0){
        printf("%d\n",abs(abs(x)-abs(y))+(y!=0));
    }
    else{
        printf("%d\n",abs(abs(x)-abs(y))+1);
    }

}
/*
1441152
*/

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    int ans = 0;
    if(a+b > 2*c){
        int num = min(x, y);
        x = x - num;
        y = y - num;
        ans = 2*c*num;
    }
    else{
        cout << a*x + b*y << endl;
        return 0;
    }
    if(a*x + b*y > 2*c*(x+y)) cout << ans + 2*c*(x+y) << endl;
    else cout << ans + a*x + b*y << endl;
    return 0;
}

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

int main(){
	int x, y, z;
	cin >> x >> y >> z;
	if (x >= y && y >= z){
	cout << z << " " << y << " " << x << endl;
	}
	else if (x >= z && z >= y){
	cout << y << " " << z << " " << x << endl;
	}
	else if (y >= x && x >= z){
	cout << z << " " << x << " " << y << endl;
	}
	else if (y >= z && z >= x){
	cout << x << " " << z << " " << y << endl;
	}
	else if (z >= x && x >= y){
	cout << y << " " << x << " " << z << endl;
	}
	else if (z >= y && y >= x){
	cout << x << " " << y << " " << z << endl;
	}

	return 0;
}


Measured memory_bytes: 3100
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

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

            long N = long.Parse(Console.ReadLine());
            var Xs = Console.ReadLine().Split(' ').Select(i => long.Parse(i));

            long sum1 = Xs.Aggregate(0L, (res, x) => res + x);
            long sum2 = Xs.Aggregate(0L, (res, x) => res + x*x);
            long P = (long)Math.Round(sum1 / ((double)N));
            Console.WriteLine(sum2 - 2 * sum1 * P + P * P*N);
            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/


signed main() {
	int a, b; cin >> a >> b;
	int ok = 0, ng = inf;
	while (ng - ok > 1) {
		int mid = (ok + ng) / 2;
		int b_ = b - mid * 2;
		b_ -= max(0LL, (mid - a) * 2);
		if (b_ >= 0)ok = mid;
		else ng = mid;
	}
	cout << ok << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader

fun main(args: Array<String>) {
    System.`in`.bufferedReader().use { println(getOutputString(it)) }
}

fun getOutputString(reader: BufferedReader): String {
    val results = reader.readLine().split(" ").map { (it.toInt() + 11) % 13 }

    return when {
        results[0] > results[1] -> "Alice"
        results[0] < results[1] -> "Bob"
        else -> "Draw"
    }
}

Measured memory_bytes: 26072
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  auto s = readln.chomp.split.map!(x=>x.toUpper);
  writefln("%s%s%s",s[0][0], s[1][0], s[2][0]);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n)
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

vector<int> a(26, 0);

int main()
{
    string s;
    cin>>s;
    REP(i,4) a[s[i]-'A']++;
    Yes(COUNT(a,2) == 2);

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
//#include<con>
using namespace std;
int c[4][4];
int main(){
    for(int i=1;i<=3;i++)
    for(int j=1;j<=3;j++)
    cin>>c[i][j];
    if
    (c[1][3]==c[3][3]-c[3][1]+c[1][1]&&c[1][2]==c[2][2]-c[2][1]+c[1][1]&&c[2][3]==c[3][3]-c[3][1]+c[2][1]&&c[3][2]==c[3][1]-c[2][1]+c[2][2])
    cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define print(v) for(auto &z:v) cout<<z<<' ';cout<<'\n'
#define hi cout<<'h'<<'i'<<'\n' 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define all(v) v.B,v.E
#define sz(v) (int)((v).size())
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define clk1 clock_t start_time=clock()
#define clk2 cout<<(clock()-start_time)/(double)CLOCKS_PER_SEC
#define clean(arr) memset(arr,0,sizeof(arr))
#define mod 1000000007
#define mod2 998244353
#define mx 2450
//<<fixed << setprecision(9)


struct edge
{
    int v,wt,cost;
};
vector<edge> G[55];
int main()
{
    int n,i,j,t;
    boost;

    int m,s;
    cin>>n>>m>>s;
    s=min(s,mx);
    rep(i,0,m)
    {
        int u,v;
        edge e;
        cin>>u>>v>>e.cost>>e.wt;
        e.v=v;
        G[u].pb(e);
        e.v=u;
        G[v].pb(e);
    }
    rep(i,1,n+1)
    {
        int c,d;
        cin>>c>>d;
        edge e={i,d,-c};
        G[i].pb(e);
    }

    priority_queue<pair<ll,pii>> pq;
    pq.push({0,{1,s}});
    ll best[n+1][mx+1];

    rep(i,1,n+1)
    {
        rep(j,0,mx+1)best[i][j]=LLONG_MAX;
    }
    best[1][s]=0;
    while(!pq.empty())
    {
        ll tm=-pq.top().F;
        int u=pq.top().S.F,silver=pq.top().S.S;
        pq.pop();
        if(tm>best[u][silver])continue;

        for(auto &e:G[u])
        {
            if(e.cost<0)
            {
                int s=min(mx,silver-e.cost);
                if(best[e.v][s]>tm+e.wt)
                {
                    best[e.v][s]=tm+e.wt;
                    pq.push({-(tm+e.wt),{e.v,s}});
                }
            }
            else if(silver>=e.cost)
            {
                if(best[e.v][silver-e.cost]>tm+e.wt)
                {
                    best[e.v][silver-e.cost]=tm+e.wt;
                    pq.push({-(tm+e.wt),{e.v,silver-e.cost}});
                }
            }
        }
    }
    rep(i,2,n+1)
    {
        ll mn=LLONG_MAX;
        rep(j,0,mx+1)mn=min(mn,best[i][j]);
        cout<<mn<<'\n';
    }
    return 0;
}



Measured memory_bytes: 6256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using static System.Math;

namespace CSharpSpiral {
	class Program {
		public static void Main(string[] args) {
			var sw = new StreamWriter(Console.OpenStandardOutput()) {
				AutoFlush=
#if DEBUG
			true
#else
			false
#endif
			};
			Console.SetOut(sw);
			new Program().Solve(new ConsoleInput(
#if DEBUG
			new StreamReader("../../../inputData.txt")
#else
			Console.In
#endif
			, ' '));
			Console.Out.Flush();
		}
		public void Solve(ConsoleInput cin) {
			var datum = cin.ReadIntArray(3);
			int L = datum[0], R = datum[1], d = datum[2];
			Console.WriteLine(Enumerable.Range(L, R-L+1).Count(i => i%d==0));
		}

	}

	static class ExtendClass {
		public static string Join<T>(this IEnumerable<T> X, string separator = " ")
			=> string.Join(separator, X);
	}
	class ConsoleInput {
		private readonly TextReader _stream;
		private readonly char _separator = ' ';
		private readonly Queue<string> inputStream;
		public ConsoleInput(TextReader stream, char separator = ' ') {
			this._separator=separator;
			this._stream=stream;
			inputStream=new Queue<string>();
		}
		public string Read {
			get {
				if(inputStream.Count!=0) return inputStream.Dequeue();
				string[] tmp = _stream.ReadLine().Split(_separator);
				for(int i = 0; i<tmp.Length; ++i)
					inputStream.Enqueue(tmp[i]);
				return inputStream.Dequeue();
			}
		}
		public string ReadLine { get { return _stream.ReadLine(); } }
		public int ReadInt { get { return int.Parse(Read); } }
		public long ReadLong { get { return long.Parse(Read); } }
		public double ReadDouble { get { return double.Parse(Read); } }
		public string[] ReadStrArray(long N) {
			var ret = new string[N];
			for(long i = 0; i<N; ++i)
				ret[i]=Read;
			return ret;
		}
		public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i<N; ++i) ret[i]=ReadInt; return ret; }
		public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i<N; ++i) ret[i]=ReadLong; return ret; }
		public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i<N; ++i) ret[i]=ReadDouble; return ret; }
		public bool isEOF {
			get { return _stream.Peek()==-1; }
		}
	}
	
}


Measured memory_bytes: 28204
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < n; ++i)
#define FORR(i, m, n) for (ll i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string a,b;cin >> a >> b;
    int n=a.size(),m=b.size();
    if(n>m){
        cout << "GREATER" << endl;
    }
    else if(n<m){
        cout << "LESS" << endl;
    }
    else{
        REP(i,n){
            int p=a[i]-'0';
            int q=b[i]-'0';
            if(p>q){
                cout << "GREATER" << endl;
                return 0;
            }
            if(p<q){
                cout << "LESS" << endl;
                return 0;
            }
        }
        cout << "EQUAL" << endl;
    }
}

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

void z_algorithm(int *s,int *z,int n){
    int c=0;
    for(int i=1;i<n;i++){
        if(i+z[i-c]<c+z[c]){
            z[i]=z[i-c];
        }else{
            int j=max(0,c+z[c]-i);
            while(i+j<n&&s[j]==s[i+j])j++;
            z[i]=j;
            c=i;
        }
    }
    z[0]=n;
}

int n;
int a[200005];
int b[200005];
int s[600005];
int z[600005];

int main(){

    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",a+i);
    for(int i=0;i<n;i++)scanf("%d",b+i);
    a[n]=a[0];
    b[n]=b[0];
    for(int i=0;i<n;i++){
        s[i]=b[i]^b[i+1];
        s[i+n]=s[i+(n<<1)]=a[i]^a[i+1];
    }
    z_algorithm(s,z,n*3);
    for(int i=n;i<n<<1;i++){
        if(z[i]>=n)printf("%d %d\n",i-n,a[i-n]^b[0]);
    }

    return 0;
}

Measured memory_bytes: 9728
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(void){
	int h=-1, w=-1;


	char tmp='.';
	cin >> h >> w;
	while (h != 0 && w != 0){
		
		for (int i = 1; i <= h; i++){
			if (i % 2 != 0){ tmp = '#'; }
			else{ tmp = '.'; }
			for (int s = 0; s < w; s++){
				cout << tmp;
				if (tmp == '#'){ tmp = '.'; }
				else{ tmp = '#'; }
				
			}
			cout << endl;
		}
		cout << endl;
		cin >> h >> w;	
	}

	return 0;
}

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

int main()
{
  int n;
  cin >> n;
  
  if (n == 1) {
    cout << "Hello World" << endl;
  }
  else if (n == 2) {
    int a, b;
    cin >> a >> b;
    cout << a+b << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

void sort(int *data)
{
	int i,j,tmp;

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

int main()
{
	int card[5];
	int count[5];
	int i,j,flg4,flg3,flg2,flgst;
	char hand[11];

	while(scanf("%d,%d,%d,%d,%d",card,card+1,card+2,card+3,card+4)!=EOF)
	{
		for(i=0;i<5;i++)
		{
			count[i]=0;
		}
		strcpy(hand,"null");
		flg4=0;flg3=0;flg2=0;flgst=1;

		for(i=0;i<5;i++)
		{
			for(j=i;j<5;j++)
			{
				if(card[i]==card[j])
				{
					count[j]++;
				}
			}
		}
		
		for(i=0;i<5;i++)
		{
			if(count[i]==4)
			{
				flg4=1;
			}
			else if(count[i]==3)
			{
				flg3=1;
			}
			else if(count[i]==2)
			{
				flg2++;
			}
		}

		if(flg4)
		{
			strcpy(hand,"four card");
		}
		else if(flg3)
		{
			if(flg2==2)
			{
				strcpy(hand,"full house");
			}
			else
			{
				strcpy(hand,"three card");
			}
		}
		else if(flg2)
		{
			if(flg2==2)
			{
				strcpy(hand,"two pair");
			}
			else
			{
				strcpy(hand,"one pair");
			}
		}
		else
		{
			sort(card);

			for(i=1;i<5;i++)
			{
				if(card[i]!=card[0]+i)
				{
					flgst=0;
				}
			}
			if(!flgst&&card[0]==1)
			{
				flgst=1;			
				for(i=1;i<5;i++)
				{
					if(card[i]!=card[0]+i+8)
					{
						flgst=0;
					}
				}
			}
			if(flgst)
			{
				strcpy(hand,"straight");
			}
			else
			{
				strcpy(hand,"null");
			}
		}
		puts(hand);
	}
	return 0;
}

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

ll i;
ll num;
double ans;
ll A,B,N;
ll jpy[1000];
float 	bit[1000];
float money;
string S,T;

int main()
{
	cin>>N;
	for(i=0;i<N;i++){
		cin>>money;
		cin>>S;
		if(S=="JPY") ans+=(money*1.0);
		else ans+=(money*380000.0);

	}
	printf("%lf",ans);
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var par, nc []int

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	as := make([]int, m)
	bs := make([]int, m)
	for i := range as {
		sc.Scan()
		as[i], _ = strconv.Atoi(sc.Text())
		as[i]--
		sc.Scan()
		bs[i], _ = strconv.Atoi(sc.Text())
		bs[i]--
	}

	par = make([]int, n)
	nc = make([]int, n)
	for i := range par {
		par[i] = i
		nc[i] = 1
	}

	ans := make([]int, m)
	p := n * (n - 1) / 2
	for i := m - 1; i >= 0; i-- {
		a, b := as[i], bs[i]
		ans[i] = p
		if !same(a, b) {
			p -= nc[root(a)] * nc[root(b)]
		}
		unite(a, b)
	}
	for i := range ans {
		fmt.Println(ans[i])
	}
}

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

func unite(x, y int) {
	rx := root(x)
	ry := root(y)
	if rx == ry {
		return
	}
	par[rx] = ry
	nc[ry] += nc[rx]
	nc[rx] = 0
}

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

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 8184
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int arr[2005];
int main()
{
	int n,k,q,ans=1e9;
	scanf("%d%d%d",&n,&k,&q);
	for (int i=0;i<n;i++)
	scanf("%d",&arr[i]);
	for (int i=0;i<n;i++)
	{
		int l=-1;
		vector<int> v;
		for (int j=0;j<=n;j++)
		{
			if (arr[j]<arr[i])
			{
				vector<int> tmp;
				for (int m=l+1;m<j;m++)
				tmp.push_back(arr[m]);
				sort(tmp.begin(),tmp.end());
				for (int m=0;m<=(int)tmp.size()-k;m++)
				v.push_back(tmp[m]);
				l=j;
			}
		}
		if (v.size()>=q)
		{
			sort(v.begin(),v.end());
			ans=min(ans,v[q-1]-v[0]);
		}
	}
	printf("%d",ans);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define INF 1e10
#define MOD 1e9+7
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; }
using Graph = vector<vector<int>>;
signed main(){
  int a;
  cin>>a;
  vector<int> b(a),c(a);
  rep(i,a)
    cin>>b[i];
  rep(i,a)
    c[i]=b[i];
  sort(all(c));
  int d=c[a-1];
  int e=c[a-2];
  rep(i,a){
  if(b[i]==d)
    cout<<e<<endl;
    else
      cout<<d<<endl;
    }
}

Measured memory_bytes: 4736
#include<stdio.h>

int main(void)
{
	int n,q,i,l,r,j,t=0,ans=0;
	char s[100001]={0};
	int a[100001];
	scanf("%d%d%s",&n,&q,s);
	for(i=1;i<=n-1;i++){
		if(s[i-1]=='A'&&s[i]=='C')
			t++;
		a[i]=t;
	}
	for(i=0;i<q;i++){
		scanf("%d%d",&l,&r);
		ans=a[r-1]-a[l-1];
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <vector>

using namespace std;

int main()	{
  int w, h, n;
  cin >> w >> h >> n;
  int x;
  int y;
  int a;
  int xmin = 0, ymin = 0;
  int xmax = w, ymax = h;
  for (int i = 0; i < n; i++)	{
    cin >> x >> y >> a;
    switch(a)	{
      case 1: xmin = max(xmin, x);
        	break;
      case 2: xmax = min(xmax, x);
        	break;
      case 3: ymin = max(ymin, y);
        	break;
      case 4: ymax = min(ymax, y);
        	break;
    }
  }
  if (xmin >= xmax || ymin >= ymax)	{
  	cout << 0 << endl;
    return 0;
  }
  cout << (xmax - xmin) * (ymax - ymin) << endl;
  return 0;
}

Measured memory_bytes: 256
using System.Collections.Generic;
using System.Linq;
using System;
using static System.Console;

class Program
{
  static void Main() => new Program().solve();

  void solve()
  {
    var param = ReadLine().Split(' ').Select(int.Parse).ToArray();
    var n = param[0];
    var m = param[1];

    var d = Enumerable.Range(0, n)
      .Select(_ => ReadLine().Split(' ').Select(long.Parse).ToArray())
      .OrderBy(e => e[0])
      .ToArray();

    var acc = 0L;
    var cnt = 0L;
    foreach(var e in d)
    {
      if(cnt + e[1] >= m)
      {
        acc += e[0] * (m - cnt);
        break;
      }

      cnt += e[1];
      acc += e[0] * e[1];
    }

    var ans = acc;
    WriteLine(ans);
  }
}

Measured memory_bytes: 27972
using System;

class Program
{
    static void Main()
    {
            int i;
            int[] hart = new int[13];
            int[] club = new int[13];
            int[] spade = new int[13];
            int[] dia = new int[13];
            for (i = 0; i < 13; i++)
            {
                hart[i] = 0;
                club[i] = 0;
                spade[i] = 0;
                dia[i] = 0;
            }
            string len = Console.ReadLine();
            string[] mark = new string[int.Parse(len)];
            int[] number = new int[int.Parse(len)];
            for (i = 0; i < int.Parse(len); i++)
            {
                string inp = Console.ReadLine();
                string[] card = inp.Split(' ');
                mark[i] = card[0];//マーク
                number[i] = int.Parse(card[1]);//数字
                switch (mark[i])
                {
                    case "H":
                        hart[number[i]-1] = 1;
                        break;
                    case "C":
                        club[number[i]-1] = 1;
                        break;
                    case "S":
                        spade[number[i]-1] = 1;
                        break;
                    case "D":
                        dia[number[i]-1] = 1;
                        break;
                }
            }//shcd
            for (i = 0; i < 13; i++)
            {
                if (spade[i] == 0)
                {
                    Console.WriteLine("S {0}",i + 1);
                }
            }
            for (i = 0; i < 13; i++)
            {
                if (hart[i] == 0)
                {
                    Console.WriteLine("H {0}", i + 1);
                }
            }
            for (i = 0; i < 13; i++)
            {
                if (club[i] == 0)
                {
                    Console.WriteLine("C {0}", i + 1);
                }
            }
            for (i = 0; i < 13; i++)
            {
                if (dia[i] == 0)
                {
                    Console.WriteLine("D {0}", i + 1);
                }
            }
    }
}


Measured memory_bytes: 9232
package main

import (
	"math/rand"
	"time"
	"os"
	"bufio"
	"fmt"
	"strconv"
)

var(
	inf = 10000000071000000
	stdin = bufio.NewReader(os.Stdin)
	mod = 1000000007
	mod9 = 1000000009
	//////////////////////////////////
	stack []byte
)

func init()  {
	rand.Seed(time.Now().UnixNano())
}


func main() {
	n,_ := goint(),goint()
	a := intLine(n,0)
	maxa := make([]int,n)
	//mina := make([]int,n)
	ma := 0//;mi := inf
	for i:=n-1;i>=0;i--{
		v := a[i]
		ma = max(ma,v)
		//mi = min(mi,v)
		maxa[i] = ma
		//mina[i] = mi
	}
	maxdiff := 0
	for i:=0;i<n;i++{
		maxdiff = max(maxdiff,maxa[i]-a[i])
	}
	count := 0
	for i:=0;i<n;i++{
		if maxdiff == (maxa[i] - a[i]){
			count++
		}
	}
	fmt.Println(count)
}

func solv(s []byte) {

}

//||||||||||||||||||||||||||入力|||||||||||||||||||||||||||||||||||||||

//次のスペースか改行まで読み込む
func gostring() string {
	byte_ls := make([]byte,0)
	for  {
		b, _ := stdin.ReadByte()
		if b == 32 || b == 10 || b == 0{
			return string(byte_ls)
		} else if b == 13 {
			continue
		} else {
			byte_ls = append(byte_ls,b)
		}
	}
}

//上の関数のintバージョン
func goint() int {
	n,_ := strconv.Atoi(gostring())
	return n
}

//数字一行
func intLine(n ,a int) []int {
	ls := make([]int,n)
	for i,_ := range ls{
		ls[i] = goint() + a
	}
	return ls
}

//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

func sum(a ...int) int {
	ans := 0
	for i:=0;i<len(a);i++{
		ans += a[i]
	}
	return ans
}

func min(a ...int) int {
	ans := a[0]
	for i:=1;i<len(a);i++{
		if ans > a[i]{
			ans = a[i]
		}
	}
	return ans
}

func abs(n int) int {
	if n >= 0{
		return n
	} else {
		return -n
	}
}

func max(a ...int) int {
	ans := a[0]
	for i:=1;i<len(a);i++{
		if ans < a[i]{
			ans = a[i]
		}
	}
	return ans
}

func intList(n,k int) []int {
	ls := make([]int,n)
	for i:=0;i<n;i++{
		ls[i] = k
	}
	return ls
}

Measured memory_bytes: 5504
function Main(input) {
  "use strict"
  const temp = input.split("\n")[0].split(" ");

  const a = parseInt(temp.shift());
  const b = parseInt(temp.shift());

  const a_min = Math.ceil(a * 12.5)
  const a_max = Math.ceil(a * 12.5 + 11.5)
  const b_min = Math.ceil(b * 10)
  const b_max = Math.ceil(b * 10 + 9)
  
  if(a_max < b_min || b_max < a_min) console.log(-1)
  else console.log(Math.max(a_min, b_min))
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 11468
N, M = map(int, input().split())
start = 0
if N == 1:
    start = 0
elif N == 2:
    start = 10
else:
    start = 100
N = str(N)

sc = [list(input().split()) for _ in range(M)]

for i in range(start, 1000):
    ansF = True
    for j in range(M):
        if str(i)[int(sc[j][0]) - 1] != sc[j][1]:
            ansF = False
            break
    if ansF:
        print(i)
        exit()

print(-1)

Measured memory_bytes: 3064
n = int(input())
D = list(map(int, input().split()))
m = int(input())
T = list(map(int, input().split()))

d1 = {}
for d in D:
    if d not in d1:
        d1[d] = 1
    else:
        d1[d] += 1
d2 = {}
for t in T:
    if t not in d2:
        d2[t] = 1
    else:
        d2[t] += 1

for k2, v2 in d2.items():
    if k2 not in d1:
        print('NO')
        exit()
    else:
        v1 = d1[k2]
        if v1 < v2:
            print('NO')
            exit()
else:
    print('YES')


Measured memory_bytes: 56672
import math
input()
L = list(map(int, input().split()))
m = [ [] for x in range(len(L))]
for i in range(len(L)):
    n = L[i]
    k = n
    for j in range(2, int(math.sqrt(n))+1):
        if j > k:
            break
        while k % j ==0:
            m[i].append(j)
            k = k // j
            if k == 1:
                break
    if k != 1:
        m[i].append(k)
s = set()
for i in m:
    s |= set(i)
lcm = 1
for i in s:
    lcm *= i**max([ m[x].count(i) for x in range(len(L))] )
print(lcm)



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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl
#define DOUBLE(d) cout << fixed << setprecision(15) << (d) << endl

int main() {
    int a, b, h;
    cin >> a >> b >> h;
    cout << (a+b)*h/2 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<cstdio>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int MAXN = 101, MAXK = 0, T = 1, C = 2, B = 3, TT = 4, CC = 5, BB = 6;

int dp[MAXN][7], UB = 10000;
int sou[MAXN];

int dif1[] = {0, C, B, T, CC, BB, TT};
int dif2[] = {0, B, T, C, BB, TT, CC};

int main()
{
    memset(dp, 0, sizeof(dp));
    memset(sou, 0, sizeof(sou));


    int n, k;
    cin >> n >> k;
    int a, b;
    REP(k){ cin >> a >> b; sou[a - 1] = b;}

    if(sou[0] == 0) dp[0][T] = dp[0][C] = dp[0][B] = 1;
    else dp[0][sou[0]] = 1;

    REP(n)
    {
        if(sou[i+1] == 0)
        {
            dp[i+1][T] = (dp[i][B] + dp[i][BB] + dp[i][C] + dp[i][CC]) % UB;
            dp[i+1][C] = (dp[i][B] + dp[i][BB] + dp[i][T] + dp[i][TT]) % UB;
            dp[i+1][B] = (dp[i][T] + dp[i][TT] + dp[i][C] + dp[i][CC]) % UB;
            dp[i+1][TT] = dp[i][T];
            dp[i+1][CC] = dp[i][C];
            dp[i+1][BB] = dp[i][B];
        }
        else
        {
            dp[i+1][sou[i+1]] = 
                (dp[i][dif1[sou[i+1] ] ] + dp[i][dif2[sou[i+1] ] ] 
                 + dp[i][dif1[sou[i+1] + 3]] + dp[i][dif2[sou[i+1] + 3]] ) % UB;
            dp[i+1][sou[i+1] + 3] = dp[i][sou[i+1]];
        }
    }
    int ans = 0;
    REP(6) ans = (ans + dp[n - 1][i + 1] ) % UB;
    //rep(j,n)REP(6) cout<<j<< " thday "  << i <<"th sourse " << dp[j][i+1] << endl;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1164