akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    // 問題:
    class A_164_Sheep_and_Wolves
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数配列の入力
            var array = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

            if (array[0] <= array[1] == true)
            {
                Console.WriteLine("unsafe");
            }
            else
            {
                Console.WriteLine("safe");
            }

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 28284
D=*0..N=gets.to_i;c=0,2,i=1;$<.map{|l|a,b=l.split.map &:to_i;D[a],D[b]=D[b],D[a];i!=a&&i!=b||i=a+b-i;c<<D[i-1]<<D[i+1]};p~-c.uniq.size

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

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

	if (a == b && b == c) {
		cout << 1 << endl;
	}
	else if (a == b || b == c || c == a) {
		cout << 2 << endl;
	}
	else {
		cout << 3 << endl;
	}

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		int W = sc.nextInt();
		int H = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();

		if(x - r < 0 || x + r > W){
			System.out.println("No");
		}
		else if(y - r < 0 || y + r > H){
			System.out.println("No");
		}
		if(x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H){
			System.out.println("Yes");
		}
	sc.close();
	}
}


Measured memory_bytes: 26328
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs)        \
  for (int i = 0; i < (xs).size(); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs)       \
  for (int i = 0; i < (xs).size(); i++) \
    scanf("%ld", &xs[i]);
#define fillDouble(xs)       \
  for (int i = 0; i < (xs).size(); i++) \
    scanf("%lf", &xs[i]);
#define fillString(xs)       \
  for (int i = 0; i < (xs).size(); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define concat(xs, ys) (xs).insert((xs).end(), (ys).begin(), (ys).end())

const int mod = 1000000007;

struct edge {
    long to;
    long cost;
};

const int MAX_V = 100005;
vector<edge> G[MAX_V];
vector<edge> Ginv[MAX_V];
long d[MAX_V];
long n;
bool use1[MAX_V];
bool usen[MAX_V];

bool bellmanFord(long s) {
  fill(d, d+n, INF*INF);
  d[s] = 0;
  for (int i = 0; i < n; i++) {
    for (int v = 0; v < n; v++) {
      if (!use1[v] || !usen[v]) continue;
      for (int k = 0; k < G[v].size(); k++) {
        edge e = G[v][k];
        if (d[v] != INF*INF && d[e.to] > d[v] + e.cost) {
          d[e.to] = d[v] + e.cost;
          if (i == n-1) {
            return true;
          } 
        }
      }
    }
  }
  return false;
}

void dfs(long s) {
  if(use1[s]) return;
  use1[s] = true;
  for(auto v: G[s]) {
    dfs(v.to);
  }
  return;
}

void dfsn(long s) {
  if(usen[s]) return;
  usen[s] = true;
  for(auto v: Ginv[s]) {
    dfsn(v.to);
  }
  return;
}

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

  long m, p;
  cin >> n >> m >> p;

  rep(i, m) {
    long a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    G[a].push_back({b, p-c});
    Ginv[b].push_back({a, p-c});
  }

  dfs(0);
  dfsn(n-1);
  bool res = bellmanFord(0);

  cout << (res?-1:max(0L, -d[n-1])) << endl;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a[3];
  int k;
  cin>>a[0];
  cin>>a[1];
  cin>>a[2];
  cin>>k;
  sort(a,a+3);
  while(k>0) a[2]*=2,k--;
  cout<<a[0]+a[1]+a[2]<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int a[n]; for (int i = 0; i < n; i++) cin >> a[i];

    int *p = max_element(a, a+n);
    if (*p <= 0) {
        cout << *p << endl << n-1 << endl;
        for (int i = 0; i < p-a; i++) cout << 1 << endl;
        for (int i = 0; i < n-(p-a)-1; i++) cout << n-(p-a)-i << endl;
        return 0;
    }

    long long sum1 = 0, sum2 = 0;
    for (int i = 0; i < n; i += 2) if (a[i] > 0) sum1 += a[i];
    for (int i = 1; i < n; i += 2) if (a[i] > 0) sum2 += a[i];
    cout << max(sum1, sum2) << endl;;

    vector<int> ans;
    if (sum1 <= sum2) ans.push_back(1);
    int i = sum1 > sum2 ? 0 : 1;
    while (i < n && a[i] <= 0) {
        ans.push_back(1); i++;
        if (i < n) { ans.push_back(1); i++; }
    }
    while (i < n-1) {
        if (i + 2 == n) {
            ans.push_back(2);
            break;
        } else if (a[i+2] > 0) {
            ans.push_back(2);
            i += 2;
        } else if (i+3 < n) {
            ans.push_back(3);
            i += 2;
        } else {
            ans.push_back(3);
            ans.push_back(2);
            break;
        }
    }
    cout << ans.size() << endl;
    for (int x : ans) cout << x << endl;
}


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

typedef long long ll;
int n;
ll a[2001];
ll dp[2001][2001];

ll max(ll x,ll y){
	if(x>y)return x;
	return y;
}

