akhauriyash/Code-Regression huggingface dataset:
# coding=utf-8

###
### for atcorder program
###

import sys
import math

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]

#R = float(input())
#A.append(list(map(int,input().split())))

#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

#abc list
#abc = [chr(ord('a') + i) for i in range(26)]

### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
#print(" {}".format(i), end="")

def get_input():
    N = []
    while True:
        try:
            N.append(input())
        except EOFError:
            break
    return N

S = input()
N = int(input())
P = []

for i in range(N):
    P.append([x for x in input().split()])

for M in P:
    if M[0] == 'print':
        a = int(M[1])
        b = int(M[2])+1
        print(S[a:b])
    elif M[0] == 'reverse':
        a = int(M[1])
        b = int(M[2])+1
        T = S[a:b]
        S = S[:a]+T[::-1]+S[b:]
    elif M[0] == 'replace':
        a = int(M[1])
        b = int(M[2])+1
        S = S[:a]+M[3]+S[b:]




Measured memory_bytes: 5696
#include <iomanip>
#include <string>
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
int main()
{
	long long int a, b, d;
	cin >> a >> b;
	long double c = pow(2, b);
	d = c;
	a = (b * 1900 + (a - b) * 100)*d;
	cout <<a<< endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define cases int t; cin >> t; while (t--)
#define fir for (ll i = 0; i < n; i++) 
using namespace std;

int main()
{
    int a[3], n =3;
    fir cin >> a[i];
    sort(a, a+n);
    cout << a[0] + a[1] << endl;
    return 0;
}

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

long long calc(int w, int h, int v, int t, int x, int y, int p, int q) {
  long long tx, ty, c = 0, d = v * t;
  for (int i = -d / w - 2; i < d / w + 2; ++i) {
    tx = i * w + (i % 2 ? w - p : p);
    if (abs(tx - x) > d) continue;
    double dy = sqrt(d * d - (tx - x) * (tx - x));
    if (abs(q - y) > dy) continue;

    int r[] = { (dy + y) / h, -(dy - y) / h - 1 };
    if (y > dy) r[1]--;
    if (r[0] == r[1]) {
      if ((tx - x) * (tx - x) + (q - y) * (q - y) <= d * d) c++;
    } else {
      c += r[0] - r[1] - 1;
      for (int k = 0; k < 2; ++k) {
        ty = r[k] * h + (r[k] % 2 ? h - q : q);
        if ((tx - x) * (tx - x) + (ty - y) * (ty - y) <= d * d) c++;
      }
    }
  }
  return c;
}

int main() {
  int w, h, v, t, x, y, p, q;
  cin >> w >> h >> v >> t >> x >> y >> p >> q;
  cout << calc(w, h, v, t, x, y, p, q) << endl;
}

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

int main(){
	int n,p;
	while(cin >> n >> p, n|p){
		vector<int> v(n,0);
		int cup=p;
		int num=0;
		while(1){
			if(cup!=0){
				v[num]++;
				cup--;
			}
			else if(v[num]!=0){
				cup=v[num];
				v[num]=0;
			}
			if(v[num]==p)
				break;
			num++;
			num%=n;
		}
		cout << num << endl;
	}
	return 0;
}

Measured memory_bytes: 1192
#include<stdio.h>
int main(){
  int a=0,b=0,c=0;
  char s[11];
  scanf("%s",s);
  while(s[a]!='\0'){
    if(s[a]=='A'||s[a]=='C'||s[a]=='G'||s[a]=='T'){
      b++;
    }else{
      b=0;
    }
    if(b>c){
      c=b;
    }
    a++;
  }
  printf("%d",c);
  return 0;}


Measured memory_bytes: 128
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  int N, S1 = 0, S2 = 0, lastTimeAbsolute = 10000;
  cin >> N;
  vector <int> W(N);

  for(int i = 0; i < N; i++) {
    cin >> W[i];
  }


  for(int T = 0; T < N; T++) {
    for(int i = 0; i < N; i++) {
      if(i <= T) {
        S1 += W[i];
      } else {
        S2 += W[i];
      }
    }
    
    if(abs(S1 - S2) == 0) {
      cout << 0 << endl;
      break;
    } else if(abs(S1 - S2) > lastTimeAbsolute){
      cout << lastTimeAbsolute << endl;
      break;
    } else {
      lastTimeAbsolute = abs(S1 -S2);
      S1 = 0;
      S2 = 0;
    }
  }

  return 0;
}

Measured memory_bytes: 256
n = gets.to_i
c = gets.chomp
i = 0
j = n - 1
count = 0
while true do
  while i < n && c[i] == "R" do
    i += 1
  end
  while j >= 0 && c[j] == "W" do
    j -= 1
  end
  if i < j
    count += 1
    i += 1
    j -= 1
  else
    break
  end
end
puts count


Measured memory_bytes: 14692
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;
int n,m,s,t;


typedef struct edge {
    ll to, yen, sunuuk;
} edge;

vector<vector<edge>> g;


void stoc(vector<ll> &dps) {
    priority_queue<P, vector<P>, greater<P>> pq;
    dps[s] = 0;
    pq.push({0,s});

    while (!pq.empty()) {
        P p = pq.top(); pq.pop();
        int v = p.second;
        for (auto &&e: g[v]) {
            if (dps[e.to] > dps[v]+e.yen) {
                dps[e.to] = dps[v]+e.yen;
                pq.push({dps[e.to],e.to});
            }
        }
    }
}

void ttoc(vector<ll> &dpt) {
    priority_queue<P, vector<P>, greater<P>> pq;
    dpt[t] = 0;
    pq.push({0,t});

    while (!pq.empty()) {
        P p = pq.top(); pq.pop();
        int v = p.second;
        for (auto &&e: g[v]) {
            if (dpt[e.to] > dpt[v]+e.sunuuk) {
                dpt[e.to] = dpt[v]+e.sunuuk;
                pq.push({dpt[e.to],e.to});
            }
        }
    }
}


