akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <bitset>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;
// const ll mod =  998244353 ;
const ll mod =  1000000007 ;
const ll inf = 1e18;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())

template<typename T> void print_vec(vector<T> a) {int n = a.size();REP(i, n) {cout >> a[i]; if(i!=n-1) cout << " "; else cout << endl;}}
ll power(ll base, ll exponent){ if(exponent % 2){ return power(base, exponent - 1) * base % mod; }else if(exponent){ ll root_ans = power(base, exponent / 2); return root_ans * root_ans % mod; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
template<typename T> ll sum(T begin, T end) {return accumulate(begin, end, 0ll);}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

using Pair = pair<ll, ll>;

map<Pair, int> edge_n;
map<Pair, int> edge_c;
vector<vector<int>> g;

void dfs(int from, int current, int node_color) {
  int color = 0;
  for(const auto next :g[current]) {
    if(next == from) continue;
    if(color == node_color) color++;
    edge_c[{current, next}] = color;
    edge_c[{next, current}] = color;
    dfs(current, next, color++);
  }
}

signed main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  g.resize(n);
  REP(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--;b--;
    edge_n[{a, b}] = i;
    edge_n[{b, a}] = i;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(-1, 0, -1);
  cout << max_element(all(edge_c), [](auto a, auto b) {return a.second < b.second;})->second + 1 << endl;
  vector<int> ans(n-1);
  for(auto a : edge_n) {
    int c = edge_c[a.first] + 1;
    ans[a.second] = c;
  }
  REP(i, sz(ans)) cout << ans[i] << endl;
  return 0;
}

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

const int mod = 1e9 + 7;
const int MAXN = 1010;

char mat[MAXN][MAXN];
int dp[MAXN][MAXN], h, w;

int solve(int i, int j)
{
	if(i < 0 or j < 0) return 0;
	if(dp[i][j] != -1) return dp[i][j];
	if(i == 0 and j == 0) return 1;
	if(mat[i][j] == '#') return 0;

	return dp[i][j] = (solve(i - 1, j) + solve(i, j - 1))%mod;
}

int main()
{
	cin >> h >> w;

	for(int i = 0; i < h; i++)
		for(int j = 0; j < w; j++)
			cin >> mat[i][j];
		
	memset(dp, -1, sizeof(dp));

	cout << solve(h - 1, w - 1) << "\n";
}

Measured memory_bytes: 5248
#include <iostream>
#include <algorithm>

const int MAX = 601;
bool G[MAX][MAX];
long double S[MAX];
long double E[MAX];
int N[MAX];
long double R[MAX][MAX];

int main()
{
    std::ios_base::sync_with_stdio(0);
    int n,m;
    std::cin >> n >> m;
    for (int i=0;i<m;++i)
    {
        int s,t;
        std::cin >> s >> t;
        G[s][t] = true;
        N[s]++;
    }
    for (int i=n-1;i>0;--i)
    {
        for (int j=i+1;j<=n;++j)
        {
            if (!G[i][j]) continue;
            S[i] += E[j];
        }
        E[i] = S[i]/N[i]+1; // N[i] > 0
        R[i][i] = E[i];
        for (int j=i+1;j<n;++j) // j.out is removed
        {
            R[i][j] = E[i];
            long double Rj = 0;
            for (int k=i+1;k<=n;++k)
            {
                if (!G[i][k]) continue;
                Rj += k <= j ? R[k][j] : E[k];
            }
            R[i][j] = std::min(R[i][j], Rj/N[i]+1);
        }
        if (N[i] > 1)
            for (int j=i+1;j<n;++j)
            {
                if (!G[i][j]) continue;
                    R[i][i] = std::min(R[i][i], (S[i]-E[j])/(N[i]-1)+1);
            }
    }
    
    long double result = E[1];
    for (int s=1;s<n;++s) result = std::min(result, R[1][s]);
    std::cout.precision(10);
    std::cout << std::fixed << result;
    return 0;
}

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

typedef vector<int> vi;
typedef pair<int,int> pii;
#define For(i,n) for(int i = 0; i < (int) n; ++i)
#define Rep(i,n) for(int i = 1; i <= (int) n; ++i)
#define ll long long
#define lld long double
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define ar array
#define INF 1e18;
#define all(v) (v).begin(),(v).end()
const int N=2e3+5,mod=1e9+7;


void solve(){
    ll s;
    cin>>s;
    ll dp[N];
    memset(dp,0,sizeof(dp));
    dp[0]=1;
    for(int i=1;i<=s;i++){
        for(int j=3;j<=i;j++){
            dp[i]=(dp[i-j]+dp[i])%mod;;
        }
    }
    cout<<dp[s]%mod<<endl;


}


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        //cout<<"Case #"<<a<<": ";
        solve();
        //a+=1;
    }
}


Measured memory_bytes: 3648
def main():
    N,M,K = map(int,input().split())
    MOD = 998244353
    
    if M == 1:
        if K == N-1:
            print(1)
        else:
            print(0)
        exit()
    
    fac = [0]*(N+1)
    fac[0],fac[1] = 1,1
    invfac = [0]*(N+1)
    invfac[0],invfac[1] = 1,1
    
    for i in range(2,N+1):
        fac[i] = (fac[i-1]*i)%MOD
        
    invfac[-1] = pow(fac[-1],MOD-2,MOD)
    
    for i in range(N,0,-1):
        invfac[i-1] = (invfac[i]*i)%MOD
    
    def comb(x,y):
        return (fac[x]*invfac[y]*invfac[x-y])%MOD
    
    ans = 0
    base = [1,pow(M-1,N-K-1,MOD)]
    for i in range(K+1):
        base.append((base[-1]*(M-1))%MOD)

    
    for i in range(K+1):
        ret = comb(N-1,i)*(M*base[-i-2])
        ans += ret
    
    print(ans%MOD)
    