ll memo(ll l,ll r){
	if(dp[l][r]!=-1)return dp[l][r];
	if(l==r)return 0;
	if((r+1)%n==l)return a[r];
	ll vl=a[(l-1+n)%n],vr=a[r];
	if(a[(l-2+n)%n]>a[r])vl+=memo((l-2+n)%n,r);
	else vl+=memo((l-1+n)%n,(r+1)%n);
	if(a[(l-1+n)%n]>a[(r+1)%n])vr+=memo((l-1+n)%n,(r+1)%n);
	else vr+=memo(l,(r+2)%n);
	return dp[l][r]=max(vl,vr);
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
	if(n<=2){
		printf("%d\n",max(a[0],a[1]));
		return 0;
	}
	ll res=0;
	memset(dp,-1,sizeof(dp));
	for(int i=0;i<n;i++){
		if(a[(i-1+n)%n]>a[(i+1)%n])res=max(res,memo((i-1+n)%n,(i+1)%n)+a[i]);
		else res=max(res,memo(i,(i+2)%n)+a[i]);
	}
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 32388
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>

using namespace std;

int main()
{
    string s, p;
    bool f = false;
    int index;
    int cnt = 0;
    cin >> s;

    while (true)
    {
        cin >> p;
        if (p == "END_OF_TEXT")
            break;

        for (int i = 0; i < p.size(); i++)
        {
            if (isupper(p[i]))
            {
                p[i] = tolower(p[i]);
            }
        }

        if (p == s)
        {
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3180
import collections
from functools import lru_cache
import bisect

INF = float("inf")
ZERO = 0
ONE = 1


def read():
    return input().strip()


def readInt():
    return int(input().strip())


def readList():
    return list(map(int, input().strip().split()))


def solve(D, T, S):
    return S*T >= D


D, T, S = readList()
print("Yes" if solve(D, T, S) else "No")


Measured memory_bytes: 68164
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String S = scanner.nextLine();
        String T = scanner.nextLine();
        String rotatedString = S;
        if(S.equals(T)){System.out.println("Yes"); return;}
        for(int x = S.length() - 1; x>0; x--){
            rotatedString = S.substring(x,x+1) + rotatedString.substring(0,S.length()-1);
            if(rotatedString.equals(T)){
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");


    }

}


Measured memory_bytes: 21844
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:

};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int K;
    cin >> K;
    int X;
    cin >> X;
    // if (X % 500 == 0) {
    //     X /= 500;
    // } else {
    //     X = 1 << 24;
    // } 
    K *= 500;
    if (K >= X) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
using ll=long long;
using namespace std;

int main(){
  string S;
  cin>>S;
  
  if(S[2]==S[3] && S[4]==S[5]){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }

    return 0;
}

Measured memory_bytes: 3592
from bisect import bisect_right
from bisect import bisect_left

n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))
cnt = 0
bn = []
for i in range(n):
    x1 = bisect_left(a, b[i])
    x2 = bisect_right(c, b[i])
    cnt += x1*(n-x2)
print(cnt)

Measured memory_bytes: 23360
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 666666, mo = 998244353;
int n,a[N],b[N],cnt[N],res=1;
void GG(){puts("0");exit(0);}
Pii seg[N];

int lzy[N<<1],val[N<<1];
void update(int k){val[k]=val[k<<1]+val[k<<1|1];}
void pushdown(int k,int l,int r){
	if(lzy[k]){
		lzy[k<<1]=lzy[k<<1|1]=1;lzy[k]=0;
		int mid=(l+r)>>1;
		val[k<<1]=mid-l+1;val[k<<1|1]=r-mid;
	}
}
void cover(int k, int l, int r, int L, int R){
	if(r<L||l>R)return;
	if(l<=L&&r>=R){lzy[k]=1;val[k]=R-L+1;return;}
	int mid=(L+R)>>1;pushdown(k,L,R);
	cover(k<<1,l,r,L,mid);cover(k<<1|1,l,r,mid+1,R);update(k);
}
int query(int k,int l,int r, int L, int R){
	if(r<L||l>R)return 0;
	if(l<=L&&r>=R)return val[k];
	pushdown(k,L,R);int mid=(L+R)>>1;
	return query(k<<1,l,r,L,mid)+query(k<<1|1,l,r,mid+1,R);
}
void shrink(int &l, int &r){
	per(i,18,0)if(l+(1<<i)<=r&&query(1,l,l+(1<<i)-1,1,n)==(1<<i))l+=1<<i;
	per(i,18,0)if(r-(1<<i)>=l&&query(1,r-(1<<i)+1,r,1,n)==(1<<i))r-=1<<i;
}
int main() {
	read(n);rep(i,1,n)read(a[i]);
	rep(s,1,n)if(a[s]==1&&a[s-1>=1?s-1:n]!=1){
		for(int i=1;i<=n;i++)b[i]=a[s+i-1<=n?s+i-1:s+i-1-n];
		memcpy(a,b,sizeof(b));break;
	}
	if(a[1]!=1)GG();
	rep(i,1,n){
		int j;for(j=i;j<=n;j++)if(a[j]!=a[i])break;
		seg[a[i]]=Pii(i,j-1);//printf("G %d\n",a[i]);
		if(cnt[a[i]])GG();cnt[a[i]]=1;i=j-1;
	}
	int x;for(x=1;x<=n;x++)if(a[x]!=1)break;x--;
//	printf("x = %d\n",x);
	int now=1;for(int i=n;i>=2;i--,now++)if(seg[i].fi){
		int l=seg[i].fi-x+1,r=seg[i].se,L=seg[i].se-x+1,R=seg[i].fi;
		shrink(l,r);shrink(L,R);
	//	printf("%d : %d %d %d %d\n",i,l,r,L,R);
		if(L>R)GG();res=1LL*res*(R-L+1)%mo;now--;
		rep(t,l,r-1)res=1LL*res*now%mo,now--;
		cover(1,l,r,1,n);
	}
	if(a[n]==1){res=1;rep(i,1,n)res=1LL*res*i%mo;cout<<res;return 0;}
	rep(i,1,now)res=1LL*res*i%mo;cout<<res;
	return 0;
}



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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

ll wa(ll a)
{
    ll cnt = a * (a + 1) / 2;
    return cnt;
}

int main()
{

    int N, K;
    cin >> N >> K;

    ll ans = 0;
    ll mod = 1000000000 + 7;
    while (K != (N + 2))
    {
        ll s = wa(K - 1);
        ll e = wa(N) - wa(N - K);
        ans += (e - s) + 1;
        ans %= mod;
        K++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;

int main(){
	
	int A, B;
	cin >> A >> B;
    int n = 1;
    int count = 0;
    while(n < B){
        
        n  += A-1;
        count++; 
    }

	cout << count << endl;
	return 0;
}



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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<"\n"

int main(){
    int r,g,b,k;
    cin >> r >> g >> b >> k;
    int count = 0;
    while(r>=g){
        g*=2;
        count++;
    }
    while(g>=b){
        b*=2;
        count++;
    }
    if(count>k)COUT("No");
    else COUT("Yes");
}

Measured memory_bytes: 3588
//@sakshjha
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define ld long double
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define FRE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define pi 3.14159265358979
const ll MOD = 1000000007;
const ll N=200005;
int main()
{
    IOS
    ll n;
    cin>>n;
    ll a[n+5][4],i,j;
    for(i=0; i<n; i++)
    {
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    ll dp[n+5][4];
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    for(i=1; i<n; i++)
    {
        dp[i][0]=max(dp[i-1][1]+a[i][0],dp[i-1][2]+a[i][0]);
        dp[i][1]=max(dp[i-1][0]+a[i][1],dp[i-1][2]+a[i][1]);
        dp[i][2]=max(dp[i-1][0]+a[i][2],dp[i-1][1]+a[i][2]);

    }
    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
    return 0;
}


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

using namespace std;
using ll = long long;

ll n, ans = 100000000000LL;

ll f(ll a, ll b){
	ll aa = 0, bb = 0;
	while(a > 0){
		aa++;
		a /= 10;
	}
	while(b > 0){
		bb++;
		b /= 10;
	}	
	return max(aa, bb);
}

int main(){
	cin >> n;
	for(ll x = 1; x*x <= n; ++x){
		if(n%x==0){
			ans = min(ans, f(n/x, x));
		}
	}
	cout << ans << endl;
}

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

const long long MOD = 1000000007LL;
const long long INF = 1e18;

long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}
long long slow_mult(long long base, long long exp, long long mod = MOD) {
    long long tot = 0;
    for(;exp > 0;exp >>= 1){
       if((exp & 1) == 1) tot = (tot + base) % mod;
       base = base * 2 % mod;
    }
    return tot;
}

long long best[1003], c[2003];
int a[2003], b[2003];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n, m; cin >> n >> m;

    for(int i = 1; i <= n; ++i)
        best[i] = -INF;
    for(int i = 0; i < m; ++i)
        cin >> a[i] >> b[i] >> c[i];

    best[1] = 0;

    for(int i = 1; i < n; ++i)
        for(int j = 0; j < m; ++j)
            if(best[a[j]] != -INF && best[a[j]] + c[j] > best[b[j]])
                best[b[j]] = c[j] + best[a[j]];

    for(int j = 0; j < m; ++j){
        if(best[a[j]] != -INF && best[a[j]] + c[j] > best[b[j]]){
            best[b[j]] = c[j] + best[a[j]];
            if(b[j] == n){
            	cout << "inf";
                return 0;
            }
        }
    }

    cout << best[n];

    return 0;
}


Measured memory_bytes: 256
import itertools as it

n = int(input())
lis = [[] for _ in range(n)]
val = list(it.product([0, 1], repeat=n))

for i in range(n):
    for j in range(int(input())):
        x, y = map(int, input().split())
        x = x - 1
        lis[i].append((x, y))


def honesty(k, lis, n):
    for i in range(n):
        if k[i] == 1:
            for l, m in lis[i]:
                if k[l] != m:
                    return False
    return True


res = 0
for k in val:
    if honesty(k, lis, n):
        res = max(res, sum(k))
print(res)


Measured memory_bytes: 8820
n = int(input())
h = list(map(int, input().split()))
count = 0
countmax = 0
H = h[0]
for i in range(1,n):
    if H >= h[i]:
        count += 1
        H = h[i]
        countmax = max(count, countmax)
    else:
        count = 0
        H = h[i]
print(countmax)

Measured memory_bytes: 14252
// はじめての高速ゼータ変換
// 理解度は50%くらい
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

typedef pair<int,int> pii;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
    auto f = [](pii p, pii q)->pii{
        int a[4] = {p.first, p.second, q.first, q.second};
        sort(a, a+4);
        return {a[3], a[2]};
    };
    int n;
    cin >> n;
    vector<pii> v(1<<n, {0,0});
    for(int i = 0; i < 1<<n; i++)   cin >> v[i].first;
    for(int j = 0; j < n; j++){
        for(int i = 0; i < 1<<n; i++){
            if((i>>j)&1){
                v[i] = f(v[i], v[i&~(1<<j)]);
            }
        }
    }
    vector<int> ans(1<<n, 0);
    for(int i = 1; i < 1<<n; i++)   ans[i] = max(ans[i-1], v[i].first+v[i].second);
    for(int i = 1; i < 1<<n; i++)   cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 6144
import java.util.Scanner;

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

        int h = sc.nextInt();
        int w = sc.nextInt();

        int[][] a = new int[h+2][w+2];
        int[][] rA = new int[][]{
                {-1, 0}, {-1, 1}, {-1, -1}, {0, 1},
                {0, -1}, {1, 0}, {1, 1}, {1, -1}
        };

        for (int i = 1; i < h+1; i++) {
            String s = sc.next();
            for (int j = 1; j < w+1; j++) {
                char c = s.charAt(j-1);
                if (c == '#') {
                    a[i][j] = -100;
                    for (int[] r : rA)
                        a[i+r[0]][j+r[1]]++;
                }
            }
        }

        for (int i = 1; i < h+1; i++) {
            for (int j = 1; j < w+1; j++) {
                if (a[i][j] < 0)
                    sb.append('#');
                else
                    sb.append(a[i][j]);
            }
            sb.append(System.getProperty("line.separator"));
        }
        System.out.print(sb.toString());
    }
}

