akhauriyash/Code-Regression huggingface dataset:
s1 = list(input())
s2 = list(input())
n = len(s1)
m = len(s2)
dp = [[0]*(m+1) for _ in range(n+1)]
for i in range(1,n+1):
    for j in range(1, m+1):
        if s1[i-1] == s2[j-1]:
            dp[i][j] = 1 + dp[i-1][j-1]
        else:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])
res = []
i, j = n, m
while i > 0 and j > 0:
    if dp[i][j] == dp[i][j-1]:
        j -= 1
    elif dp[i][j] == dp[i-1][j]:
        i -= 1
    else:
        res.append(s1[i-1])
        i -= 1
        j -= 1
print(''.join(res[::-1]))

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

int main(){
  int N;
  cin >> N;
  string s;
  cin >> s;
  int r=0, b=0;
  for(int i=0; i<N; i++){
    if(s[i]=='R') r++;
    if(s[i]=='B') b++;
  }

  if(r>b) cout <<"Yes" << endl;
  else cout <<"No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> A(M);
  for (auto &a: A) {
    cin >> a;
  }
  sort(begin(A), end(A));
  int d = lower_bound(begin(A), end(A), X) - begin(A);
  cout << min(d, M - d) << endl;

  return 0;
}


Measured memory_bytes: 256
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")
// -------------------</optimizations>--------------------

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define f first
#define s second
#define sz(x) int(x.size())
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define SIZE 26     
#define watch(x) cout << (#x) << " is " << (x) << endl
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
 
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
 
const ll mod = 1e9 + 7;
const int inf = 1e9 + 5;
const int N = 3005;

signed main(){
    fastio;
    ll i,j,n;
    cin>>n;
    ld dp[n+1][n+1],p[n+1],ans=0;
    for(i=1;i<=n;++i){
        cin>>p[i];
    }
    fill(dp,0);
    dp[0][0]=1;
    for(i=1;i<=n;++i){
        for(j=0;j<i;++j){
            dp[i][j+1]+=dp[i-1][j]*p[i];
            dp[i][j]+=dp[i-1][j]*(1-p[i]);
        }
    }
    for(i=n;i>n/2;--i){
        ans+=dp[n][i];
    }
    cout<<fixed<<setprecision(10)<<ans;
    return 0;
}


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


int main()
{
  int n,W;cin>>n>>W;
  vector<int> v(n), w(n);
  for (int i = 0; i < n; i++)
  {
    cin >> v.at(i) >> w.at(i);
  }

  int dp[105][10005];
  for (int i = 0; i <= W; i++)
  {
    dp[0][i] = 0;
  }

  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j <= W; j++)
    {
      if (j - w.at(i) >= 0)
      dp[i + 1][j] = max(dp[i][j],dp[i][j - w.at(i)] + v.at(i));
      else
      dp[i + 1][j] = dp[i][j];
      
    }
    
  }
  
  cout << dp[n][W] << endl;

}


Measured memory_bytes: 7052
#include <stdio.h>

