akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
    */
int main(){
    string S;
    cin >> S;
    S[3] = '8';
    cout << S << endl;
}

Measured memory_bytes: 256
import java.util.*;
	public class Main{
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            //入力
            long n = Integer.parseInt(sc.next());
            long m = Integer.parseInt(sc.next());
            long ret = 0;
            
            if(n>1 && m>1){
            	ret = (n-2) * (m-2);
            }else if(n==1 && m==1){
            	ret = 1;
            }else{
            	ret = Math.max(n, m) - 2;
            }
            
            //出力
            System.out.println(ret);
            sc.close();
        }
    }
	

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;

void print() { cout << endl; }
template <typename Head, typename... Tail>
void print(Head head, Tail... tail) {
    int size = sizeof...(Tail);
    cout << head;
    if (size > 0) {
        cout << " ";
    }
    print(tail...);
}

void print0() {}
template <typename Head, typename... Tail>
void print0(Head head, Tail... tail) {
    cout << head;
    print0(tail...);
}

struct xstruct {
    ll val;
};
bool operator<=(const xstruct& lhs, const xstruct& rhs) {
    return lhs.val <= rhs.val;
}
bool operator<(const xstruct& lhs, const xstruct& rhs) {
    return lhs.val < rhs.val;
}
bool operator>=(const xstruct& lhs, const xstruct& rhs) {
    return lhs.val >= rhs.val;
}
bool operator>(const xstruct& lhs, const xstruct& rhs) {
    return lhs.val > rhs.val;
}
bool operator==(const xstruct& lhs, const xstruct& rhs) {
    return lhs.val == rhs.val;
}
bool operator!=(const xstruct& lhs, const xstruct& rhs) {
    return lhs.val != rhs.val;
}
ostream& operator<<(ostream& os, xstruct const& xst) {
    return os << xst.val;
}

struct edge {
    ll u;
    ll v;
    ll cost;
};
bool operator<=(const edge& lhs, const edge& rhs) {
    return lhs.cost <= rhs.cost;
}
bool operator<(const edge& lhs, const edge& rhs) {
    return lhs.cost < rhs.cost;
}
bool operator>=(const edge& lhs, const edge& rhs) {
    return lhs.cost >= rhs.cost;
}
bool operator>(const edge& lhs, const edge& rhs) {
    return lhs.cost > rhs.cost;
}
bool operator==(const edge& lhs, const edge& rhs) {
    return lhs.cost == rhs.cost;
}
bool operator!=(const edge& lhs, const edge& rhs) {
    return lhs.cost != rhs.cost;
}

void dijkstra(ll n, ll start, vector<vector<edge>>& edgemap, vector<ll>& min_cost, vector<ll>& dists) {
    vector<bool> done(n + 1);
    for (ll j = 0; j <= n; j++) {
        min_cost[j] = -1;
        dists[j] = -1;
        done[j] = false;
    }
    priority_queue<edge, vector<edge>, greater<edge>> pq;

    pq.push(edge{u : -1, v : start, cost : 0});
    while (!pq.empty()) {
        edge e = pq.top();
        pq.pop();
        if (done[e.v]) {
            continue;
        }
        dists[e.v] = e.u;
        done[e.v] = true;
        min_cost[e.v] = e.cost;
        for (auto next_e : edgemap[e.v]) {
            if (!done[next_e.v]) {
                edge total_next_e = next_e;
                total_next_e.cost = min_cost[next_e.u] + next_e.cost;
                pq.push(total_next_e);
            }
        }
    }
}

int main() {
    ll N, M;
    cin >> N >> M;
    vector<edge> edges(M);
    vector<vector<edge>> edgemap(N + 1);

    for (ll i = 0; i < M; i++) {
        ll a, b;
        cin >> a >> b;
        // a--;
        // b--;
        edge e1 = edge{u : a, v : b, cost : 1};
        edge e2 = edge{u : b, v : a, cost : 1};
        edges.push_back(e1);
        edges.push_back(e2);
        edgemap[a].push_back(e1);
        edgemap[b].push_back(e2);
    }
    vector<ll> min_cost(N + 1);
    vector<ll> dists(N + 1);
    dijkstra(N, 1, edgemap, min_cost, dists);

    print("Yes");
    for (ll i = 2; i <= N; i++) {
        print(dists[i]);
    }
}


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

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

int main() {
	int n;
	cin >> n;
	vector<int> a;
	map<int, int> b;
	rep(i, n) {
		int x;
		cin >> x;
		a.push_back(x);
		b[x]++;
	}

	ll all = n;

	sort(a.begin(), a.end());
	for (auto itr = b.begin(); itr != b.end(); itr++) {
		//itr->second--;
		all--;
	}

	if (all % 2 == 0)cout << b.size() << endl;
	else cout << b.size() - 1 << endl;

	return 0;
}

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

#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define MOD 1000000007

const int MAX_M = 100000;