if __name__ == "__main__":
    main()
    

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

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

ll gcd(ll a, ll b)
{
    if(b==0)
    {
        return a;
    }

    return gcd(b, a%b);
}

const ll L = 1e5+5;
const ll mod = 1e9+7;

ll fact[4005];

void factorial()
{
    fact[0] = 1;

    for(ll i=1; i<4005; i++)
    {
        fact[i] = (fact[i-1]*i)%mod;
    }
}

ll modexp(ll a, ll b, ll c)
{
    a%=c;

    ll ans = 1;

    while(b)
    {
        if(b&1)
        {
            ans = (ans*a)%c;
        }

        a = (a*a)%c;
        b>>=1;
    }

    return ans;
}

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

    factorial();

    for(ll i=1; i<=k; i++)
    {
        if(n-k-i+1 < 0)
        {
            cout << 0 << endl;
            continue;
        }

        ll ans = fact[k-1];
        ans*=modexp(fact[i-1], mod-2, mod);
        ans%=mod;
        ans*=modexp(fact[k-i], mod-2, mod);
        ans%=mod;

        ll res = fact[n-k+1];
        res*=modexp(fact[i], mod-2, mod);
        res%=mod;
        res*=modexp(fact[n-k-i+1], mod-2, mod);
        res%=mod;

        cout << (ans*res)%mod << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;


int main(){
  string s;
  cin >> s;
  int n=s.size();
  rep(i,n){
    if((i+1)%2==1){cout << s[i];}
  }
  cout << endl;
}

Measured memory_bytes: 3784
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct node
{
  int id;
  struct node *parent;
  struct node *child[2];
} *nodePointer;
nodePointer root;
nodePointer make1node(int);
void insert(nodePointer);
void preorderWalk(nodePointer);
void inorderWalk(nodePointer);
int main(void)
{
  int i;//counter
  int n;//the number of operation
  char op[10];//operation
  int id;//inserted number
  nodePointer p;
  root=NULL;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%s",op);
      if(strcmp(op,"insert")==0)
	{
	  scanf("%d",&id);
	  p=make1node(id);
	  insert(p);
	}
      else if(strcmp(op,"print")==0)
	{
	  inorderWalk(root);
	  preorderWalk(root);
	}
      else
	{
	  printf("undefined operation\n");
	  exit(1);
	}
    }
  return 0;
}
nodePointer make1node(int id)
{
  nodePointer p;
  p=(nodePointer)malloc(sizeof(struct node));
  p->id=id;
  p->parent=NULL;
  p->child[0]=NULL;
  p->child[1]=NULL;
  return p;
}
void insert(nodePointer p)
{
  nodePointer parent=NULL;//parent of p
  nodePointer temp=root;
  while(temp!=NULL)
    {
      parent=temp;
      if(p->id < temp->id) temp=temp->child[0];
      else temp=temp->child[1];
    }
  p->parent=parent;
  if(parent==NULL) root=p;
  else if(p->id < parent->id) parent->child[0]=p;
  else parent->child[1]=p;
}
void preorderWalk(nodePointer p)
{
  if(p!=NULL)
    {
      printf(" %d",p->id);
      preorderWalk(p->child[0]);
      preorderWalk(p->child[1]);
      if(p==root)
	{
	  printf("\n");
	}
    }
}
void inorderWalk(nodePointer p)
{
  if(p!=NULL)
    {
      inorderWalk(p->child[0]);
      printf(" %d",p->id);
      inorderWalk(p->child[1]);
      if(p==root)
	{
	  printf("\n");
	}
    }
}




Measured memory_bytes: 25156
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
string nxt(string s){
  int n=s.size();
  for(int i=0,d=1;0<=i&&i<n;){
    if(s[i]=='A') s[i]='B',d*=-1,i+=d;
    else s[i]='A',i+=d;
  }
  return s;
}

signed main(){
  int n,k;
  cin>>n>>k;
  string s;
  cin>>s;

  deque<int> dq;
  for(int i=0;i<n;i++)
    dq.emplace_back(s[i]=='A'?0:1);

  const int MAX = 1e6;
  if(k>MAX) k-=(k-MAX)/2*2;

  int all=0;
  auto get=[&](int k){return dq[k]^all;};
  auto put=[&](int v){dq.emplace_back(v^all);};
  for(int i=0;i<k;i++){
    if(!get(0)){
      dq[0]^=1;
      continue;
    }
    dq.pop_front();
    all^=1;
    put(0);
  }

  for(int i=0;i<n;i++)
    cout<<char('A'+get(i));
  cout<<endl;
  return 0;
}


Measured memory_bytes: 1540
from collections import defaultdict