int main(int argc, char const *argv[]) {
    cin >> n >> m >> s >> t;
    --s, --t;
    g.resize(n);

    REP(i,m) {
        ll u,v,a,b;
        cin >> u >> v >> a >> b;
        --u,--v;
        edge tmp1; tmp1.to = v; tmp1.yen = a; tmp1.sunuuk = b;
        edge tmp2; tmp2.to = u; tmp2.yen = a; tmp2.sunuuk = b;
        g[u].push_back(tmp1);
        g[v].push_back(tmp2);
    }

    vector<ll> mark(n);
    vector<ll> dps(n+10, LINF), dpt(n+10, LINF);
    stoc(dps);
    ttoc(dpt);

    REP(i,n) {
        ll tmp = dps[i]+dpt[i];
        mark[i] = tmp;
    }

    ll path = mark[n-1];
    deque<ll> dq;

    for (int i = n-1; i >= 0; --i) {
        ll ans = 1e15;
        path = min(path, mark[i]);
        dq.push_front(ans-path);
    }

    while (!dq.empty()) {
        ll ret = dq.front(); dq.pop_front();
        cout << ret << endl;
    }
    

    return 0;
}

Measured memory_bytes: 13720
#include <stdio.h>
#include <math.h>
// using namespace std;
int N;
int i = 2;
int num;
char buf[8], out[20];
char k;
s;
size_t ii;
int main()
{
  s = read(0, buf, 8);
  for (;;)

  {
    k = buf[ii++];
    if (k < '0')
      break;
    N = N * 10 + k - '0';
  }
  // printf("%d\n", N);
  long long ans = (long long)N * (N + 1) - 1;

  for (; i * i <= N; i++)
  {
    num = N / i;
    // ans += (long long)(num - i + 1) * i * (i + num) - i * i;
    ans += (long long)i * ((long long)num * num - i * i + num);
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 1600
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    string k;
    string l;
    cin >> n;
    cin >> k;
    cin >> l;
    long long int c;
    if(k[0] == l[0])
    {
        c = 3;
    }
    else
    {
        c = 6;
    }
    for(int i = 1; i < n; i++)
    {
        if(k[i] == l[i] && k[i-1] == l[i-1])
        {
            c = (2 * c) % 1000000007 ;
        }
        else if(k[i] == l[i])
        {
            c = c;
        }
        else if(k[i] == k[i-1])
        {
            c = c;
        }
        else if(k[i-1] == l[i-1])
        {
            c = (2 * c) % 1000000007 ;
        }
        else
        {
            c = (3 * c) % 1000000007 ;
        }
    }
    
    cout << c << endl;


}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <utility>
#include <cmath>
#include <cstdio>
#include <string>

using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;
LL MOD = 1000000007;

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<LL>> dp(N, vector<LL>(M, 0));
    dp[0][0] = 1;
    for(int i=0; i<N; i++) {
        string s;
        cin >> s;
        for(int j=0; j<s.size(); j++) {
            if(s[j] == '#') continue;
            if(i>0) dp[i][j] += dp[i-1][j];
            if(j>0) dp[i][j] += dp[i][j-1];
            dp[i][j] %= MOD;
        }
    }
    cout << dp[N-1][M-1] << endl;

    return 0;
}

Measured memory_bytes: 8064
from collections import defaultdict