int main(void) {
	int S,h,m,s,x;
	scanf("%d",&S);
	h=S/3600;
	x=S%3600;
	m=x/60;
	s=x%60;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef deque<int> DI;
typedef deque<LL> DLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL MOD = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

int main() {
	sll(n); sll(m);
	LL likes[m+1];	clr(likes);
	rep(i, 0, n) {
		sll(k);
		rep(j, 0, k)	likes[scanLong()]++;
	}
	LL cnt = count(likes, likes+m+1, n);
	pll(cnt); nl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

int main(void)
{
	char str[1001] = {};
	char tempStr[1001] = {};
	std::cin >> str;
	int q;
	std::cin >> q;
	char in[8] = {};
	for (int i = 0; i < q; i++)
	{
		std::cin >> in;
		if (in[0] == 'r' 
			&& in[1] == 'e' 
			&& in[2] == 'p' 
			&& in[3] == 'l' 
			&& in[4] == 'a' 
			&& in[5] == 'c'
			&& in[6] == 'e'
			&& in[7] == '\0')
		{
			int a, b;
			std::cin >> a >> b;
			std::cin >> tempStr;
			for (int i = 0; i < b - a + 1; i++)
			{
				str[a + i] = tempStr[i];
			}
		}
		else if (in[0] == 'r'
			&& in[1] == 'e'
			&& in[2] == 'v'
			&& in[3] == 'e'
			&& in[4] == 'r'
			&& in[5] == 's'
			&& in[6] == 'e'
			&& in[7] == '\0')
		{
			int a, b;
			std::cin >> a >> b;
			for (int i = 0; i < b - a + 1; i++)
			{
				tempStr[i] = str[a + i];
			}
			for (int i = 0; i < b - a + 1; i++)
			{
				str[a + i] = tempStr[b - a - i];
			}
		}
		else if (in[0] == 'p'
			&& in[1] == 'r'
			&& in[2] == 'i'
			&& in[3] == 'n'
			&& in[4] == 't'
			&& in[5] == '\0')
		{
			int a, b;
			std::cin >> a >> b;
			for (int i = a; i <= b; i++)
			{
				std::cout << str[i];
			}
			std::cout << '\n';
		}
	}
	return 0;
}

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

int main() {
  int n,x,y;
  cin>>n>>x>>y;
  x=x-1;
  y=y-1;
  vector<int> vec(n-1);
 for (int i = 0; i < n; i++) {
   for (int j= i+1; j < n; j++) {
     int m;
     m=min(j-i,abs(i-x)+1+abs(j-y));
     vec.at(m-1)++;
     
}  
}
  for(int i=0;i<n-1;i++){
  cout<<vec.at(i)<<endl;}


            
            
            
}


Measured memory_bytes: 384
loop{
  n=gets.to_i
  break if n==0
  buf=Array.new
  n.times do 
      buf.push(gets.chop.split(" ").map{|e|e.to_i})
  end
  2.times do
    buf=buf.transpose
    buf.each do |c|
      c.push(c.inject(:+))
    end
  end
  buf.each do |a|
    a.each do |b|
      print '%5d' % [b] 
    end
    puts
  end
}

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

int x,y,z,n,m;
char tmp;
pair<int,int> ar[100005];
string s1,s2;

int main() {
	cin >> x;
	for (int i = 0; i < x; i++) {
		cin >> ar[i].first;
		ar[i].second = i;		
	}
	sort(ar,ar+x);
	for (int i = 0; i < x; i++) {
		if (ar[i].second%2 != i%2) {
			n++;
		}
	}
	cout << n/2;
}

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

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

			//出力の都度更新をやめる
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);


			Ans();

			//更新する
			Console.Out.Flush();
			
		}
	public static void Ans() {

			checked {
				var inputArray = retreiveStringArray();
				var inputCount = 1;

				// 不正な入力は処理しない
				if (inputArray.Length != inputCount) {
					Console.WriteLine("invalid input");
					return;
				}
				var s = inputArray[0].Select(x => x).ToArray();

				var K = retreiveLongArray()[0];
				var z = (int)'z';
				for (int i = 0; i < s.Count(); i++) {


					var need = s[i]=='a' ? 0 :z - (int)s[i] + 1;
					if (need <= K) {
						s[i] = 'a';
						K -= need;
					}

					if (i == s.Count() - 1) {
						var change = ((s[i] - 'a') + K) % 26;
						s[i] = (char)('a' + change);
						continue;
					}

				}


				//答えの出力
				var ans = string.Join("", s);
				Console.WriteLine(ans);
			}
			

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}


		/// <summary>
		/// 2組みずつの入力データ(数値)からTuppleListを作成する
		/// </summary>
		/// <param name="N"></param>
		/// <returns></returns>
		private static List<Tuple<long, long>> createLongTuppleList(long N) {
			var inpList = new List<Tuple<long, long>>();

			for (int i = 0; i < N; i++) {
				var inp = retreiveLongArray();
				var item1 = inp[0];
				var item2 = inp[1];
				inpList.Add(new Tuple<long, long>(item1, item2));
			}
			return inpList;
		}
	}
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	int d,n;
	cin >> d >> n;

	if(d == 0){
		if(n == 100){
			cout << 101 << endl;
		}else{
			cout << n << endl;
		}
	}else if(d == 1){
		if(n == 100){
			cout << 10100 << endl;
		}else{
			cout << 100 * n << endl;
		}
	}else{
		if(n == 100){
			cout << 1010000 << endl;
		}else{
			cout << 10000 * n << endl;
		}
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int a = sc.nextInt();
		int b = sc.nextInt();

		if (a < b) {
			System.out.println("a < b");
		} else if (a > b) {
			System.out.println("a > b");
		} else if (a == b) {
			System.out.println("a == b");
		}
	}
}



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

