akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
static const int MAX =10000;
static const int INFTY =(1<<20);
static const int WHITE =0;
static const int GRAY =1;
static const int BLACK =2;
int n;
vector<pair<int,int> > adj[MAX];
void dijkstra(){
  priority_queue<pair<int,int> > PQ;
  int color[MAX];
  int d[MAX];
  for(int i=0;i<n;i++){
    d[i]=INFTY;
    color[i]=WHITE;
  }
  d[0]=0;
  PQ.push(make_pair(0,0));
  color[0]=GRAY;
  while(!PQ.empty()){
  pair<int,int>f=PQ.top();PQ.pop();
  int u=f.second;
  color[u]=BLACK;
  if(d[u]<f.first*(-1))continue;
  for(int j=0;j<adj[u].size();j++){
    int v=adj[u][j].first;
    if(color[v]==BLACK)continue;
    if(d[v]>d[u]+adj[u][j].second){
      d[v]=d[u]+adj[u][j].second;
      PQ.push(make_pair(d[v]*(-1),v));
      color[v]=GRAY;
    }
  }
}
for(int i=0;i<n;i++){
  cout << i << " " << ( d[i] == INFTY ? -1 : d[i] ) << endl;
 }
}
int main(){
  int k,u,v,c;
  cin >> n;
  for(int i = 0;i<n;i++){
    cin >> u >> k;
    for(int j=0;j<k;j++){
      cin >> v >> c;
      adj[u].push_back(make_pair(v,c));
    }
  }
  dijkstra();
  return 0;
}



Measured memory_bytes: 8076
#include<stdio.h>

int main(void){
  int n;
  int a=0;
  scanf("%d", &n);
  if(n/100==7 || n%10==7 || (n/10)%10==7){
    a=1;
  }
  if(a==1){
    printf("Yes\n");
  }else{
    printf("No\n");
  }

  return 0;
}


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

int main(){
  int A, B,ans;
  cin >> A >>B;
	int a,b,c;
    a = A + B;
    b = A - B;
    c = A * B;
    ans = max(a,b);
  	ans = max(ans,c);
  cout << ans << endl;
}


Measured memory_bytes: 3512
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define int long long
#define MAX 210
#define MAX_R 10

const int INF = 1L << 50;

int dist[MAX][MAX];

int n, m, R;
int ans;
int r[MAX_R];
bool used[MAX_R];

void init() {
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      dist[i][j] = INF;
    }
  }
}

void warshall_floyd() {
  for (int k = 1; k <= n; k++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
}

void dfs(int k, int last, int d) {
  if (k == R) {
    ans = min(ans, d);
    return;
  }
  for (int i = 0; i < R; i++) {
    if (!used[i]) {
      used[i] = true;
      if (k == 0) {
        dfs(k + 1, i, d);
      } else {
        dfs(k + 1, i, d + dist[r[last]][r[i]]);
      }
      used[i] = false;
    }
  }
}

signed main() {
  cin >> n >> m >> R;
  for (int i = 0; i < R; i++) {
    cin >> r[i];
  }
  init();
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    dist[a][b] = c;
    dist[b][a] = c;
  }
  warshall_floyd();
  fill(used, used + R, false);
  ans = INF;
  dfs(0, 0, 0);
  cout << ans << endl;
  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

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

  ll N;
  cin>>N;
  vector<ll> A(N);
  rep(i,N)cin>>A[i];

  vector<ll> dp(N+1,0);
  dp[0]=1000;
  rep(i,N){
    maxch(dp[i+1],dp[i]);
    rep(j,i){
      ll c=(dp[j]/A[j]);
      maxch(dp[i+1],(dp[j]%A[j])+c*A[i]);
    }
  }
  cout<<dp[N]<<endl;

  return 0;
}


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

#define int long long
#define fi first
#define se second
#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 rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define INF LONG_LONG_MAX
#define MOD 1000000007
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;

int ans,dp[2020];
string s;

signed main() {
    int now = 0;
    cin >> s;
    rep(i,s.size()) {
        int tmp[2020] = {};
        now = now*10 + (int)(s[i]-'0');
        rep(j,2020) tmp[(j*10)%2019] += dp[j];
        rep(j,2020) dp[j] = tmp[j];
        now %= 2019;
        ans += dp[now];
        dp[now]++;
        if (!now) ans++;
    }
    cout << ans << endl;
}




Measured memory_bytes: 3800
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

struct D {
    int node;
    int step;
    this(int node, int step) {
        this.node = node;
        this.step = step;
    }

    int opCmp(ref const D other) const {
        if (step == other.step) return 0;
        return step < other.step ? -1 : 1;
    }
}

int calc(int n, int s, int t, int[][] adj) {

    auto pq = new BinaryHeap!(Array!D, "a > b");
    pq.insert(D(s, 0));

    auto used = new int[][](n + 1, 3); // [ノード数][mod 3]
    while (!pq.empty) {
        auto d = pq.front; pq.popFront();
        if (used[d.node][d.step % 3]++) continue;
        if (d.node == t && d.step % 3 == 0) return d.step / 3;

        foreach (e; adj[d.node]) {
            pq.insert(D(e, d.step + 1));
        }
    }
    return -1;
}