Measured memory_bytes: 22996
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

constexpr ll INF = (1LL << 60);

int N, M;
ll L;
ll G[300][300];

void init_G() {
	for (int i = 0; i < 300; ++i)
		for (int j = 0; j < 300; ++j)
			if (i != j)
				G[i][j] = INF;
}

void input() {
	cin >> N >> M >> L;
	for (int i = 0; i < M; ++i) {
		int a, b; ll c;
		cin >> a >> b >> c;
		--a, --b;
		G[a][b] = c; G[b][a] = c;
	}
}

void WF() {
	for (int k = 0; k < N; ++k) {
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				if (G[i][j] > G[i][k] + G[k][j])
					G[i][j] = G[i][k] + G[k][j];
			}
		}
	}
}

void solve() {
	init_G();
	input();
	WF();
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			if (i == j) G[i][j] = 0;
			else if (G[i][j] <= L) G[i][j] = 1;
			else G[i][j] = INF;
		}
	}
	WF();
}

void query(int s, int t) {
	--s, --t;
	if (G[s][t] >= INF) cout << -1 << endl;
	else cout << (G[s][t] - 1) << endl;
}

int main() {
	solve();
	int Q; cin >> Q;
	while (Q--) {
		int s, t; cin >> s >> t;
		query(s, t);
	}
	return 0;
}