int main(){
	int N, i, ans = 1000000;
	scanf("%d", &N);
	vector<int> W(N);
	for(i = 0; i < N; i++){
		scanf("%d", &W[i]);
	}
	for(int T = 0; T < N; T++){
		int a = 0, b = 0;
		for(i = 0; i < N; i++){
			if(i <= T){
				a += W[i];
			}
			else{
				b += W[i];
			}
		}
		ans = min(ans, abs(a - b));
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#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()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

struct UnionFind{
	vl p;
	vl rank;
	vl cnt;

	UnionFind(ll n){
		rank.resize(n,0);
		p.resize(n,0);
		cnt.resize(n,0);
		rep(i,n){
			p[i] = i;
			rank[i] = 0;
			cnt[i] = 1;
		}
	}

	ll find(ll x){
		if(x != p[x]) p[x] = find(p[x]);
		return p[x];
	}

	bool same(ll x, ll y){
		return find(x) == find(y);
	}

	void unite(ll x, ll y){
		x = find(x);
		y = find(y);
		if(x == y) return;
		if(rank[x] > rank[y]){
			p[y] = x;
			cnt[x] += cnt[y];
		}else{
			p[x] = y;
			cnt[y] += cnt[x];
			if(rank[x] == rank[y]) rank[y]++;
		}
	}

	ll size(ll x){
		return cnt[find(x)];
	}
};

int main(){
	ll n,m; cin >> n >> m;
	UnionFind uf(n);
	rep(i,m){
		ll x,y,z; cin >> x >> y >> z;
		x--; y--;
		uf.unite(x,y);
	}
	vl v(n,0);
	ll ans = 0;
	rep(i,n){
		if(!v[uf.find(i)]) v[uf.find(i)] = 1, ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repa(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define COUT(x) cout << (x) << endl
#define _GLIBCXX_DEBUG

int main(){
  
  int a, b, c;
  cin >> a >> b >> c;

  cout << min(min(a+b, b+c), c+a) << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <cstdio>
#define MAX 100005
#define NIL -1 
using namespace std;

int color[MAX];
int n,m,s,t,q;
vector<int> G[MAX];

void dfs(int x, int y) {
	stack<int> S;
	S.push(x);
	color[x]=y;
	while(!S.empty()) {
		int tmp=S.top();
		S.pop();
		for(int i=0;i<G[tmp].size();i++) {
			int l=G[tmp][i];
			if(color[l]==NIL) {
				color[l]=y;
				S.push(l);
			}
		}
	}
}

void assigncolor() {
	int num=0;
	for(int i=0;i<n;i++) color[i]=NIL;
	for(int i=0;i<n;i++) {
		if(color[i]==NIL) dfs(i,num++);
	}
}

int main() {
	int i,j;
	scanf("%d %d",&n,&m);
	for(i=0;i<m;i++) {
		scanf("%d %d",&s,&t);
		G[s].push_back(t);
		G[t].push_back(s);
	}
	
	assigncolor();
	
	scanf("%d",&q);
	for(i=0;i<q;i++) {
		scanf("%d %d",&s,&t);
		if(color[s]==color[t]) printf("yes\n");
		else printf("no\n");
	}
	
	return 0;
}


Measured memory_bytes: 8976
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ull = long long unsigned;
using P = pair<int,int>;
const int INF=1001001;
const int NMAX=8;
const int mod = 1000000007;


int main()
{
	int n,m;
	cin>>n>>m;
	vector<vector<int>> g(n);
	rep(i,m){
		int u,v;
		cin>>u>>v;
		u--;v--;
		g[u].emplace_back(v);
	}
	int S,T;
	cin>>S>>T;
	S--;T--;
	int d[n][3];
	rep(i,n)rep(j,3)d[i][j]=INF;
	queue <P> q;
	q.push(make_pair(S,0));
	while (!q.empty()){
		P now=q.front();
		q.pop();
		int node=now.first;
		int dist=now.second;
	//	cout<<node<<'n'<<dist<<'d'<<endl;

		for(int to:g[node]){
	//		cout<<to<<endl;
			int d_new=dist+1;
			int cat=d_new%3;
			if (d[to][cat]!=INF)continue;
			d[to][cat]=d_new;
			q.push(make_pair(to,d_new));
		}
	}
	int ans;
	if (d[T][0]==INF ) ans=-1;
	else ans=d[T][0]/3;
	cout<<ans;

}


Measured memory_bytes: 6912
using System;
using System.Linq;

class Program {
  public static void Main() {
    string[] strInput = Console.ReadLine().Split(' ');
    int[] numInput = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
    string sel = Console.ReadLine();
    
    if (strInput[0] == sel)
      numInput[0]--;
    else
      numInput[1]--;
    
    Console.WriteLine("{0} {1}", numInput[0], numInput[1]);
  }
}

Measured memory_bytes: 13396
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}

#define MAX 200005

long long beki(long long a,int n)
{
  long long s=1LL;
  while(n){
    if(n%2)s=(s*a)%MOD;
    a=(a*a)%MOD;
    n/=2;
  }
  return s;
}
// mod P において、a/bは　a*beki(b,P-2) と等価

long long fac[MAX], finv[MAX], inv[MAX];

void init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

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


signed main(void) {
    int b,w;
    cin >> b >> w;
    int n = b+w;
    vi p(n+1,0),q(n+1,0);
    init();
    rep(i,n){
        p[i+1] = ncr(i, b-1) * beki(beki(2,i+1),MOD-2);
        p[i+1] %= MOD;
        p[i+1] += p[i];
        p[i+1] %= MOD;

        q[i+1] = ncr(i, w-1) * beki(beki(2,i+1),MOD-2);
        q[i+1] %= MOD;
        q[i+1] += q[i];
        q[i+1] %= MOD;
    }
    rep(i,n){
        int ans = (1 - p[i] + q[i] + MOD) % MOD;
        ans *= beki(2,MOD-2);
        cout << ans % MOD << endl;
    }
}


Measured memory_bytes: 9984
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

vector<vector<pair<int,int>>>edges;

int memo[17][1 << 16];
struct aa {
	int now;
	bitset<17>eats;
	int time;
};
class Compare {
public:
	//aaが昇順に並ぶ
	bool operator()(const aa&l, const aa&r) {
		return l.time> r.time;
	}
};


int main() {
	while (1) {
		for (int i = 0; i < 17; ++i) {
			for (int j = 0; j < (1 << 16); ++j) {
				memo[i][j] =99999999;
			}
		}
		int N, M, L, S, T; cin >> N >> M >> L >> S >> T;
		if (!N)break;
		S--;
		edges.clear();
		edges.resize(L+1);
		int diss[300][300];
		for (int i = 0; i < N; ++i) {
			
			for (int j = 0; j< N; ++j) {

				diss[i][j] = i==j?0:99999999;

			}
			
		}
		for (int i = 0; i < M; ++i) {
			int a, b, c; cin >> a >> b >> c;
			a--; b--;
			diss[a][b] = c;
			diss[b][a] = c;
		}

		for (int i = 0; i < N; ++i) {
			for (size_t j = 0; j < N; j++)
			{
				for (size_t k = 0; k < N; k++)
				{
					diss[j][k] = min(diss[j][k],diss[j][i] + diss[i][k]);
				}
			}
		}
		vector<pair<int, int>>ramens;
		ramens.push_back(make_pair(S, 0));
		for (int i = 0; i < L; ++i) {
			int j, e; cin >> j >> e;
			j--;
			ramens.push_back(make_pair(j,e));
		}
		for (int i = 0; i < L+1; ++i) {
			for (int j = 0; j< L + 1; ++j) {
				if (i != j) {
					edges[i].push_back(make_pair(j, diss[ramens[i].first][ramens[j].first]));
				}
			}
		}

		priority_queue<aa, vector<aa>, Compare>que;
		que.push(aa{ 0,bitset<17>(1),0 });


		memo[0][0] = 0;
		int ans = 0;
		while (!que.empty()) {
			aa atop(que.top());
			que.pop();
			bitset<17>nbs(atop.eats);
			if (atop.now == 0) {
				ans = max(ans, int(nbs.count()));
				if (ans == L + 1)break;
			}

			for (auto j : edges[atop.now]) {
				const int nextplace = j.first;		
				const int nexttime = atop.time + j.second;
				if (nexttime < memo[nextplace][nbs.to_ulong()/2] && nexttime <= T) {
					memo[nextplace][nbs.to_ulong()/2] = nexttime;
					que.push(aa{ nextplace,nbs,nexttime });

					if (!nbs[nextplace]) {
						nbs[nextplace] = true;
						int alltime = nexttime + ramens[nextplace].second;
						if (alltime < memo[nextplace][nbs.to_ulong() / 2] && alltime <= T) {
							memo[nextplace][nbs.to_ulong() / 2] = alltime;
							que.push(aa{ nextplace,nbs, alltime });
						}
						nbs[nextplace] = false;
					}
				}
			}
		}
		cout << ans-1 << endl;
	}
	return 0;
}

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

int a[105];
int r[10];

int main()
{
  int n;

  scanf("%d",&n);

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

  int ans = 0,cnt = 0;
  for (int i = 0;i < n;i++)
  {
    if (a[i] >= 1 && a[i] <= 399) r[1]++;
    else if (a[i] >= 400 && a[i] <= 799) r[2]++;
    else if (a[i] >= 800 && a[i] <= 1199) r[3]++;
    else if (a[i] >= 1200 && a[i] <= 1599) r[4]++;
    else if (a[i] >= 1600 && a[i] <= 1999) r[5]++;
    else if (a[i] >= 2000 && a[i] <= 2399) r[6]++;
    else if (a[i] >= 2400 && a[i] <= 2799) r[7]++;
    else if (a[i] >= 2800 && a[i] <= 3199) r[8]++;
    else cnt++;
  }

  for (int i = 1;i <= 8;i++)
  {
    if (r[i]) ans++;
  }

  printf("%d %d\n",ans == 0 ? 1 : ans,ans+cnt);

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 212345
int n, q;
char s[N], t[N], d[N], u[2];

bool fun(int x, int y, int z){
	int xx=x;
	REP(i, q){
		if(s[x]==t[i]){
			if(d[i]=='L') x--;
			else x++;
		}
		DEBUG("%d ", x);
		if(x==y){
			DEBUG("%d -> fall to %d\n", xx, y);
		 	return true;
		}
		if(x==z){
			DEBUG("%d -> no, fall to %d\n", xx, y);
		 	return false;
		}
	}
	DEBUG("%d -> %d\n", xx, x);
	return false;
}

int main(){
	scanf("%d%d%s", &n, &q, s);
	REP(i, q){
		scanf("%s", u);
		t[i]=u[0];
		scanf("%s", u);
		d[i]=u[0];
	}
	int ans=n;
	{ // fall left?
		int lo=-1, hi=n; // lo->ok, hi->ng
		while(hi-lo>1){
			int md=(lo+hi)/2;
			if(fun(md, -1, n)){
				lo = md;
			} else {
				hi = md;
			}
		}
		ans-=lo+1;
	}
	{ //fall right?
		int lo=-1, hi=n; // lo->ng, hi->ok
		while(hi-lo>1){
			int md=(lo+hi)/2;
			if(fun(md, n, -1)){
				hi = md;
			} else {
				lo = md;
			}
		}
		ans-=n-hi;
	}
	printf("%d\n", ans);
}


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

int i,n,x;
fscanf(stdin,"%d",&n);
for(i=1;i<=n;i++){
x=i;
if(x%3==0){
printf(" %d",i);
continue;
}
do{
if(x%10==3){
printf(" %d",i);
break;
}
x/=10;
}while(x);
}
printf("\n");
return 0;
}



Measured memory_bytes: 2116
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input())
    F = []
    P = []
    for i in range(N):
        F.append(list(int(_) for _ in input().split()))
    for i in range(N):
        P.append(list(int(_) for _ in input().split()))
        
    ans = -1 * INF
    for i in range(1,2**10):
        tmp_ans =0
        for j in range(N):
            cnt = 0
            for k in range(len(F[j])):
                if ( i & (1 << k) )and(F[j][k] == 1):
                    cnt +=1
            tmp_ans += P[j][cnt]
        ans = max(ans,tmp_ans)
    print(ans)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include <stdio.h>

int main(void) {

	int W, H, x, y, r;

	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

	if (x - r < 0 || y - r < 0) {
		printf("No\n");
	}
	else if (x + r > W) {
		printf("No\n");
	}
	else if (y + r > H) {
		printf("No\n");
	}


	else {
		printf("Yes\n"); //当てはまらない場合
	}

	return(0);

}


Measured memory_bytes: 2100
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-}

import qualified Data.ByteString.Char8 as B
import qualified Data.Set              as S

main :: IO ()
main = solve <$> readParams >>= B.putStrLn

readParams :: IO [B.ByteString]
readParams = B.words <$> B.getContents

solve :: [B.ByteString] -> B.ByteString
solve = S.elemAt 0 . (["1","2","3"] S.\\) . S.fromList


Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll x;
  cin >> x;
  ll cnt=0;
  ll n=100;
  while(n<x){
    n *=1.01;
    cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3640
#include<stdio.h>
#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))
#define abs(a) (((a)>0)?(a):(-a))
int main()
{
	int a, b, c, ans;
	scanf("%d %d %d", &a, &b, &c);
	ans = abs((a - b)) + abs((b - c)) + abs((c - a));
	ans -= max(abs((a - b)), max(abs((b - c)), abs((c - a))));
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 128
from collections import Counter

N = int(input())
A = list(map(int,input().split()))
a = list(set(A))
cc = Counter(A)
dup = set([x for x in a if cc[x] > 1])
c_l = [(cc[i]-1)*(cc[i])/2 for i in a]
al = sum(c_l)

# for k in A:
#     if k in dup:
#         print(int(al-cc[k]+1))
#     else :
#         print(int(al))
[print(int(al-cc[k]+1)) if k in dup else print(int(al)) for k in A]

Measured memory_bytes: 28852
def getindex(i):
    for a in range(K+1):
        if i*2**a >= K:
            return a

N, K = map(int, input().split())
result = 0

for i in range(1,N+1):
    x = getindex(i) if i < K else 0
    pulas = (1/N)*((0.5)**x) if x > 0 else 1/N
    result += pulas

print(result)


Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define arep(i, v) for (auto i : v)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define fi first
#define se second
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
template <class T>
inline void dump(T& v) {
    irep(i, v) { cout << (*i) << ((i == --v.end()) ? '\n' : ' '); }
}
inline string getline() {
    string s;
    getline(cin, s);
    return s;
}
inline void yn(const bool b) { b ? fin("yes") : fin("no"); }
inline void Yn(const bool b) { b ? fin("Yes") : fin("No"); }
inline void YN(const bool b) { b ? fin("YES") : fin("NO"); }
struct io {
    io() {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-11;

/* --------------------   ここまでテンプレ   -------------------- */

int main() {
    
    
    int d,t,s;
    cin>>d>>t>>s;
    int cost=ceil(d/(double)s);
    Yn(cost<=t);
}

Measured memory_bytes: 3632
{-# LANGUAGE BangPatterns #-}
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as C
import Data.List

r' :: IO [Int]
r' = unfoldr (C.readInt . C.dropWhile (==' ')) <$> C.getLine

-- editorial
main = do
    [n,k] <- r'
    xs <- UM.replicate (k+1) 0
    calc <- U.freeze =<< tab n k k xs
    print $ U.foldr1' (+%) $ U.imap (*%) calc

over n k x = (div k x) ^% n

tab n k 0 xs = return xs
tab n k x xs = do
    y <- foldr (+%) 0 <$> mapM (UM.read xs) [2*x,3*x..k]
    UM.write xs x (over n k x -% y)
    tab n k (x-1) xs


mdl = 1000000007

(^%) :: Int -> Int -> Int
b ^% e = powAux (b `rem` mdl) e 1 `mod` mdl
    where 
        powAux _ 0 !ac = ac
        powAux b e !ac = powAux (b*b `rem` mdl) (e `quot` 2)
            (if odd e then b*ac `rem` mdl else ac)

(+%), (-%), (*%), (/%) :: Int -> Int -> Int
a +% b = (a + b) `rem` mdl
a -% b = (a - b) `mod` mdl
a *% b = (a * b) `rem` mdl
a /% b = (a * invMod b) `mod` mdl
    where   invMod :: Int -> Int
            invMod = (^% (mdl-2))

Measured memory_bytes: 12072
package main

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

func main() {
	S := ReadString()
	if S[len(S)-1] == 's' {
		fmt.Println(S + "es")
	} else {
		fmt.Println(S + "s")
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}


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

int main() {
	ll a;
	double b;
	cin >> a;
	cin >> b;
	int num_lp = (int)(100*b + 0.01);
	ll ans = 0;
	rep(i,num_lp) ans += a;
	ans /= 100;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int h, w,a, b; cin >> h >> w >> a >> b;
    dunk(h*w - h*b - w*a + a*b);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(int, N);
    vector<ll> name(5, 0);

    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        if ( s[0] == 'M' ) name[0]++;
        if ( s[0] == 'A' ) name[1]++;
        if ( s[0] == 'R' ) name[2]++;
        if ( s[0] == 'C' ) name[3]++;
        if ( s[0] == 'H' ) name[4]++;
    }

    ll ans = 0;

    ans += name[0] * name[1] * name[2];
    ans += name[0] * name[1] * name[3];
    ans += name[0] * name[1] * name[4];
    ans += name[0] * name[2] * name[3];
    ans += name[0] * name[2] * name[4];
    ans += name[0] * name[3] * name[4];
    ans += name[1] * name[2] * name[3];
    ans += name[1] * name[2] * name[4];
    ans += name[1] * name[3] * name[4];
    ans += name[2] * name[3] * name[4];

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

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> ans(H);
  for(int i = 0; i < H; i++) {
    cin >> ans[i];
  }
  for(string s:ans) {
    cout << s << endl;
    cout << s << endl;
  }
}

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

int main() {
string s;
  cin >> s;
  if(s.at(0) == s.at(1) && s.at(2) == s.at(3) && s.at(1) != s.at(2)|| s.at(1) == s.at(2) &&
     s.at(0) == s.at(3) && s.at(0) != s.at(1)|| s.at(1) == s.at(3) && s.at(2) == s.at(0) &&s.at(1) != s.at(2)){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N,L;
    cin>>N>>L;
    vs S(N);
    rep(i,N) cin>>S.at(i);
    sort(all(S));
    rep(i,N) cout<<S.at(i);
    cout<<endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split(' '))
H_ls = list(map(int, input().split(' ')))
edge, rst = [ [] for i in range(N) ], 0
for i in range(M):
    a, b = map(int, input().split(' '))
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)
for i in range(N):
    is_peak = True
    for j in edge[i]:
        if H_ls[i] <= H_ls[j]:
            is_peak = False
            break
    if is_peak:
        rst += 1
print(rst)

Measured memory_bytes: 29356
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
int main()
{
  int n,t,a;
  vector<int> h(1001);
  cin>>n>>t>>a;
  for(int i=0;i<n;i++) cin>>h.at(i);

  double tmp=100000,det,deg;
  int flag;
  for(int i=0;i<n;i++)
  {
    deg=t-h.at(i)*0.006;
    det=fabs(deg-a);
    if(det<tmp)
    {
      tmp=det;
      flag=i+1;
    }
  }

  cout<<flag<<endl;
}

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

int main(){
    ll H, W; cin >> H >> W;
    vector<string> s(H);
    rep(i, 0, H) cin >> s[i];

    vector<vector<ll>> dp(H, vector<ll>(W,1e9));
    
    dp[0][0] = 0;
    if(s[0][0] == '#') dp[0][0] = 1;
    rep(h, 0, H){
        rep(w, 0, W){
            if(h+1 < H){
                if(s[h][w] == s[h+1][w]){
                    dp[h+1][w] = min(dp[h+1][w], dp[h][w]);
                }else if(s[h+1][w] == '#'){
                    dp[h+1][w] = min(dp[h+1][w], dp[h][w]+1);
                }else{
                    dp[h+1][w] = min(dp[h+1][w], dp[h][w]);
                }
            }
            if(w+1 < W){
                if(s[h][w] == s[h][w+1]){
                    dp[h][w+1] = min(dp[h][w+1], dp[h][w]);
                }else if(s[h][w+1] == '#'){
                    dp[h][w+1] = min(dp[h][w+1], dp[h][w]+1);
                }else{
                    dp[h][w+1] = min(dp[h][w+1], dp[h][w]);
                }
            }
        }
    }
    cout << dp[H-1][W-1] << endl;
    return 0;
}

Measured memory_bytes: 384
c=[0,2,5,5,4,5,6,3,7,6]
N,M=gets.split.map &:to_i
A=gets.split.map &:to_i
d=Array.new(N+1,p)
d[0]=0
0.upto(N){|i|q=A.map{|x|c[x]<=i&&d[i-c[x]]?d[i-c[x]]*10+x:p}.compact;q.any?&&d[i]=q.max}
p d[N]

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


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

	LL mi, ma, sum; cin >> mi;
	ma = mi;
	sum = mi;

	for (int i = 1; i < n; i++) {
		LL x; cin >> x;

		mi = min(mi, x);
		ma = max(ma, x);
		sum += x;
	}

	cout << mi <<" "<< ma <<" " << sum << endl;
	return 0;
}


Measured memory_bytes: 3112
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include <iomanip>
#include<algorithm>
#include<vector>
#include <map>
#define rep(i,N) for(int (i)=0;(i) < (N); ++(i))
typedef long long ll;
using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;

  if(k > (n - 1)*(n - 2)/2){
    cout << -1 << "\n";
  }else{
    int max = (((n - 1) * (n - 2))/ 2) - k;
    cout << (max + n - 1) << "\n";
    for(int i = 2; i <= n; ++i){
        cout << 1 << " " << i << "\n";
    }

    int count = 0;
    for(int i = 2; i < n && count < max; ++i){
      for(int j = i + 1; j <= n && count < max; ++j){
        ++count;
        cout << i << " " << j << "\n";
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
def sub():
    N, M = [int(e) for e in input().split()]
    Xs = [int(e) for e in input().split()]
    if N >= M:
        print(0)
        return

    Xs = sorted(Xs)
    ds = [Xs[i+1] - Xs[i] for i in range(M-1)]
    ds = sorted(ds)
    # print(ds) 
    if N == 1:
        print(sum(ds))
        return
    nb_take = N - 1
    print(sum(ds[:-nb_take]))


if __name__ == "__main__":
    sub()




Measured memory_bytes: 58152
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FR first
#define SC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=9000000009;

signed main(){
  map<string,int> mp;
  string s;
  getline(cin,s);
  string maxsent="";
  vector<int> p;
  REP(i,s.size())if(s[i]==' ')p.PB(i);
  int h=0;
  for(int i=0;i<p.size()+1;i++){
    string t;
    t=s.substr(h,p[i]-h);
    h=p[i]+1;
    mp[t]++;
    if(maxsent.size()<t.size())maxsent=t;
  }
  string mostsent;
  int mode=0;
  for(auto x:mp){
    if(x.SC>mode){
      mode=x.SC;
      mostsent=x.FR;
    }
  }
  cout<<mostsent<<' '<<maxsent<<endl;
  return 0;
}



Measured memory_bytes: 3156
n = int(input())
a = list(map(int, input().split()))
ans1 = max(a)
a.remove(ans1)
val = ans1 / 2
ans2 = int(1e10)
val2 = int(1e10)
# print(val)
for i in range(n-1):
    if abs(a[i] - val) < val2:
        ans2 = a[i]
        val2 = abs(a[i] - val)
        #print(ans2,abs(a[i] - val))
print(ans1, ans2)


Measured memory_bytes: 14428
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {
			String line = null;
			while ((line = br.readLine()) != null) {
				String[] split = line.split(" ");
				int sum = Integer.parseInt(split[0]) + Integer.parseInt(split[1]);
				System.out.println(sum);
			}
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
}

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

long long D = 365, type = 26;
vector<long long> C(type);
vector<vector<long long>> S(D,vector<long long>(type));

long long calc(long long day, long long t, vector<long long> &last){
  long long score = S[day][t];
  last[t] = day;
  for(int i=0;i<type;i++){
    score -= C[i] * (day - last[i]);
  }
  return score;
}

int main(){
  cin >> D;
  for(int i=0;i<type;i++) cin >> C[i];
  for(int i=0;i<D;i++){
    for(int j=0;j<type;j++){
      cin >> S[i][j];
    }
  }
  
  long long score=0;
  vector<long long> last(type,-1);
  for(int i=0;i<D;i++){
    long long t;
    cin >> t;
    t--;
    score += calc(i,t,last);
    cout << score << endl;
  }
  return 0;
}


Measured memory_bytes: 3688
n = gets.strip.to_i
a = readlines.map {|line| line.strip.split.map(&:to_i) }

# 1.本当に最短距離の行列かどうかを判定する
# 2. 最短距離の和を求める、再帰を利用する

# 1
n.times do |via|
  n.times do |from|
    a_from_via = a[from][via]
    next if a_from_via.zero?
    (from+1...n).each do |to|
      next if (a_from_to = a[from][to]).zero? || (a_via_to = a[via][to]).zero?
      if a_from_to == a_from_via + a_via_to
        a[from][to]=a[to][from]=0 
      end
      if a_from_to > a_from_via + a_via_to
        p -1
        exit
      end
    end
  end
end

p a.flatten.inject(:+)/2



Measured memory_bytes: 5628
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int h=sc.nextInt();
		int a=sc.nextInt();
		int cnt=0;
		
		for(int i=0;h>0;i++) {
			h-=a;
			cnt++;
		}
		System.out.println(cnt);
	}

}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define forn(i, n) for (long long i = 0; i < (long long)(n); ++i)
#define for1(i, n) for (long long i = 1; i <= (long long)(n); ++i)
#define fore(i, l, r) for (long long i = (long long)(l); i <= (long long)(r); ++i)
#define fordn(i, n) for (long long i = (long long)(n) - 1; i >= 0; --i)
#define ford1(i, n) for (long long i = (long long)(n); i >= 1; --i)
#define all(x) (x).begin(), (x).end()
#define PI 3.141592653589793
using namespace std;
using ll = long long;
using ld = long double;

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int diff = 'a' - 'A';
    int n, k;
    string s;
    cin >> n >> k >> s;

    s[k-1] = s[k-1] + diff;
    cout << s << endl;
}

Measured memory_bytes: 256
// ternary operation
#[allow(unused_macros)]
macro_rules! _if {
  ($_test:expr, $_then:expr, $_else:expr) => {
    if $_test { $_then } else { $_else }
  };
  ($_test:expr, $_pat:pat, $_then:expr, $_else:expr) => {
    match $_test {
      $_pat => $_then,
      _     => $_else
    }
  };
}

use std::io::{ stdin, BufRead };

fn itp1_2_a<R>(input: &mut R) -> String
  where R: BufRead
{
  let mut f = my::AsciiReader::new(input, 8);
  let a = f.read_int_until_sp::<i32>();
  let b = f.read_int_until_lf::<i32>();

  if a == b {
    format!("a == b\n")
  } else if a < b {
    format!("a < b\n")
  } else {
    format!("a > b\n")
  }
}

fn main() {
  let stdin = stdin();
  print!("{}", itp1_2_a(&mut stdin.lock()));
}

mod my {
  use std::io::BufRead;
  use std::fmt::Debug;
  use std::ops::{ Add, Sub, Mul, Neg };

  const SP: u8 = b' ';
  const LF: u8 = b'\n';

  #[derive(Debug)]
  pub struct AsciiReader<R> {
    input : R,
    buf   : Vec<u8>,
  }

  impl<R> AsciiReader<R>
    where R: BufRead
  {
    #[allow(dead_code)]
    pub fn new(input: R, capa: usize) -> Self {
      AsciiReader {
        input : input,
        buf   : Vec::with_capacity(capa),
      }
    }

    fn read_until(&mut self, delim: u8) -> usize {
      self.buf.clear();
      self.input.read_until(delim, &mut self.buf).unwrap()
    }

    fn parse_int<T>(&self) -> T
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      let len = self.buf.len();
      let mut i = 0;
      let mut n = T::default();
      let mut minus = false;

      if self.buf[i] == b'-' {
        minus = true;
        i += 1;
      } else if self.buf[i] == b'+' {
        i += 1;
      }

      while i < len && b'0' <= self.buf[i] && self.buf[i] <= b'9' {
        n = (n * T::from(10)) + T::from(self.buf[i] - b'0');
        i += 1;
      }

      _if!(minus,
        n.neg(),
        n)
    }

    #[allow(dead_code)]
    pub fn read_int_until_delim<T>(&mut self, delim: u8) -> T
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      self.read_until(delim);
      self.parse_int()
    }

    // s -> n
    #[allow(dead_code)]
    pub fn read_int_until_lf<T>(&mut self) -> T
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      self.read_int_until_delim(LF)
    }

    // s -> n
    #[allow(dead_code)]
    pub fn read_int_until_sp<T>(&mut self) -> T
      where T: Add<Output=T> +
               Sub<Output=T> +
               Mul<Output=T> +
               Neg<Output=T> +
               Default +
               From<u8> +
               Debug
    {
      self.read_int_until_delim(SP)
    }
  }
}



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

long long n, k;
vector<long long> a, res;

void solve();

int main() {
  cin >> n >> k;
  a.resize(n);
  for (auto &p : a) cin >> p;
  solve();
  for (int i = 0; i < n; ++i) cout << res[i] << " \n"[i == n - 1];
  return 0;
}

void solve() {
  while (k--) {
    res.assign(n + 1, 0);
    for (int i = 0; i < n; ++i) {
      ++res[max(0LL, i - a[i])];
      --res[min(n, i + a[i] + 1)];
    }
    for (int i = 1; i < n; ++i) res[i] += res[i - 1];
    a = res;
    bool ch = 1;
    for (int i = 0; i < n; ++i)
      if (res[i] != n) ch = 0;
    if (ch) break;
  }
}


Measured memory_bytes: 7940
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdlib>

using namespace std;

int main()
{
    string a,b;
    cin >> a>>b;
    string c,d;
    while(!a.empty()){
        char y = 'z';
        int s=0,count=0;
        for(char x:a){
            if(y >= x){
                y = x;
                count = s;
            }
            s++;
        }
      //  cout<<a<<endl;
        a.erase(a.begin()+count);
        c.push_back(y);
    }
    //cout<<endl;
    while(!b.empty()){
        char y = 'a';
        int s=0,count=0;
        for(char x:b){
            if(y <= x){
                y = x;
                count = s;
            }
                s++;
        }
       // cout <<b<<endl;
        b.erase(b.begin()+count);
        d.push_back(y);
    }
    if(c < d){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    //cout <<c <<" "<<d<<endl;
    return 0;
}


Measured memory_bytes: 256