void main() {
    int n, m; scan(n, m);

    int[][] adj;
    for (int i = 0; i <= n; i++) adj ~= [[]];

    for (int i = 0; i < m; i++) {
        int u, v; scan(u, v);
        adj[u] ~= v;
    }

    int s, t; scan(s, t);
    writeln(calc(n, s, t, adj));
}


Measured memory_bytes: 12668
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<unsigned long> a(N);
  for(int i = 0; i<N; i++){
    cin >> a.at(i);
  }
for(int i = 0; i< N; i++){
  if(a.at(i) == 0){
    cout << 0 << endl;
    return 0;
  }
}
  unsigned long ans = a.at(0);
  for(int i = 1; i<N; i++){
    ans*= a.at(i);
  }
    if(ans<=1000000000000000000&&ans>0){
      cout << ans<< endl;
      return 0;
    }
    else{
  cout << -1 << endl;
  return 0;
}
}

Measured memory_bytes: 4052
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 1
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	fmt.Fprintln(writer, 180*(n-2))
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
	int a,b,c,x;
	cin >> a >> b >> c >> x;
	int ans = 0;
	for (int i = 0; i <= a; i++) {
		for (int j = 0; j <= b; j++) {
			for (int k = 0; k <= c; k++) {
				if (x == i*500 + j*100 + k*50) {
					ans++;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int gcd(int a, int b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
int digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}

int pr[] = { 3,5,7,11,13 };

int main() {
	int n;
	cin >> n;
	int ans = 0;
	if (n >= 27 * 5)ans++;
	if (n >= 27 * 7)ans++;
	int tmp = 0;
	FOR(i, 1, n + 1) {
		int tmp = 0;
		REP(j, 5) {
			if (i % pr[j] == 0)tmp++;
		}
		if (tmp == 3)ans++;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int A[100010];
    rep(i, N) cin >> A[i];
    sort(A, A + N);
    int ans = 0;
    vector<pair<int, int>> v;
    int sum = A[0];
    rep(i, N - 2) {
        //cout << sum << " " << A[N - i - 2] << endl;
        if (A[N - i - 2] <= 0) {
            v.push_back({A[N - 1], A[N - i - 2]});
            A[N - 1] -= A[N - i - 2];
        } else {
            v.push_back({sum, A[N - i - 2]});
            sum -= A[N - i - 2];
        }
    }
    ans = A[N - 1] - sum;
    v.push_back({A[N - 1], sum});
    
    
    cout << ans << endl;
    rep(i, N - 1) {
        cout << v[i].first << " " << v[i].second << endl;
    }

    return 0;
}


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

int main(){
	int D, N;
	cin >> D >> N;
	int ans;
	if(N == 100) N++;
	
	if(D == 0) ans = N;
	else if(D == 1) ans = 100 * N;
	else if(D == 2) ans = 10000 * N;
	cout << ans << endl;
}

Measured memory_bytes: 256
/*
* @Author: Kabid
* @Date:   2020-04-19 17:59:10
*/

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#define in(x)  scanf("%d", &x);
#define ins(x)  scanf("%s", &x);
#define out(x) printf("%d", x);
#define lin puts("");
#define _ putchar(' ');
double r;
int main(){
	double pi=acos(-1);
	scanf("%lf",&r);
	printf("%lf",2*pi*r);

	
    return 0;
}

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

int main() {
    int a, b, c, x;
    int i, j, k;
    int ans=0;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    scanf("%d", &x);
    for (i=0;i<a+1;i++) {
        for (j=0;j<b+1;j++) {
            for (k=0;k<c+1;k++) {
                if ((i*500+j*100+k*50)==x) ans++;
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1688
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
 
#define mo 1000000007
#define inf 1e18
#define rep(i, s, n) for (ll i = s; i < n; i = i + 1)
#define rrep(i,s,n) for(ll i=s;i>=n;i--)
#define adiii \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);  \
  cout.tie(NULL);									
 
ll mod(ll n) { return (n % (ll)mo + (ll)mo)%(ll)mo;}
ll gcd(ll a,ll b) {if (b == 0) return a;return gcd(b, a % b);}
 
ll binpow(ll a, ll b) {ll res = 1;while (b > 0) {if (b & 1) res = res * a;a = a * a;b >>= 1;}return res;}
	
 
int main(){
	adiii
	ll h,w;cin>>h>>w;
	vector <string> s;
	string in;
	rep(i,0,h) cin>>in,s.pb(in);
	
	ll dp[h+1][w+1];
	memset(dp,0,sizeof(dp));
	dp[1][1] = 1;
	rep(r,1,h+1){
		rep(c,1,w+1){
			//cout<<r<<" "<<c<<endl;
			if(r>=2 && s[r-2][c-1] != '#'){
				dp[r][c] = mod(dp[r][c] + dp[r-1][c]);
			}
			if(c>=2 && s[r-1][c-2] != '#'){
				dp[r][c] = mod(dp[r][c] + dp[r][c-1]);
			}
			//cout<<dp[r][c]<<endl;
			
		}
	}
	cout<<dp[h][w]<<endl;
	 
}


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

int main(){
    int n, m;
    cin >> n >> m;
    if(m >= n){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        int[] h = new int[n];
        for(int i=0; i<n; i++) {
            h[i] = in.nextInt();
        }
        Arrays.sort(h);
        long count = 0;
        for(int i=0; i<n-k; i++) {
            count += h[i];
        }
        System.out.println(count);
    }
}


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

int main(){
	// sengen
	int n;
	// nyuryoku
	cin >> n;
	map<LL,LL> mp;
	LL a,b;
	for(int i=0;i<n;i++){
		cin >> a >> b;
		mp[b] += a;
	}
	// keisan
	LL sum = 0;
	int flag = 1;
	for(auto x:mp){
		sum += x.second;
		if(x.first < sum){
			flag = 0;
			break;
		}
	}
	// syutsuryoku
	if(flag){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 16048
#include<bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;
typedef long long int lli;
#define mod 1000000007
#define fLoop for(lli i = 0; i < N; i++)
lli termSum(lli S, lli *DP) {
	if(S == 0) {
		return 1;
	}
	if(S < 0) {
		return 0;
	}
	if(DP[S] != -1) {
		return DP[S];
	}
	int output = 0;
	for(int i = 3; i <= S; i++) {
		output = (output % mod + termSum(S - i, DP) % mod) % mod;
	}
	return DP[S] = output;
} 
main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    lli S;
    cin >> S;
    lli *DP = new lli[S + 1];
    for(lli i = 0; i <= S; i++) {
    	DP[i] = -1;
	}
    cout << termSum(S, DP);
}

Measured memory_bytes: 3652
#include <cstdio>
#include <cassert>
#include <algorithm>    
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <bitset>
#define pb push_back
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define int long long
using namespace std;

typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef tuple<int, int, int> tiii;
typedef unsigned long long ull; 
typedef vector<int> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const long long INF = 1e18;
const int M = 1e9 + 7;
//__int128

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

signed main() {
  // freopen("in.txt", "r", stdin);
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int h, w;
  cin >> h >> w;
  string s;
  memset(dp, 0x3f, sizeof(dp));
  priority_queue<pii, std::vector<pii>, greater<pii> > pq;
  for(int i = 0; i < h; ++i) {
    cin >> s;
    for(int j = 0; j < w; ++j) {
      if(s[j] == '#') {
        dp[i][j] = 0;
        pq.push(pii(0, i * w + j));
      }
    }
  }
  while(!pq.empty()) {
    auto cur = pq.top(); pq.pop();
    int x = cur.se / w, y =  cur.se % w;
    if(dp[x][y] < cur.fi) continue;
    // cout << x << ' ' << y << ' ' << cur.fi << endl;
    for(int i = 0; i < 4; ++i) {
      int tx = x + dx[i], ty = y + dy[i];
      if(0 <= tx && tx < h && 0 <= ty && ty < w) {
        if(dp[tx][ty] > cur.fi + 1) {
          dp[tx][ty] = cur.fi + 1;
          pq.push(pii(cur.fi + 1, tx * w + ty));
        }
      }
    }
  }
  int res = 0;
  for(int i = 0; i < h; ++i) {
    res = max(res, *max_element(dp[i], dp[i] + w));
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 13548
#include<iostream>
using namespace std;
int n;
int b[15];
int a[5][5];
bool v[5][5];
int main()
{
	bool isfind=0;
	for(int i=1;i<=3;i++)
	{
		for(int j=1;j<=3;j++)
		{
			cin>>a[i][j];
		}
	}
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>b[i];
	for(int k=1;k<=n;k++)
	{
		for(int i=1;i<=3;i++)
		{
			for(int j=1;j<=3;j++)
			{
				if(b[k]==a[i][j])
				{
					v[i][j]=1;
				}
			}
		}
	 } 
	 for(int i=1;i<=3;i++)
	 {
		if(v[1][i]&&v[2][i]&&v[3][i])
			isfind=1;
	 	if(v[i][1]&&v[i][2]&&v[i][3])
	 		isfind=1;
	 }
	 if(v[1][1]&&v[2][2]&&v[3][3])
	 	isfind=1;
	if(v[1][3]&&v[2][2]&&v[3][1])
		isfind=1;
	 if(isfind)
	 	cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        s: [chars; 3],
    }
    for c in s {
        print!("{}", c[0].to_uppercase().next().unwrap());
    }
    println!("");
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <algorithm>
using namespace std;
int n, m, s; pair<int, int> d[1000000];
int main() {
	while (true) {
		scanf("%d", &n);
		if (n == 0) break;
		for (int i = 0; i < n; i++) {
			scanf("%d", &d[i].second); d[i].first = 0;
			for (int j = 0; j < 4; j++) scanf("%d%d", &m, &s), d[i].first += m * 60 + s;
		}
		sort(d, d + n);
		printf("%d\n%d\n%d\n", d[0].second, d[1].second, d[n - 2].second);
	}
	return 0;
}

Measured memory_bytes: 2712
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

//INSERT ABOVE HERE
signed main(){
  Int n,m,x;
  cin>>n>>m>>x;
  vector<Int> h(n);
  for(Int i=0;i<n;i++) cin>>h[i];
  using P = pair<Int, Int>;
  vector<vector<P> > G(n);
  for(Int i=0;i<m;i++){
    Int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    G[a].emplace_back(b,c);
    G[b].emplace_back(a,c);
  }

  const Int INF = 1e17;
  vector<Int> dp1(n,INF);
  priority_queue<P,vector<P>,greater<P> > pq;
  dp1[0]=0;
  pq.emplace(dp1[0],0);
  while(!pq.empty()){
    Int d,v;
    tie(d,v)=pq.top();pq.pop();
    if(dp1[v]<d) continue;
    for(auto e:G[v]){
      Int u,cost;
      tie(u,cost)=e;
      Int nh=min(h[u],x-(dp1[v]+cost));
      if(nh<0||dp1[u]<=x-nh) continue;
      dp1[u]=x-nh;
      pq.emplace(dp1[u],u);
    }
  }

  if(dp1[n-1]<INF){
    cout<<dp1[n-1]+h[n-1]-(x-dp1[n-1])<<endl;
    return 0;
  }
  
  vector<Int> dp2(n,INF);
  for(Int v=0;v<n;v++){
    for(auto e:G[v]){
      Int u,cost;
      tie(u,cost)=e;
      if(h[v]<cost||dp1[v]+cost<=x) continue;
      dp2[u]=min(dp2[u],dp1[v]+(cost-(x-dp1[v]))+cost);
      pq.emplace(dp2[u],u);
    }
  }

  while(!pq.empty()){
    Int d,v;
    tie(d,v)=pq.top();pq.pop();
    if(dp2[v]<d) continue;
    for(auto e:G[v]){
      Int u,cost;
      tie(u,cost)=e;
      if(h[v]<cost||dp2[u]<=dp2[v]+cost*2) continue;
      dp2[u]=dp2[v]+cost*2;
      pq.emplace(dp2[u],u);
    }
  }
  
  if(dp2[n-1]>=INF) cout<<-1<<endl;
  else cout<<dp2[n-1]+h[n-1]<<endl;
  return 0;
}



Measured memory_bytes: 39328
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp> 
//using namespace __gnu_pbds; 
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define trace(x)  cerr << #x << ": " << x << endl;
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
int main()
{
	ll n,x,t;cin>>n>>x>>t;
	ll p=ceil((double)n/x);
	cout<<p*t;
}

Measured memory_bytes: 3740
N, M = map(int, input().split())
A = []
B = []
for i in range(N):
  a = str(input())
  A.append(a)
for i in range(M):
  b = str(input())
  B.append(b)
  
flag = False
for i in range(N-M+1):
  for j in range(N-M+1):
    if A[i][j:j+M] == B[0]:
      k = 1
      while k < M:
        if A[i+k][j:j+M] == B[k]:
          k += 1
        else:
          break
      if k == M:
        flag = True
        break
        
if flag:
  print('Yes')
else:
  print('No')

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

int main() {
  string s;cin>>s;
  if (s.size()==2)cout<<s;
  else {
    reverse(s.begin(), s.end());
    cout<<s;
  }
}


Measured memory_bytes: 3492
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

const ll MOD = 1e9 + 7;

// return a^b O(log b)
template<typename T>
T mypow(T a, T b){
    if (b == 0)
        return 1;
    T tmp = mypow(a, b / 2);
    if (b % 2)
        return (((tmp * tmp) % MOD) * a) % MOD;
    else
        return (tmp * tmp) % MOD;
}

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

    ll n, k;
    cin >> n >> k;

    vll mem(k + 1);
    for (ll i = 1; i <= k; i++) {
        mem[i] = mypow(k / i, n);
    }
    for (ll i = k; i >= 1; i--) {
        for (ll j = 2 * i; j <= k; j += i) {
            mem[i] = (mem[i] + MOD - mem[j]) % MOD;
        }
    }
    ll res = 0;
    REP(i, k) {
        res += mem[i + 1] * (i + 1) % MOD;
        res %= MOD;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3996
#include <stdio.h>

int main (void)
{
    unsigned int K;
    scanf("%u", &K);
    if (K % 2 ==0) {
        printf("%d", K*K/4);
    } else {
        printf("%d", (K+1)/2*((K+1)/2 - 1));
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int n,s[3][105],x,ans;
int main()
{
    cin>>n;
    for(int i=1;i<=2;i++)
        for(int j=1;j<=n;j++)
            cin>>x,s[i][j]=s[i][j-1]+x;
    for(int i=1;i<=n;i++)
        ans=max(ans,s[1][i]+s[2][n]-s[2][i-1]);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as np

H, W = list(map(int, input().split()))
S = ["." + input() + "." for i in range(H)]
S = ["." * (W + 2)] + S + ["." * (W + 2)]
# print(H)
# print(W)
a = []
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if S[i][j] == ".":
            # print(i, j, S[i][j])
            tmp = S[i - 1][j - 1] + S[i - 1][j] + S[i - 1][j + 1] + S[i][j -
                                                                         1] + S[i][j + 1] + S[i + 1][j - 1] + S[i + 1][j] + S[i + 1][j + 1]
            c = str(tmp.count("#"))
            a.append(c)
        else:
            a.append("#")

a = np.reshape(a, (H, W))
for raw in a:
    ls = ""
    for item in raw:
        ls += item
    print(ls)


Measured memory_bytes: 27064
N = int(input())
A = [[int(a) for a in input().split()] for _ in range(2)]
total_1 = sum(A[0])
total_2 = sum(A[1])+A[0][0]
max_total = max(total_1, total_2)
for x in range(N-1, 0, -1):
    total = (total_1-sum(A[0][x:]))+(sum(A[1][x-1:]))
    if total > max_total:
        max_total = total
print(max_total)

Measured memory_bytes: 3064
#require 'pp'

n, c = gets.split.map(&:to_i)
sw = []
sw2 = []
memo = {}
t_max = 0

n.times do |i|
    s, t, c = gets.split.map(&:to_i)
    memo[c] ||= []
    memo[c] << [s, t]
end

memo.each do |ch, r|
    r.sort!

    while r.size >= 2
        x1 = r.shift
        x2 = r.shift
 
        if x1[1] == x2[0]
            r.unshift([x1[0], x2[1]])
        else
            r.unshift(x2)

            sw << x1[0]
            sw2 << x1[1]
    
            if x1[1] > t_max
                t_max = x1[1]
            end 
        end
    end
    x1 = r.shift
    sw << x1[0]
    sw2 << x1[1]

    if x1[1] > t_max
        t_max = x1[1]
    end 
end
#pp memo
sw.sort!
sw2.sort!

#pp sw
#pp sw2
#pp t_max

counter = Array.new(t_max + 1, 0)
counter2 = Array.new(t_max + 1, 0)
sw.each do |s|
    counter[s - 1] += 1
end
sw2.each do |s|
    counter2[s] += 1
end
1.upto(counter.length - 1) do |i|
    counter[i] = counter[i - 1] + counter[i]
end
1.upto(counter2.length - 1) do |i|
    counter2[i] = counter2[i - 1] + counter2[i]
end

ans = 0
1.upto(counter.length - 1) do |i|
    d = counter[i] - counter2[i]
    if d > ans
        ans = d
    end
end

puts ans


Measured memory_bytes: 13712
const SIZE: usize = 51;
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let a: Vec<usize> = sc.vec(n);
    let b: Vec<usize> = sc.vec(n);

    let mut ans = vec![];
    for k in (1..SIZE).rev() {
        if !ok(k - 1, &a, &b, &ans) {
            ans.push(k);
        }
    }

    if ok(0, &a, &b, &ans) {
        println!("{}", ans.into_iter().map(|k| 1 << k).sum::<usize>());
    } else {
        println!("-1");
    }
}

fn ok(from: usize, a: &Vec<usize>, b: &Vec<usize>, ans: &Vec<usize>) -> bool {
    let mut can = [[false; SIZE]; SIZE];
    for k in 0..SIZE {
        can[k][k] = true;
    }

    for &ans in ans.iter() {
        for i in 0..SIZE {
            can[i][i % ans] = true;
        }
    }

    for k in 1..(from + 1) {
        for i in 0..SIZE {
            can[i][i % k] = true;
        }
    }

    for k in 0..SIZE {
        for i in 0..SIZE {
            for j in 0..SIZE {
                can[i][j] |= can[i][k] & can[k][j];
            }
        }
    }

    a.iter().zip(b.iter()).all(|(&a, &b)| can[a][b])
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  int r,c;
  const int mod=1e9+7;
  cin>>r>>c;
  vector<vector<char>> grid(r,vector<char> (c));
  vector<vector<ll>> dp(r,vector<ll> (c,0));
  for(int i=0;i<r;i++){
  	for(int j=0;j<c;j++){
    	cin>>grid[i][j];
    }
  }
  for(int i=1;i<r;i++){
      
      if(grid[i][0]!='#')
      dp[i][0]=1;
      else break;
  }
  for(int i=0;i<c;i++){
  	if(grid[0][i]!='#')
      dp[0][i]=1;
    else break;
  }
  for(int i=1;i<r;i++){
  	for(int j=1;j<c;j++){
    	if(grid[i][j]=='#')	
      	    dp[i][j]=0;
      	else{
        	dp[i][j]=(dp[i-1][j] + dp[i][j-1])%mod;
        }
    }
  }
  cout<<dp[r-1][c-1]<<endl;
  return 0;
  
  
}


Measured memory_bytes: 12164
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
#define int long long


signed main(void){
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a,a+3);
  if(a[0]%2 && a[1]%2 && a[2]%2){
    cout << a[0]*a[1] << "\r\n";
  }else{
    cout << "0\r\n";
  }


}


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

using namespace std;

int main(void) {
  int n;
  cin >> n;
  vector <int> x(n);
  for(int i = 0; i < n; i++) {
    cin >> x[i];
  }
  
  vector <int> y(n);
  for(int i = 0; i < n; i++) {
    y[i] = x[i];
  }
  sort(y.begin(), y.end());
  int small = y[n / 2 - 1];
  int large = y[n / 2];
  for(int i = 0; i < n; i++) {
    if(x[i] <= small) {
      cout << large << endl;
    }
    else {
      cout << small << endl;
    }
  }
}

Measured memory_bytes: 3712
def is_unique(seq):
    return len(seq) == len(set(seq))


def main():
    n = int(input())
    valid = False
    w = []
    for i in range(n):
        w.append(input())

    for i in range(n-1):
        if w[i][-1] != w[i + 1][0] or not is_unique(w):
            valid = False
            break
        else:
            valid = True

    print("Yes" if valid else "No")


if __name__ == '__main__':
    main()

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

int main() {
	vector<int> city(5,0);
  	int a,b;
  	for(int i=1;i<=3;i++){
    	cin>>a>>b;
      	city[a]++;
      	city[b]++;
    }
  
   	for(int i=1;i<=4;i++){
  		if(city[i]>=3){
        	cout<<"NO"<<endl;
          	return 0;
        }
    }
  	cout<<"YES"<<endl;
}



Measured memory_bytes: 256
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
int a[10];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b;
    cin>>a>>b;
    if(a%2==b%2)
    {
        cout<<(a+b)/2<<endl;
    }
    else
        cout<<"IMPOSSIBLE"<<endl;


}




Measured memory_bytes: 3612
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	// sc.Split(bufio.ScanWords)
	// a := nextInt()

	var a, b, c, d, e int

	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	fmt.Scan(&d)
	fmt.Scan(&e)

	sum := a + b + c + d + e

	fmt.Println(15 - sum)

}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;



int main() {
    int T; cin >> T;
    while(T>0){
        int N; cin >> N;
        vector<vector<int>> fr(N+1);
        vector<vector<int>> bc(N+1);

        ll ans = 0;
        REP(i,N){
            int k,l,r; cin >> k >> l >> r;
            ans += min(l,r);
            if(l-r>0) fr[k].push_back(l-r);
            else bc[N-k].push_back(r-l);
        }

        priority_queue<int, vector<int>, greater<int>> q_fr;
        priority_queue<int, vector<int>, greater<int>> q_bc;
        FOR(i,1,N+1){
            for(auto j: fr[i]) q_fr.push(j);
            while(q_fr.size()>i) q_fr.pop();

            for(auto j: bc[i]) q_bc.push(j);           
            while(q_bc.size()>i) q_bc.pop();
        }

        while(!q_fr.empty()){
            ans += q_fr.top(); q_fr.pop();
        }
        while(!q_bc.empty()){
            ans += q_bc.top(); q_bc.pop();
        }

        cout << ans << endl;       

        T--;
    }
    return 0;
}

Measured memory_bytes: 18224
//  Mayank Agarwal
//  IIIT Hyderabad



#include<bits/stdc++.h>
using namespace std;
const long long int M = 1000000007; 
#define ll long long int
#define ld double
#define pb push_back
#define mp make_pair
ll power(ll x, ll y,  ll p) 
{ 
    ll res = 1;      
    x = x % p;   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;x = (x*x) % p; 
    } return res%p; 
} 
ll modinver(ll a,ll b)
{
    return (power(a,1,M)*power(b,M-2,M))%M;
}
void SieveOfEratosthenes(int n) 
{   
    bool prime[10005]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
} 
std::vector<ll> v[200002];
ll vis[200003];
ll dfs(ll x)
{
    vis[x]=1;
    ll ans=1;
    for(auto i:v[x])
    {
        if(vis[i]==0)
        {
            ans+=dfs(i);
        }
    }
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,m;
    cin>>n>>m;
    for (int i = 0; i < m; ++i)
    {
        ll a,b;
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    ll ans=1;
    for (int i = 1; i <=n; ++i)
    {
        if(vis[i]==0)
        {
            ans=max(ans,dfs(i));
        }
    }
    cout<<ans<<'\n';
}


Measured memory_bytes: 25416
#include <stdio.h>
#include <stdlib.h>
#define N 500000

struct BiT_Node{
  int key;
  struct BiT_Node *p;
  struct BiT_Node *left;
  struct BiT_Node *right;
};

typedef struct BiT_Node *Node;

Node root;

void insert (int v){
  Node y = NULL;
  Node x = root;
  Node z;
  z = malloc(sizeof(struct BiT_Node));
  z->key = v;
  z->left = NULL;
  z->right = NULL;
  y = NULL;
  while(x != NULL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  
  z->p = y;

  if(y == NULL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

void in_walk(Node u){
  if(u != NULL){
    in_walk(u->left);
    printf(" %d",u->key);
    in_walk(u->right);
  }
}

void pre_walk(Node u){
  if(u == NULL) return;
  printf(" %d",u->key);
  if(u->left != NULL) pre_walk(u->left);
  if(u->right != NULL) pre_walk(u->right);
}

int find(int key){
  Node u;
  u = root;
  while(u != NULL){
    if(u->key == key) return 1;
    else if(key > u->key) u = u->right;
    else u = u->left;
  }
  return 0;
}

int main()
{
  int n,i,tmp;
  char buf[20];
  scanf("%d",&n);
  for(i = 0 ; i < n; i++){
    scanf("%s",buf);
    if(buf[0] == 'i'){
      scanf("%d",&tmp);
      insert(tmp);
    }
    else if(buf[0] == 'f') {
      scanf("%d",&tmp);
      if(find(tmp) == 1) printf("yes\n");
      else printf("no\n");
    }
    else if(buf[0] == 'p') {
      in_walk(root);
      printf("\n");
      pre_walk(root);
      printf("\n");
    }
  }
  return 0;
}




Measured memory_bytes: 20464
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

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

    for (int i = 0; i < 50000; i++) {
        if ((int)(i * 1.08) == n) {
            std::cout << i << std::endl;
            return 0;
        }
    }

    std::cout << ":(" << std::endl;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
ll n,m,i,j,k,l,t;
int main()
{
    scanf("%lld",&n);
    while(n)
    {
        m=n%10;
        if(m==7)
            k=1;
        n/=10;
    }
    if(k)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;

const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main()
{
    int h,w;
    cin >> h >> w;
    char a[h][w];
    for(int i = 0; i < h; i++) for(int j = 0; j < w; j++) cin >> a[i][j];
    int cnt = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(a[i][j] == '#') cnt++;
        }
    }
    cout << (cnt != w+h-1 ? "Impossible" : "Possible") << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    ll N; cin >> N;
    vector<ll> A(N);for(auto& in:A) cin >> in;
    for(int i = 0; i < N;i++) A[i] -= (i+1);
    sort(A.begin(),A.end());
    ll B = A[N/2];
    ll res = 0;
    for(auto a:A) res += abs(a-B);
    cout << res << endl;
    return 0;
}


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

int main() {
	int n,k;
	cin>>n>>k;
	int A[n];
	for(int i=1;i<=n;i++)
	cin>>A[i];
	int dp[n];
	dp[1]=0;
	dp[2]=abs(A[2]-A[1]);
	// cout<<dp[2]<<" ";
	// cout<<dp[2]+abs(A[3]-A[2]);
	for(int i=3;i<=min(k,n);i++)
	{
		dp[i]=INT_MAX;
		for(int j=1;j<i;j++)
		{
			dp[i]=min(dp[i-j]+abs(A[i]-A[i-j]),dp[i]);
		
		// cout<<dp[i]<<" "; 
		}
	}
	if(k<n){
	for(int i=k+1;i<=n;i++)
	{
		dp[i]=INT_MAX;
		for(int j=1;j<=k;j++)
		dp[i]=min(dp[i-j]+abs(A[i]-A[i-j]),dp[i]);
		// cout<<dp[i]<<" ";
	}
	}
	cout<<dp[n];
	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstring>
#include <regex>
#include <sstream>

typedef long long ll;
constexpr double PI = 3.141592653589793;
constexpr int INF = 1e9 + 10;
constexpr ll INFL = 1e18 + 10;

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;
}

struct edge
{
public:
    int to;
    int cost;
};

// O(|E|(log|V|))
void dijkstra(std::vector<int> &dist, const std::vector<std::vector<edge>> &graph, int s)
{
    typedef std::pair<int, int> P;
    std::priority_queue<P, std::vector<P>, std::greater<P>> pq;
    for (auto &e : dist)
    {
        e = INF;
    }

    dist[s] = 0;
    // P(distance from start, vertex index)
    pq.push(P(0, s));
    while (!pq.empty())
    {
        P cur = pq.top();
        pq.pop();
        int v = cur.second;
        int cost = cur.first;
        if (dist[v] < cost)
        {
            continue;
        }
        for (const auto &next : graph[v])
        {
            if (dist[next.to] > next.cost + dist[v])
            {
                dist[next.to] = next.cost + dist[v];
                pq.push(P(dist[next.to], next.to));
            }
        }
    }
}

void restorePath(
    std::vector<int> &path,
    const std::vector<int> &dist,
    const std::vector<std::vector<edge>> &graph,
    int e)
{
    int cur = e;
    path.push_back(e);
    while (dist[cur] != 0)
    {
        for (const auto &n : graph[cur])
        {
            if (dist[n.to] + n.cost == dist[cur])
            {
                path.push_back(n.to);
                cur = n.to;
                break;
            }
        }
    }
    std::reverse(path.begin(), path.end());
}

using namespace std;
//    cout << setprecision(20) << ans << "\n";

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

    int n, m;
    cin >> n >> m;
    vector<int> l(m), r(m);
    for (size_t i = 0; i < m; i++)
    {
        cin >> l[i] >> r[i];
        l[i]--;
        r[i];
    }

    sort(l.begin(), l.end());
    sort(r.begin(), r.end());
    vector<int> count(n, 0);

    for (size_t i = 0; i < m; i++)
    {
        count[l[i]]++;
        if (r[i] >= n){
            continue;
        }
        count[r[i]]--;
    }
    vector<int> sim(n, 0);
    sim[0] = count[0];
    for (size_t i = 1; i < n; i++)
    {
        sim[i] += sim[i - 1] + count[i];
    }

    int ans = 0;
    for (int e : sim)
    {
        if(e == m){
            ans++;
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 4768
# -*- coding: utf-8 -*-
N, K = map(int,input().split())
A = list(map(int,input().split()))
if K == 2:
    print(N - 1)
elif N % (K - 1) == 0 or N % (K - 1) == 1:
    print(N // (K - 1))
else:
    print((N // (K - 1)) + 1)

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

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

  ll N; cin >> N;
  vector<ll> A(N), B(N), C(N);
  for (ll i = 0; i < N; i++) {
    ll a, b, c;
    cin >> A[i] >> B[i] >> C[i];
  }

  vector<vector<ll>> dp(3, vector<ll>(N + 1, 0));
  for (int i = N - 1; i >= 0; i--) {
    dp[0][i] = A[i] + max(dp[1][i + 1], dp[2][i + 1]);
    dp[1][i] = B[i] + max(dp[2][i + 1], dp[0][i + 1]);
    dp[2][i] = C[i] + max(dp[0][i + 1], dp[1][i + 1]);
  }
  ll ans = max({dp[0][0],dp[1][0],dp[2][0]});
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 5760
//#include<bits_stdc++.h>
#include <iostream>
#include <math.h>
#include <vector>
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define ll long long
using namespace std;
int main() {
    int n, res = 0;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    rep(i, n) {
        int minj = i;
        REP(j, i, n) {
            if(a[j] < a[minj]) {
                minj = j;
            }
        }
        swap(a[i], a[minj]);
        if(i != minj) {
            res++;
        }
    }
    rep(i, n - 1) cout << a[i] << " ";
    cout << a[n - 1] << endl << res << endl;
}



Measured memory_bytes: 3108
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long N, L, T;
  cin >> N >> L >> T;
  vector<long> xs(N, 0), ws(N, 0);
  for (long i = 0; i < N; ++i) {
    cin >> xs[i] >> ws[i];
  }

  vector<long> last_poses(N, 0);
  long counter = 0;
  for (long i = 0; i < N; ++i) {
    if (ws[i] == 1) {
      last_poses[i] = (xs[i] + T) % L;
      counter -= (xs[i] + T) / L;
    } else {
      if (xs[i] - T >= 0) {
        last_poses[i] = xs[i] - T;
        // counterは変化なし
      } else {
        last_poses[i] = (((xs[i] - T) % L) + L) % L;
        counter += (T - (xs[i] + 1) + L) / L;
      }
    }
  }

  sort(last_poses.begin(), last_poses.end());
  counter = (counter % N + N) % N;

  vector<long> res(N, 0);
  for (long i = 0; i < N; ++i) {
    res[(i + counter) % N] = last_poses[i];
  }

  for (auto &e : res) {
    cout << e << endl;
  }
  return 0;
}

Measured memory_bytes: 4352
def getFindList(S) :
    j=-1
    findList = []
    while(1) :
        j = S.find("RL", j+1)
        if j == -1 :
            break
        findList.append(j)
    return findList

S = input()
i = 0
itr = 0
findList = getFindList(S)
result = [0] * len(S)

for i in range(len(S)) :
    if itr < len(findList) and i > findList[itr] :
        itr += 1
        
    if S[i] == "R" :
        if (findList[itr] - i) % 2 == 0:
            result[findList[itr]] += 1
        else :
            result[findList[itr]+1] += 1
        
        
        
    if S[i] == "L" : 
        if (findList[itr-1] - i) % 2 == 0:
            result[findList[itr-1]] += 1
        else :
            result[findList[itr-1]+1] += 1
        
print(" ".join(map(str, result)))

Measured memory_bytes: 12532
#include<bits/stdc++.h>
using namespace std;
double a[105],sum=0;
int n,m; 
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%lf",&a[i]),sum+=a[i];
	sort(a+1,a+n+1);
	if(a[n-m+1]*4*m>=sum){
		printf("Yes");
	}
	else printf("No");
	return 0;
}

Measured memory_bytes: 256