Measured memory_bytes: 1280
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>

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

using namespace std;

template<class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmix(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

#define ALL(x) (x).begin(), (x).end()
template<class T>
using vc = vector<T>;
using vi = vc<int>;
using vvi = vc<vi>;

using ll = long long;


int main() {
    auto   ans = vi(26);
    string s;
    while (getline(cin, s)) {
        REP(i, int(s.size())) ans[tolower(s[i]) - 'a'] += 1;
    }

    REP(i, 26) cout << char('a' + i) << " : " << ans[i] << "\n";

    return 0;
}



Measured memory_bytes: 3204
N, M = map(int, input().split())
A = []
B = []
for i in range(M):
    p, y = map(int, input().split())
    A.append([p, y, i])
A.sort()

cur = 1
cnt = 1
for i in range(M):
    if A[i][0] == cur:
        A[i].append(cnt)
        cnt += 1
    else:
        cur = A[i][0]
        cnt = 1
        A[i].append(cnt)
        cnt += 1
A.sort(key=lambda x: x[2])

for a in A:
    print("%06d%06d" % (a[0], a[3]))

Measured memory_bytes: 31180
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    ans = 0
    pre = -INF
    for a in A:
        ans += B[a-1]
        if pre == a-1:
            ans += C[pre-1]

        pre = a
    # 最後
    print(ans)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    C = [int(next(tokens)) for _ in range(N - 1)]  # type: "List[int]"
    solve(N, A, B, C)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define N 105
using namespace std;
int n,K;
int F[N][N];
void solve(){
	scanf("%d %d",&n,&K);
	if(K>(n-1)*(n-2)/2){
		puts("-1");
		return;
	}
	int tt=(n-1)*(n-2)/2-K;
	printf("%d\n",tt+n-1);
	for(int i=2;i<=n;i++)printf("%d %d\n",1,i);
	for(int i=2;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(tt==0)break;
			printf("%d %d\n",i,j);
			tt--;
		}
		if(tt==0)break;
	}
}
int main(){
	solve();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    int ans=0;
    for(int i=1;i<=N;i+=2){
        int cnt=0;
        for(int j=1;j<=i;j++){
            if(i%j==0) cnt++;
        }
        if(cnt==8) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        char[] s=sc.next().toCharArray();
        int i=0,j,count=0;
        while(n>i){
            j=i+1;
            while(n>j&&s[i]==s[j]) j++;
            count++;
            i=j;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 28232
#include <bits/stdc++.h>
using namespace std;
 
 
 
#define int long long int
#define rep(i,n) \
    for(int i = 0; i < n; i++)
#define rep2(i, a, b) \
    for(int i = a; i < b; i++)
#define all(c) \
    c.begin(), c.end()
#define init(arr, num) \
    memset(arr, num, sizeof(arr))
#define fast\
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inputFile \
    freopen("input.txt", "r", stdin); 
#define outputFile \
    freopen("output.txt", "w", stdout);
#define modM 1000000007
#define PI 3.1415926535897932

#ifdef Voneone
#define TRACE
#endif
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std::endl;

}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); 
    cout.write(names, comma - names) << " : " << arg1 << " | "; 
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

 
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< int, int > ii;
typedef unordered_set<int> usi;
 

void solve() 
{ 

    

    int r; 
    cin >> r;

    cout << setprecision(10) << 2*PI*r;


} 
 
 
 
 
signed main()
{
 
    
    #ifdef Voneone
    inputFile;
    #endif
    #ifndef Voneone
    fast;
    #endif


    int T = 1;
    // cin >> T;
    while(T--){
        solve();
        cout << endl;
        
        

    }
    
    
    return 0;
 
}






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

int main() {
  int input;
  vector<int> A(4);
  cin >> input;

  A.at(0) = input/1000; input -= A.at(0)*1000;
  A.at(1) = input/100; input -= A.at(1)*100;
  A.at(2) = input/10; input -= A.at(2)*10;
  A.at(3) = input;

  for (int i = 0; i < (1 << 3); i ++) {
    bitset<3> tmp(i);
    int sum = A.at(0);
    vector<char> op(3);
    for (int j = 0; j < 3; j++) {
      if(tmp.test(j)) {
        sum+=A.at(j+1);
        op.at(j)='+';
      } else {
        sum-=A.at(j+1);
        op.at(j)='-';
      }
    }
    if (sum == 7) {
    for(int step = 0; step < 3; step++) {
      cout << A.at(step) << op.at(step);
    }
    cout << A.at(3) << "=" << "7" << endl;
    break;
    }
  }
}

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

int main() {
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> a(A), b(B), x(M), y(M), c(M);
    int minA = 1e9, minB = 1e9;
    rep(i, A) {
        cin >> a[i];
        minA = min(a[i], minA);
    }
    rep(i, B) {
        cin >> b[i];
        minB = min(b[i], minB);
    }
    rep(i, M) cin >> x[i] >> y[i] >> c[i];

    int ans = minA + minB;
    rep(i, M){
        ans = min(a[x[i]-1] + b[y[i]-1] - c[i], ans);
    }
    cout << ans;
}


Measured memory_bytes: 2176
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(void)
{
	char num_str[1002];
	int num;
	long sum = 0;
	int i;
	char tmp;
	
	while (1){
		fgets(num_str, sizeof(num_str),stdin);
		
		if (num_str[0] == '0') break;
		for (i = 0; i < strlen(num_str)-1;i++)
		{
			tmp = num_str[i];
			num = atoi(&tmp);
			sum = sum + num;
		}
		
		printf("%d\n",sum);
		
		sum = 0;
		memset(num_str,1002,0);
	}
	return 0;
}

Measured memory_bytes: 528
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	int ans=0,n;
	cin>>n>>s;
	int pt1=0,pt2=n-1;
	while(pt1<pt2){
	    if(s[pt1]=='R'){
	        pt1++;
	    }
	    if(s[pt2]=='W'){
	        pt2--;
	    }
	    if(s[pt1]=='W' and s[pt2]=='R'){
	        ans++;
	        pt1++;
	        pt2--;
	    }
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3720
N,M=map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
G={}
for i in range(1,N*M+1):
  G[i]=[]
for i in range(N):
  G[A[i]].append(i+1)
for i in range(M):
  G[B[i]].append(-(i+1))
A=sorted(A)
B=sorted(B)
ans=1
import bisect
mod=10**9+7
for i in range(N*M,0,-1):
  if len(G[i])>2:
    print(0)
    exit()
  elif len(G[i])==2:
    if G[i][0]*G[i][1]>0:
      print(0)
      exit()
  elif len(G[i])==1:
    if G[i][0]>0:
      d=bisect.bisect_left(B,i)
      ans*=M-d
      ans%=mod
    else:
      e=bisect.bisect_left(A,i)
      ans*=N-e
      ans%=mod
  else:
    d=bisect.bisect_left(B,i)
    e=bisect.bisect_left(A,i)
    f=N*M-i
    if f<0:
      exit()
    ans*=(M-d)*(N-e)-f
    ans%=mod
print(ans)


Measured memory_bytes: 236796
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll n, m;
  cin >> n >> m;
  ll ans = (1900*m+100*(n-m))*(1ll<<m);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
ll memo[100];
ll f(int l) {
  if(memo[l] != -1) return memo[l];
  if(l == 0) return 2;
  if(l == 1) return 1;
  return memo[l] = f(l - 1) + f(l - 2);
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  FOR(i,0,100) memo[i] = -1;
  cout << f(N) << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import defaultdict,deque
import math
def main():
    n = input()
    tmp = 0
    for i in range(len(n)):
        tmp += int(n[i])
        tmp%=9
    if(tmp%9==0):
        print("Yes")
    else:
        print("No")
if __name__ == '__main__':
    main()


Measured memory_bytes: 9580
#include <stdio.h>

int main(void)
{
	int a,b[101],i,sum=0,ssum=0,mina;
	scanf("%d",&a);
	
	for(i=0;i<a;i++){
		scanf("%d",&b[i]);
		sum=sum+b[i];
	}
	mina=sum;
	
	for(i=0;i<a;i++){
		sum=sum-b[i];
		ssum=ssum+b[i];
		if(mina>abs(sum-ssum))mina=abs(sum-ssum);
	}
	printf("%d\n",mina);
	
	return 0;
}


Measured memory_bytes: 128
package main

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

const inf = 1 << 60

func main() {
	n := getInt()
	as := make([]int, n)
	bs := getIntSlice(n - 1)

	for i := range as {
		x, y := inf, inf
		if i > 0 {
			x = bs[i-1]
		}
		if i < n-1 {
			y = bs[i]
		}

		as[i] = min(x, y)
	}

	ans := sum(as...)
	fmt.Println(ans)
}

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

func sum(ns ...int) int {
	var sum int
	for _, n := range ns {
		sum += n
	}
	return sum
}

// -----------------------------------------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
}

func getInt() int {
	i, err := strconv.Atoi(getString())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;

namespace arc087_a
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = GetInt();
            var al = GetIntList();
            var ad = new Dictionary<int, int>();

            for(int i = 0; i< N; i++) 
            {
                if (!ad.ContainsKey(al[i])) ad.Add(al[i], 0);
                ad[al[i]]++;
            }

            long r = 0;            
            foreach (var k in ad.Keys)
                if (k != ad[k])
                    if (k > ad[k])
                        r += ad[k];
                    else
                        r += ad[k] - k;

            Console.WriteLine(r);
          
        }

        public static string GetStr() => Console.ReadLine();
        public static int GetInt() => int.Parse(Console.ReadLine());
        public static long GetLong() => long.Parse(Console.ReadLine());
        public static double GetDouble() => double.Parse(Console.ReadLine());
        public static decimal GetDecimal() => decimal.Parse(Console.ReadLine());

        public static List<string> GetStrList() => Console.ReadLine().Split(' ').ToList();
        public static List<int> GetIntList() => Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
        public static List<long> GetLongList() => Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
        public static List<double> GetDoubleList() => Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToList();
        public static List<decimal> GetDecimalList() => Console.ReadLine().Split(' ').Select(x => decimal.Parse(x)).ToList();

    }
}