class TwoSat:
    def __init__(self, N):
        self.N = 2*N
        self.ans = None
        self.__e = []
        self.__v = list(range(self.N))

    def add_clause(self, i, f, j, g):
        self.__e.append((2*i + (0 if f else 1), 2*j + (1 if g else 0)))
        self.__e.append((2*j + (0 if g else 1), 2*i + (1 if f else 0)))

    @staticmethod
    def scc(V, E):
        g = defaultdict(list)
        rg = defaultdict(list)
        for u, v in E:
            g[u].append(v)
            rg[v].append(u)

        o = []
        done = set()
        for u in V:
            if u in done:
                continue

            s = [(u, True)]
            while s:
                u, f = s.pop()
                if f:
                    if u in done:
                        continue
                    done.add(u)
                    s.append((u, False))
                    for v in g[u]:
                        if v in done:
                            continue
                        s.append((v, True))
                else:
                    o.append(u)

        done = set()
        ans = []
        while o:
            u = o.pop()
            if u in done:
                continue

            s = [u]
            vv = [u]
            done.add(u)
            while s:
                u = s.pop()
                for v in rg[u]:
                    if v in done:
                        continue
                    vv.append(v)
                    s.append(v)
                    done.add(v)
            ans.append(vv)

        return ans

    def satisfiable(self):
        scc = TwoSat.scc(self.__v, self.__e)
        cid = [-1] * (self.N)

        for i, s in enumerate(scc):
            for v in s:
                cid[v] = i

        for i in range(self.N//2):

            if cid[2*i] == cid[2*i+1]:
                self.ans = None
                return False

        self.ans = []
        for i in range(self.N//2):
            self.ans.append(cid[2*i] < cid[2*i+1])

        return True


def atcoder_practice2_h():
    N, D = map(int, input().split())
    XY = [list(map(int, input().split())) for _ in range(N)]

    ts = TwoSat(N)
    for i, (x1, y1) in enumerate(XY):
        for j in range(i+1, N):
            x2, y2 = XY[j]
            if abs(x1 - x2) < D:
                ts.add_clause(i, False, j, False)

            if abs(y1 - y2) < D:
                ts.add_clause(i, True, j, True)

            if abs(x1 - y2) < D:
                ts.add_clause(i, False, j, True)

            if abs(y1 - x2) < D:
                ts.add_clause(i, True, j, False)

    if not ts.satisfiable():
        print('No')
    else:
        print('Yes')
        for i, b in enumerate(ts.ans):
            print(XY[i][0 if b else 1])


if __name__ == "__main__":
    atcoder_practice2_h()


Measured memory_bytes: 71396
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <ctime>
using namespace std;
int n;
int m;
string s;
vector<string> g;
int main() {
    cin >> n >> m;
    cin >> s;
    string tmp = "";
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '-') {
            g.push_back(tmp);
            tmp = "";

        } else {
            tmp += s[i];
        }
    }
    g.push_back(tmp);
    if (g.size() != 2 || g[0].size() != n || g[1].size() != m) {
        cout << "No" << endl;
    } else cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp {
    char name[100];
    int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x) {
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

P dequeue() {
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int min(int a, int b) { return a < b ? a : b; }

int main() {
    int elaps = 0, c;
    int i, q;
    P u;
    scanf("%d %d", &n, &q);

    for(i = 1; i <= n; i++) {
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }

    head = 1; tail = n + 1;

    while(head != tail) {
        u = dequeue();
        c = min(q, u.t);
        u.t -= c;
        elaps += c;
        if(u.t > 0) enqueue(u);
        else {
            printf("%s %d\n", u.name, elaps);
        }
    }

    return 0;
}


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

namespace atcoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			bool ans = false;
			for(int i = 0;i <= input[0];i++)
			{
				for(int j = 0;j <= input[1];j++)
				{
					if((long)j * input[0] + (long)i * input[1] - 2 * i * j == input[2])
					{
						ans = true;
					}
				}
			}
			if (ans) Console.WriteLine("Yes");
			else Console.WriteLine("No");
			//Console.ReadLine();
		}
	}
}

Measured memory_bytes: 13396
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

func Solve() {
  var N, a, b, u, v int
  var C []int
  NextInt(&N)
  NextIntVec(&C)
  for i := range C { C[i]-- }
  T := make([][]int, N)
  for i := 1; i < N; i++ {
    NextInt(&a, &b)
    a--; b--
    T[a] = append(T[a], b)
    T[b] = append(T[b], a)
  }
  P := make([]int, N)
  for i := range P[1:] { P[i + 1]-- }
  Q := make([]int, N)
  pos := 1
  for _, u = range Q {
    for _, v = range T[u] {
      if v == P[u] { continue }
      P[v] = u
      Q[pos] = v
      pos++
    }
  }
  S := make([]int, N)
  for i := 0; i < N; i++ { S[i]++ }
  for i := N - 1; 0 < i; i-- {
    v = Q[i]
    S[P[v]] += S[v]
  }
  CC := make([][]int, N)
  for i := range CC { CC[i] = []int{N} }
  A := make([]int, N)
  for i := range A { A[i] = N * (N + 1) / 2 }
  var DFS func(int)
  DFS = func(u int) {
    c := C[u]
    l := len(CC[c])
    CC[c][l - 1] -= S[u]
    CC[c] = append(CC[c], S[u])
    for _, v := range T[u] {
      if v == P[u] { continue }
      s := CC[c][l]
      DFS(v)
      t := CC[c][l]
      A[c] -= (S[v] - s + t) * (S[v] - s + t + 1) / 2
    }
    CC[c] = CC[c][:l]
  }
  DFS(0)
  for i, c := range CC {
    A[i] -= c[0] * (c[0] + 1) / 2
  }
  for _, a := range A { Write(a) }
}