int main(){
  ll n, m;
  bool ok = true;
  //string s;
  cin >> n >> m;
  
  vector<ll> a(n);
  rep(i,0,n)
    cin >> a.at(i);
  
  sort(all(a), greater<int>());
  ll sum = accumulate(all(a),0);
  
  rep(i,0,m){
    if(a.at(i)*4*m < sum){
      ok = false;
      break;
    }
  }
  
  
  cout << ((ok)? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
bool dp[1000001];
int main(){
    bool latte[1000001];
    fill(latte,latte+1000001,true);
    latte[0]=latte[1]=false;
    for(int i=2;i<=1000000;i+=2)latte[i]=false;
    for(int i=3;i<=1000000;i+=2){
        if(latte[i])
            for(int j=i+i;j<=1000000;j+=i)
                latte[j]=false;

    }
    int n,l;
    while(cin>>n>>l,n||l){
        int v[30];
        for(int i=0;i<n;i++)cin>>v[i];
        fill(dp,dp+l,false);
        dp[0]=true;
        for(int i=0;i<=l;i++){
            if(!dp[i])continue;
            for(int j=0;j<n;j++){
                int to=i+v[j];
                if(to>l)continue;
                dp[to]=true;
            }
        }
        bool NAFlag=true;
        for(int i=l;i>=0;i--){
            if(dp[i]&&latte[i]){
                cout<<i<<endl;
                NAFlag=false;
                break;
            }
        }
        if(NAFlag)cout<<"NA"<<endl;
    }

    return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
inline int power(int a, int b) {
    long long res = a, ans = 1;
    for (; b; b >>= 1, res = res * res % mod) if (b & 1) ans = ans * res % mod;
    return ans;
}
int n, k, m, a[25010];
int buc[410];
int dp[2][25010][410];
#define dp1 dp[0]
#define dp2 dp[1]
int main() {
    scanf("%d%d%d", &n, &k, &m);
    int llen = 0, rlen = 0;
    set < int > s;
    for (int i = 1; i <= m; i++) scanf("%d", a + i);
    if (m >= k) {
        int now = 0;
        for (int i = 1; i <= k; i++) {
            if (!buc[a[i]]++) now++;
        }
        if (now == k) return cout << 1ll * power(k, n - m) * (n - m + 1) % mod << endl, 0;
        for (int i = k + 1; i <= m; i++) {
            if (!buc[a[i]]++) now++;
            if (!--buc[a[i - k]]) now--;
            if (now == k) return cout << 1ll * power(k, n - m) * (n - m + 1) % mod << endl, 0;
        }
    }
    while (llen != m && !s.count(a[llen + 1])) s.insert(a[++llen]);
    s.clear();
    while (rlen != m && !s.count(a[m - rlen])) s.insert(a[m - rlen++]);
    if (llen == m) {
        dp1[1][1] = k;
        for (int i = 1; i < n; i++) {
            for (int j = k - 1; j > 0; j--) {
                dp1[i + 1][j] = (dp1[i + 1][j + 1] + dp1[i][j]) % mod;
            }
            for (int j = 1; j < k - 1; j++) dp1[i + 1][j + 1] = (dp1[i + 1][j + 1] + 1ll * dp1[i][j] * (k - j)) % mod;
        }
        for (int i = 1; i < k; i++) dp2[n][i] = 1;
        for (int i = n; i --> 0; ) {
            for (int j = 1; j < k; j++) dp2[i][j] = (dp2[i][j - 1] + dp2[i + 1][j]) % mod;
            for (int j = 1; j < k - 1; j++) dp2[i][j] = (1ll * dp2[i + 1][j + 1] * (k - j) + dp2[i][j]) % mod;
        }
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = m; j < k; j++) {
                ans = (ans + 1ll * dp1[i][j] * dp2[i][j]) % mod;
            }
        }
        for (int i = k; i > k - m; i--) ans = 1ll * ans * power(i, mod - 2) % mod;
        return cout << (mod - ans + 1ll * power(k, n - m) * (n - m + 1)) % mod << endl, 0;
    }
    else {
        for (int t = 0; t < 2; t++) {
            dp[t][0][t ? llen : rlen] = 1;
            for (int i = 0; i < n; i++) {
                for (int j = k - 1; j > 0; j--) {
                    dp[t][i + 1][j] = (dp[t][i + 1][j + 1] + dp[t][i][j]) % mod;
                }
                for (int j = 1; j < k - 1; j++) dp[t][i + 1][j + 1] = (dp[t][i + 1][j + 1] + 1ll * dp[t][i][j] * (k - j)) % mod;
            }
        }
        int ans = 0;
        for (int i = 0; i <= n - m; i++) {
            int sum1 = 0, sum2 = 0;
            for (int j = 1; j < k; j++) sum1 = (sum1 + dp[0][i][j]) % mod;
            for (int j = 1; j < k; j++) sum2 = (sum2 + dp[1][n - m - i][j]) % mod;
            ans = (ans + 1ll * sum1 * sum2) % mod;
        }
        return cout << (mod - ans + 1ll * power(k, n - m) * (n - m + 1)) % mod << endl, 0;
    }
}

Measured memory_bytes: 80384
using System;
class Program
{
	static void Main(string[] args)
	{
		// スペース区切りの整数の入力
		string[] input = Console.ReadLine().Split(' ');
		int a = int.Parse(input[0]);
		int b = int.Parse(input[1]);
		//出力
		Console.WriteLine(a * b % 2 == 0 ? "Even" : "Odd");
	}
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long int x,d;
   cin>>x>>d;
   long long int count=0;

   for(int i=0;i<x;i++)
   {
       long long int x1,y1;
       cin>>x1>>y1;
       if(abs(x1)>d || abs(y1)>d)
        continue;
       if(sqrt((x1*x1)+(y1*y1))<=d)
       {   count++;
          
       }

   }
   cout<<count;
    return 0;
}


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

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		long k = Long.parseLong(sa[1]);
		long[][][] dp = new long[61][n][n];
		for (int i = 0; i < n; i++) {
			sa = br.readLine().split(" ");
			for (int j = 0; j < n; j++) {
				dp[0][i][j] = Long.parseLong(sa[j]);
			}
		}
		br.close();

		int mod = 1000000007;
		for (int i = 0; i < 60; i++) {
			for (int j = 0; j < n; j++) {
				for (int j2 = 0; j2 < n; j2++) {
					for (int x = 0; x < n; x++) {
						dp[i + 1][j][j2] += dp[i][j][x] * dp[i][x][j2];
						dp[i + 1][j][j2] %= mod;
					}
				}
			}
		}

		long[][] a = new long[n][n];
		boolean first = true;
		for (int i = 0; i < 60; i++) {
			if ((k >> i & 1) == 1) {
				if (first) {
					a = dp[i];
					first = false;
				} else {
					long[][] b = new long[n][n];
					for (int j = 0; j < n; j++) {
						for (int j2 = 0; j2 < n; j2++) {
							for (int x = 0; x < n; x++) {
								b[j][j2] += a[j][x] * dp[i][x][j2];
								b[j][j2] %= mod;
							}
						}
					}
					a = b;
				}
			}
		}

		long ans = 0;
		for (int j = 0; j < n; j++) {
			for (int j2 = 0; j2 < n; j2++) {
				ans += a[j][j2];
			}
		}
		ans %= mod;
		System.out.println(ans);
	}
}