Measured memory_bytes: 30044
#include <stdio.h>

int main()
{
        int a,b,c, temp;

        scanf("%d %d %d",&a,&b,&c);

        if(b < a){
                temp = a;
                a = b;
                b = temp;
        }

        if(c < b){
                temp = b;
                b = c;
                c = temp;
        }

        if(b < a){
                temp = a;
                a = b;
                b = temp;
        }

        printf("%d %d %d\n",a,b,c);

        return 0;
}

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

using namespace std;

int length;
vector<int> rn;
double dp[(1 << 12)][12];

const int INF = 1000000;

void solve(){
  //  cout << rn.size() << endl;
  for(int i = 0; i < (1 << rn.size()); i++){
    fill(dp[i],dp[i]+rn.size(),INF);
  }
  
  for(int i = 0; i < rn.size(); i++){
    dp[1<<i][i] = 2*rn[i];
  }
  
  for(int s = 1; s < (1 << rn.size()); s++){
    for(int j = 0; j < rn.size(); j++){
      if(((s >> j) & 1) == 0){
	continue;
      } 
      for(int i = 0; i < rn.size(); i++){
	if(((s >> i) & 1) == 0){
	  dp[s|1<<i][i] = min(dp[s|1<<i][i]
			      ,dp[s][j] + 2*sqrt(rn[j]*rn[i])-rn[j]+rn[i]);
	}
      }
    }
  }
  double minNum = INF;
  for(int i = 0; i < rn.size(); i++){
    minNum = min(minNum,dp[(1<<(rn.size()))-1][i]);
  }
  
  
  if(minNum <= (double)length){
    cout << "OK" << endl;
  }
  else
    cout << "NA" << endl;
}