func main() {
  Solve()
  Output()
}

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}

Measured memory_bytes: 134104
n,a,b=map(int,input().split())
mod=(10**9)+7
ans=pow(2,n,mod)-1
comb=1
for i in range(n-a+1,n+1):
    comb*=i
    comb%=mod
for i in range(1,a+1):
    comb*=pow(i,mod-2,mod)
    comb%=mod
comb2=1
for i in range(n-b+1,n+1):
    comb2*=i
    comb2%=mod
for i in range(1,b+1):
    comb2*=pow(i,mod-2,mod)
    comb2%=mod
ans=ans-comb-comb2
ans%=mod
print(ans)

Measured memory_bytes: 3064
from bisect import bisect, bisect_left


size = 10 ** 5 + 1

is_prime = [True] * size
is_prime[0] = is_prime[1] = False

# √size まで
for i in range(2, 317):
  j = 2 * i
  while j < size:
    is_prime[j] = False
    j += i

like_numbers = [
  i 
  for i, x in enumerate(is_prime)
  if x and (i + 1) % 2 == 0 and is_prime[(i + 1) // 2]
]

Q = int(input())

# print(like_numbers[:20])

for _ in range(Q):
  l, r = map(int, input().split())
  if l == r:
    print(1 if l in like_numbers else 0)
  else:
  	print(bisect(like_numbers, r) - bisect_left(like_numbers, l))  
  

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

int main() {
    int N, X;
    cin >> N >> X;
    int L[105];
    for (int i = 0; i < N; i++) {
        cin >> L[i];
    }

    int cnt = 0;
    int i = 0;
    int D = 0;
    for (int i = 0; i < N+1; i++) {
        cnt++;
        D += L[i];
        if (D > X) {
            break;
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <cstdio>

int main() {
    int a,b,c;
    std::scanf("%d %d %d",&a,&b,&c);

    if(a < b&&b < c){
        std::printf("Yes\n");
    }
    
    else if(a >= b){
        std::printf("No\n");
    }
    else if(a >= c){
        std::printf("No\n");
    }
    else if(b >= c){
        std::printf("No\n");
    }

return 0;
}


Measured memory_bytes: 2604
h,w,m=list(map(int,input().split()))

s=set()
d={}
e={}
for i in range(m):
    a,b=list(map(int,input().split()))
    s.add((a,b))
    if a in d:
        d[a]+=1
    else:
        d[a]=1
    if b in e:
        e[b]+=1
    else:
        e[b]=1
ma=0
for i in e:
    ma=max(ma,e[i])
mi=0
for i in d:
    mi=max(mi,d[i])
a=[]
for i in d:
    if d[i]==mi:
        a.append(i)
b=[]
for i in e:
    if e[i]==ma:
        b.append(i)
r=0
for i in a:
    for j in b:
        if (i,j) not in s:
            r=1
            
            break
if r==1:
    print(mi+ma)
else:    
    print(ma+mi-1)


    

Measured memory_bytes: 180152
import java.util.*;
 
public class Main {
	
  	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int K = Integer.parseInt(sc.next());
        int[] a = new int[N];
        for(int i = 0; i < N; i++){
            a[i] = Integer.parseInt(sc.next());
        }
        sc.close();

        Arrays.sort(a);

        int result = a[N-1] - a[0];
        for(int i = 0; i <= N - K; i++){
            result = Math.min(result, a[K + i - 1] - a[i]);
        }
        
        System.out.println(result);
    }
}

Measured memory_bytes: 47360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;cin >> n;
	for(ll i=1;;++i){
		if(i*i>n){
			cout << (i-1)*(i-1) << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
play' :: Int -> [Int] -> [Int]
play' k (s1:[]) = [s1]
play' k (s1:s2:ss) =
  if (s1 `mod` k) > (s2 `mod` k)
  then s2:play' k (s1:ss)
  else s1:play' k (s2:ss)

play [] zk = zk
play (m:ms) zk =
  let zk' = play' m zk
  in
    play ms zk'

main = do
  nm <- getLine
  zk <- getContents
  let [n,m] = map read $ words nm :: [Int]
      zk' = map read $ lines zk :: [Int]
      o = play [2..m] zk'
  mapM_ print o
  

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

int main()
{
    vector<int> A(3);
    cin >> A[0] >> A[1] >> A[2];
    sort(A.begin(), A.end());
    bool ret = false;
    if ((A[0] == A[1] && A[1] != A[2])
        || (A[1] == A[2] && A[0] != A[1]))
        ret = true;
    cout << (ret ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np
from scipy.sparse.csgraph import bellman_ford, connected_components
input = sys.stdin.readline


def main():
    n, m, p = map(int, input().split())
    
    l = np.zeros((n, n))
    for i in range(m):
        a, b, c =map(int, input().split())
        c = p-c
        if c == 0:
            c = 10**(-7.9)
        if l[a-1][b-1] == 0:
            l[a-1][b-1] = c
        else:
            l[a-1][b-1] = min(l[a-1][b-1], c)
    x = l[-1, 0]
    l[-1][0] = 10**(-7.9)
    n, labels = connected_components(l, connection="strong")
    l = l[labels == labels[0]][:, labels == labels[0]]
    l[-1, 0] = x
    
    try:
        print(max(0, int(round(bellman_ford(l, indices=0)[-1]))*(-1)))
    except:
        print(-1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 226980
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
   int n;
   cin>>n;
   vector<int> x(n);
   rep(i, n) cin>>x[i];

   int mn=INT_MAX;
   rep(p, 101){
      int sm=0;
      rep(i, n) sm+= (x[i]-p)*(x[i]-p);
      mn=min(mn, sm);
   }

   cout<<mn<<endl;
   return 0;
}


Measured memory_bytes: 3628
ARGF.each_line do |line|
  h, w = line.split.map(&:to_i)
  break if h == 0 && w == 0
  rec = ("#" * w) + "\n"
  rec += ("#" + "." * (w - 2) + "#" + "\n") * (h - 2)
  rec += ("#" * w) + "\n\n"
  puts rec
end

Measured memory_bytes: 6220
a,b,i,j,N,p,P,t[36],c[36],T[36],C[36];
Q(int*a,int*b){
    for(i=0;i<N;printf("%c%d%s",a[i],b[i],i==N-1?"\n":" "),i++);
}
B(){
    for(i=0;i<N;i++)
    for(j=N-1;j>0;j--)
        if(t[j-1]>t[j]){
            t[j]^=t[j-1]^=t[j]^=t[j-1];
            c[j]^=c[j-1]^=c[j]^=c[j-1];
        }
    Q(c,t);
    puts("Stable");
}
S(){
    for(i=0;i<N;i++){
        for(j=p=i;j<N;j++)if(T[j]<T[p])p=j;
        P=T[p];T[p]=T[i];T[i]=P;
        P=C[p];C[p]=C[i];C[i]=P;
    }
    Q(C,T);
    for(i=p=0;i<N;i++)if(c[i]==C[i]&&t[i]==T[i])p++;
    puts(p==N?"Stable":"Not stable");
}

int main(){
    for(scanf("%d",&N);i<N;scanf(" %c%d",&c[i],&t[i]),T[i]=t[i],C[i]=c[i],i++);
    B();S();

}

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



void swap (int *x, int *y) {
  int temp;

  temp = *x;
  *x = *y;
  *y = temp;

  return;
}

int gcd(int a,int b){
  if(a<b){
    swap(&a,&b);
  }

  if(b==0){
    return a;
  }

  int r=a%b;
  while(r!=0){
    a = b;
    b = r;
    r = (a%b);
  }

  return b;
}

/* クイックソート */
int dn(const void*a,const void*b){return*(int*)b-*(int*)a;}


long int modpow(long int a,long int n,long int mod){
  long int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

long int modinv(long int a,long int mod){
  return modpow(a,mod-2,mod);
}

int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}

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

void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }

  return;
}

void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }

  return;
}

/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

int main(void){
  /*
  解法2
  (答え)=((総和の2乗)-(2乗の総和))/2
  ということがわかるので，それを実装

  2で割る部分は解法1と同じ

  */
  long int t=2;
  long int n;
  scanf("%ld",&n);

  long int A[n];
  
  //総和
  long int all=0;
  
  //2乗の総和
  long int sq_all=0;

  long int MOD=1e9+7;

  for(int i=0;i<n;i++){
    scanf("%ld",&A[i]);
    all+=A[i];

    //常にMODを取る！
    all%=MOD;

    sq_all+=modpow(A[i],t,MOD);
    
    //常にMODを取る！
    sq_all%=MOD;
  }


  //MOD上の2の逆元
  long int v=modinv(2,MOD);

  long int ans=modpow(all,t,MOD);
  ans-=sq_all;
  ans+=10*MOD;
  ans%=MOD;

  //常にMODを取る！
  printf("%ld\n",ans*v%MOD);

  return 0;
}

Measured memory_bytes: 3284
import math
N, K = map(int, input().split())
h = list(map(int, input().split()))
 
S = [0] * N
S[0] = 0
 
for i in range(1, N):
    value = math.inf
    for step in range(1, K + 1):
        if i - step < 0:
            break
        value = min(value, S[i - step] + abs(h[i] - h[i - step]))
    S[i] = value
print(S[N - 1])


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

using namespace std;

int main()
{
	string S;
	cin >> S;

	cout << S[0] << S.length() - 2 << S[S.length() - 1] << endl;

}






Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int h, w; cin >> h >> w;
    char photo[h][w];
    REP(i, h){
        REP(j, w){
            cin  >> photo[i][j];
        }
    }
    REP(i, h){
        REP(j, w){
            cout << photo[i][j];
        }
        cout << endl;
        REP(j, w) cout << photo[i][j];
        cout << endl;
    }
}

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

int main(){
    vector<vector<int>> data(3, vector<int>(3));

    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>data.at(i).at(j);
        }
    }
    string T = "No";
    for(int i=0;i<=100;i++){
        for(int j=0;j<=100;j++){
            for(int k=0;k<=100;k++){
                if(i<=data.at(0).at(0) and i<=data.at(0).at(1) and i<=data.at(0).at(2)){
                    int x=data.at(0).at(0)-i;
                    int y=data.at(0).at(1)-i;
                    int z=data.at(0).at(2)-i;
                    if(j+x==data.at(1).at(0) and j+y==data.at(1).at(1) and j+z==data.at(1).at(2)
                    and k+x==data.at(2).at(0) and k+y==data.at(2).at(1) and k+z==data.at(2).at(2)){
                        T="Yes";
                    }
                }
            }
        }
    }
    cout<<T<<endl;
}


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