Measured memory_bytes: 37572
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<bitset>
#include<math.h>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;


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

  if(a.size()!=b.size()){
    if(a.size()>b.size()) cout<<"GREATER"<<endl;
    else cout<<"LESS"<<endl;
  }else{
    for(int i=0;i<(int)a.size();i++){
      if(a[i]==b[i]) continue;
      if(a[i]>b[i]) cout<<"GREATER"<<endl;
      else cout<<"LESS"<<endl;
      return 0;
    }
    cout<<"EQUAL"<<endl;
  }
  
}


Measured memory_bytes: 256
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000

typedef long long ll;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

int main(void) {
    int T;
    cin >> T;
    while (T--) {
        int p, q;
        cin >> p >> q;
        int P = p*p + q*q;
        int cnt = 0;
        int ma = 0;
        for (int i = 0; i*i <= P; i++) ma = i;
        for (int m = -ma; m <= ma; m++) {
            for (int n = -ma; n <= ma; n++) {
                int tmp = m*m + n*n;
                if (tmp == 0) continue;
                if (P % tmp == 0) {
                    int mp = m*p + n*q;
                    int mq = m*q - n*p;
                    if (mp % tmp == 0 && mq % tmp == 0) cnt++;
                }
            }
        }
        if (cnt == 8) cout << "P" << endl;
        else cout << "C" << endl;
    }
    return 0;
}

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