int main(){

  string str;
  while(1){
    rn.clear();
    getline(cin,str);
    if(cin.eof())
      break;
    bool flag = true;
    string s;
    for(int i = 0; i < str.size(); i++){
      if(str[i] == ' '){
	if(flag){
	  length = atoi(s.c_str());
	  flag = false;
	}
	else{
	  rn.push_back(atoi(s.c_str()));
	}
	s = "";
      }
      else if(i == str.size()-1){
	s += str[i];
	rn.push_back(atoi(s.c_str()));
      }
      else
	s += str[i];
    }

    solve();
  }
  
  return 0;
}

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

int main(){
  string s;
  cin >> s;
  if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I')cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.List (unfoldr)
import Data.Maybe (catMaybes)

main :: IO ()
main = do
  let
    primeFactors :: Int -> [(Int, Int)]
    primeFactors = catMaybes . unfoldr next . (,) 2
      where
        next :: (Int, Int) -> Maybe (Maybe (Int, Int), (Int, Int))
        next (_, 1)             = Nothing
        next (d, m) | m < d * d = Just (Just (m, 1), (0, 1))
                    | otherwise = Just . ((,) <$> fmap ((,) d) . fst <*> (,) (succ d) . snd) $ ord d m
        ord :: Int -> Int -> (Maybe Int, Int)
        ord d = go 0
          where
            go :: Int -> Int -> (Maybe Int, Int)
            go c m | r == 0 = go (succ c) m'
              where
                (m', r) = m `divMod` d
            go 0 m = (Nothing, m)
            go c m = (Just c, m)
    f :: Int -> Int
    f m = unsafeBinaryMaxInt p (1, 8)
      where
        unsafeBinaryMaxInt :: (Int -> Bool) -> (Int, Int) -> Int
        unsafeBinaryMaxInt p = check
          where
            check :: (Int, Int) -> Int
            check ij@(_, j) | p j       = j
                            | otherwise = search ij
            search :: (Int, Int) -> Int
            search = fst . until ((==) <$> fst <*> pred . snd) halve
              where
                halve :: (Int, Int) -> (Int, Int)
                halve (i, j) | p m       = (m, j)
                             | otherwise = (i, m)
                  where
                    m = (i + j) `div` 2
        p :: Int -> Bool
        p = (<= 2 * m) . ((*) <$> id <*> succ)
  n <- unsafeTextToInt <$> T.getLine :: IO Int
  print . sum . map (f . snd) . primeFactors $ n

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


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

using namespace std;
int main(int argc, char* argv[])
{
	int r;
	int D;
	int weight;
	cin >> r;
	cin >> D;
	cin >> weight;
	const int diffAge = 10;
	int sumWeight = weight;
	for (int i = 0; i < diffAge; ++i)
	{
		std::cout << (sumWeight = r * sumWeight - D) << std::endl;
	}
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

# D - Replacing
def get_sum(dic):
	sum = 0
	
	for k, v in dic.items():
		sum += k * v
	
	return sum


n = int(input())
a = list(map(int, input().split()))
q = int(input())
dic = dict()

for ai in a:
	dic.setdefault(ai, 0)
	dic[ai] += 1

for i in range(q):
	b, c = map(int, input().split())

	count = dic.pop(b, 0)
	
	if count > 0:
		dic.setdefault(c, 0)
		dic[c] += count

	if i == 0:	
		sum = get_sum(dic)
	else:
		sum += (c - b) * count
	
	print(sum)

Measured memory_bytes: 93524
def partition(a, p, r):
    x = a[r]
    i = p - 1
    for j in range(p, r):
        if a[j] <= x:
            i = i + 1
            a[i], a[j] = a[j], a[i]
    a[i + 1], a[r] = a[r], a[i + 1]
    return i + 1

n = int(input())
a = list(map(int, input().split()))
q = partition(a, 0, len(a) - 1)
a[q] = '[{}]'.format(a[q])
print(*a)

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

#define mod 1000000007
using namespace std;
int n,k;
vector<int> rad[100005];

long long gv(int now,int from,int l1,int l2)
{
    long long ret =1;
    int nm = 0;
    long long tm = 1;

    for(int i=0;i<rad[now].size();++i)
    {
        if(rad[now][i]==from) continue;
        ret *= gv(rad[now][i],now,1,l1+rad[now].size()-1-(from==-1?0:1));
        ret %= mod;
        tm *= k-l1-1-nm;
        tm %= mod;
        ++nm;
    }
    return ret*tm%mod;
}

int main()
{
    scanf("%d%d",&n,&k);
    int l,r;
    for(int i=1;i<n;++i)
    {
        scanf("%d%d",&l,&r);
        rad[l].push_back(r);
        rad[r].push_back(l);
    }

    printf("%lld\n",gv(1,-1,0,0)*k%mod,0,0);
    return 0;
}


Measured memory_bytes: 12800
# https://atcoder.jp/contests/abc085/tasks/abc085_d

n, hp = gets.split.map(&:to_i)

swords = []

n.times { swords << gets.split.map(&:to_i) }

strongest_slash_damage = swords.sort_by{ |s| s[0] }.reverse[0][0]

res = 0

valid_throw_damages = swords.find_all { |s| s[1] >= strongest_slash_damage }.map { |s| s[1] }.sort.reverse

valid_throw_damages.each do |damage|
  break if hp <= 0
  hp -= damage
  res += 1
end
hp = 0 if hp <= 0

res += (hp.to_f / strongest_slash_damage).ceil

puts res

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

using namespace std;

int main() {
	map<string, vector<int> > dict;
	
	string s;
	int p;
	while (cin >> s >> p) {
		dict[s].push_back(p);
	}
	
	map<string, vector<int> >::iterator it;
	for (it = dict.begin(); it != dict.end(); it++) {
		vector<int> v = (*it).second;
		int size = v.size();
		
		sort(v.begin(), v.end());
		
		cout << (*it).first << endl;
		for (int i = 0; i < size - 1; i++) {
			cout << v[i] << " ";
		}
		cout << v[size - 1] << endl;
	}
	
	return 0;
}

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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

long long int n, m;

int main(){
	cin >> n >> m;
	cout << (abs(n-m)<=1 ? "Brown":"Alice") << endl;
	return 0;
}

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

int p[100010];
int _next[100010],last[100010];
int last2[100010],next2[100010];
int main()
{
    int n;scanf("%d",&n);
    for (int i=1;i<=n;i++) scanf("%d",&p[i]);
    p[0]=n+1;p[n+1]=n+1;
    last[0]=0;_next[n+1]=n+1;
    for (int i=1;i<=n;i++)
    {
        int tmp=i-1;
        while (p[tmp]<=p[i])
            tmp=last[tmp];
        last[i]=tmp;
        tmp--;
        if (tmp<0) tmp=0;
        while(p[tmp]<=p[i])
            tmp=last[tmp];
        last2[i]=tmp;
    }
    for (int i=n;i>0;i--)
    {
        int tmp=i+1;
        while (p[tmp]<=p[i])
            tmp=_next[tmp];
        _next[i]=tmp;
        tmp++;
        if (tmp>n+1) tmp=n+1;
        while(p[tmp]<=p[i])
            tmp=_next[tmp];
        next2[i]=tmp;
    }
    long long ans=0;
    for (int i=1;i<=n;i++)
    {
        //printf("%d %d %d %d\n",last2[i],last[i],next[i],next2[i]);
        ans+=1LL*p[i]*(i-last[i])*(next2[i]-_next[i]);
        ans+=1LL*p[i]*(_next[i]-i)*(last[i]-last2[i]);
        //cout<<ans<<endl;
    }
    cout<<ans;
}



Measured memory_bytes: 2176
N,M = map(int, input().split())
A = list(map(int, input().split()))
count = 0
all = 0

for i in range(N):
  all = all + A[i]

for i in range(N):
  if A[i] >= all / (4 * M):
    count = count + 1

if count >= M:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef pair<int,int> P;
int ds[4]={1,8,3,6};
int main(){
	while(true){
		int h,w;
		cin>>w>>h;
		if(h==0) break;
		int s=0,g=0;
		map<int,int> d;
		rep(i,9){
			int a;
			cin>>a;
			s=s*9+a;
		}
		rep(i,9){
			int a;
			cin>>a;
			g=g*9+a;
		}
		priority_queue<P,vector<P>,greater<P> > que;
		d[s]=0;
		que.push(P(0,s));
		while(!que.empty()){
			P p=que.top();
			que.pop();
			int a=p.sc;
			int c=p.fs;
			if(c!=d[a]) continue;
			if(a==g) break;
			int v[9];
			int ac=a;
			rep(i,9){
				v[8-i]=ac%9;
				ac/=9;
			}
			int z=0;
			rep(i,9) if(v[i]==0) z=i;
			rep(i,4){
				swap(v[z],v[(z+ds[i])%9]);
				int na=0;
				rep(j,9) na=na*9+v[j];
				swap(v[z],v[(z+ds[i])%9]);
				int cost=(i<2?w:h);
				if(!d.count(na)||c+cost<d[na]){
					d[na]=c+cost;
					que.push(P(c+cost,na));
				}
			}
		}
		cout<<d[g]<<endl;
	}
}

Measured memory_bytes: 19168
#include <map>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <tr1/unordered_map>
#define num(x) (x>='0' && x<='9')
typedef unsigned long long ull;
typedef long long ll;
using namespace std::tr1;
using namespace std;
int read(){
    int p=0, q=1;
    char ch=getchar();
    while (!num(ch))
        (ch=='-'?q=-1:0),
        ch=getchar();
    while (num(ch)) p=p*10+ch-'0', ch=getchar();
    return p*q;
}
#define N 55
#define M 25
#define ND 60000000
#define EDGE 90000000
int n, l[N], c[N], pre[N];
char s[N][M], res[N][M];
int nex[EDGE], nu[EDGE];
ll dist[ND], va[EDGE];
bool flag[ND];
int st, cnt;
ll INF=1ll*1999999999*1999999999;
struct node{
	int n;
	ll dist;
	node (int n, ll dist): n(n), dist(dist){}
	bool operator <(const node &o) const {return this->dist<o.dist;}
	bool operator >(const node &o) const {return this->dist>o.dist;} 
};
priority_queue<node, vector<node>, greater<node> > q;
void add(int u, int v, int w){
	nex[++cnt]=nex[u];nex[u]=cnt;nu[cnt]=v;va[cnt]=w;
}
void dijkstra(){
	for (int i=1;i<=st;i++) dist[i]=INF, flag[i]=0;
	dist[st]=0;
	q.push(node(st,0));
	while (!q.empty()){
		node curNode=q.top();
		q.pop();
		int u=curNode.n;
		flag[u]=1;
		for (int j=nex[u];j;j=nex[j]){
			int v=nu[j];
			if (!flag[v] && dist[u]+va[j]<dist[v])
				dist[v]=dist[u]+va[j],
				q.push(node(v,dist[v]));
		}
		while (!q.empty() && flag[q.top().n]) q.pop();
	}
}
#define get(i,j,x,y) (pre[i-1]+j+1)*1010+pre[x-1]+y+1
inline void construct(int i, int j, int k, int p){
	int u=get(i,j,k,p);
	if (j<l[i]-1 && p<l[k]-1){
		if (s[i][j+1]==res[k][p+1]){
			int tj=j, tp=p;
			while (tj<l[i]-1 && tp<l[k]-1 && s[i][tj+1]==res[k][tp+1]) 
				tj++, tp++;
			add(u,get(i,tj,k,tp),0);
		}
	}
	else if (j<l[i]-1){
		for (int x=1;x<=n;x++)
			if (s[i][j+1]==res[x][0]) 
				add(u,get(i,j+1,x,0),c[x]);
	}
	else if (p<l[k]-1){
		for (int x=1;x<=n;x++)
			if (s[x][0]==res[k][p+1]) 
				add(u,get(x,0,k,p+1),c[x]);
	}
	else{
		for (int x=1;x<=n;x++)
			for (int y=1;y<=n;y++)
				if (s[x][0]==res[y][0])
					add(u,get(x,0,y,0),c[x]+c[y]);
	}
}
int main(){
	n=read();
	for (int i=1;i<=n;i++){
		scanf("%s", &s[i]);
		c[i]=read();
		l[i]=strlen(s[i]);
		pre[i]=pre[i-1]+l[i];
		for (int j=0;j<l[i];j++) res[i][j]=s[i][l[i]-1-j];
	}
	ll ans=INF;
	for (int beg=1;beg<=n;beg++){
		st=1005*1010, cnt=st;
		for (int i=1;i<=cnt;i++) nex[i]=0;
		for (int y=1;y<=n;y++)
			if (s[beg][0]==res[y][0])
				add(st,get(beg,0,y,0),c[beg]+c[y]);
		for (int i=1;i<=n;i++)
			for (int k=1;k<=n;k++){
				for (int j=0;j<l[i];j++)
					construct(i,j,k,0),
					construct(i,j,k,l[k]-1);
				for (int p=0;p<l[k];p++)
					construct(i,0,k,p),
					construct(i,l[i]-1,k,p);
			}
		dijkstra();
		ll res=INF;
		for (int x=1;x<=n;x++)
			res=min(res,dist[get(x,l[x]-1,beg,l[beg]-1)]);
		ans=min(ans,res);
	}
	if (ans==INF) ans=-2;
	cout<<ans/2<<endl;
    return 0;
}

Measured memory_bytes: 62768
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long Mod = 998244353;
  int n,m,k;
  cin >> n >> m >> k;
  long long inv[200000+10];
  inv[0]=0;
  inv[1]=1;
  for(int i=2; i<n+5; i++){
    inv[i] = ((Mod-Mod/i) * inv[Mod%i])%Mod;
  }
  long long c[200000+10];
  long long a[200000+10];
  c[0] = 1;
  for(int i=1; i<n+5; i++){
    c[i] = (c[i-1] * (n-i))%Mod;
    c[i] = (c[i]* inv[i])%Mod;
  }
  a[0] = m;
  //cout << Mod << endl;
  for(int i=1; i<n+5; i++){
    a[i]=(a[i-1]*(m-1))%Mod;
    //cout << a[i] << endl;
  } 
  long long s=0;
  for(int i=0; i<=k; i++){
    s = (s + c[i] * a[n-1-i])%Mod;
  }
  cout << s;
  
}

Measured memory_bytes: 8300
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 200000000000
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()

bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
// 入力



int main() {
    string S;
    cin >>S;
    ll ans =0;
    if(1){
        rep(i,S.size()/2){
            if(S[i] != S[S.size()-1-i]){
                ans++;
            }
        }
    }
    
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 3632