int main() {
	int n,i;
	char c[75]={};
	char d[75]={};
	char a,b;
		for(int i=0; i<75 ;i++){
			d[ i ]='0'+i;
		}
	while( true ){
		cin >> n;
		if( n == 0 ){
			return 0;
		}
		for(int i=0; i<75 ;i++){
			c[ i ]=d[i];
		}
		for( int i=0;i<n;i++){
			cin >> a >> b;
			c[a - '0' ]=b;
		}
		cin >> n;
		for( int i=0;i<n;i++){
			cin >> a;
			cout << c[a - '0'];
		}
		cout << endl;
	}
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    int n;
    cin >> n;
    vector<lint> a(n);
    repeat(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    
    lint longer_side = 0;
    for (int i = n - 1; i >= 0; --i) {
        auto itl = lower_bound(a.begin(), a.end(), a[i]);
        auto itu = upper_bound(a.begin(), a.end(), a[i]);
        lint cnt = distance(itl, itu);
        if (cnt >= 4 && longer_side == 0) {
            cout << a[i] * a[i] << endl;
            return 0;
        }
        else if (cnt >= 2) {
            if (longer_side > a[i]) {
                cout << a[i] * longer_side << endl;
                return 0;
            }
            else {
                longer_side = a[i];
            }
        }
    }
    cout << 0 << endl;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
    bool s[30];
    for(int i=0;i<30;i++)s[i]=false;
    for(int i=0;i<28;i++){
        int a;
        cin>>a;
        s[a-1]=true;
    }
    for(int i=0;i<30;i++){
        if(!s[i])cout<<i+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;

int main(){

    int n;
    int a[110];

    cin >> n;
    rep(i,n) cin >> a[i];    
    int ans = 0;
    int max = a[0];
    int min = a[0];

    rep(i,n){
       if(a[i]>max) max = a[i];
       if(a[i]<min) min = a[i];
    }

    ans = max - min;
    cout << ans << endl;

    return 0;
};


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    struct Position { internal int x, y; }

    class PropertyDistribution
    {
        readonly int H, W;

        readonly int[] moveX = new int[] { 1, 0, -1, 0 };
        readonly int[] moveY = new int[] { 0, 1, 0, -1 };

        char[][] map;
        int count;

        public PropertyDistribution(int H, int W)
        {
            this.H = H;
            this.W = W;

            map = new char[H][];
        }

        public void MakeMap(string source, int n)
        {
            map[n] = source.ToCharArray();
        }

        public int Count()
        {
            count = 0;

            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    if (map[i][j] != '0')
                    {
                        Position pos;
                        pos.x = j;
                        pos.y = i;

                        CheckMap(pos, map[i][j]);
                        count++;
                    }
                }
            }
            return count;
        }

        private void CheckMap(Position pos, char ch)
        {
            Stack<Position> stk = new Stack<Position>();

            stk.Push(pos);

            while (stk.Count > 0)
            {
                Position cur = stk.Pop();
                map[cur.y][cur.x] = '0';

                for (int i = 0; i < 4; i++)
                {
                    Position next;
                    next.x = cur.x + moveX[i];
                    next.y = cur.y + moveY[i];

                    if (IsValid(next) && map[next.y][next.x] == ch)
                    {
                        stk.Push(next);
                    }
                }
            }
        }

        private bool IsValid(Position pos)
        {
            if (pos.x < 0) return false;
            if (pos.y < 0) return false;
            if (pos.x >= W) return false;
            if (pos.y >= H) return false;
            return true;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                string[] input = Console.ReadLine().Split(' ');
                int H = int.Parse(input[0]);
                int W = int.Parse(input[1]);

                if (H == 0 && W == 0) break;

                PropertyDistribution PD = new PropertyDistribution(H, W);

                for (int i = 0; i < H; i++)
                {
                    PD.MakeMap(Console.ReadLine(), i);
                }

                sb.AppendLine(PD.Count().ToString());
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 10444
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> p;
const int inf=100000000;
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)
	
int main(){
	int n;
	cin>>n;
	string s[110];
	bool x;
	rep(i,0,n){
		cin>>s[i];
	}
	rep(i,0,n){
		rep(j,0,n){
			if(i!=j){
				if(s[i]==s[j]){
					cout<<"No"<<endl;
				return 0;
				}
			}
		}
	}
	rep(i,1,n){
		if(s[i-1][s[i-1].size()-1]!=s[i][0]){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
/* ex2_1
    riverstone*/
 
#include<stdio.h>
#include <stdlib.h>

#define LIM 100100 //limit of num
int chmin(int a, int b);

 
int main(void){
    int i;
    int num, depth[LIM];//variable for N and matrix for depths
    int dp[LIM]={0};//matrix for Dynamic Programming

    //input
    scanf("%d", &num);
    for (i = 0; i < num; i++){
        scanf("%d", &depth[i]);
    }
    
    //initialization
    dp[0] = 0;
    dp[1] = abs(depth[0] - depth[1]);

    //Dynamic Programming
    for (i = 2; i < num; i++){
        dp[i]+=chmin(abs(depth[i] - depth[i - 2]) + dp[i - 2], abs(depth[i] - depth[i - 1]) + dp[i - 1]);
    }
    printf("%d\n", dp[num-1]);//output the result
    return 0;
}

//min funciton
int chmin(int a, int b) {
    if (a < b)
        return a;
    else
        return b;
}

Measured memory_bytes: 896
#include<iostream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include <algorithm>
#include <set>
#include<math.h>
#include<vector>
#include<map>
#include<vector>
#include<cstring>

using namespace std;

int main(){
    string S;
    cin >> S;
    int cnt = 0;
    int cnts[10] = {0,0,0,0,0,0,0,0,0,0};
    int t = 0;
    for(int i = 0;i < S.length();i++){
        if(S[i] != 'A' && S[i] != 'G' && S[i] != 'C' && S[i] != 'T'){
            cnts[t] = cnt;
            cnt = 0;
            t++;
        }else{
            cnt++;
        }
    }
    cnts[t] =cnt;

    sort(cnts,cnts+10,greater<int>());
    cout << cnts[0] << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 300005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pii pair<int,int>
const int mod = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll cur = 100;
    ll tar;
    cin >> tar;
    int ans = 0;
    while(cur < tar) {
        cur += cur / 100;
        ans++;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 3608
//////////////////////////// ⛎🎱💲♏☢🤘(NOOB 383)
//////////////////////////// 🇨🇸🇪 48
//////////////////////////// 🇯🇦🇭🇦🇳🇬🇮🇷🇳🇦🇬🇦🇷 🇺🇳🇮🇻🇪🇷🇸🇮🇹🇾((JU))

#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define DL double
#define MLL map<LL,LL>::iterator
#define MSL map<string,L>::iterator
#define MLS map<LL,string>::iterator
#define MSS map<string,string>::iterator
#define MCL map<char,LL>::iterator
#define SL set<LL>::iterator
#define SS set<string>::iterator
#define VL vector<LL>::iterator
#define G getline
#define SZ size()
#define IN insert
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
void Y()
{
    cout<<"YES"<<endl;
}
void N()
{
    cout<<"NO"<<endl;
}
int main()
{
    FAST;
    LL n,m,i,j,k,p,q,o,l,s,t,z;
    string a;
    cin>>n>>m>>o;
    cout<<o<<" "<<n<<" "<<m<<endl;
    return 0;
}


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

int main() {
	int n;
	cin >> n;
	vector<bool> v(n + 1);
	string s;
	cout << 0 << endl;
	cin >> s;
	if (s == "Vacant") {
		return 0;
	}
	v[0] = v[n] = s == "Male";
	cout << n / 2 << endl;
	cin >> s;
	if (s == "Vacant") {
		return 0;
	}
	v[n / 2] = s == "Male";
	int b, t, m;
	if ((v[0] != v[n / 2]) == (n / 2) % 2) {
		b = n / 2 + 1;
		t = n;
	} else {
		b = 1;
		t = n / 2;
	}
	while (b < t) {
		m = (b + t) / 2;
		cout << m << endl;
		cin >> s;
		if (s == "Vacant") {
			break;
		}
		v[m] = s == "Male";
		if ((v[b - 1] != v[m]) == (m - b + 1) % 2) {
			b = m + 1;
		} else {
			t = m;
		}
	}
	return 0;
}


Measured memory_bytes: 852
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

// int A, B, F, H, I, J, K, L, M, N, S, T, U;
int A, B, F, H, I, J, K, L, M, N, S, T, U;
// string S, T, U;
// int A, B;
int ans = -1;

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

	cin >> A >> B;

	for (int i = 1; i <= 1000; i++)
	{
		if (i * 0.08 >= A && i * 0.08 < A + 1) {
			if (i * 0.1 >= B && i * 0.1 < B + 1) {
				ans = i;
				break;
			}
		}
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF=1<<30;
const int MAXN=110;
int N,M,F[MAXN][MAXN];char s[MAXN][MAXN];
int flag;
int main()
{
	cin>>N>>M;
	for (int i=1;i<=N;++i) scanf("%s",s[i]+1);
	for (int i=1;i<=N;++i)
		for (int j=1;j<=M;++j)
			F[i][j]=INF;
	if (s[1][1]=='#') F[1][1]=1;
	else F[1][1]=0;
	for (int i=1;i<=N;++i)
		for (int j=1;j<=M;++j)
		{
			if (i<N)
			{
				if (s[i][j]=='.' && s[i+1][j]=='#') F[i+1][j]=min(F[i+1][j],F[i][j]+1);
				else F[i+1][j]=min(F[i+1][j],F[i][j]);
			}
			if (j<M)
			{
				if (s[i][j]=='.' && s[i][j+1]=='#') F[i][j+1]=min(F[i][j+1],F[i][j]+1);
				else F[i][j+1]=min(F[i][j+1],F[i][j]);
			}
		}
	cout<<F[N][M]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    int N, M;
    cin >> N >> M;
    int a[M];
    int w = 0;
    for (int i = 0; i < M; i++)
    {
        cin >> a[i];
        w += a[i];
    }

    if(N - w < 0) cout << "-1" << endl;
    else cout << N - w << endl;

}

Measured memory_bytes: 3640
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	ll a, b, c, d;
	string s;
	scanf("%d/%d/%d", &a, &b, &c);
	printf("%04d/%02d/%02d\n", a+1, b, c);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
  string s; cin >> s;
  int l = s.size();
  bool ok = false;
  string k = "keyence";
  for (int i = 0; i <= 7; i++)
  {
    string t = s.substr(0,i) + s.substr(l-(7-i),7-i);
    
    if (t == k) ok = true;
  }
  if (ok) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
int main()
{
    she_told_me_dont_worry
    int n, i;
    cin>>n;
    int a[n+5];
    set<int> s;
    int ans = 0;
    FOR0(i, n)
    {
        cin>>a[i];
        a[i] --;
        if(s.lower_bound(a[i]) == s.begin())
            ans++;
        s.insert(a[i]);
    }
    cout<<ans<<endl;
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 10496
#include <stdio.h>
#include <math.h>
int main()
{
    int i,n;
    double ax, ay, ar;
    double bx, by, br;
    double dist;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%lf %lf %lf", & ax, & ay, & ar);
        scanf("%lf %lf %lf", & bx, & by, & br);
        dist = sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));
        if(dist>ar+br) {
            printf("0\n");
        }
        else if(dist==ar==br){
            printf("1\n");
        }
        else if(dist<ar-br&&ar>br) {
            printf("2\n");
        }
        else if(dist<br-ar&&ar<br) {
            printf("-2\n");
        }
        else {
            printf("1\n");
        }
    }
    return 0;
}

Measured memory_bytes: 616
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		//knapSack();
		longestPath();
	}


	private static void longestPath() {
		Scanner sc = new Scanner(System.in);
		int nodes = sc.nextInt();
		int M = sc.nextInt();
		Map<Integer,ArrayList<Integer>> adj = new HashMap<>();
		
		for(int i =0;i<M;i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			ArrayList<Integer> cur= adj.getOrDefault(x, new ArrayList<Integer>());
			cur.add(y);
			adj.put(x,cur);
		}
		
		Set<Integer> visited = new HashSet<>();
		int dp[] = new int[nodes+1];
		Arrays.fill(dp, -1);
		int ans = 0;
		for(Integer k : adj.keySet()) {
			if(dp[k]==-1) {
				ans = Math.max(ans, dfs(k, dp,adj));
			}
		}
		//System.out.println(Arrays.toString(dp));
		System.out.println(ans);
		
	}


	private static int dfs(Integer k, int[] dp, Map<Integer, ArrayList<Integer>> adj) {
		//System.out.println("k "+ k);
		if(dp[k]!=-1) {
			//System.out.println("quick return k "+ k + " dp[k] "+ dp[k]);
			return dp[k];
		}
		
		int ans = 0;
		if(adj.get(k)==null) {
			dp[k]=0;
			return 0;
		}
		for(int i: adj.get(k)) {
			//System.out.println(" k "+k+" i "+ i + " dp[i] "+ dp[i]);
			if(dp[i] != -1) {
				ans = Math.max(ans, dp[i]+1);
			}else {
				ans = Math.max(ans, dfs(i, dp,adj)+1);
			}
		}
		dp[k]= ans;
		//System.out.println("result updated dp["+ k+"] "+ dp[k]);
		return ans;
	}


	public static void knapSack() {
		Scanner sc = new Scanner(System.in);
		int items = sc.nextInt();
		int weight = sc.nextInt();
		
		int[] values = new int[items];
		int[] weights = new int[items];
		for(int i =0;i<items;i++) {
			weights[i] = sc.nextInt();
			values[i] = sc.nextInt();
		}
		
		long[][]dp = new long[items+1][weight+1];
		knapSackHelper(dp, items,weight,weights, values);
		System.out.println(dp[items][weight]);
	}

	private static long knapSackHelper(long[][] dp, int items, int WT, int[] weights, int[] values) {
		System.out.println("items "+ items +" WT "+ WT + "current Item ");
		if(items <=0) {
			return 0;
		}
		
		if(dp[items][WT]!=0) {
			return dp[items][WT];
		}
		
		if(WT>=weights[items-1]) {
			dp[items][WT] = knapSackHelper(dp, items-1,WT-weights[items-1],weights,values)+values[items-1];
		}
		
		dp[items][WT] = Math.max(dp[items][WT], knapSackHelper(dp, items-1, WT, weights, values));
		//System.out.println("dp ["+ items+"]["+WT+"] "+dp[items][WT]);
		
		return dp[items][WT];
	}
}


Measured memory_bytes: 80444
if __name__ == '__main__':

    s = list(input())
    s.reverse()
    n = len(s)
    now = 0
    mods = [0] * 2019
    mods[0] += 1
    ten = 1
    for i in range(n):
        now += ten * int(s[i])
        now %= 2019
        ten *= 10
        ten %= 2019
        mods[now] += 1
    ans = 0
    for i in mods:
        ans += (i * (i - 1)) // 2
    print(ans)


Measured memory_bytes: 10504
#include <bits/stdc++.h>
#define r(i, n) for (int i=0;i<n;i++)
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<double> a(n);
  r(i, n) cin >> a.at(i);
  sort(a.begin(), a.end());
  r(i, n-1) a.at(i+1)=(a.at(i)+a.at(i+1))/2;
  cout << a.at(n-1) << endl;
  return 0;
}

Measured memory_bytes: 256