int main(int argc, char* argv[]) {
  long long N;
  scanf("%lld", &N);

  cout << int(pow(N, 3)) << endl;
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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 A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 256
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
  return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
  read_all = [tuple(map(int, input().split())) for _ in range(N)]
  return map(list,zip(*read_all))

#################

def BF(E,s,n):
  inf=float("inf")
  d=[inf for _ in range(n)]
  d[s]=0
  for i in range(n+1):
    for e in E:
      if e[0]!=inf and d[e[1]-1]>d[e[0]-1]+e[2]:
        d[e[1]-1] = d[e[0]-1] + e[2]
    if i==n-1:t=d[-1]
    if i==n and t!=d[-1]:
      return 'loop'
  return d

def main():
  N,M = II()
  E = []
  for _ in range(M):
    a,b,c = II()
    E.append([a,b,-c])

  d = BF(E,0,N)

  if d=='loop':
    print('inf')
  else:
    print(-d[N-1])

if __name__ == '__main__':
  main()

Measured memory_bytes: 42092
#include<stdio.h>
int main(void)
{
	int n,x,y,a,b,c,d,x1,y1,x2,y2,l,f;
	scanf("%d %d %d %d %d",&n,&a,&b,&c,&d);
	x1=n/a;
	y1=n/c;
	l=n%a;
	f=n%c;
	if(l>=1){
		x1=x1+1;
	}
	if(f>=1){
		y1=y1+1;
	}
	x2=x1*b;
	y2=y1*d;
	if(x2<=y2){
		printf("%d\n",x2);
	}
	else if(y2<=x2){
		printf("%d\n",y2);
	}
	return 0;
}


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

int main(){
  long long N, K;
  cin >> N >> K;
  long long x = N%K;
  long long g = x-K;
  if(g<0)g*=-1;
  if(x <g )cout << x << endl;
  if(x >= g) cout << g << endl;
  return 0;
}

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

bool isPrime(int x) {
    if (x == 2) {
    	return true;
    }
    if (x < 2 || x % 2 == 0) {
    	return false;
    }
    int i = 3;
    while (i <= sqrt(x)) {
    	if (x % i == 0) {
    		return false;
    	}
    	i = i + 2;
    }
    return true;
}
int main() {
    int n;
    cin >> n;
    int count = 0;
    for (int i = 0; i < n; i++){
        int x;
        cin >> x;
        if (isPrime(x) == true) {
        	count++;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
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; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>pppp(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}
 
 bool re(vector<int>x,vector<int>y){
   bool ok=true;
   for(int i=0;i<x.size();i++){
     if(x[i]!=y[i]){ok=false;}
   }
   return ok;
  }

int main() {
  string s;
  cin>>s;
  int cnt=0;
  for(int i=0;i<s.size()-1;i++){
   if(s[i+1]!=s[i]){cnt++;}
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
#define all(arr) arr.begin(), arr.end() 
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 0;
bool vis[4];

int main(){
	IOS
	int a, b;
	cin >> a >> b;
	vis[a]=1, vis[b]=1;
	for(int i=1;i<=3;i++){
		if(!vis[i]){
			cout << i << '\n'; return 0;
		}
	}
}


Measured memory_bytes: 3632
from collections import deque

N = int(input())
ABC = [list(map(int, input().split())) for _ in range(N - 1)]
Q, K = map(int, input().split())
XY = [list(map(int, input().split())) for _ in range(Q)]

G = [[] * N for _ in range(N)]
for a, b, c in ABC:
  G[a - 1].append((b - 1, c))
  G[b - 1].append((a - 1, c))

D = [-1] * N
D[K - 1] = 0

q = deque()
q.append(K - 1)
while q:
  n = q.popleft()
  for i, c in G[n]:
    if D[i] < 0:
      q.append(i)
      D[i] = D[n] + c

for x, y in XY:
  print(D[x - 1] + D[y - 1])

Measured memory_bytes: 87828
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        Scanner scn= new Scanner(System.in);
        String S = scn.next();
        int red = 0;
        int blue = 0;
        for(int i=0;i<S.length();i++){
            char cube = S.charAt(i);
            if(cube=='0'){
                red++;
            }else{
                blue++;
            }
        }
        System.out.println(Math.min(red,blue)*2);
    }
}


Measured memory_bytes: 25428
#include <iostream>
#include <utility>
#include <stdint.h>
#include <vector>

using namespace std;

const int MAX = 1000001;
const int MOD = 1000000007;

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

// テーブルを作る前処理
void COMinit(uint32_t max) {
    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] * uint64_t(i) % MOD;
      inv[i] = MOD - uint64_t(inv[MOD%i]) * (MOD / i) % MOD;
      finv[i] = uint64_t(finv[i - 1]) * inv[i] % MOD;
    }
}

// 二項係数計算
uint32_t COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return uint64_t(fac[n]) * (finv[k] * uint64_t(finv[n - k]) % MOD) % MOD;
}

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

  int n = X+Y;
  int nb = 2*X-Y;
  if (n%3!=0 || nb%3!=0) {
    cout << 0 << endl;
    return 0;
  }

  nb /= 3;
  n /= 3;
  int na = n - nb;

  int r = min(na,nb);

  cerr << n << ',' << r << endl;
  COMinit(n);
  cout << COM(n,r) << endl;

  return 0;
}


Measured memory_bytes: 10624
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

    vector< vector<int> > c(3, vector<int>(3));
    REP(i, 3)REP(j, 3) cin >> c[i][j];

    bool f = true;
    REP(i, 3){
        if(c[0][0]-c[0][1] != c[i][0]-c[i][1]) f = false;
        if(c[0][0]-c[0][2] != c[i][0]-c[i][2]) f = false;
        if(c[0][2]-c[0][1] != c[i][2]-c[i][1]) f = false;
    }    
    REP(i, 3){
        if(c[0][0]-c[1][0] != c[0][i]-c[1][i]) f = false;
        if(c[0][0]-c[2][0] != c[0][i]-c[2][i]) f = false;
        if(c[2][0]-c[1][0] != c[2][i]-c[1][i]) f = false;
    }

    puts(f ? "Yes" : "No");

    return 0;
}

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