def main():
        
    N = int(input())
    S = input()

    X = S[:N]
    Y = S[N:]
    Y = Y[::-1]

    dx = defaultdict(int)
    dy = defaultdict(int)

    for bit in range(1 << N):
        red = ""
        blue = ""
        for i in range(N):
            if bit & (1 << i):
                red += X[i]
            else:
                blue += X[i]

        dx[(red, blue)] += 1

    for bit in range(1 << N):
        red = ""
        blue = ""
        for i in range(N):
            if bit & (1 << i):
                red += Y[i]
            else:
                blue += Y[i]

        dy[(red, blue)] += 1

    # 前後が同じになる組がいくつできるか。
    ans = 0
    for k,v in dx.items():
        ans += dy[k] * v

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 150500
import java.util.*;
public class Main{
	public static void main(String args[]){
		
		Scanner ob = new Scanner(System.in);
		int N, R, I;

		N = ob.nextInt();
		R = ob.nextInt();

		if(N >= 10){
			I = R;	
		}
		else{
			I = R + 1000 - 100 * N;
		}
		System.out.println(I);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

 ll Gcd(ll a,ll b){
    if(a < b)swap(a, b);

	if(a%b == 0)return(b);

	else return(Gcd(b, a%b));
}

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

    ll a[n];
    rep(i, n)cin >> a[i];

    ll gcd_l[n];
    ll gcd_r[n];
    gcd_l[0] = a[0];
    gcd_r[n-1] = a[n-1];

    rep(i, n-1){
        gcd_l[i+1] = Gcd(gcd_l[i], a[i+1]);
        gcd_r[n-2-i] = Gcd(gcd_r[n-1-i], a[n-2-i]);
    }

    ll ans = 1;
    rep(i, n){
        if(i == 0)ans = max(ans, gcd_r[1]);
        else if(i == n-1)ans = max(ans, gcd_l[n-2]);
        else {
            ans = max(ans, Gcd(gcd_l[i-1], gcd_r[i+1]));
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 2560
#[allow(unused_imports)]
use std::{cmp::Reverse, collections::*};

#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Chars, Usize1},
};

#[allow(unused_imports)]
use itertools::Itertools;

#[allow(unused_imports)]
use num::Integer;

#[fastout]
pub fn main() {
    input! {
        n: usize,
        w: [String; n],
    }

    let mut set = HashSet::new();
    let mut prev = String::new();
    let mut ok = true;
    for w in w {
        if set.contains(&w) {
            ok = false;
            break;
        }
        if !prev.is_empty() {
            if prev.chars().rev().next().unwrap() != w.chars().next().unwrap() {
                ok = false;
                break;
            }
        }
        prev = w.clone();
        set.insert(w);
    }
    println!("{}", if ok { "Yes" } else { "No" });
}


Measured memory_bytes: 2164
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Fri Aug 16 09:50:37 2019
//
package main

import "fmt"

func main() {
	var k, x int
	fmt.Scanf("%d %d", &k, &x)
	for i := x - k + 1; i <= x+k-1; i++ {
		if i != x-k+1 {
			fmt.Print(" ")
		}
		fmt.Print(i)
	}
	fmt.Println()
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
#define double long double
#define N 14
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
int G[N][N];
int n;
double p;
 
double calc(int b,int c){
  double res = 1;
  for(int i=0;i<n;i++) 
    for(int j=i+1;j<n;j++)
      if(((b>>i&1) && (c>>j&1) && G[i][j]) ||
         ((b>>j&1) && (c>>i&1) && G[i][j])) res *= p;
      return res;
}
 
 
double mem[1<<N],used[1<<N];
double dfs(int bit){
  if(bit == 0) return 0;
  if((bit&-bit) == bit) return 1;
  if(used[bit]++) return mem[bit];
 
  double res = 1;
  for(int i = (i-1)&bit;i > 0;i=(i-1)&bit){
    if(i % 2 == 0) continue;
    int j = bit ^ i;
    double p = dfs(i);    
    res -= p * calc(i,j); 
  } 
  return mem[bit] = res;
}
 
 
signed main(){
  int m;
  cin>>n>>m>>p; p/=100;
  for(int i=0,a,b;i<m;i++){
    cin>>a>>b;
    G[a-1][b-1] = G[b-1][a-1] = 1;
  }
   
  printf("%.10Lf\n",dfs((1<<n)-1));
  return 0;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
signed main(){
  long long n,ans[1050000],mem,ans1=0,e,a,b,c,d=0,ans2=0;
  vector<long long> day;
  long long day2[100000];
  cin>>n;
  for(int l=0;l<n;l++){
    cin>>mem;
    day.push_back(mem);
  }
  for(int bit =1;bit<(1<<n);bit++){
    vector<long long > S;
    for(int i=0;i<n;i++){
      if(bit & (1<<i)){
	S.push_back(day[i]);
      }
    }
    ans[bit]=1;
    for(int j=0;j<(int)S.size();j++){
      a=S[j];
      b=ans[bit];
      for(;;){
	if(a<b)
	  swap(a,b);
	if(a%b==0){
	  e=b;
	  break;
	}
	else{
	  c=a;
	  a=b;
	  b=c%b;
	}
      }
      ans[bit]=ans[bit]*S[j]/e;
    }
    for(int k=0;k<n;k++){
      if(ans[bit]%day[k]==0)
	ans2++;
    }
    if(ans2>(int)S.size())
      ans1++;
    ans2=0;
  }
  cout<<(1<<n)-1-ans1<<endl;
  return(0);
}  



Measured memory_bytes: 11344
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
typedef long long ll;
typedef pair<int, int> P;
typedef struct{
  int first;
  int second;
  int third;
}T;

//昇順
bool comp_Se(T& l, T& r){
  return l.second < r.second;
}

vector<vector<int> > G;
int x,y;
bool dfs(int cur, int pare){
  if(cur == x && pare != -1) return true;
  if(cur == y) return false;
  bool ret = false;
  for(int & e : G[cur]){
    if(e == pare)continue;
    if(dfs(e,cur)) return true;
  }
  return false;
}

int main(void){
  int N,M;
  cin >> N >> M;
  G = vector<vector<int> >(N);
  vector<int> v(N,0);
  int i,a,b;
  REP(i,M){
    cin >> a >> b;
    v[--a]++;
    v[--b]++;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int n_6,n_4,n_2;
  n_6 = n_4 = n_2 = 0;
  REP(i,N){ if(v[i]%2){
      cout << "No" << endl;
      return 0;
    }
    if(v[i]>=6)++n_6;
    else if(v[i] == 4){
      ++n_4;
      swap(x,y);
      x = i;
    }
    else ++n_2;
  }
  if(n_6>=1 || n_4 >=3 ) cout << "Yes" << endl;
  else if(n_4 == 2){
    if(dfs(x,-1)) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  else cout << "No" << endl;
  return 0;
}


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

using namespace std;

void LoopUntilZeroInpput() {
	int N = 0;
	while (cin >> N && N != 0) {
	}
}

int ans[100000];

void UpdateAns(int max, int hoge) {
	for (int i = 0; i <= hoge; i++) {
		ans[i] = 0;
	}
	ans[0] = max;
}

int main() {
	int N, T;
	cin >> N >> T;
	int A[100000];
	int B[100000];
	

	int currentMin = 1000000001;
	ans[0] = -1000000001;
	int indexAid = 1;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		if (currentMin>A[i])
			currentMin = A[i];
		B[i] = currentMin;
	}
	for (int i = N - 1; i > 0; i--) {
		int mayMax = A[i] - B[i];
		if (ans[0] < mayMax) {
			UpdateAns(mayMax, indexAid);
			indexAid = 1;
		}
		else if (ans[0] == mayMax) {
			int j = 1;
			while (ans[j] != B[i]) {
				j += 2;
				if (j > indexAid) {
					indexAid = j;
					ans[j] = B[i];
					ans[j + 1] = A[i];
				}
			}
		}
	}

	cout << (indexAid / 2) + 1 << endl;




	//LoopUntilZeroInpput();
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;
typedef pair<int,pi> edge;

const int INF=123456789;

struct UF{
    int n;
    //??£?????£????????????????????????,????????£???????????§??£?????????????????°
    vector<int> d;
    UF() {}
    UF(int N):n(N), d(N,-1){}
    int root(int v){
        if(d[v]<0) return v;
        return d[v]=root(d[v]);
    }
    bool unite(int X,int Y){
        X=root(X); Y=root(Y);
        if(X==Y) return false;
        if(size(X) < size(Y)) swap(X,Y);
        d[X]+=d[Y];
        d[Y]=X;
        return true;
    }
    int size(int v){ return -d[root(v)]; }
    bool same(int X,int Y){ return root(X)==root(Y); }
};

int main()
{
    int n,m;
    while(cin >>n >>m,n)
    {
        vector<edge> e(m);
        rep(i,m)
        {
            int a,b,w;
            scanf(" %d %d %d", &a, &b, &w);
            --a;
            --b;
            e[i]=edge(w,pi(a,b));
        }
        sort(all(e));

        int ans=INF;
        rep(i,m)
        {
            int min_cost=e[i].fi;
            int max_cost=INF;

            UF uf(n);
            for(int j=i; j<m; ++j)
            {
                int a=e[j].se.fi, b=e[j].se.se;
                if(!uf.same(a,b)) uf.unite(a,b);

                if(uf.size(0)==n)
                {
                    max_cost=e[j].fi;
                    break;
                }
            }

            // printf(" %d - %d\n", max_cost, min_cost);
            if(uf.size(0)==n) ans=min(ans,max_cost-min_cost);
        }

        if(ans==INF) ans=-1;
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 3256
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	@SuppressWarnings("unchecked")
	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			int m = scanner.nextInt();
			if ((n | m) == 0)
				break;
			List<Point>[] lists = new ArrayList[n + 1];
			for (int i = 0; i <= n; i++)
				lists[i] = new ArrayList<Point>();
			for (int i = 1; i <= n; i++) {
				int k = scanner.nextInt();
				for (int j = 0; j < k; j++) {
					int x = scanner.nextInt();
					int cost = scanner.nextInt();
					lists[i - 1].add(new Point(1, x, cost));
					if (i != 1)
						lists[i - 2].add(new Point(2, x, cost));
					if (i == n - 1)
						lists[i].add(new Point(2, x, 0));
					if (i == n)
						lists[i].add(new Point(1, x, 0));

				}
			}
			PriorityQueue<Point> pq = new PriorityQueue<Main.Point>();
			pq.offer(new Point(0, 0, 0, 0, m));
			int[][][] dp = new int[m + 1][n + 1][1001];
			for (int[][] d : dp)
				for (int[] dd : d)
					Arrays.fill(dd, Integer.MAX_VALUE);
			dp[m][0][0] = 0;
			while (!pq.isEmpty()) {
				Point point = pq.poll();
				int y = point.y;
				int x = point.x;
				int cost = point.cost;
				int total = point.total;
				int mm = point.m;

				if (y >= n) {
					System.out.println(total);
					break;
				}
				if (dp[mm][y][x] < total)
					continue;
				for (Point p : lists[y]) {
					int nc = (cost + p.cost) * Math.abs(x - p.x) + total;
					int ny = Math.min(n, y + p.y);
					if (p.y == 2) {
						if (mm >= 1) {
							if (dp[mm - 1][ny][p.x] > nc) {
								dp[mm - 1][ny][p.x] = nc;
								pq.offer(new Point(ny, p.x, p.cost, y == 0 ? 0
										: nc, mm - 1));
							}
						}
					} else {
						if (dp[mm][ny][p.x] > nc) {
							dp[mm][ny][p.x] = nc;
							pq.offer(new Point(ny, p.x, p.cost,
									y == 0 ? 0 : nc, mm));
						}
					}
				}
			}

		}
	}

	class Point implements Comparable<Point> {
		int y, x, cost, total, m;

		public Point(int y, int x, int cost, int total, int m) {
			super();
			this.y = y;
			this.x = x;
			this.cost = cost;
			this.total = total;
			this.m = m;
		}

		public Point(int y, int x, int cost) {
			super();
			this.y = y;
			this.x = x;
			this.cost = cost;

		}

		@Override
		public String toString() {
			return "Point [y=" + y + ", x=" + x + ", cost=" + cost + ", total="
					+ total + ", m=" + m + "]";
		}

		@Override
		public int compareTo(Point o) {
			if (this.total == o.total)
				return o.y - this.y;
			return this.total - o.total;
		}
	}
}

Measured memory_bytes: 170332
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

#pragma region _define

#define int LL
#define f(i,a,b) for(LL i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define ei else if
#define all(a) a.begin(),a.end()
#define size(s) ((LL)s.size())
#define F first
#define S second
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl
#define int_INF 1<<29
#define ll_INF 1LL<<60
#define MOD 1000000007

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using qi = queue<LL>;
using qc = queue<char>;
using qs = queue<st>;
using si = stack<LL>;
using sc = stack<char>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using mll = map<LL, LL>;
using mcl = map<char, LL>;
using vpi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50  //グラフの最大位数　適宜変更
//bool graph[node][node]; bool visited[node] = { false };
#define link(a,b,m) f(i,0,m){cin>>a[i]>>b[i]; a[i]--; b[i]--; graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;}

#pragma endregion

void y_n(bool p) {
	p ? _y() : _n();
}

void Y_N(bool p) {
	p ? _Y() : _N();
}

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

//素数判定
bool is_prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n % i == 0) {
			return false;
		}
	}
	return true;
}

//階乗計算
LL factorial(LL n) {
	LL a = 1, ret = 1;
	while (a < n) {
		a++;
		ret *= a;
		ret %= MOD;
	}
	return ret;
}

#pragma endregion 




/*****************************************************************************/

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

	st s, t;
	cin >> s >> t;
	vvi dp(size(s) + 1, vi(size(t) + 1, 0));
	f(i, 0, size(s)) {
		f(j, 0, size(t)) {
			if (s[i] == t[j]) {
				dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
			}
			dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j]);
			dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j+1]);
		}
	}
	st ans = "";
	int i = size(s), j = size(t);
	while (i > 0 && j > 0) {
		if (dp[i][j] == dp[i - 1][j]) {
			i--;
		}ei(dp[i][j] == dp[i][j - 1]) {
			j--;
		}
		else {
			ans = s[i - 1] + ans;
			i--; j--;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 70784
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <bitset>
#include <complex>
using namespace std;

const double EPS = 1e-9;
const double PI = 3.14159265359;

typedef complex<double> P;

int main(){
	string s;
	stringstream ss;

	while(getline(cin, s)){
		vector<string> v;
		for(int i = 0; i < s.size(); i++){
			if(s[i] == ',' || s[i] == '.'){
				s[i] = ' ';
			}
		}
		ss << s;
		while(ss >> s){
			if(s.size() >= 3 && s.size() <= 6){
				v.push_back(s);
			}
		}
		bool f = true;
		for(int i = 0; i < v.size(); i++){
			if(!f){
				cout << ' ';
			}
			f = false;
			cout << v[i];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
int n;

int main() {
    while(cin >> n, n){
    int a[1001]={0};
    for(int i=0; i<n; ++i)  cin >> a[i];
    sort(a, a+n);
    int minV=1000000;
    for(int i=1; i<n; ++i){
        minV = min(minV, abs(a[i]-a[i-1]));
    }
    cout << minV << endl;
    }
    return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
 
using namespace std;
 
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define vvi vector<vector<int> >
#define ss second
#define ff first
#define ll long long
#define mod (1000*1000*1000+7)
#define pq priority_queue< int >
#define endl '\n'
#define int ll
#define gcd __gcd
#define search(arr, c) binary_search(arr.begin(), arr.end(), c)

void solve(){
    
    int n;
    cin >> n;
    string a;
    cin >> a;
    int count_r = 0;
    for (int i = 0 ; i < n ; i++){
        if (a[i] == 'R') count_r++;
    }
    int ans = 0;
    for (int i = 0 ; i < count_r ; i++){
        if (a[i] == 'W') ans++;
    }
    cout << ans << endl;
}


int32_t main(){

    #ifndef ONLINE_JUDGE 
  
    freopen("input.txt", "r", stdin); 
  
    freopen("output.txt", "w", stdout); 
  
    #endif 

    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
 

    int t = 1;
    // cin >> t;
    while(t--){
        solve();
        // cout << "Case #" << (tt+1) <<":" << endl;
    }
}

Measured memory_bytes: 3764
import java.util.Scanner;


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

    input = input.substring(0, input.length() - 1);
    while (!isEvenStr(input)) {
      input = input.substring(0, input.length() - 1);
    }
    System.out.println(input.length());
  }

  static boolean isEvenStr(String target) {

    if (target.length() % 2 != 0) {
      return false;
    }
    return target.substring(0, target.length() / 2)
        .equals(target.substring(target.length() / 2));
  }
}


Measured memory_bytes: 23636
#include<bits/stdc++.h>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=(int)j;i<=(int)k;++i)
using namespace std;

const int maxn=2e5+1e2;
int n;
ll Ans;
int a[maxn];

inline void file() {
	freopen("ARC098D.in","r",stdin);
	freopen("ARC098D.out","w",stdout);
}

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

int main() {
//	file();
	n=read();
	int p=1,sum=0;
	For (i,1,n) {
		a[i]=read();
		while ((sum^a[i])!=(sum+a[i])) sum^=a[p++];
		sum^=a[i]; Ans+=1ll*(i-p+1);
	}
	printf("%lld",Ans);
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void) {
    int n, count = 0, max = 0;
    scanf("%d", &n);
    int h[n];
    for(int i = 0; i < n; i++) {
        scanf("%d", &h[i]);
        if(i > 0) {
            if(h[i-1] >= h[i]) {
                count++;
            } else {
                if(max < count) {
                    max = count;
                }
                count = 0;
            }
        }
    }
    if(max < count) max = count;
    printf("%d\n", max);
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    int k,n;
    cin>>k>>n;
    int a[200010];
    for(int i=0;i<n;i++)cin>>a[i];
    int b=k-a[n-1]+a[0];
    for(int i=1;i<n;i++){
        b=max(a[i]-a[i-1],b);
    }
    cout<<k-b;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define inf 1000000000
#define md 1000000007
#define md2 13
#define pb push_back
#define li 100005
#define int long long
using namespace std;
int n,pw[li],dp[li][15];
char s[li];
inline int add(int x,int y){
	if(x+y>=md) return x+y-md;
	return x+y;
}
inline int mul(int x,int y){
	return (x%md2)*(y%md2)%md2;
}
int dfs(int node,int kalan){
	int cev=0;
	if(node==n+1){
		if(kalan==5) return 1;
		return 0;
	}
	if(~dp[node][kalan]) return dp[node][kalan];
	if(s[node]!='?'){
		int tut=s[node]-'0';
		int hop=kalan+tut*pw[n-node];
		hop%=13;
		cev=add(cev,dfs(node+1,hop));
	}
	else{
		for(int i=0;i<=9;i++){
			int hop=kalan+i*pw[n-node];
			hop%=13;
			cev=add(cev,dfs(node+1,hop));
		}
	}
	return dp[node][kalan]=cev;
}
main(){
	memset(dp,-1,sizeof(dp));
	pw[0]=1;
	for(int i=1;i<=100002;i++) pw[i]=mul(pw[i-1],10);
	scanf("%s",s+1);
	n=strlen(s+1);
	int ty=dfs(1,0);
	printf("%lld\n",ty);
	return 0;
}




Measured memory_bytes: 19072
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

const ll mod = 1e9 + 7;
const ll inf = 1e18;

vector<ll> factorization(ll N){
    ll n = N;
    vector<ll> A;
    ll sq = sqrt(n);
    FOR(i, 2, sq+1){
        while(n%i==0){
            n /= i;
            A.push_back(i);
        }
    }
    if(n!=1){
        A.push_back(n);    
    }
    return A;
}

const int N_MAX = 200010;
ll Per[N_MAX] = {}; // n!
ll Per_inv[N_MAX] = {}; //(n!)^-1

ll nCr(ll n, ll r){
    if(n<r) return 0;
 
    if (n == r || r == 0)
        return 1;
    else
        return Per[n] * Per_inv[n-r] % mod * Per_inv[r] % mod;  
}
 
// a^b mod p
ll mod_pow(ll a, ll b){
    if(b==0) return 1;
 
    // 肩が奇数
    if(b%2==1){
        return a * mod_pow(a, b-1) % mod;
    }
    else{
        return mod_pow(a*a % mod, b/2) % mod;
    }
}

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

    // input
    ll N, M;
    cin >> N >> M;

    // nCr高速化準備
    Per[1] = 1;
    FOR(i, 2, N_MAX){
        Per[i] = i * Per[i-1] % mod;
    }
    Per_inv[1] = 1;
    FOR(i, 2, N_MAX){
        Per_inv[i] = mod_pow(Per[i], 1000000005);
    }

    auto list = factorization(M);
    map<ll, ll> mp;
    for(ll a : list){
        mp[a]++;
    }

    ll answer = 1;
    for(auto p : mp){
        ll c = p.second;
        answer *= nCr(c + N -1, c);
        answer %= mod;
    }

    p(answer);

    return 0;
}

Measured memory_bytes: 3328
def main():
    from collections import deque


    INF = float('inf')
    n, m = map(int, input().split())
    s = list(map(int, input()))

    dp = [INF] * (n + 1)
    dp[n] = 0
    queue = deque([0])

    i = n - 1
    while i >= 0:
        while True:
            if not queue:
                print(-1)                
                return            
            if queue[0] != INF and len(queue) <= m:
                break
            queue.popleft()
            
        if s[i] == 0:
            dp[i] = queue[0] + 1
        queue.append(dp[i])
        i -= 1

    ans = []
    v = dp[0]
    num = 0
    for i in dp:
        if i != v and i != INF:
            ans.append(num)
            v = i
            num = 1
        else:
            num += 1

    print(*ans, sep=' ')


if __name__ == '__main__':
    main()    

Measured memory_bytes: 11276
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
	int n;cin >> n;
	if(n%2){
		int a = n/2;
		int b = n/2+1;
		cout << a*b << endl;
		return 0;
	}
	cout << n*n/4 << endl;
	return 0;
}

Measured memory_bytes: 3596
const fs = require('fs')
const stdin = fs.readFileSync('/dev/stdin', 'utf8')

const [N, A, B, C, D, E] = stdin.split('\n').map(Number)

const bottleneck = Math.min(A, B, C, D, E)

const pathBottleNeck = Math.ceil(N / bottleneck)

console.log(pathBottleNeck + 4)


Measured memory_bytes: 7372
#include <bits/stdc++.h>
 
using namespace std;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const double PI = 4*atan(1);
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
// ll gcd(ll a, ll b) { 
//     if (a == 0) return b; 
//     return gcd(b % a, a); 
// }
ll mod(ll x) {
	x%=MOD;
	if(x<0)x+=MOD;
	return x;
}
// ll power(int base, int power) {
// 	ll prod = 1;
// 	ll b = base;
// 	while(power) {
// 		if (power & 1) {
// 			prod = mod(prod*b);
// 		}
// 		b = mod(b*b);
// 		power/=2;
// 	}
// 	return prod;
// }
// struct line {
//     int m, c;
//     ll eval(int x) { return 1LL * m * x + c; }
//     double intersectX(line l) { return (double) (c - l.c) / (l.m - m); }
//0 is white, 1 is black
string s, t;
void solve() {
	cin >> s >> t;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] != t[i]) {
			cout << "No\n";
			return;
		}
	}
	cout << "Yes\n";
}
int main() {
	int t=1;
	// cin >> t;
	for (int i = 1; i <= t; i++) { 
		// cout << "Case #" << i << ": ";
		solve();
	}
}

