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

constexpr int INF = 1e9;

int main() {
    int n, m, l, s, t;
    while(cin >> n >> m >> l >> s >> t, n) {
        s--;
        vector<vector<int>> d(n, vector<int>(n, INF));
        for(int i=0; i<n; ++i) {
            d[i][i] = 0;
        }
        for(int i=0; i<m; ++i) {
            int a, b, c;
            cin >> a >> b >> c;
            a--; b--;
            d[a][b] = d[b][a] = c;
        }
        for(int k=0; k<n; ++k) {
            for(int i=0; i<n; ++i) {
                for(int j=0; j<n; ++j) {
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
                }
            }
        }
        vector<int> rp(l), e(l);
        for(int i=0; i<l; ++i) {
            cin >> rp[i] >> e[i];
            rp[i]--;
        }

        vector<vector<int>> dp(1 << l, vector<int>(l, INF));
        for(int i=0; i<l; ++i) {
            dp[1 << i][i] = d[s][rp[i]];
        }
        for(int S=1; S<(1<<l); ++S) {
            for(int i=0; i<l; ++i) {
                for(int j=0; j<l; ++j) {
                    if((S >> j) & 1) {
                        continue;
                    }
                    int nS = S | (1 << j);
                    dp[nS][j] = min(dp[nS][j], dp[S][i] + d[rp[i]][rp[j]]);
                }
            }
        }
        int res = 0;
        for(int S=0; S<1<<l; ++S) {
            int sum = INF;
            for(int i=0; i<l; ++i) {
                sum = min(sum, dp[S][i] + d[rp[i]][s]);
            }
            for(int i=0; i<l; ++i) {
                if((S >> i) & 1) {
                    sum += e[i];
                }
            }
            if(sum <= t) {
                res = max(res, __builtin_popcount(S));
            }
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 9908
import java.util.Scanner;

/**
 * ZAKIREN第5章
 *
 * @author K.Yamauchi
 *
 */
public class Main {

	/** 入力用 */
	private static Scanner scan = new Scanner(System.in);

	/** 出力用 */
	private static StringBuilder stringBuilder = new StringBuilder();

	/**
	 *
	 * @param args
	 */
	public static void main(String[] args) {

		int n = scan.nextInt(); // 要素数

		// ソート対象配列の読み込み
		int[] targetArray = new int[n];
		for (int i = 0; i < n; i++) {
			targetArray[i] = scan.nextInt();
		}

		// 読み込み終了
		scan.close();
		scan = null;

		// シェルソートを実行
		shellSort(targetArray, n);

		// 結果出力
		for (int i = 0; i < targetArray.length; i++) {
			stringBuilder.append(targetArray[i]);
			stringBuilder.append('\n');
		}		System.out.print(stringBuilder.toString());

	}

	/**
	 *
	 * @param array
	 * @param number
	 * @param g
	 * @param cnt
	 * @return
	 */
	private static int insertionSort(int[] array, int number, int g) {

		// gからn-1まで
		int cnt = 0;
		for (int i = g, j = 0; i < number; i++) {
			int temp = array[i];
			j = i - g;

			// 自分より大きいやつが見つかるまで
			while (j >= 0 && array[j] > temp) {
				array[j + g] = array[j];
				j = j - g;
				cnt++;
			}
			array[j + g] = temp;
		}
		return cnt;
	}

	/**
	 *
	 * @param array
	 * @param number
	 */
	private static void shellSort (int[] array, int number) {

		// Gの準備
		int[] G = new int[15];

		int gSize = 0;
		for (int i = 1; i <= number; i = i * 3 + 1) {
			// 3g + 1
			G[gSize++] = i;
		}

		// ソートしながら結果出力
		int cnt = 0;
		stringBuilder.append(gSize);
		stringBuilder.append('\n');
		for (int i = gSize - 1; i >= 0 ; i--) {
			stringBuilder.append(G[i]);
			if (i != 0)
				stringBuilder.append(' ');
			cnt += insertionSort(array, number, G[i]);
		}
		G = null;

		// 結果出力
		stringBuilder.append('\n');
		stringBuilder.append(cnt);
		stringBuilder.append('\n');
	}
}



Measured memory_bytes: 299160
s = input()
ans = 0
for i in range(len(s)):
    for j in range(i, len(s) + 1):
        if s[i:j].count('A') + s[i:j].count('C') + s[i:j].count('G') + s[i:j].count('T') == len(s[i:j]):
            ans = max(ans, len(s[i:j]))
print(ans)

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef vector<xy_t> polygon;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, PP> PPP;
typedef pair<string, int> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 29;
const double EPS = 1e-10;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
#define repD(i, n) for(int i = n; i >= 0; i--)

char field[30][30];
bool memo[30][30][20][4];

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

void doit(int x, int y, int& num, int& d, queue<PPP> &que){
	char c = field[y][x];
	if(c == '<'){
		d = 2;
	}else if(c == '>'){
		d = 0;
	}else if(c == '^') {
		d = 3;
	}else if(c == 'v'){
		d = 1;
	}else if(c == '_'){
		if(num == 0) d = 0;
		else d = 2;
	}else if(c == '|'){
		if(num == 0) d = 1;
		else d = 3;
	}else if(c == '?'){
		int x2, y2;
		for(int d2 = 0; d2 < 4; d2++){
			x2 = (x + dx[d2] + m) % m;
			y2 = (y + dy[d2] + n) % n;
			if(!memo[x2][y2][num][d2]){
				memo[x2][y2][num][d2] = true;
				que.push(PPP(d2, PP(num, P(x2, y2))));
			}
		}
		return;
	}else if(isdigit(c)){
		num = c - '0';
	}else if(c == '+'){
		num = (num + 1) % 16;
	}else if(c == '-'){
		num = (num + 15) % 16;
	}
	x = (x + dx[d] + m) % m;
	y = (y + dy[d] + n) % n;
	if(!memo[x][y][num][d]){
		memo[x][y][num][d] = true;
		que.push(PPP(d, PP(num, P(x, y))));
	}
}

int main(){
	int x, y, d, num;
	cin >> n >> m;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			cin >> field[i][j];
		}
	}
	x = 0, y = 0, d = 0, num = 0;
	memset(memo, false, sizeof(memo));
	memo[0][0][0][0] = true;
	queue<PPP> que;
	que.push(PPP(d, PP(num, P(x, y))));
	while(!que.empty()){
		PPP ppp = que.front();
		que.pop();
		d = ppp.first;
		num = ppp.second.first;
		x = ppp.second.second.first;
		y = ppp.second.second.second;
		if(field[y][x] == '@'){
			cout << "YES" << endl;
			return 0;
		}
		doit(x, y, num, d, que);
	}
	cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>

int main(void){

	double a,b,c,d,e,f;
	double x,y;
	
	 while (scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f) != EOF) {
        y = (c * d - a * f) / (b * d - a * e);
        x = (c - b * y) / a;
		x = (double)((int)(x * 10000)/10)/1000;
		y = (double)((int)(y * 10000)/10)/1000;

	 	printf("%.3lf %.3lf\n", x, y);

	}
	return 0;
}

Measured memory_bytes: 652
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
#define rint register int
#define rep(i,l,r) for(rint i=l;i<=r;i++)
#define per(i,l,r) for(rint i=l;i>=r;i--)
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define fir first
#define sec second
#define mset(s,t) memset(s,t,sizeof(s))
template<typename T1,typename T2>void ckmin(T1 &a,T2 b){if(a>b)a=b;}
template<typename T1,typename T2>void ckmax(T1 &a,T2 b){if(a<b)a=b;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
int read(){
  int x=0,f=0;
  char ch=getchar();
  while(!isdigit(ch))f|=ch=='-',ch=getchar();
  while(isdigit(ch))x=10*x+ch-'0',ch=getchar();
  return f?-x:x;
}
const int N=100005;
int f[N];
int n,m;
int find(int x){
  return f[x]==x?x:f[x]=find(f[x]);
}
int main(){
  n=read(),m=read();
  for(int i=1;i<=n;i++){
    f[i]=i;
  } 
  int ans=n;
  while(m--){
    int u=read(),v=read();
    u=find(u),v=find(v);
    if(u!=v){
      ans--;
      f[u]=v;
    }
  }
  printf("%d\n",max(0,ans-1));
  
}

Measured memory_bytes: 4048
#include<bits/stdc++.h>
using namespace std;
#define mne 10000000000000000
long long a[201010], n,b[201010], mn = mne, x;

int main(){
cin >> n;
b[0]=0;
for(int i =1; i<=n; i++){
    cin >> a[i];
    b[i]=a[i]+b[i-1];
}
for(int i =1; i<=n-1; i++){
    x = abs(2*b[i] - b[n]);
    mn = min(x, mn);
}
cout << mn << endl;


return 0;}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define Int long long
#define rep(i,n) for(int i=0; i<n; ++i)
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  int N; cin >> N;
  cout << ((1+N)*N)/2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main(void){
    
  int a,b;
  cin>>a;   cin>>b;
  
  if(a<b){cout<<"a < b";
  } else if(a>b){ cout<<"a > b";
  }else {cout<<"a == b";
  }
  cout<<endl;
  
}


Measured memory_bytes: 3104
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
using namespace std;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int k,m,n;
char c[50010];
bool check(int x,int y,int z){
	int flag[4];
	memset(flag,0,sizeof(flag));
	flag[0]=1;
	for(register int i=1;i<=n;i++){
		if(c[i]-'0'==z && flag[2])return true;
		if(c[i]-'0'==y && flag[1]){flag[2]=1;continue;}
		if(c[i]-'0'==x && flag[0])flag[1]=1;
	}
	return false;
}

int main(){
	n=read();
	scanf("%s",c+1);
	int ans=0;
	for(register int i=0;i<=9;i++){
		for(register int j=0;j<=9;j++){
			for(register int k=0;k<=9;k++){
				if(check(i,j,k))ans++;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <map>
#include <algorithm>
#include <functional>
#include <set>

using namespace std;

int main() {
    int n, m, a, b, d = 1, ans = 0;
    scanf("%d%d", &n, &m);
    map< int, multiset<int, greater<int> > > v;
    multiset< int, greater<int> > p;
    for (int i = 0; i < n; ++i) {
        scanf("%d%d", &a, &b);
        v[a].insert(b);
    }
    for (auto i = v.begin(); d <= m; ++d) {
        if ((*i).first == d) {
            for (auto j = (*i).second.begin(); j != (*i).second.end(); ++j) p.insert(*j);
            ++i;
        }
        if (!p.empty()) ans += *p.begin(), p.erase(p.begin());
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 14208
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

int main() {

	int a[151][151] = {};

	for (int i = 1; i <= 150; i++) {
		for (int j = i + 1; j <= 150; j++) {
			a[i][j] = i*i + j*j;
		}
	}

	for (int h, w; cin >> h >> w && h && w;) {
		int m = 150 * 150 + 150 * 150;
		int n = h*h + w*w;
		int H, W;
		for (int i = 150; i >= 1; i--) {
			for (int j = i + 1; j <= 150; j++) {
				if (m >= a[i][j] && a[i][j] >= n && !(i == h&&j == w)) {
					if (a[i][j] == n&&i < h)continue;
					m = a[i][j];
					H = i; W = j;
				}
			}
		}
		cout << H << " " << W << endl;
	}
	return 0;
}

Measured memory_bytes: 1256
N = gets.to_i
as = gets.split.map(&:to_i)
ans = 0
61.times do |i|
    cnt = 0
    N.times do |j|
        cnt += 1 if as[j][i] == 1 
    end
    ans += (cnt)*(N-cnt)*(1<<i)
    ans %= 1000000007
end
puts ans


Measured memory_bytes: 36868
#include<cstdio>
using namespace std;
int n,K;
bool p1[10];
bool pd(int k)
{
	while (k)
	{
		if (p1[k%10]) return false;
		k/=10;
	}
	return true;
}
int main()
{
	scanf("%d%d",&n,&K);
	for (int i=1,t;i<=K;i++)
	{
		scanf("%d",&t);
		p1[t]=true;
	}
	for (int i=n;i<=100000;i++)
	{
		if (pd(i))
		{
			printf("%d",i);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;

class Solver {

    private final int[] students;

    Solver(Scanner in){
        int N = in.nextInt();
        students = new int[N];
        for (int i = 0; i < N; i++) {
            students[in.nextInt() - 1] = i + 1;
        }
    }

    void solve() {
        System.out.println(Arrays.stream(students).mapToObj(String::valueOf).collect(Collectors.joining(" ")));
    }
}

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

        new Solver(in).solve();

        in.close();
    }
}

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

using namespace std;
typedef long long ll;

const int N = 1000;
bool board[N][N];
typedef pair<int, int> pii;
int d[N][N];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    int n, m, k;
    cin >> n >> m >> k;
    pii pos;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < m; j++) {
            if (s[j] == 'S') {
                pos = {i, j};
                board[i][j] = true;
            } else if (s[j] == '.') {
                board[i][j] = true;
            }
        }
    }
    queue<pii> q;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            d[i][j] = 1e9;
        }
    }
    q.push(pos);
    d[pos.first][pos.second] = 0;
    while (!q.empty()) {
        auto p = q.front();
        q.pop();
        int x = p.first;
        int y = p.second;
        if (x > 0 && board[x - 1][y]) {
            if (d[x - 1][y] > d[x][y] + 1) {
                d[x - 1][y] = d[x][y] + 1;
                q.push({x - 1, y});
            }
        }
        if (x < n - 1 && board[x + 1][y]) {
            if (d[x + 1][y] > d[x][y] + 1) {
                d[x + 1][y] = d[x][y] + 1;
                q.push({x + 1, y});
            }
        }
        if (y > 0 && board[x][y - 1]) {
            if (d[x][y - 1] > d[x][y] + 1) {
                d[x][y - 1] = d[x][y] + 1;
                q.push({x, y - 1});
            }
        }
        if (y < m - 1 && board[x][y + 1]) {
            if (d[x][y + 1] > d[x][y] + 1) {
                d[x][y + 1] = d[x][y] + 1;
                q.push({x, y + 1});
            }
        }
    }
    int res = 1e9;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (d[i][j] <= k) {
                int tmp = min(i, n - 1 - i);
                tmp = min(tmp, min(j, m - 1 - j));
                res = min(res, (tmp + k - 1) / k);
            }
        }
    }
    cout << res + 1 << endl;
    return 0;
}


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

//const int M[6]= {};

const int maxn = 3e4+19;


int f[maxn][11], f1[maxn][11];

int res[maxn];

int main() {
//	freopen("inp.txt", "r", stdin);
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n = 0;
	cin >> n;
	string s;
	cin >> s;
	for(int i=0;i<n;i++) s[i] -= '0';
	f[0][s[0]] = 1;
	for(int i=1;i<n;i++) {
		for(int j=0;j<10;j++) {
			f[i][j] = f[i - 1][j];
		}
		
		f[i][s[i]] ++;
	}
	
	for(int i=n-1;i>=0;i--) {
		for(int j=0;j<10;j++) {
			f1[i][j] = f1[i+1][j];
		}
		f1[i][s[i]] ++;
	}
	
	
	for(int i=1;i<n-1;i++) {
		for(int j=0;j<10;j++) {
			for(int k=0;k<10;k++) {
				if (f[i-1][j] && f1[i+1][k]) {
					int t = (j * 100 + s[i] * 10 + k);
					res[t] = 1;
				}
			}
		}
	}
	
	int ans = 0;
	for(int i=0;i<1000;i++) ans += res[i];
	
	cout << ans;
	return 0;
}


Measured memory_bytes: 2944
#include<iostream>

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

using namespace std;
using ll = long long;

int main()
{
    // 整数の入力
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    
    while(a > 0 && b > 0){       
        c-=b;
        if(c <= 0){ cout << "Yes"<< endl; break;}
        a-=d;
        if(a <= 0){ cout << "No"<< endl; break;}
    }
    
    
    return 0;
}


Measured memory_bytes: 3592
using System;
using System.Collections;
using System.Collections.Generic;

class Program
{
    public static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        int[] V = new int[N];
        var s = Console.ReadLine().Split(' ');
        for (int i = 0; i < N; i++)
            V[i] = int.Parse(s[i]);
        s = Console.ReadLine().Split(' ');
        for (int i = 0; i < N; i++)
            V[i] -= int.Parse(s[i]);

        int k = 0;
        foreach(var i in V)
        {
            if (i > 0)
                k += i;
        }
        Console.WriteLine(k);
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
char s[200000+7];
long long  mp[200000+7];
int main(){
	long long  n,p;
	cin>>n>>p;
	cin>>s+1;
	if(p==2||p==5){
		long long  ans=0;
		for(long long i=n;i>=1;i--){
			if((s[i]-'0')%p==0){
				ans+=i; 
			}
		}
		cout<<ans<<endl;
		return 0;
	}
	long long ans=0;
	long long  t=1,tmp=0;
	mp[0]++;
	for(int i=n;i>=1;i--){
		tmp=(tmp+(s[i]-'0')*t)%p;
		mp[tmp]++;
		t=t*10%p;
	}
	for(int i=0;i<=p;i++) {
		ans+=(mp[i]-1)*(mp[i])/2;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int s1 = 0, s2 = 0;
    rep(i, n) s2 += a[i];
    int ans = INF;
    rep(i, n - 1)
    {
        s1 += a[i];
        ans = min(ans, abs(s2 - 2 * s1));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
const int MAX=1e5+5;

vector<int> G[MAX];

int main(){
	int N;
	cin>>N;
	rep(i,N-1){
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<int> c(N);
	rep(i,N)cin>>c[i];
	sort(c.begin(), c.end());
	int M=0;
	rep(i,N-1)M+=c[i];
	
	int d[MAX];
	rep(i,N)d[i]=-1;
	
	priority_queue<P, vector<P>, greater<P>> q;
	int k[MAX];
	
	rep(i,N){
		k[i]=sz(G[i]);
		q.push(make_pair(k[i],i));
	}
	int ct=0;
	while(!q.empty()){
		P p=q.top();
		q.pop();
		int x=p.first;
		int v=p.second;
		if(d[v]!=-1)continue;
		if(x!=1)continue;
//		cout<<v<<" ";
		d[v]=c[ct];
		ct++;
		rep(i,sz(G[v])){
			int u = G[v][i];
			k[u]--;
			q.push(make_pair(k[u],u));
		}
	}
//  	cout<<endl;
	cout<<M<<endl;
	rep(i,N)cout<<d[i]<<" ";
	cout<<endl;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define ll long long
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//オーバーフローに注意 long long　にする
//'1'+=16;      で大文字Aに
//'大文字'+=32;  で小文字に
//string s = to_string(int数);
//int n = stoi(string文字列);


 
int main() {
 
  int n;
  cin >> n;
  
  int sum = 0;
  int naga = 0;
  
  vector<int> p(n);
  rep(i,n) {
  cin >>p[i];
  sum+=p[i];
  naga = max(naga, p[i]);
  }
  
  cout << (naga<sum-naga?"Yes":"No") << endl;
  
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  ld a;
  cin >> a;
  
  cout << fixed << setprecision (20);  
  cout << (ld)a*a*a/27 << endl;
    
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

ll n;
vector<ll> G[105];
ll depth[105];

ll p[105],q[105],r[105],b[105];
ll cnt[105];
ll sum[105];

vector<ll> lis_d[105];

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

    cin >> n;
    while(n){
    memset(depth,0,sizeof(depth));
    memset(cnt,0,sizeof(cnt));
    memset(sum,0,sizeof(sum));
    for (int i = 0;i < 105;i++){
        G[i] =  lis_d[i] = vector<ll>(0);
    }
    for (int i = 1;i <= n;i++){
        cin >> p[i] >> q[i] >> r[i] >> b[i];
        if(r[i]) G[i].push_back(r[i]);
        if(b[i]) G[i].push_back(b[i]);
        cnt[r[i]]++;
        cnt[b[i]]++;
    }

    int st;

    for (int i = 1;i <= n;i++){
        if(cnt[i] == 0){
            st = i;
            break;
        }
    }

    //cout << st << endl;

    queue<P> que;
    que.push(P(st,0));
    depth[st] = 0;
    lis_d[0].push_back(st);

    while(que.size()){
        P p = que.front(); que.pop();
        ll from = p.first;
        ll dep = p.second;
        for (int i = 0;i < G[from].size();i++){
            ll to = G[from][i];
            depth[to] = dep+1;
            //cout << to << " " << depth[to] << endl;
            lis_d[depth[to]].push_back(to);
            que.push(P(to,depth[to]));
        }
    }

    for (int i = 103;i >= 0;i--){
        for (int j = 0;j < lis_d[i].size();j++){
            ll now = lis_d[i][j];
            //cout << now << endl;
            if(G[now].size() == 0){
                sum[now] = (p[now]+q[now])/__gcd(p[now],q[now]);
            }else if(G[now].size() == 1){
                ll p_ = p[now], q_ = q[now];
                ll ch = G[now][0];
                if(G[now][0] == b[now]) swap(p_,q_);
                ll sig = q_/__gcd(p_*sum[ch],q_);
                ll w = p_*sum[ch]/__gcd(p_*sum[ch],q_);
                sum[now] = w+sig*sum[ch];
            }else{
                ll p_ = p[now], q_ = q[now];
                ll w1 = sum[G[now][0]], w2 = sum[G[now][1]];
                //cout << w1 << " " << w2 << "sdfsd" << endl;
                //if(G[now][0] == b[now]){ swap(p_,q_); cout << "fsdfas" << endl;}
                //ll lcm = w1*p_/__gcd(w1*p_,w2*q_)*w2*q_;
                sum[now] = w1*w2*q_/__gcd(w1*p_,w2*q_) + w1*p_*w2/__gcd(w1*p_,w2*q_);
            }
            //cout << sum[now] << " " << now << " " << i << endl;
        }
    }

    //cout << st << endl;

    cout << sum[st] << endl;
    cin >> n;
    }

    return 0;

}


Measured memory_bytes: 3252
c = [[int(i) for i in input().split()] for i in range(3)]
flag = 1
for i in range(3):
    for j in range(3):
        if c[(i+1)%3][j] + c[i][(j+1)%3] != c[i][j] + c[(i+1)%3][(j+1)%3]:
           flag = 0
if flag == 0:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 3060
#include <iostream>
#include <queue>
#include <map>

using namespace std;

typedef pair<int, int> pii;

// ?????°
constexpr int MAX_SCALE = 1010;
constexpr int INF = 1000;

// input
int height, width, max_search_num;
int sx, sy;
int gx, gy;
char maze[MAX_SCALE][MAX_SCALE];

// ???????????§??????????????¢?????????
int d[MAX_SCALE][MAX_SCALE];

int ans = 0;

int bfs(pii relay_pos, int num)
{
    // init
    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            d[y][x] = INF;
            if (maze[y][x] == num + '0') {
                gx = x; gy = y;
            }
        }
    }

    // ??????????¨??????????
    queue<pii> que;
    que.push(relay_pos);
    int dx[4] = {1, 0, 0, -1};
    int dy[4] = {0, -1, 1, 0};

    // start??°???
    d[relay_pos.second][relay_pos.first] = 0;

    while (!que.empty()) {
        pii p = que.front(); que.pop();

        if (p.first == gx && p.second == gy) {
            break;
        }

        for (int i = 0; i < 4; ++i) {
            int nx = p.first + dx[i], ny = p.second + dy[i];

            if (nx >= 0 && nx < width && ny >= 0 && ny < height && maze[ny][nx] != 'X' && d[ny][nx] == INF) {
                que.push(pii(nx, ny));
                d[ny][nx] = d[p.second][p.first] + 1;
            }
        }
    }

    ans += d[gy][gx];

    if (num != max_search_num) bfs(pii(gx, gy), num + 1);

    return ans;
}

void solve()
{
    int res = bfs(pii(sx, sy), 1);

    cout << res << endl;
}

int main()
{
    cin >> height >> width >> max_search_num;

    for (int y = 0; y < height; ++y) {
        for (int x = 0; x < width; ++x) {
            cin >> maze[y][x];
            if (maze[y][x] == 'S') {
                sx = x; sy = y;
            }
        }
    }

    solve();
    
    return 0;
}

Measured memory_bytes: 6192
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  string s, t;
  cin >> s >> t;
  
  ll ans=0;
  rep(i, s.size()) if(s[i]!=t[i]) ans++;
  cout << ans << newl;
  return 0;
}

Measured memory_bytes: 3872
#include <stdio.h>
#define WHITE 0
#define BLACK 2
#define GRAY 1

void dfs(void);
void visitdfs(int);


int n, d[200], f[200], color[100] ,a[100][100];
int totalcount=0;

int main(){

  int i, j, k, u, v;

  scanf("%d", &n);

  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      a[i][j]=0;
    }
  }
  for(i=0; i<n; i++){
    scanf("%d %d", &u, &k);//u...頂点の番号 k...いくつ頂点が隣接してるか

    for(j=0; j<k; j++){
      scanf("%d", &v);
      a[u-1][v-1]=1;
    }
  }

  dfs();

  //print
  for(u=0; u<n; u++){
    printf("%d %d %d\n",u+1, d[u], f[u]); 
  }

  return 0;
}

void dfs(){

  int u;//uは頂点番号

  //まず全部をWHITEにする
  for(u=0; u<n; u++){
    color[u]=WHITE;
  }

  //WHITEな頂点を訪れる
  for(u=0; u<n; u++){
    if(color[u]==WHITE){

      visitdfs(u);
    }
  }

}
void visitdfs(int u){

  int v; // vはuの次の頂点

  //訪れたのでまずはGRAYになる。countは1増える
  color[u]=GRAY;

  totalcount++;

  d[u]=totalcount;

  for(v=0; v<n; v++){
    if(a[u][v]==0) continue; //0..つまり継承関係にない場合
    if(color[v]==WHITE) visitdfs(v);
  }

  color[u]=BLACK;
  totalcount++;
  f[u]=totalcount;
}




Measured memory_bytes: 2088
A1 = input().split()
A2 = input().split()
A3 = input().split()
n = int(input())
B = []
for _ in range(n):
    B.append(input())
C1 = []
C2 = []
C3 = []
for Ae in A1:
    if Ae in B:
        C1.append('t')
    else:
        C1.append('f')
for Ae in A2:
    if Ae in B:
        C2.append('t')
    else:
        C2.append('f')
for Ae in A3:
    if Ae in B:
        C3.append('t')
    else:
        C3.append('f')
# print(C1)
# print(C2)
# print(C3)
D1 = [C1[0], C2[0], C3[0]]
D2 = [C1[1], C2[1], C3[1]]
D3 = [C1[2], C2[2], C3[2]]
E1 = [C1[0], C2[1], C3[2]]
E2 = [C1[2], C2[1], C3[0]]
# print(D1)
if 'f' not in C1 or 'f' not in C2 or 'f' not in C3:
    print('Yes')
    exit()
if 'f' not in D1 or 'f' not in D2 or 'f' not in D3:
    print('Yes')
    exit()
if 'f' not in E1 or 'f' not in E2:
    print('Yes')
    exit()
print('No')


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

int main(){
  int N, K; 
  cin >> N >> K;
  
  int sum=1;
  for (int i=0; i<N; i++){
    if(sum >= K)
      sum += K;
    if(sum < K)
      sum *= 2;
  }
  
  cout << sum << endl;
}


Measured memory_bytes: 3588
N,K = gets.split.map(&:to_i)
s = gets.strip

if K == 1
  puts s[0].downcase + s[1,N]
elsif K == N
  puts s[0,N-1] + s[N-1].downcase
else
  puts s[0,K-1] + s[K-1].downcase + s[K,N]
end


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

int main(){
  string s; cin>>s;
  string alp="abcdefghijklmnopqrstuvwxyz";
  int ans=100000;
  int i=0;
  while(i!=alp.size()){
    int now=0,cnt=0,c=0;
    while(now!=s.size()){
      if(s[now]==alp[i]){
        c=max(c,cnt);
        cnt=0;
      }else{
        cnt++;
      }now++;
    }c=max(c,cnt);
    i++;
    ans=min(ans,c);
  }
  cout<<ans<<endl;
}

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

int main() {
  int a, b, d, x, y;
  cin >> x >> y;
  b = x;
  d = y;
  while (true) {
    a = b;
    b = d;
    d = a % b;
    if (d == 0) {
      break;
    }
  }
  cout << b << endl;
  return 0;
}



Measured memory_bytes: 3052
fun main(args: Array<String>) {
    val n = readInt()
    val x = readIntList()

    val p = mutableListOf<Int>()
    for (i in 1..100) {
        p.add(x.sumBy { (it - i) * (it - i) })
    }
    println(p.min())
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

Measured memory_bytes: 36012
import java.util.*;

class Main {
	Scanner sc;
	int N;
	Vec[] v;
	
	static class Vec implements Comparable<Vec> {
		double x,y;
		double theta() {
			if (x == 0d && y == 0d) return 0d;
			return Math.atan2(y, x);
		}
		@Override public int compareTo(Vec t) {
			return Double.compare(theta(), t.theta());
		}
	}
	Main() {
		sc = new Scanner(System.in);
	}
	
	void calc() {
		N = sc.nextInt();
		v = new Vec[N];
		for (int i = 0; i < N; i++) {
			v[i] = new Vec();
			v[i].x = sc.nextInt();
			v[i].y = sc.nextInt();
		}
		
		Arrays.sort(v);
		double max = -1;
		for (int a = 0; a < N; a++) {
			for (int b = a+1; b < a+1+N; b++) {
				double len = len(a, b);
				if (len > max) max = len;
			}
		}
		System.out.println(max);
	}
	
	double len(int a, int b) {
		double x = 0d;
		double y = 0d;
		for (int i = a; i < b; i++) {
			x += v[i%N].x;
			y += v[i%N].y;
		}
		return Math.sqrt(x*x + y*y);
	}
	
	public static void main(String[] args) {
		new Main().calc();
	}

}

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

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

using namespace std;

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

  double sum=0;
  rep(i,n){
    double x;
    string u;
    cin>>x>>u;
    if(u=="BTC"){
      sum+=380000.0*x;
    }else{
      sum+=x;
    }
  }

  cout<<fixed<<setprecision(4)<<sum;

  return 0;
}

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

int main(){

  string s;

  while(getline(cin,s)){
    while(s.find("the")==string::npos && s.find("this")==string::npos && s.find("that")==string::npos){
      for(int i=0; i<s.size(); i++){
        if('a'<=s[i]&&s[i]<='y')
          s[i] ++;
        else if(s[i]=='z'){
          s[i]='a';
        }
      }
    }
    cout << s << endl;
  }


  return 0;
}

Measured memory_bytes: 1176
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF 1LL<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;
const int mod = 1e9 + 7;

int main(){
    string s; cin >> s;
    if(s.size()==2) cout << s << endl;
    else{
        cout << s[2] << s[1] << s[0] << endl;
    }
}

Measured memory_bytes: 256
function Main(input) {
  // 1行目がinput[0], 2行目がinput[1], …に入る
  const [a, b] = input.split("\n");
  const reg = new RegExp(a + '[A-Za-z]+');
  if (reg.test(b)) {
    console.log('Yes');
  } else {
    console.log('No');
  }
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29628
import java.util.*;

public class Main {
	public static void main(String[] args) {

		// 入力
		Scanner sc = new Scanner(System.in);
		
		// 数値
		int x = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		int i = 0;
		int k = 0;
		if (x > a) {
			i = x-a;
		} else {
			i = a-x;
		}
		if (x > b) {
			k = x-b;
		} else {
			k = b-x;
		}
		
		String ans = "A";
		if (i > k) {
			ans = "B";
		}
		// 出力
		System.out.println(ans);

		sc.close();

	}
}

Measured memory_bytes: 20820
c=eval('[0]*50,'*50)
r=0
for a in[*open(0)][1:]:
 a=round(float(a)*1e9);x=y=0
 while a%2<1:a//=2;x+=1
 while a%5<1:a//=5;y+=1
 r+=sum(sum(d[max(0,18-y):])for d in c[max(0,18-x):]);c[x][y]+=1
print(r)

Measured memory_bytes: 90904
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)
#define FOR(i, m, n) for(int i = (m); i < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

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


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

using namespace std;
using ll = long long;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;

int main() {
    int H, W, N;
    int sy, sx;
    cin >> H >> W >> N;
    cin >> sy >> sx;

    string s, t;
    cin >> s >> t;
    int maxR = W + 1, maxL = 0, maxU = 0, maxD = H + 1;

    for (int i = N-1; i >= 0; --i) {
        if (t[i] == 'L')maxR = min(maxR + 1, W + 1);
        if (t[i] == 'R')maxL = max(maxL - 1, 0);
        if (t[i] == 'D')maxU = max(maxU - 1, 0);
        if (t[i] == 'U')maxD = min(maxD + 1, H + 1);

        if (s[i] == 'R')maxR--;
        if (s[i] == 'L')maxL++;
        if (s[i] == 'U')maxU++;
        if (s[i] == 'D')maxD--;

        if (maxR - maxL <= 1 or maxD - maxU <= 1) {
            puts("NO");
            return 0;
        }
    }

    if (sx < maxR and sx > maxL and sy > maxU and sy < maxD)puts("YES");
    else puts("NO");

    return 0;
}


Measured memory_bytes: 776
#include<iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;

const int maxn=(1<<21);
int G[110][110];///构造图
int d[110];///该顶点到顶点1的距离
bool vis[110];
int n;

void BFS(){
    queue<int> q;
    q.push(1);
    d[1]=0;
    vis[1]=true;
    while(!q.empty()){
        int top=q.front();
        q.pop();
        //vis[top]=true;
        for(int i=1;i<=n;i++){
            if(G[top][i]&&vis[i]==false){
       //     if(G[top][i]&&d[i]==maxn){
                d[i]=d[top]+1;
                vis[i]=true;
                q.push(i);
            }
        }
    }
}


int main(){
    scanf("%d",&n);
    memset(G,0,sizeof(G));
    memset(vis,0,sizeof(vis));
    fill(d,d+110,maxn);

  //  memset(d,maxn,sizeof(d));
    for(int i=0;i<n;i++){
        int u,k;
        scanf("%d%d",&u,&k);
        for(int j=0;j<k;j++){
            int v;
            scanf("%d",&v);
            G[u][v]=1;
        }
    }

    BFS();
    for(int i=1;i<=n;i++){
        printf("%d %d\n",i,(d[i]==maxn)?(-1):d[i]);
    }
    return 0;
}


Measured memory_bytes: 3284
import sys, math
from collections import defaultdict
from itertools import product
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N, x = mi()
    a = list(mi())

    cnt = max(a[0]-x, 0)
    a[0] = min(a[0], x)

    for i in range(N-1):
        if a[i]+a[i+1] > x:
            cnt += a[i]+a[i+1]-x
            if a[i+1] < a[i]+a[i+1]-x:
                a[i+1] = 0
                a[i] = x
            else:
                a[i+1] = x-a[i]
    print(cnt)


if __name__ == '__main__':
    main()

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

typedef long long ll;

void printArray(vector<int> arr) {
	for (int a: arr) cout << a << " ";
	cout << '\n';
}

int main() {
	std::ios_base::sync_with_stdio(false);
	int x,n;
	cin >> x >> n;
	set<int>p;
	for (int i =0;i<n; i++) {
		int temp;
		cin >> temp;
		p.insert(temp);
	}
	int i = x;
	int j = x;
	int ret = 0;
	while (true) {
		if (p.find(i) == p.end()) {ret = i; break;}
		if (p.find(j) == p.end()) {ret = j; break;}
		i--;
		j++;
	}
	cout << ret << '\n';
	
}



Measured memory_bytes: 3540
#include <bits/stdc++.h>
using namespace std;
int main()
{
long int n,a,b,i,d=0,x=0;
	cin>>n>>a>>b;
	string s;
	cin>>s;
	for(i=0;i<n;i++)
	{
		if(s[i]=='c')
		{
			cout<<"No"<<endl;
		}
		
		if(s[i]=='a')
		{
			if(d<a+b)
			{
				cout<<"Yes"<<endl;
				d++;
			}
			else
			{
				cout<<"No"<<endl;
			}
		}
		
		if(s[i]=='b')
		{
			x++;
			if(d<a+b && x<=b)
			{
				cout<<"Yes"<<endl;
				d++;
			}
			else
			{
				cout<<"No"<<endl;
			}
		}
		
		
	}
}

Measured memory_bytes: 3704
n = int(input())
a = list(map(int, input().split()))

d = dict()

for i in a:
    d[i] = d.get(i, 0) + 1

d = sorted(d.items(), key=lambda x:x[0])

d = [(0, 0)] + d + [(0, 0)]

ans = 1

for i in range(1, len(d)-1):
    temp = d[i][1]
    if d[i-1][0] + 1 == d[i][0]:
        temp += d[i-1][1]
    if d[i+1][0] == d[i][0] + 1:
        temp += d[i+1][1]
    ans = max(ans, temp)

print(ans)

Measured memory_bytes: 15096
#include <cstdio>
#include <cmath>
using namespace std;

int main()
{
	int n, a, b;
	scanf("%d%d%d", &n, &a, &b);
	if ((a == 1 && b == 2) || (a == n && b == n-1) || ((int)(abs(a-b)) % 2 == 1) || n == 2)
		printf("Borys");
	else printf("Alice");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
using namespace std; // 575

const int MAX = 100000;
int main() {
	int N, M;
	static pair<int, int> drink[MAX];
	cin >> N >> M;
	for (int i = 0;i < N;++ i) cin >> drink[i].first >> drink[i].second;
	sort(drink, drink+N);
	long ans = 0;
	for (int i = 0, j = 0;i < M;++ i, j += -- drink[j].second ? 0 : 1) ans += drink[j].first;
	cout << ans;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

安い順に買えるだけ買っていくのが最適
答えはlong型になる可能性に注意
*/

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define per(i,n) for(int i = (n)-1; i >= 0; --i)
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main() {
    int n; cin >> n;
    vl a(n); rep(i,n) cin >> a[i];
    vl dp(n,0);
    ll ans = 0;
    rep(i,n) {
        int L = i - a[i], R = i + a[i];
        if (L >= 0) ans += dp[L];
        if (R < n) dp[R]++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6428
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
	return b==0?a:(gcd(b,a%b));
}
int main()
{
	int n;
	long long sum=0;
	cin >> n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			for(int k=1;k<=n;k++){
				sum+=gcd(i,gcd(j,k));
			}
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] ary = new int[n];
        int[] idx = new int[n];
        for (int i = 0; i < n; i++) {
            ary[i] = Integer.parseInt(sc.next());
            idx[ary[i] - 1] = i;
        }
        for (int a : idx) {
            System.out.print(a + 1 + " ");
        }
    }
}

Measured memory_bytes: 49112
#include<stdio.h>

int main(void){
  int D;
  scanf("%d",&D);
  if (D==25){
    printf("Christmas");
  }
  if(D==24){
    printf("Christmas Eve");
  }
  if(D==23){
    printf("Christmas Eve Eve");
  }
  if(D==22){
    printf("Christmas Eve Eve Eve");
  }
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int n,x,d[100];
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>d[i];
        x+=d[i];
    }
    long long ans=0;
    for(int i=0;i<n;i++){
        ans+=(x-d[i])*d[i];
    }
    cout<<ans/2<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

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

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll s,w;
    cin>>s>>w;
    if(s>w) cout<<"safe"<<endl;
    else cout<<"unsafe"<<endl;
    return 0;
}


Measured memory_bytes: 3664
L, R = map(int, input().split())
if (L // 2019) != (R // 2019):
    print(0)
    exit()
else:
    ans = float('inf')
    for i in range(L, R + 1):
        for j in range(i + 1, R + 1):
            ans = min((i * j) % 2019, ans)
    print(ans)


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


#define rep(p,q) for(int i = p;i < q;i++)
#define ll long long

using namespace std;

const int cons = 1e9 + 7;

int n;
vector<double> v;
vector<double> l;
vector<double> r;
double speed(double t) {
	double maxV = 100;
	rep(0, n + 2) {
		double reti = 0;
		if (t <= l[i]) reti = v[i] + l[i] - t;
		else if (r[i] <= t) reti = v[i] + t - r[i];
		else reti = v[i];
		maxV = min(maxV, reti);
	}
	return maxV;
}

//D

int main(void) {
	cout<<fixed<<setprecision(4);
	cin >> n;	
	v = vector<double>(n + 2);
	l = vector<double>(n + 2);
	r = vector<double>(n + 2);
	v[0] = 0; l[0] = 0; r[0] = 0;
	v[n + 1] = 0;
	int T= 0;
	rep(1, n+1) {
		int ti = 0;
		cin >> ti;
		r[i] = r[i - 1] + ti;
		l[i] = r[i - 1];
		T += ti;
	}
	l[n] = r[n - 1];
	rep(1, n + 1) {
		cin >> v[i];
	}
	l[n + 1] = T; r[n + 1] = T;
	double ans = 0;
	for (double i = 0; i < T; i += 0.5) {
		double s1 = speed(i);
		double s2 = speed(i + 0.5);
		ans += 0.25*(s1 + s2);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define LL long long
#define MOD 1000000007
#define INF 2000000000000
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
ll N, M, K, H, W, L, R, l, r, u, d, sum, Q;
LL ans;
LL no;
bool b, bb[100001];
string s, t;

LL gcd(int p, int q) {
	if (p % q == 0)return q;
	return gcd(q, p % q);

}

int main() {
	cin >>K;
	ans = 0;
	for (LL i = 1; i <= K;i++) {
		for (LL j = 1; j <= K; j++) {
			for (LL k = 1; k <= K; k++) {
				ans += gcd(gcd(i, j), k);
			}
		}

	}
	cout << ans<<endl;
	return 0;
}



Measured memory_bytes: 3608
# 全DP C - 高橋君とカード / Tak and Cards

import numpy as np

N, A = map(int, input().split())
x = np.array(list(map(int, input().split())))

x_diff = x - np.array(A)
X = max(A, max(x))

dp = np.zeros((N+2, 2*N*X+2)) #dp[i+1][j]はx_diff[i]までの数からいくつか選んで合計j-N*Xにするような選び方のパターン
dp = dp.tolist()
dp[0][N*X] = 1

for i in range(N):
    for j in range(2*N*X+1):
        if j < x_diff[i] or x_diff[i] < j - 2*N*X: # x_diff[i]を足しても絶対にj-N*Xにならないとき
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = dp[i][j] + dp[i][j-x_diff[i]]
            
print(int(dp[N][N*X] - 1))

Measured memory_bytes: 22196
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<int> a(3);
  cin>>a[0]>>a[1]>>a[2];
  sort(a.begin(),a.end());
  if(a[0]==a[1])cout<<a[2];
  else if(a[1]==a[2])cout<<a[0];
}

Measured memory_bytes: 256
// E.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <cstdio>


using lolo=long long;
using namespace std;
using vec=vector<lolo>;
using vvec=vector<vec>;
using vecb=vector<bool>;
#define FOR(i,n) for (lolo i=0; i<n; ++i)
#define FORN(i,a,b) for (lolo i=a; i<b; ++i)
#define REV(i,a,b) for (lolo i=a; i>b; --i)
#define ALL(x) x.begin(), x.end()
struct UnionFind
{
	vector<lolo> data;
	UnionFind(lolo size) : data(size, -1) {}
	bool unionSet(lolo x, lolo y)
	{
		x = root(x); y = root(y);
		if ( x != y )
		{
			if ( data[y] < data[x] ) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(lolo x, lolo y)
	{
		return root(x) == root(y);
	}
	lolo root(lolo x)
	{
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	lolo size(lolo x)
	{
		return -data[root(x)];
	}
};

int main()
{
	lolo N, M;
	cin >> N >> M;
	UnionFind u(N + 1);
	FOR(i, M)
	{
		lolo x, y, z;
		cin >> x >> y >> z;
		u.unionSet(x, y);		
	}
	set<lolo> s;
	lolo ans = 0;

	FORN(i, 1, N + 1)
	{
		if ( !s.count( u.root(i)) )
		{
			s.insert(u.root(i));
			ans += 1;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 5760
function Main(input) {
	input = input.split(" ");
	const a1 = parseInt(input[0]);
	const a2 = parseInt(input[1]);
	const a3 = parseInt(input[2]);

	if (a1<a2) {
		if (a1<a3 && a3<a2) {
			console.log("Yes");
		} else {
			console.log("No");
		}
	} else {
		if (a1>a3 && a3>a2) {
			console.log("Yes");
		} else {
			console.log("No");
		}
	}

}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
??´?????????
"""

# ?????°??¨?????°???????????????
inp = input().split(" ")
n = int(inp[0])
m = int(inp[1])

# n*m ??????????????????
ArrA = []
for i in range(n):
    l = list(map(int,input().split(" ")))
    ArrA.append(l)

# m*1 ??????????????????
ArrB = []
for i in range(m):
    ArrB.append(int(input()))

# ArrA * ArrB
for i in range(n):
    x = 0
    for j in range(m):
        x += ArrA[i][j] * ArrB[j]
    print(str(x))

Measured memory_bytes: 7920
using System;
using System.Text;
using System.Collections.Generic;
class Solve{
    long x;
    int p;
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Read();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        x = (x+1)/2;
        double ans = (double)(x*100)/p;
        sb.Append(ans+"\n");
    }
    void Read(){
        x = Int64.Parse(Console.ReadLine());
        p = int.Parse(Console.ReadLine());
    }    
}

Measured memory_bytes: 2648