int main ()
{
    string str = "yuiohjklnmp";
    set<char> s;

    for (int i = 0; i < str.size(); i++) {
        s.insert(str[i]);
    }

    while (cin >> str, str != "#") {
        int res = 0;
        bool pre, now;
        pre = (s.find(str[0]) == s.end()) ? false : true;
        for (int i = 1; i < str.size(); i++) {
            if (s.find(str[i]) == s.end()) {
                now = false;
            } else {
                now = true;
            }
            if (now != pre) {
                res++;
            }
            pre = now;
        }
        cout << res << endl;
    }


    return 0;
}

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

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  sort(h.begin(), h.end());
  k = min(n,k);
  rep(i,k) {
    h.pop_back();
  }
  ll sum = 0;
  rep(i, h.size()) sum += h[i];
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
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; }
const double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

    int N, K;
    cin >> N >> K;
    priority_queue<P> que1;
    priority_queue<P, vector<P>, greater<P>> que2;
    map<int, int> mp;
    rep(i,N){
        int a, b;
        cin >> a >> b;
        que1.push(P(b,a));
    }
    int num = 0;
    int sum = 0;
    rep(i,K){
        P p = que1.top();
        que1.pop();
        int x = p.first;
        int y = p.second;
        sum += x;
        if(mp[y] == 0){
            ++num;
            mp[y]++;
        }
        else{
            que2.push(p);
            mp[y]++;
        }
    }
    int ans = sum + num * num;
    while(!que2.empty() && !que1.empty()){
        P p = que1.top();
        que1.pop();
        int x = p.first;
        int y = p.second;
        if(mp[y] >= 1) continue;
        mp[y]++;
        ++num;
        sum += x;
        P p1 = que2.top();
        que2.pop();
        int x1 = p1.first;
        int y1 = p1.second;
        mp[y1]--;
        sum -= x1;
        chmax(ans, sum+num*num);
    }
    cout << ans << endl;
}