Measured memory_bytes: 3624
use v5.18; # strict say state
use warnings;

chomp (my $n = <STDIN>);
my @x;
for my $i (0..$n-1) {
  my ($p, $l) = split ' ', <STDIN>;
  $x[$i][0] = $p - $l;
  $x[$i][1] = $p + $l;
}
@x = sort {$a->[1] <=> $b->[1]} @x;
my $ans = 0;
my $cur = -1e9;
for my $i (0..$n-1) {
  next if $cur > $x[$i][0];
  $ans++;
  $cur = $x[$i][1];
}
say $ans;

Measured memory_bytes: 20352
#include<bits/stdc++.h>
#include <math.h>
#include <limits.h>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
const long long INF = 1LL<<60;
const long long MOD = 1e9+7;
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void Yes(){cout<<"Yes"<<endl;}
void No(){cout<<"No"<<endl;}
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}

int main(void){
  int n;
  cin >> n;
  int v;
  deque<int> values(3);
  int answer = 0;
  for(int i=0;i<n;i++){
    cin >> v;
//    cout << "???" << v << endl;
    values.push_back(v);
    if(values.size()>3){
      values.pop_front();
    }
//    cout << "???" << values[0] << ":" << values[1] << ":" << values[2] << endl;
    if(i>=2){
      if(values[0]<values[1] && values[1]<values[2]){
        answer++;
//        cout << values[0] << ":" << values[1] << ":" << values[2] << endl;
      }
      else if(values[0]>values[1] && values[1]>values[2]){
        answer++;
//        cout << values[0] << ":" << values[1] << ":" << values[2] << endl;
      }
      else{
//        cout << "!!!" << values[0] << ":" << values[1] << ":" << values[2] << endl;
      }
    }
  }
  cout << answer << endl;
  return 0;
}