Measured memory_bytes: 6640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
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; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    V<bool> in(n), out(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        if(a == 0) out[b] = true;
        else if(b == n - 1) in[a] = true;
    }
    rep(i, n) {
        if(in[i] && out[i]) {
            cout << "POSSIBLE" <<endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 3708
from bisect import bisect_left

N = int(input())
L = [int(x) for x in input().split()]
L.sort()

ans = 0
for i in range(N-2):
	for j in range(i+1,N-1):
		ans += bisect_left(L, L[i]+L[j])-j-1
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using pint = pair<int,int>;
using vec = vector<int>;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

int main() {
    int n; cin>>n;
    vll a(n+1);
    ll sum = 0;
    for(int i=1; i<=n; i++) {cin>>a[i]; sum += a[i];}

    vll x(n+1,0);

    ll sum_odd = 0;
    for(int i=1; i<=n; i+=2) sum_odd += a[i]*2;

    x[1] = sum_odd - sum;

    for(int i=2; i<=n; i++){
        x[i] = a[i-1]*2 - x[i-1];
    }

    for(int i =1; i<=n; i++){
        cout<<x[i]<<" ";
    }

}

Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

int n, k;
int ans[300000];

int main() {
    std::cin >> n >> k;
    
    if(1 == k || 2 * n - 1 == k) {
        std::cout << "No" << std::endl;        
        
        return 0;
    }
    
    const int s = 2 * n - 1;
    
    std::cout << "Yes" << std::endl;
    
    int min = 1, max = s;
    for(int i = 1; i < n; ++i) {
        if(min == k)
            ++min;
        if(max == k)
            --max;

        ans[s / 2 - i] = min;
        ++min;
        
        ans[s / 2 + i] = max;
        --max;
    }
    ans[s / 2] = k;
    
    for(int i = 0; i < s; ++i) {
        std::cout << ans[i] << std::endl;
    }
}

Measured memory_bytes: 2304
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
ll Max = 10 + 1e12;
int N = 5 + 1e5;

int main()
{
	string s, t;
	cin >> t >> s;
	cout << s << t;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;
    t=1;
    while(t--)
    {
        int n,x;
        cin>>x>>n;
        if(n==0)
        {
            cout<<x;
            continue;
        }
        map<int,int> mp;
        for(int i=0;i<n;i++)
            {
                int m;
                cin>>m;
                mp[m]=1;
            }
        int a1=x,a2=x;
        while(1)
        {
            if(mp[a1]==0)
                break;
            a1--;
        }
        while(1)
        {
            if(mp[a2]==0)
                break;
            a2++;
        }
        if(abs(x-a1)<=abs(x-a2))
            cout<<a1;
        else
            cout<<a2;
    }
    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
main(){
  int n,t,a,b,s=0;
  cin>>n>>t>>a;
  for(int i=1;i<=n;i++){
    if(i<n){
      cin>>b;
      s+=min(t,b-a);
      a=b;
    }
    else s+=t;
  }
  cout<<s;
}

Measured memory_bytes: 256
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 n = sc.nextInt();
		int x = sc.nextInt();

		int absPos[] = new int[n];

		for(int i = 0; i < n; i++){
			absPos[i] = Math.abs(x - sc.nextInt());
		}

		int gcd = absPos[0];
		for(int i = 1; i < n; i++){
			gcd = gcd(gcd, absPos[i]);
		}

		System.out.println(gcd);
	}

	static int gcd(int a, int b){
        int tmp;

        while (a % b != 0)
        {
            tmp = b;
            b = a % b;
            a = tmp;
        }
        return b;
    }
}


Measured memory_bytes: 50448
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

const int INF = 1000000000;

int N, M, L, K, A, H;
int ans;
bool isfreeze[100];
int v[100][100];

int main() {

  while(1){
    cin>>N>>M>>L>>K>>A>>H;
    if(N==0) break;
    REP(i,0,100) isfreeze[i] = false;
    isfreeze[A] = true;
    isfreeze[H] = true;
    REP(i,0,L){
      int t;
      cin>>t;
      isfreeze[t] = true;
    }
    REP(i,0,100)REP(j,0,100){
      if(i == j) v[i][j] = 0;
      else v[i][j] = INF;
    }
    REP(i,0,K){
      int x, y, t;
      cin>>x>>y>>t;
      v[x][y] = t;
      v[y][x] = t;
    }

    //WF
    REP(k,0,N){
      REP(i,0,N){
        REP(j,0,N){
          v[i][j] = min(v[i][j], v[i][k] + v[k][j]);
        }
      }
    }

    //??????????¨???????????????\????????????????????¨????????????????????±????¶???????
    //??????????¨???????????????§??????M??\??????????????????????????°????????±????¶???????
    REP(i,0,N){
      REP(j,0,N){
        if(!isfreeze[i] || !isfreeze[j] || v[i][j] > M) v[i][j] = INF;
      }
    }

    //??´??°???????????°????????§WF
    REP(k,0,N){
      REP(i,0,N){
        REP(j,0,N){
          v[i][j] = min(v[i][j], v[i][k] + v[k][j]);
        }
      }
    }

    if(v[A][H] == INF) cout<<"Help!"<<endl;
    else cout<<v[A][H] + max(0,v[A][H]  - M)<<endl;
  }

  return 0;
}

Measured memory_bytes: 3036
#include <stdio.h>

int main()
{
  int a,b,count=0;

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

  if(b==1){
    printf("0");
    return 0;}
    
  while(1){
    count++;
    if((count*a - count + 1)>= b )
    break;
  }

  printf("%d", count);

  return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
set<int> E[101010];
int num=0;
int did[101010];

void dfs(int cur,int step,int tar1,int tar2) {
	if(step>0 && (cur==tar1 || cur==tar2)) return;
	
	int x=*E[cur].begin();
	E[cur].erase(x);
	E[x].erase(cur);
	dfs(x,step+1,tar1,tar2);
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,M) {
		cin>>x>>y;
		E[x-1].insert(y-1);
		E[y-1].insert(x-1);
	}
	FOR(i,N) if(E[i].size()%2) return _P("No\n");
	FOR(i,N) if(E[i].size()>=6) return _P("Yes\n");
	vector<int> C;
	FOR(i,N) if(E[i].size()==4) C.push_back(i);
	
	if(C.size()>=3) return _P("Yes\n");
	if(C.size()<=1) return _P("No\n");
	
	int num=0;
	while(E[C[0]].size()) {
		dfs(C[0],0,C[0],C[1]);
		num++;
	}
	if(num==4) return _P("No\n");
	else _P("Yes\n");
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 16000
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1LL<<60;
constexpr int inf = 1e9;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

ll C[100][100];

void comb_table(int N){
  for(int i=0; i<N; i++){
    for(int j=0; j<=i; j++){
      if(j==0 || j==1){
        C[i][j] = 1LL;
      }else{
        C[i][j] = C[i-1][j-1]+C[i-1][j];
      }
    }
  }
}

int main(){
  int N,A,B;
  cin >> N >> A >> B;
  vector<ll> v(N);
  map<ll,ll> mp;
  for(int i=0; i<N; i++){
    cin >> v[i];
    mp[v[i]]++;
  }
  comb_table(60);
  sort(v.begin(),v.end(),greater<ll>());
  double max_average = 0;
  for(int i=0; i<A; i++){
    max_average += v[i];
  }
  max_average /= A;
  ll ans = 0;
  int cnt = 0;
  if(mp[v[0]]>A){
    for(int i=A; i<=min((ll)B,mp[v[0]]); i++){
      ans += C[mp[v[0]]+1][i+1];
    }
  }else{
    for(int i=0; i<A; i++){
      if(v[A-1]==v[i]) cnt++;
    }
    ans = C[mp[v[A-1]]+1][cnt+1];
  }
  // for(int i=0; i<N; i++){
  //   for(int j=0; j<N; j++){
  //     cout << "check:" << i << " " << j << " ";
  //     cout << C[i][j] << endl;
  //   }
  // }
  cout << fixed << setprecision(10) << max_average << endl;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
s = str(input())
a = ['dream', 'dreamer', 'erase', 'eraser']

f = True
while f:
    os = s
    for i in a:
        if s.endswith(i):
            s = s[:-len(i)]
            if len(s) == 0:
                print("YES")
                f = False
    if len(os) == len(s):
        print("NO")
        f = False


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

int main() {
  int a, b, c, d, sum;
  sum = 0;
  cin >> a >> b;
  vector<int> vec(a);
  
  for (int i = 0; i < a; i++) {
    cin >> vec.at(i);
  }

  for (int i = 0; i < a; i++) {
    sum += vec.at(i);
  }
  
  int rest = b - sum;
  int re = 0;
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  for (int i = 0; i < a; i++) {
    c = rest / vec.at(i);
    d = c;
    c += d;
    // rest = rest - vec.at(i) * c;
  }
 cout << c / 2 + a << endl;
}


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

int n,w,d;
struct state {
  int id,x;
  bool in;
  state(){}
  state(int x,int id,bool in):id(id),x(x),in(in){}
  bool operator<(const state& st) const {
    if( x== st.x ) return in > st.in;
    return x < st.x;
  }
};
vector<state> v;
const int INF = 1<<30;
string dc="NESW";

int getX(int id, int x, int y ){
  id%=4;
  if( id == 0 )
    return max( 0, x-(d-y) );
  else if( id == 1 )
    return min( w, x+(d-y) );
  else if( id == 2 )
    return min( w, x+y );  
  return max( 0, x-y );
}
int getY(int id, int x, int y ){
  id%=4;
  if( id == 0 )
    return min( d, y+x );
  else if( id == 1 )
    return min( d, y+(w-x) );
  else if( id == 2 )
    return max( 0, y-(w-x) );
  return max( 0, y-x );
}

int getInter(int x,int y){ 
  if( x == 0 ) return y;
  if( x == w ) return d+w+(d-y);
  if( y == d ) return d+x;
  return 2*d + 2*w - x;
}

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

int solve(int st){
  int used[1111]={};
  int m = v.size();
  for(int i=0;i<m;i++)
    if( v[i].in && v[i].id == st ){
      st = i; break;
    }
  queue<int> q;
  int ret = 0;
  //cout << "solve " << endl;
  for(int i=st;i<m;i++){
    state p = v[i];
    //cout << p.id << " " << p.x << " " << p.in << endl;
    if( p.in ) {
      if( !used[p.id] ) {
        used[p.id]++; q.push( p.id );
      }
    } else if( used[p.id] == 1 ) {
      if( q.empty() ) continue;
      ret++;
      while( !q.empty() ) {
        int nid = q.front(); q.pop();
        if( used[nid]==1 ) {
          used[nid]++;
        }
      }
    }
  }
  return ret;
}

int main(){
  cin >> n >> w >> d;
  for(int l=0;l<n;l++){
    int x,y; char c; cin >> x >> y >> c;
    int id;
    for(int i=0;i<4;i++)
      if( dc[i] == c ) id = i;
    int in = getInter( getX( id, x, y ), getY( id, x, y ) );
    int out= getInter( getX( id+1, x, y ), getY( id+1, x, y ) );
    //cout << in << " - " << out << endl;
    v.push_back( state( in, l, true ) );
    v.push_back( state( out, l, false ) );
    v.push_back( state( in+2*d+2*w, l, true ) );
    v.push_back( state( out+2*d+2*w, l, false ) );
    v.push_back( state( in+(2*d+2*w)*2, l, true ) );
    v.push_back( state( out+(2*d+2*w)*2, l, false ) );
  }

  sort( v.begin(), v.end() );
  int res = INF;
  for(int i=0;i<n;i++){
    res = min( res, solve(i) );
  }
  cout << res << endl;
}

Measured memory_bytes: 3360
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1000005;
int a[N],b[N],c[N],d[N];
int n,k,q;
int main()
{
	//freopen("input.txt","r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(0);
	int ans=0x3f3f3f3f;
	cin >>n>>k>>q;
	for(int i=1;i<=n;i++)cin >>a[i];
	for(int i=1;i<=n;i++)
	{
		memset(c,0,sizeof(c));
		int tmp=0;
		for(int j=1;j<=n;j++)
			b[j]=a[j];
		for(int j=1;j<=n;j++)if(a[j]<a[i])c[j]=1;
		//for(int j=1;j<=n;j++)cout <<c[j]<<' ';cout <<endl;
		for(int j=1;j<=n;j++)
		{
			if(!c[j])
			{
				int l=j,r=l;
				while(!c[r+1]&&r+1<=n)r++;
				//cout <<l<<' '<<r<<endl;
				if(r-l+1<k){j=r+1;continue;}
				sort(b+l,b+r+1);
				for(int tmp1=l;tmp1<=r-k+1;tmp1++)d[++tmp]=b[tmp1];
				j=r+1;
			}
		}
		sort(d+1,d+1+tmp);
		//for(int j=1;j<=tmp;j++)cout <<d[j]<<' ';cout <<endl;
		if(tmp>=q)ans=min(ans,d[q]-d[1]);
		//cout <<tmp<<' '<<d[q]-d[1]<<endl;
		//cout <<ans<<endl;
		//cout <<endl;
	}
	cout <<ans<<endl;
	return 0;
}

Measured memory_bytes: 8448
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read();

    let mut s: HashSet<String> = HashSet::new();
    let mut last: char = '0';
    let mut flag = true;
    for i in 0..n {
        let w: String = read();
        if i != 0 {
            if s.contains(&w) || w.chars().nth(0).unwrap() != last {
                flag = false;
            }
        }
        last = w.chars().nth(w.len() - 1).unwrap();
        s.insert(w);
    }

    if flag {
        println!("Yes");
    } else {
        println!("No");
    }
}

Measured memory_bytes: 4352
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <tr1/unordered_map>
using namespace std;
#define ll long long
#define re register
#define pb push_back
#define fi first
#define se second
const int N=4e6+10;
const int mod7=1e9+7;
const int mod=1e9+7;
void read(int &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0')
        if(ch=='-')
            d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9')
        a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
void read(ll &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0')
        if(ch=='-')
            d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9')
        a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
pair <int,int> a[N];
int s(int x) {return x*x;}
int main()
{
    string t="";
    int n,div=1;read(n);
    for(re int i=1;i<=n;i++) t+=i+'0',div*=i;
    int ans=0;
    do
    {
        for(re int i=0;i<t.size();i++)
        {
            if(t[i]=='1'&&t[i+1]=='2')
            {
                ans++;
                break;
            }
        }
    }while(next_permutation(t.begin(),t.end()));
    ans<<=1;double sum=0;
    for(re int i=1;i<=n;i++)
    {
        read(a[i].fi),read(a[i].se);
        for(re int j=1;j<i;j++)
        {
            sum+=ans*sqrt((double)(s(a[i].fi-a[j].fi)+s(a[i].se-a[j].se)));
        }
    }
    printf("%.10lf",sum/div);
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <iostream>
#include <deque>
#include <functional>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <string>
#include <vector>
#include <vector>

using namespace std;

#define int long long

#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

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

#define debug(x) cerr << #x << ": " << x << endl;

const int MOD = 1e9 + 7;

signed main(void)
{
  int W, H; cin >> W >> H;
  int x, y; cin >> x >> y;
  cout << W * H / 2. << " " << (2 * x == W && 2 * y == H ? 1 : 0) << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import numpy as np


def solve(K: int, S: str):
    if len(S)>K:
        print(S[:K]+"...")
    else:
        print(S)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(K, S)

if __name__ == '__main__':
    main()


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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<string> s(n);
    for(int i = 0; i < n; ++i){
        cin >> s[i];
        sort(begin(s[i]), end(s[i]));
    }
    sort(begin(s), end(s));
    string t = s[0];
    int cnt = 1;
    ll ans = 0;
    for(int i = 1; i < n; ++i){
        if(t == s[i]) ++cnt;
        else {
            ans += (ll)cnt * (cnt-1) / 2;
            t = s[i];
            cnt = 1;
        }
    }
    ans += (ll)cnt * (cnt-1) / 2;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 5760
#include<stdio.h>
int main()
{
  int d=9,a[5],i,t=0,sum=0;
   for(i=0;i<5;i++)
	{
      scanf("%d",&a[i]);
	  if(d>=(a[i]%10)&&(a[i]%10)!=0)
		  d=(a[i]%10);
   }  
     for(i=0;i<5;i++)  
	 {
		if(a[i]%10==d)
		{
		  t=a[i];
		  a[i]=a[4];
          a[4]=t;
		}
	 }
	 for(i=0;i<5;i++)
	 {
		if(((a[i]%10)!=0)&&(i<4))
	  {
         a[i]=((a[i]/10)+1)*10;
         sum+=a[i];
	
	  }
	 
	  else
	     sum+=a[i];
	
	 }	
      printf("%d\n",sum);

   return 0;
}

Measured memory_bytes: 128
// header {{{
using namespace std;

// C++
#include <algorithm>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <math.h>
#pragma GCC optimization_level 3

// util {{{
#define print(x)	        cout << (x)
#define printvec(x)       for(int i = 0;i < (x).size();i++)cout << (x).at(i) << " ";cout << endl
#define println(x)	        cout << (x) << endl
#define printn		        cout << endl
#define read(x)	            cin >> (x)
#define readvec(x)        for(int i = 0; i < (x).size();i++)cin >> (x).at(i)

#define rep(i, n)	        for(int i = 0; i < (int)(n); i++)
#define rep_1(i, n) 	    for(int i = 1; i <=(int)(n); i++)

#define all(x) 		        (x).begin(),(x).end()
#define vint                vector<int>
#define outif(x,y,z)        if(x) cout<<(y)<<endl; else cout<<(z)<<endl
#define loop 		        while(true)

// }}}

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

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

void solve() {
    double r;
    read(r);
    cout << M_PI * double(r * r) << " " << 2 * M_PI * r << endl;
}

signed main() {
    solve();
    return 0;
}


Measured memory_bytes: 3256