Measured memory_bytes: 256
while(n,m=gets.split.map &:to_i)[0]>0
s=?#*n+?Z
m.times{(c=gets[0])<?B?(i=s.index ?#):c<?C?(i=n-1
i-=1 while i>=0&&(s[i]>?#||s[j=i+1]==?A||s[i-1]==?A)
i<0&&i=j-1):c<?D?(j=0
j+=1 while j<n&&(s[j]<?A||s[i=j+1]>?#&&s[i=j-1]>?#)
j>=n&&i=n/2):(w=z=1e20
t=[]
u=[]
(0..n-1).map{|k|s[k]>?#&&w=0;t<<w+=1;s[n-1-k]>?#&&z=0;u.unshift z+=1}
v=t.zip(u).map &:min
i=v.index v.max)
s[i]=c}
puts s.chop
end

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

int main() {
  int N, D, X, A[200];

  cin >> N >> D >> X;
  rep(i, N) cin >> A[i];

  int eat = 0;
  rep(i, N) {
    eat += (D - 1) / A[i] + 1;
  }

  int ans = eat + X;

  cout << ans << endl;

  return 0;

}

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

using namespace std;

int arr[1000][1000];

int func(int l,int n,int k) {
	if (n == 0)
		return 1;
	else {
		int ans = 0;
		for (int i = 0; i < k; i++) {
			if (i != l) {
				if(arr[i][n-1] == 0)
					arr[i][n - 1] = func(i, n - 1, k);
				ans += arr[i][n - 1];
			}
		}
		return ans;
	}
}

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

	int n,k;
	cin >> n >> k;

	cout << func(-1,n,k) << endl;

	return 0;

}

Measured memory_bytes: 4096
#include<iostream>
using namespace std;
 
int main(){
	int n, p[20], i, ans = 0;
	cin >> n;
	for (i = 0; i < n; i++){
		cin >> p[i];
	}
	for (i = 1; i < n - 1; i++){
		if (p[i - 1] < p[i]){
			if (p[i] < p[i + 1]){
				ans++;
			}
		}
		else if (p[i - 1] > p[i]){
			if (p[i] > p[i + 1]){
				ans++;
			}
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#define inf 10e9

int ip(int a, int b) {
  return !b ? 1 : ip(a, b - 1) * a;
}

int main(void) {
  int n, i, j, x = inf, y = inf, z = inf;
  scanf("%d", &n);
  int a[n];
  for(i = 0; i < n; ++i) scanf("%d", &a[i]);
  for(i = 0; i < n; ++i) {
    for(j = 0; j < n; ++j) {
      if(i != j) {
        int t = a[j] + a[i] * ip(10, (int)log10(a[j]) + 1);
        if(t < x) z = y, y = x, x = t;
        else if(t < y) z = y, y = t;
        else if(t < z) z = t;
      }
    }
  }
  printf("%d\n", z);
  return 0;
}


Measured memory_bytes: 2972
N = int(input())
A = list(map(int, input().split()))

A.sort()

n = A[-1]
r1 = n / 2
temp = 10 ** 9
r = 0

for i, x in enumerate(A):
  if abs(r1 - x) <= temp and i != N-1:
    r = x
    temp = abs(r1 - x)

print(str(n)+" "+str(r))

Measured memory_bytes: 20120
def resolve():
    r, g, b, n = map(int, input().split())
    ans = 0
    for i in range((n//r)+1):
        for j in range(((n-(r*i))//g)+1):
            if (n-(i*r + j*g)) % b == 0:
                ans += 1
    print(ans)
resolve()

Measured memory_bytes: 39152
// God put a smile upon your face <3

#include <bits/stdc++.h>`

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

#define mod 958585860497

#define base 2001487

using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

vector < ll > g[100005];
ll passage[100005];

bool solve(ll n)
{
	queue < ll > q;

	q.push(1);

	passage[1] = 1;

	while(!q.empty())
	{
		ll top = q.front();
		q.pop();

		for(auto it: g[top])
		{
			if(passage[it] == -1)
			{
				passage[it] = top;
				q.push(it);
			}
		}
	}

	for(ll i = 1; i <= n; i++) if(passage[i] == -1) return 0;

	return 1;
}
int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

    while(cin >> n)
    {
		for(i = 1; i <= n; i++)
		{
			passage[i] = -1;
			g[i].clear();
		}

		cin >> m;

		for(i = 1; i <= m; i++)
		{
			ll u, v;
			cin >> u >> v;
			g[u].pb(v);
			g[v].pb(u);
		}

		if(solve(n) == 0) printf("No\n");
		else
		{
			printf("Yes\n");
			for(i = 2; i <= n; i++) cout << passage[i] << "\n";
//			cout << '\n';
		}
    }


}





Measured memory_bytes: 12936
import java.util.*;
import java.math.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long mod=1000000007;
		long[] c=new long[n];
		for(int i=0; i<n; i++){
			c[i]=sc.nextLong();
		}
		long two=1;
		long[] mm=new long[n+1];
		for(int i=0; i<=n; i++){
			mm[i]=two;
			two*=2;
			two%=mod;
		}
		Arrays.sort(c);
		long ans=(c[n-1]*mm[n-1])%mod;
		for(int i=0; i<n-1; i++){
			ans+=c[i]*(((mm[n-1-i]+(mm[n-2-i]*(n-1-i))%mod)*mm[i])%mod);
			ans%=mod;
		}
		ans*=mm[n];
		System.out.println(ans%mod);
	}
}


Measured memory_bytes: 93892
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    string a, b;
    cin >> a >> b;
    if(a[0] == b[2] && a[1] == b[1] && a[2] == b[0]){
        cout << "YES";
    }
    else
    {
        cout << "NO";
    }
    
    
    cout << endl;
}


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

template <typename T> void chmin(T&x,const T &y)
{
	if(x>y)x=y;
}
template <typename T> void chmax(T &x,const T &y)
{
	if(x<y)x=y;
}
typedef long long s64;
typedef unsigned long long u64;
typedef unsigned int u32;
typedef pair<int,int> pii;
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define rep0(i,l,r) for(int i=l;i<r;++i)
#define gc (c=getchar())
int read()
{
	char c;
	while(gc<'-');
	if(c=='-')
	{
		int x=gc-'0';
		while(gc>='0')x=x*10+c-'0';
		return -x;
	}
	int x=c-'0';
	while(gc>='0')x=x*10+c-'0';
	return x;
}
#undef gc

const int N=3e5+5,D=998244353;
int a0[N],a[N],mx_suf_k[N],pre_da[N],suf_da[N];
s64 jie[N];
int cnt[N];bool ap[N];

int main()
{
#ifdef kcz
	freopen("1.in","r",stdin);//freopen("1.out","w",stdout);
#endif
	int n=read();
	int c1=0,p1=0;
	rep(i,1,n)
	{
		a0[i]=read();
		if(a0[i]==1){++c1;p1=i;}
	}
	jie[0]=1;
	rep(i,1,n)jie[i]=jie[i-1]*i%D;
	if(!c1)
	{
		puts("0");
		exit(0);
	}
	if(c1==n)
	{
		cout<<jie[n];
		exit(0);
	}
	while(a0[p1]==1)p1=(p1==1)?n:p1-1;
	rep(i,1,n)a[i]=a0[p1+i-(p1+i>n?n:0)];
	int k=c1;
	deque<int>q;
	per(i,n,1)
	{
		while(!q.empty()&&a[i]>a[q.back()])q.pop_back();
		q.push_back(i);
		while(q.front()-i>=k)q.pop_front();
		mx_suf_k[i]=a[q.front()];
		++cnt[mx_suf_k[i]];
	}
	rep(i,1,n)
	{
		int j=i-1;
		while(j&&a[j]<=a[i])j=pre_da[j];
		pre_da[i]=j;
	}
	per(i,n,1)
	{
		int j=i+1;
		while(j<=n&&a[j]<=a[i])j=suf_da[j];
		suf_da[i]=j;
	}
	s64 ans=1;
	for(int i=1;i<=n;)
	{
		if(ap[a[i]])
		{
			puts("0");
			exit(0);
		}
		ap[a[i]]=1;
		int j=i;
		while(a[j]==a[i])++j;
		int l=pre_da[i],r=suf_da[i];
		if(r<=n)r-=k;
		r=min(i,r);
		++l;
		l=max(l,j-k);
		if(l>r)
		{
			puts("0");
			exit(0);
		}
		ans=ans*(r-l+1)%D;
		i=j;
	}
	int can=0; 
	rep(i,1,n)
	{
		can+=cnt[i]-ap[i];
		if(!ap[i])ans=ans*(can--)%D;
	} 
	cout<<ans;
}


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

using namespace std;

const int N = 3e3+7;

int n, m, num, cnt;
int a[N][N], res[N][N];

int main()
{
    cin >> n >> m >> num;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            char c;
            cin >> c;
            a[i][j] = (c == '#' ? 1 : 0);
        }
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if (a[i][j]) {
                ++cnt;
                res[i][j] = cnt;
                for (int k = j-1; k; --k) {
                    if (res[i][k] || a[i][k]) break;
                    res[i][k] = cnt;
                }
                for (int k = j+1; k <= m; ++k) {
                    if (res[i][k] || a[i][k]) break;
                    res[i][k] = cnt;
                }
            }
        }
    }
    for (int i = 1; i <= n; ++i) {
        if (!res[i][1]) continue;
        for (int k = i-1; k; --k) {
            if (res[k][1]) break;
            for (int j = 1; j <= m; ++j)
                res[k][j] = res[i][j];
        }
        for (int k = i+1; k <= n; ++k) {
            if (res[k][1]) break;
            for (int j = 1; j <= m; ++j)
                res[k][j] = res[i][j];
        }
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            cout << res[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 7808
#include <stdio.h>

int main(void) {
    int n, i,  p, ans;
    scanf("%d", &n);
    int min = 1000001;
    int min1 = 101;
    int max = 0;
    int x[n];
    for (i = 0; i < n; i++) {
        scanf("%d", &x[i]);
        if (max < x[i]) max = x[i];
        if (min1 > x[i]) min1 = x[i];
    }

    for (p = min1; p <= max; p++) {
        ans = 0;
        for (i=0 ; i < n; i++) {
            ans += (x[i]-p)*(x[i]-p);
        }
        if (min > ans) min = ans;
    }
    printf("%d\n", min);
    return 0;
}

Measured memory_bytes: 128
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
#include<atcoder/fenwicktree>
using namespace std;
using namespace atcoder;
using lli = long long int;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
/*__int128 read()
{
	__int128 ans = 0;
	int sgn = 1;
	char c = getchar();
	while (!isdigit(c))
	{
		if (c == '-')
			sgn *= -1;
		c = getchar();
	}
	while (isdigit(c))
	{
		ans = ans * 10 + c - '0';
		c = getchar();
	}
	return ans * sgn;
}
void print(__int128 x)
{
	if (x > 9)
		print(x / 10);
	putchar(x % 10 + '0');
}*/
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n = 0, q = 0, ch = 0, p = 0, l = 0, r = 0; lli x = 0ll;
	cin >> n >> q;
	fenwick_tree<lli> v(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> x; v.add(i, x);
	}
	for (int i = 0; i < q; ++i)
	{
		cin >> ch;
		if (ch == 0)
		{
			cin >> p >> x; v.add(p, x);
		}
		else
		{
			cin >> l >> r; cout << v.sum(l, r) << "\n";
		}
	}
}

Measured memory_bytes: 8252
def solv(G):
  new_V = [0]
  new_E = []

  while len(new_V) < len(G):
    u, e = select_min(G, new_V)
    new_V.append(u)
    new_E.append(e)

  return sum(new_E)

def select_min(G, V):
  min_u = -1
  min_e = float('inf')
  for v in V:
    for u, e in enumerate(G[v]):
      if (e < 0) or (u in V): continue
      if e < min_e:
        min_u = u
        min_e = e
  return min_u, min_e

n = int(input())
G = [list(map(int, input().split())) for _ in range(n)]
print(solv(G))

Measured memory_bytes: 8016