akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define x first
#define y second
typedef pair<int,int> pii;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x,T y){x<y?x=y:T();}
template <typename T> void chkmin(T &x,T y){x>y?x=y:T();}
template <typename T> void readint(T &x)
{
	x=0;int f=1;char c;
	for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
	for(;isdigit(c);c=getchar())x=x*10+c-'0';
	x*=f;
}
const int MOD=998244353;
inline int dmy(int x){return x>=MOD?x-MOD:x;}
inline void inc(int &x,int y){x=dmy(x+y);}
int qmi(int x,int y)
{
	int ans=1;
	for(;y;y>>=1,x=1ll*x*x%MOD)
		if(y&1)ans=1ll*ans*x%MOD;
	return ans;
}
const int MAXK=105;

ll n;
int k;
ll p[MAXK];
void exgcd(ll a,ll b,ll &x,ll &y)
{
	if(!b){x=1;y=0;return;}
	exgcd(b,a%b,x,y);
	ll t=x;x=y;y=t-(a/b)*y;
}

int main()
{
	#ifdef LOCAL
	freopen("code.in","r",stdin);
//	freopen("code.out","w",stdout);
	#endif
	readint(n);
	if(n==1)return 0*printf("1\n");
	n<<=1;
	ll u=n;
	for(ll i=2;i*i<=u;++i)
	{
		if(u%i)continue;
		ll x=1;
		while(!(u%i))u/=i,x*=i;
		p[k++]=x;
	}
	if(u>1)p[k++]=u;
	ll ans=n;
	for(int s=0;s<(1<<k);++s)
	{
		ll a=1;
		for(int i=0;i<k;++i)
			if(s&(1<<i))a*=p[i];
		ll b=n/a,x,y;
		exgcd(a,b,x,y);
		x=(x%b+b-1)%b+1;
		y=(a*x-1)/b;
		if(!y)y+=a,x-=b;
		chkmin(ans,b*y);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
int n;cin>>n;
vector<ll> h(n);
for(int i=0;i<n;i++)cin>>h[i];
vector<ll>d(n);
d[0]=0;
d[1]=abs(h[1]-h[0]);
for(ll i=2;i<n;i++)d[i]=min(d[i-1]+abs(h[i]-h[i-1]),d[i-2]+abs(h[i]-h[i-2]));
 
cout<<d[n-1]<<endl;
 
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#include <map>
using namespace std;
int t,n,sx,sy;
bool used[1111][1111];
int dx[] = {1,-1,0,0,1,-1};
int dy[] = {0,0,1,-1,1,-1};
int main(void){
  while(cin >> t >> n && t){
    memset(used,false,sizeof(used));
    for(int i = 0; i < n; i++){
      int x,y;
      cin >> x >> y;
      used[x+300][y+300] = true;;
    }
    cin >> sx >> sy;

    queue<pair<int,pair<int,int> > > que;
    que.push(make_pair(0,make_pair(sx+300,sy+300)));
    used[sx+300][sy+300] = true;
    int res = 0;
    while(!que.empty()){
      int nt = que.front().first;
      int x = que.front().second.first;
      int y = que.front().second.second;
      que.pop();
      if(nt > t) continue;
      res++;
      for(int i = 0; i < 6; i++){
	int nx = x + dx[i];
	int ny = y + dy[i];
	if(used[nx][ny]) continue;
	used[nx][ny] = true;
	que.push(make_pair(nt+1,make_pair(nx,ny)));
      }
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 2428
import java.util.Scanner;
import java.util.Set;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] cells = line.split(" ");
        int h = Integer.parseInt(cells[0]);
        int w = Integer.parseInt(cells[1]);
        char[][] grid = new char[h][w];
        for(int i=0;i<h;i++){
            grid[i] = sc.nextLine().toCharArray();
        }
        boolean can = true;
        for(int i=0;i<h;i++){
            if(can){
                for(int j=0;j<w;j++){
                    if(grid[i][j]=='.'){continue;}
                    if(searchBomb(grid, i, j)){
                        continue;
                    }else{
                        can = false;
                        break;
                    }
                }
            }else{
                break;
            }
        }
        if(can){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }

    private static boolean searchBomb(char[][] grid, int i, int j){
        final int[] dx = new int[]{1, 0, -1, 0};
        final int[] dy = new int[]{0, 1, 0, -1};
        boolean exist = false;
        for(int idx = 0;idx<4;idx++){
            int ni=i+dx[idx], nj=j+dy[idx];
            if(ni<0||grid.length<=ni){continue;}
            if(nj<0||grid[i].length<=nj){continue;}
            if(grid[ni][nj]=='#'){exist=true; break;}
        }
        return exist;
    }
}

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

int main()
{
	int a,b,c;
    cin>>a>>b>>c;
    if(a==b and a!=c)
        cout<<"Yes";
    else if(a==c and a!=b)
        cout<<"Yes";
    else if(b==c and b!=a)
        cout<<"Yes";
    else
        cout<<"No";
	return 0;
}

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

string replaceWholeSentence(const string& str, string before, string after) {
  string str2(str);
  int idx = 0;

  while( (idx = str2.find(before, idx)) >= 0) {
	str2.replace(idx, before.length(), after);
  }
  return str2;
}

int main() {
  int n;
  string buf;

  cin >> n;
  cin.ignore();
  
  for(int i = 0; i < n; ++i) {
	getline(cin, buf);
	cout << replaceWholeSentence(buf, "Hoshino", "Hoshina") << endl;
  }

  return 0;
}

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

#define int long long

typedef pair<int,int>pint;
typedef vector<int>vint;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}
int toint(string &s){stringstream ss(s);int ret;ss>>ret;return ret;}
string tostring(int d){stringstream ss;ss<<d;return ss.str();}


const int X=-1000000000000ll;

int get(){
    string str;
    cin>>str;
    if(str=="x")return X;
    return toint(str);
}

string solve(vint &v){
    bool none=false;
    int N=v.size();
    rep(i,N-1){
        if(v[i]==X&&v[i+1]==X)none=true;

        if(v[i]==X)continue;
        if(v[i+1]==X)continue;

        if(i&1){
            if(v[i]<=v[i+1])none=true;
        }
        else{
            if(v[i]>=v[i+1])none=true;
        }
    }

    if(none)return "none";

    int l=-1000000000-10,u=1000000000+10;

    rep(i,N){
        if(v[i]!=X)continue;

        if(i&1){
            if(i)l=max(l,v[i-1]+1);
            if(i<N-1)l=max(l,v[i+1]+1);
        }
        else{
            if(i)u=min(u,v[i-1]-1);
            if(i<N-1)u=min(u,v[i+1]-1);
        }
    }

    if(l==u)return tostring(l);
    if(l>u)return "none";
    return "ambiguous";
}

signed main(){
    int N;
    while(cin>>N,N){
        vint vec(N);
        rep(i,N)vec[i]=get();
        cout<<solve(vec)<<endl;
    }
    return 0;
}

Measured memory_bytes: 1240
import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    N = int(input())
    A = list(map(int,input().split()))

    INF = 10 ** 9

    L = np.array([0 for i in range(N+1)])
    R = np.array([0 for i in range(N+1)])

    for i in range(N):
        temp = A[i]
        if i+1+temp <= N:
            L[i+1+temp] += 1
        if i+1-temp >= 0:
            R[i+1-temp] += 1

    res = np.sum(L*R)

    print(res)




main()


Measured memory_bytes: 51144
#include <bits/stdc++.h>
using namespace std;
int main()
{
    std::cout<<std::fixed<<std::setprecision(5);
    int n,v[10000];cin>>n;
    float ans=0;
    for (int i = 0; i < n; ++i)
    {
        cin>>v[i];
    }
    sort(v,v+n);
    float temp=pow(2,n-1);
    for (int i = 0; i < n; ++i)
    {
        if(i<2)ans+=v[i];
        else ans+=pow(2,i-1)*v[i];
    }
    ans=ans/temp;
    cout<<ans<<endl;

}


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

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

    ll n,t=5,a=0;
    cin>>n;
    if(n&1)
    {
        cout<<"0"<<'\n';
        return 0;
    }
    n/=2;
    while(n/t>0)
    {
        a+=n/t;
        t*=5;
    }
    cout<<a<<'\n';
    return 0;
}

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

using ll = long long;

int main() {
	ll r, g, b, n;
	cin >> r >> g >> b >> n;
	ll ans = 0;
	for(ll i = 0; i <= 3000; i++) {
		for(ll j = 0; j <= 3000; j++) {
			ll x = n - r * i - g * j;
			if(x >= 0 && x % b == 0) ans++;
		}
	} cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
# coding=UTF-8
from collections import deque
from operator import itemgetter
from bisect import bisect_left, bisect
import itertools
import sys
import math
import numpy as np
import time
sys.setrecursionlimit(10**6)
# input = sys.stdin.readline


def main():
    s = input()
    t = input()
    if s == t[:-1]:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Measured memory_bytes: 27084
s = input()
k = int(input())
c = len(s)
d = 0
a = []
d = min(c,5)
for i in range(d):
  b = [s[j:i+j+1] for j in range(c-i)]
  b = list(set(b))
  a = a + b
a.sort()
print(a[k-1])


Measured memory_bytes: 4168
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

vector<string> explode(string const & s, char delim) {
    vector<string> result;
    istringstream iss(s);

    for (string token; getline(iss, token, delim);) {
        result.push_back(move(token));
    }
    return result;
}

void solve() {
    int n;
    cin >> n;
    list<int> l;
    string comm;
    int m;
    REP(i, n) {
        cin >> comm;
        if (comm == "insert") {
            cin >> m;
            l.push_front(m);
        } else if (comm == "delete") {
            cin >> m;
            auto itr = find(ALL(l), m);
            if (itr != l.end()) l.erase(itr);
        } else if (comm == "deleteFirst") {
            l.pop_front();
        } else if (comm == "deleteLast") {
            l.pop_back();
        }
    }
    int c = 0;
    int s = sz(l);
    for (auto a : l) cout << a << (c++ == s - 1 ? endl : ' ');
}



Measured memory_bytes: 34340
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        String S = sc.nextLine();

        int length = S.length();
        int[] ans = new int[length];

        int rightMost = S.length() - 1;
        for(int i = length - 1; i >= 0; i--){
            if(S.charAt(i) == 'L'){
                rightMost = i;
            }
            if(S.charAt(i) == 'R'){
                if((rightMost - i) % 2 == 1){
                    ans[rightMost - 1] += 1;
                }else{
                    ans[rightMost] += 1;
                }
            }
        }

        int leftMost = 0;
        for(int i = 0; i < length; i++){
            if(S.charAt(i) == 'R'){
                leftMost = i;
            }
            if(S.charAt(i) == 'L'){
                if((i - leftMost) % 2 == 1){
                    ans[leftMost + 1] += 1;
                }else{
                    ans[leftMost] += 1;
                }
            }
        }

        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        for(int i = 0; i < length; i++){
            bw.write(String.format("%d ", ans[i]));
        }
        bw.flush();

    }
}


Measured memory_bytes: 71212
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var ABC = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var answer = 0;
            Array.Sort(ABC);
            var left = (ABC[2] - ABC[0]) / 2;
            var mid = (ABC[2] - ABC[1]) / 2;
            answer = left + mid;
            ABC[0] += 2 * left;
            ABC[1] += 2 * mid;
            if (ABC[0] == ABC[1] && ABC[1] == ABC[2])
            {
                Console.WriteLine(answer);
                return;
            }
            Array.Sort(ABC);
            answer += ABC[0] == ABC[1] ? 1 : 2;
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
	int n, k;
	int a[210000] = {};
	int ans = 0;
	cin >> n >> k;
	int div = 0;
	int d[210000]={};
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		d[a[i] - 1]++;
	}
	for (int i = 0; i < n; i++) {
		if (d[i] != 0) {
			div++;
		}
		else d[i] = 1000000;
	}
	sort(d, d + n);
	int index = 0;
	while (true) {
		if (div <= k) {
			cout << ans << endl;
			return 0;
		}
		ans += d[index];
			index++;
		div--;
	}
	return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "NO" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N;
    int A[214514];
    cin >> N;
    REP(i,N){
        cin >> A[i];
    }
    sort(A,A+N);
    REP(i,N-1){
        if(A[i]==A[i+1]){
            GOODBYE;
        }
    }
    cout << "YES" << endl;
    return 0;
}



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

void func(vector<int> const &abcd, vector<int> v, int n)
{
    if (n == 3)
    {
        int calc =
            abcd[0] + abcd[1] * v[0] + abcd[2] * v[1] + abcd[3] * v[2];
        if (7 == calc)
        {
            string ans{};
            ans += to_string(abcd[0]);
            for (int i = 1; i < 4; i++)
            {
                ans += v[i - 1] == 1 ? '+' : '-';
                ans += to_string(abcd[i]);
            }
            cout << ans + "=7" << endl;
            exit(0);
        }
    }
    else
    {
        v[n] = 1;
        func(abcd, v, n + 1);
        v[n] = -1;
        func(abcd, v, n + 1);
    }
}
int main()
{
    string S;
    cin >> S;
    vector<int> abcd(4);
    for (int i = 0; i < 4; i++)
    {
        abcd[i] = (int)S[i] - (int)'0';
    }
    vector<int> v(3);
    func(abcd, v, 0);
    return 0;
}


Measured memory_bytes: 256
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))

def main():
    r = II()
    g = II()
    print(2*g-r)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
use std::cmp;

fn main(){
  let n: usize = read();
  let mut cards: Vec<Vec<usize>> = Vec::new();
  let mut dp: Vec<Vec<usize>> = vec![vec![0; n]; n];
  
  for _ in 0 .. n {
    cards.push(read_vec());
  }

  for d in 1 .. n {
    for i in 0 .. n - d {
      let j = i + d;
      let mut cost: usize = 2147483648;
      for k in i .. j {
        cost = cmp::min(cost, dp[i][k] + dp[k+1][j] + cards[i][0] * cards[k][1] * cards[k+1][0] * cards[j][1]);
      }
      dp[i][j] = cost;
    }
  }
  println!("{}", dp[0][n-1]);
}

fn read<T>() -> T
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.trim().parse().unwrap()
}

fn read_vec<T>() -> Vec<T>
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.split_whitespace().map(|e| e.parse().unwrap()).collect()
}



Measured memory_bytes: 5048
n = int(input())
s = input()

dic = {k: 0 for k in "RGB"}

for i in range(n):
  dic[s[i]] += 1
  
res = dic['R'] * dic['G'] * dic['B']

for i in range(n):
  for j in range(i+1, n):
    k = 2*j - i
    if k >= n: continue
    if s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]: res -= 1

print(res)

Measured memory_bytes: 9216
#include <iostream>
#include <string>
#include <cmath>
#include <ctime>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <set>
using namespace std;

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

for(int i = 0; i < 1010; i++){
    if(a <= k*i && k*i <= b){
        cout << "OK" << endl;
        return 0; 
    }

}

cout << "NG" << endl;

return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <stdlib.h>

typedef struct {
	int P, Y, tmp1, tmp2;
} s;

int compare1(const void *x, const void *y)
{
	return ((s*)x)->Y - ((s*)y)->Y;
}

int compare2(const void *x, const void *y)
{
	return ((s*)x)->tmp1 - ((s*)y)->tmp1;
}

int main(void)
{
	int N, M, tmp2[100000] = {0}, i;
	s tmp1[100000];
	scanf("%d%d", &N, &M);
	for (i = 0; i < M; ++i) {
		scanf("%d%d", &tmp1[i].P, &tmp1[i].Y);
		tmp1[i].tmp1 = i;
	}
	qsort(tmp1, M, sizeof(s), compare1);
	for (i = 0; i < M; ++i) {
		++tmp2[tmp1[i].P - 1];
		tmp1[i].tmp2 = tmp2[tmp1[i].P - 1];
	}
	qsort(tmp1, M, sizeof(s), compare2);
	for (i = 0; i < M; ++i) printf("%06d%06d\n", tmp1[i].P, tmp1[i].tmp2);
	return 0;
}

Measured memory_bytes: 4972
#include <iostream>

const int MAX=1<<12;
const int INF = 1000000000;

int C[MAX];

int main()
{
    std::ios_base::sync_with_stdio(0);
    int n, m;
    std::cin >> n >> m;
    int nn = 1<<n;
    for (int i=0;i<nn;++i) C[i] = INF;
    for (int i=0;i<m;++i)
    {
        int a,b;
        std::cin >> a >> b;
        int s = 0;
        for (int j=0;j<b;++j)
        {
            int c;
            std::cin >> c;
            --c;
            s |= 1 << c;
        }
        C[s] = std::min(C[s], a);
    }
    for (int k=0;k<n;++k)
    {
        for (int i=0;i<nn;++i)
        {
            for (int j=i+1;j<nn;++j)
            {
                C[i|j] = std::min(C[i|j], C[i]+C[j]);
            }
        }
    }
    int result = C[nn-1];
    if (result == INF) result = -1;
    std::cout << result;
    return 0;
}

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


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


# このグラフ構造の中で一番遠い連結成分では？
H, W = read_ints()
S = read_map(H)

# おとなしく深さ優先探索

mvx = (1, 0, -1, 0)
mvy = (0, 1, 0, -1)

from itertools import product, combinations
from collections import deque


def ret_shortest(si, sj):
    visited = [[False] * W for _ in range(H)]
    que = deque([(si, sj, 0)])
    visited[si][sj] = True

    ans = 0
    while que:
        i, j, cost = que.popleft()
        ans = max(ans, cost)
        for di, dj in zip(mvy, mvx):
            ni, nj = i + di, j + dj
            if not (-1 < ni < H) or not (-1 < nj < W):
                continue
            if S[ni][nj] == '.' and not visited[ni][nj]:
                que.append((ni, nj, cost + 1))
                visited[ni][nj] = True

    return ans


ans = 0

ans = 0
for i, j in product(range(H), range(W)):
    if S[i][j] == '.':
        ans = max(ret_shortest(i, j), ans)
print(ans)


Measured memory_bytes: 45036
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
//#define int long long 
#define inf 1000000000
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111
	
	int dp[31][1<<20];
	int x[31][31];
	
	void solve(){

		FOR(i,0,31)FOR(i1,0,1<<20)dp[i][i1] = inf;
		FOR(i,0,31)FOR(i1,0,31)x[i][i1] = inf;
		ini(n);
		ini(n1);
		FOR(i,0,n1){
			ini(x1,tmp1,tmp);
			x[x1][tmp1] = tmp;
		}
		dp[0][1] = 0;
		FOR(i,0,1<<n){
			FOR(i1,0,n){
				if(dp[i1][i]!=inf){
					//out("start:",i1,"to",i);
					FOR(i2,0,n){
						if(!((1<<i2)&i)){
							dp[i2][i+(1<<i2)] = min(dp[i2][i+(1<<i2)],dp[i1][i]+x[i1][i2]);
							//out("in: ",i1,"i2: ",i2,"kore",dp[i2][i+(1<<i2)]);
						}
					}
					//out("end:",i1,"to",i);
				}
			}
		}
		int rick  = inf;
		FOR(i,0,n){
			rick  = min(rick,dp[i][(1<<n)-1]+x[i][0]);
		}
		if(rick == inf)rick = -1;
		out(rick);
	
		
		

		


		
		
	}























int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}



Measured memory_bytes: 130180
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac

setrecursionlimit(1000000)


def main():
	a,b = map(int,input().split())
	print(a-b+1)

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll i,j;
    ll n,k;
    cin >> n >> k;
    vector<ll> p(n);
    vector<ll> c(n);
    rep(i,n){
        cin >> p.at(i);
        --p.at(i);
    }
    rep(i,n) cin >> c.at(i);

    vector<vector<ll>> dub(n, vector<ll>(32));
    vector<vector<ll>> cnt(n, vector<ll>(32));
    vector<vector<ll>> mmx(n, vector<ll>(32));
    rep(i,n) dub.at(i).at(0) = p.at(i);
    rep(i,n){
        cnt.at(i).at(0) = c.at(p.at(i));
    }
    rep(i,n){
        mmx.at(i).at(0) = c.at(p.at(i));
    }
    rep(j,31){
        for(i = 0;i < n;++i){
            dub.at(i).at(j+1) = dub.at(dub.at(i).at(j)).at(j);
            cnt.at(i).at(j+1) = cnt.at(i).at(j) + cnt.at(dub.at(i).at(j)).at(j);
            mmx.at(i).at(j+1) = max(mmx.at(i).at(j), cnt.at(i).at(j) + mmx.at(dub.at(i).at(j)).at(j));
        }
    }
    ll ans = -(1ll << 60);
    ll kk = 31 - __builtin_clz(k);
    rep(i,n){
        ll mb = kk;
        ll now = i;
        ll pre = 0;
        while(mb >= 0){
            if((k & (1ll << mb))){
                ans = max(ans, pre + mmx.at(now).at(mb));
                pre += cnt.at(now).at(mb);
                now = dub.at(now).at(mb);
            }
            --mb;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 7612
//Utkarsh-raj

#include<bits/stdc++.h>

#define ll long long int
#define vc vector
#define mod 100000000007
#define mp make_pair
#define pb push_back
#define nl cout<<endl;
#define ff first
#define ss second

using namespace std;

int n;
int arr[100010][3];

void solve(){
    for(int i=1; i<n; i++){
        arr[i][0] += max(arr[i-1][1], arr[i-1][2]);
        arr[i][1] += max(arr[i-1][0], arr[i-1][2]);
        arr[i][2] += max(arr[i-1][0], arr[i-1][1]);
    }
    cout<<max(arr[n-1][0], max(arr[n-1][1], arr[n-1][2]))<<endl;
}

int main()
{
    ifstream myFile("task.in");
    if(!myFile.fail())
    {
        assert(freopen("task.in", "r", stdin));
    }

    cin>>n;
    for(int i=0; i<n; i++){
        cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
    }
    solve();

    return 0;
}


Measured memory_bytes: 1408
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int x[] = new int[n];

    for(int i = 0; i < n; i ++){
      x[i] = scan.nextInt();
    }

    String answer = "APPROVED";

    for(int i = 0; i < n; i ++){
      if(x[i] % 2 ==0){
        if(x[i] % 3 != 0 && x[i] % 5 != 0){
          answer = "DENIED";
        }
      }
    }
    System.out.println(answer);
    }
  }

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

int main() {
  int n, t[100005], x[100005], y[100005];

  cin >> n;
  for (int i = 1; i <= n; i++) cin >> t[i] >> x[i] >> y[i];

  int dist, time;
  x[0] = y[0] = t[0] = 0;
  for (int i = 1; i <= n; i++) {
    dist = abs(x[i]-x[i-1]) + abs(y[i]-y[i-1]);
    time = t[i] - t[i-1];
    if (dist > time) {
      cout << "No" << endl;
      return 0;
    } else if ((dist+time) % 2 != 0) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;

}

Measured memory_bytes: 1408
#include "stdio.h"

char letter[13];

int main() {
	scanf("%s", letter);
	for (int i = 0; i < 4; i++) {
		printf("%c",letter[i]);
	}
	printf(" ");
	for (int i = 4; i < 12; i++) {
		printf("%c", letter[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long ll; 

using namespace std;

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

	if (a + b >= c) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
from numpy import*;from scipy.sparse import*;(n,m),*p=[map(int,o.split())for o in open(0)];e=array([(i,j+n-1,1)for i,q in enumerate(p)for j in list(q)[1:]]).T;print("YNEOS"[1in csgraph.connected_components(csr_matrix(((e[2],e[:2])),[n+m]*2))[1][:n]::2])

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

int main(){
   int N;
   cin >> N;
   vector<int> d(N);
   for (int i=0; i<N; i++)
      cin >> d.at(i);

   int sum = 0;
   for (int i=0; i<N-1; i++)
      for (int i2=i+1; i2<N; i2++)
         sum = sum + d.at(i)*d.at(i2);

   cout << sum << endl;
}



Measured memory_bytes: 256
n,a,b=map(int,input().split())
h=[int(input()) for i in range(n)]
l=0;r=max(h)//b+1
while abs(l-r)>1:
  x=(l+r)//2
  ct=0
  for i in range(n):
    ct+=((a-b-1)+max(0,h[i]-b*x))//(a-b)
  if ct<=x:
    r=x
  else:
    l=x
print(r)

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

#ifndef DEBUG
#define endl '\n'
#define debug(...)
#else
#define debug(...) __VA_ARGS__
#endif
#define debugf(...) debug(printf(__VA_ARGS__);)

const int N = 1e5 + 5;

using ll = long long;
vector<ll> nums;
void dfs(ll x, int digits) {
    nums.emplace_back(x);

    if (digits >= 10)
        return;

    for (int delta = -1; delta <= 1; delta++) {
        int d = (x%10) + delta;
        if (d >= 0 && d <= 9)
            dfs(10*x + d, digits+1);
    }
}

int (((((main)))))() <%
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n; cin >> n;

    for (int d = 1; d <= 9; d++)
        dfs(d, 1);

    sort(nums.begin(), nums.end());

    debugf("%d numbers generated\n", (int)nums.size());

    cout << nums[n - 1] << endl;

    return 0;
%>

Measured memory_bytes: 2420
#include<stdio.h>

int main (void){
	
	int n,ice,i,j;
	int sell[11]={0};
	for(;;){
		scanf("%d",&n);
			if(n == 0) break;
		
		for(i=0;i<10;i++){
			sell[i] = 0;
		}
		for(i=0;i<n;i++){
			scanf("%d",&ice);
			
			sell[ice] += 1;
		}
		
		for(i=0;i<10;i++){
			if(sell[i] == 0){
				printf("-\n");
			}else{
				for(j=0;j<sell[i];j++){
					printf("*");
				}
				printf("\n");
			}
		}
	}	
return 0;

}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=105;
const int M=1e5+5;
const int MOD=1e9+7;

int n, k;
int a[N];
int cache[N][M];

int dp(int idx, int k)
{
	if(k<0)
		return 0;
	if(k==0)
		return 1;
	if(idx==n+1)
		return 1;
	int &ans=cache[idx][k];
	if(ans!=-1)
		return ans;
	int mini=min(k, a[idx]);
	ans=dp(idx+1, k) - dp(idx+1, k-(mini)-1) + MOD;
	ans%=MOD;
	ans+=dp(idx, k-1);
	ans%=MOD;
	return ans;
}

int32_t main()
{
	IOS;
	memset(cache, -1, sizeof(cache));
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	int ans=dp(1, k) - dp(1, k-1) + MOD;
	ans%=MOD;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 88576
package main

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

var debug = false

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var targets []string
	for i := 0; i < 3; i++ {
		if sc.Scan() {
			targets = append(targets, sc.Text())
		}
	}

	res := GetAnswer(targets)
	fmt.Printf("%v\n", res)
}

// GetAnswer ...
func GetAnswer(targets []string) string {
	prt("inputs: targets:%#v", targets)
	result := "No"
	// 配列の最初の3つをa1が0と仮定してbへ入れてから整合性確認
	tmatrix := make([][]int, 3)

	for i, target := range targets {
		tarr := getIntArray(target)
		prt("tarr: %#v", tarr)
		tmatrix[i] = tarr
	}
	prt("tmatrix: %#v", tmatrix)

	b := []int{0, 0, 0}

	a1min := getMin(tmatrix[0])
	a2min := getMin(tmatrix[1])
	a3min := getMin(tmatrix[2])
FOR_LABEL:
	for a1 := 0; a1 <= a1min; a1++ {
		b[0] = tmatrix[0][0] - a1
		b[1] = tmatrix[0][1] - a1
		b[2] = tmatrix[0][2] - a1
		prt("a1: %v b1,2,3= %v %v %v", a1, b[0], b[1], b[2])
		for a2 := 0; a2 <= a2min; a2++ {
			if tmatrix[1][0]-a2 == b[0] && tmatrix[1][1]-a2 == b[1] && tmatrix[1][2]-a2 == b[2] {
				for a3 := 0; a3 <= a3min; a3++ {
					if tmatrix[2][0]-a3 == b[0] && tmatrix[2][1]-a3 == b[1] && tmatrix[2][2]-a3 == b[2] {
						result = "Yes"
						break FOR_LABEL
					}
				}
			}
		}
	}

	return result
}

func getMin(intarr []int) int {
	result := intarr[0]
	for _, i := range intarr {
		if result > i {
			result = i
		}
	}
	return result
}

func getIntArray(str string) []int {
	strarr := strings.Split(str, " ")
	intarr := []int{}
	for _, st := range strarr {
		ti, _ := strconv.Atoi(st)
		intarr = append(intarr, ti)
	}
	return intarr
}

func prt(format string, inputs ...interface{}) {
	if debug {
		fmt.Printf(format+"\n", inputs...)
	}
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<list>

using namespace std;
using ll = long long;

ll eu(ll x,ll y){
    if(y == 0) return x;
    return eu(y,x%y);
}

ll div_num(ll x,ll y,ll div){
    ll result;
    if(x%div == 0) result = y/div-x/div+1;
    else result = y/div-x/div;
    return result;
}

int main(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll div_c = div_num(a,b,c);
    ll div_d = div_num(a,b,d);

    ll lcm = c*d / eu(c,d);
    ll div_lcm = div_num(a,b,lcm);

    ll yo = div_c +div_d - div_lcm;

    ll ans = b-a+1 - yo;

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using P = pair<int,int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;

ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

int main(){
	ll n, a, b;
	cin >> n >> a >> b;
	
	ll diff = b - a;
	ll ans = 0;
	if(diff % 2 == 0){
		ans = diff / 2;
	}
	else{
		ans = min(a-1, n-b) + 1 + (b - a - 1) / 2;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int N;
    int AC = 0, WA = 0, TLE = 0, RE = 0;

    cin >> N;

    for (int i = 0; i < N; ++i)
    {
        string input;
        cin >> input;
        if (input == "AC")
        {
            AC++;
        }
        else if (input == "WA")
        {
            WA++;
        }
        else if (input == "TLE")
        {
            TLE++;
        }
        else if (input == "RE")
        {
            RE++;
        }
    }

    cout << "AC x " << AC << endl;
    cout << "WA x " << WA << endl;
    cout << "TLE x " << TLE << endl;
    cout << "RE x " << RE << endl;
}

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

const int maxn = 1e5+10;
const int mod = 1e9+7;
int n,k;
int arr[maxn];

int32_t main()
{
    cin >> n >> k;
    for(int i = 1;i<=n;i++){
        cin >> arr[i];
    }
    int dp[maxn];
    dp[1] = 0;
    dp[2] = abs(arr[2] - arr[1]);
    for(int i = 3;i<=k+1;i++){
        dp[i] = abs(arr[i] - arr[1]);
        for(int j = 1;j<i;j++){
            dp[i] = min(dp[i],dp[j] + abs(arr[i] - arr[j]));
        }
    }
    for(int i = k+2;i<=n;i++){
        dp[i] = dp[i-k] + abs(arr[i-k] - arr[i]);
        for(int j = i - k;j<i;j++){
            dp[i] = min(dp[i],dp[j] + abs(arr[i] - arr[j]));
        }
    }
    cout << dp[n] << endl;
}


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

#define llong long long 
#define xx first
#define yy second
#define len(x) ((int)x.size())
#define rep(i,n) for (int i = -1; ++ i < n; )
#define rep1(i,n) for (int i = 0; i ++ < n; )
#define all(x) x.begin(), x.end()

#define maxn 101010
int n;
int nchild[maxn];
map<llong, int> inv_d;

int main(void) {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    rep1(i, n) {
      llong d; cin >> d;
      inv_d[d] = i;
    }
    rep1(i, n) nchild[i] = 1;

    vector<pair<int, int>> ans;
    while (len(inv_d) > 1) {
      llong d = inv_d.rbegin()->xx;
      int u = inv_d.rbegin()->yy;
      inv_d.erase(--inv_d.end());
      llong td = d - 1ll * (n - 2 * nchild[u]);
      // clog << u << ' ' << d << ' ' << nchild[u] << endl;
      if (!inv_d.count(td)) {
        cout << "-1";
        return 0;
      }
      int v = inv_d[td];
      ans.push_back({u, v});
      // clog << u << ' ' << v << endl;
      nchild[v] += nchild[u];
    }
    llong droot = inv_d.begin()->xx;
    int root = inv_d.begin()->yy;
    llong s = 0;
    rep1(i, n) if (i != root) s += nchild[i];
    // clog << root << ' ' << s << endl;
    if (s != droot) {
      cout << -1;
      return 0;
    }
    rep(i, n - 1) cout << ans[i].xx << ' ' << ans[i].yy << '\n';

    return 0;
}

Measured memory_bytes: 8952
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 2000000000
#define InfLL 2000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	ll N, K;
	cin >> N >> K;
	vl Aplus_less;
	vl Aplus_greater;
	vl Aminus_less;
	vl Aminus_greater;
	ll Nplus = 0;
	ll Nminus = 0;
	ll Nnotzero = 0;
	rep(i, N) {
		ll Atmp;
		cin >> Atmp;
		if (Atmp > 0) {
			Aplus_less.push_back(Atmp);
			Aplus_greater.push_back(Atmp);
			Nplus++;
			Nnotzero++;
		}
		else if (Atmp < 0) {
			Aminus_less.push_back(Atmp);
			Aminus_greater.push_back(Atmp);
			Nminus++;
			Nnotzero++;
		}
	}
	sort(Aplus_less.begin(), Aplus_less.end(), less<ll>());
	sort(Aminus_less.begin(), Aminus_less.end(), less<ll>());
	sort(Aplus_greater.begin(), Aplus_greater.end(), greater<ll>());
	sort(Aminus_greater.begin(), Aminus_greater.end(), greater<ll>());

	ll ansminus = Nplus * Nminus * 2;
	ll anszero = N * (N - 1) - Nnotzero * (Nnotzero - 1);

	K = K * 2 - 1;

	ll L = -InfLL;
	ll R = InfLL;
	while (1) {
		ll M = min(L, R);
		M += abs(L - R) / 2LL;
		if (L == M)
			break;
		ll anstmp = 0;
		if (M > 0) {
			int j;
			j = 0;
			rep(i, Nminus) {
				while (1) {
					if (j == Nminus)
						break;
					if (Aminus_less[i] * Aminus_greater[j] >= M)
						break;
					j++;
				}
				anstmp += j;
				if (i + j >= Nminus)
					anstmp--;
			}
			j = 0;
			rep(i, Nplus) {
				while (1) {
					if (j == Nplus)
						break;
					if (Aplus_greater[i] * Aplus_less[j] >= M)
						break;
					j++;
				}
				anstmp += j;
				if (i + j >= Nplus)
					anstmp--;
			}
			anstmp += anszero;
			anstmp += ansminus;
		}
		else if (M == 0) {
			anstmp += ansminus;
		}
		else {
			int j;
			j = 0;
			rep(i, Nminus) {
				while (1) {
					if (j == Nplus)
						break;
					if (Aminus_greater[i] * Aplus_greater[j] >= M)
						break;
					j++;
				}
				anstmp += j;
			}
			anstmp *= 2;
		}
		if (anstmp < K)
			L = M;
		else
			R = M;
	}


	cout << L << endl;
	return 0;
}

Measured memory_bytes: 3564
// F.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

int n, k;
vector<double> x, y, c;

struct Point {
	double x;
	double y;
	double dist(const Point& p) {
		double dx = x - p.x, dy = y - p.y;
		return sqrt(dx * dx + dy * dy);
	}
};

struct Circle {
	Point p;
	double c;
	double r;
	vector<Point> cross(const Circle& c) {
		vector<Point> pp;
		double dist = p.dist(c.p);
		if (dist <= r + c.r && r <= dist + c.r && r + dist >= c.r) {
			double dx = c.p.x - p.x, dy = c.p.y - p.y;
			double a = (dx * dx + dy * dy + r * r - c.r * c.r) / 2, dd = dx * dx + dy * dy;
			pp.push_back({
				(a * dx + dy * sqrt(dd * r * r - a * a)) / dd + p.x,
				(a * dy - dx * sqrt(dd * r * r - a * a)) / dd + p.y
			});
			pp.push_back({
				(a * dx - dy * sqrt(dd * r * r - a * a)) / dd + p.x,
				(a * dy + dx * sqrt(dd * r * r - a * a)) / dd + p.y
			});
		}
		return pp;
	}
};

int main(int argc, char* argv[]) {
	cout.precision(20);
#ifdef _MSC_VER
	while (true)
#endif
	{
		n = -1;
		cin >> n >> k;
		if (n < 0) return 0;
		x.resize(n);
		y.resize(n);
		c.resize(n);
		vector<Circle> cc(n);
		for (int i = 0; i < n; ++i) {
			cin >> x[i] >> y[i] >> c[i];
			cc[i].p.x = x[i];
			cc[i].p.y = y[i];
			cc[i].c = c[i];
		}
		double left = 0, right = 1e9;
		for (int t = 0; t < 100; ++t) {
			double mid = (left + right) / 2;
			for (int i = 0; i < n; ++i) {
				cc[i].r = mid / cc[i].c;
			}
			vector<Point> pp;
			for (int i = 0; i < n; ++i) {
				pp.push_back(cc[i].p);
				for (int j = i + 1; j < n; ++j) {
					for (auto p : cc[i].cross(cc[j])) {
						pp.push_back(p);
					}
				}
			}
			int mc = 0;
			for (auto p : pp) {
				int cnt = 0;
				for (auto c : cc) {
					cnt += p.dist(c.p) <= c.r + 1e-12;
				}
				mc = max(mc, cnt);
			}
			if (mc >= k) {
				right = mid;
			} else {
				left = mid;
			}
		}
		cout << right << endl;
	}
	return 0;
}

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

void fnInput(vector<string>& rvsStrX, vector<string>& rvsStrY)
{
  int nMaxSiz;
  cin >> nMaxSiz;
  rvsStrX.resize(nMaxSiz);
  rvsStrY.resize(nMaxSiz);

  for (int i = 0; i < nMaxSiz; ++i)
  {
    cin >> rvsStrX[i] >> rvsStrY[i];
    rvsStrX[i] = ' ' + rvsStrX[i];
    rvsStrY[i] = ' ' + rvsStrY[i];
  }
}

int fnLngCmnSubseq(const vector<string>& cnrvsStrX, const vector<string>& cnrvsStrY)
{
  vector<vector<int>> vvnLcsDP;
  for (int i = 0; i < cnrvsStrX.size(); ++i)
  {
    const int nMAXNX = cnrvsStrX[i].size();
    const int nMAXNY = cnrvsStrY[i].size();

    vvnLcsDP.clear();
    vvnLcsDP.resize(nMAXNX, vector<int>(nMAXNY, 0));

    for (int nx = 1; nx < nMAXNX; ++nx)
      for (int ny = 1; ny < nMAXNY; ++ny)
        if (cnrvsStrX[i][nx] == cnrvsStrY[i][ny])
          vvnLcsDP[nx][ny] = vvnLcsDP[nx - 1][ny - 1] + 1;
        else
          vvnLcsDP[nx][ny] = max(vvnLcsDP[nx - 1][ny], vvnLcsDP[nx][ny - 1]);

    cout << vvnLcsDP[nMAXNX - 1][nMAXNY - 1] << endl;
  }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<string> vsStrX, vsStrY;

  fnInput(vsStrX, vsStrY);
  fnLngCmnSubseq(vsStrX, vsStrY);
  return 0;
}

Measured memory_bytes: 6908
n = int(input())
a = list(map(int, input().split()))
b = [(i, a[i]) for i in range(n)]
b = sorted(b, key=lambda x: x[1])[::-1]

dp = [[0] * (n+1) for _ in range(n+1)]
ans = 0
for l in range(0, n+1):
    for r in range(0, n+1):
        if l + r == n:
            ans = max(ans, dp[l][r])
            break
        idx, activeness = b[l+r]
        dp[l+1][r] = max(dp[l+1][r], 
                         dp[l][r] + abs(idx - l) * activeness)
        dp[l][r+1] = max(dp[l][r+1],
                         dp[l][r] + (n-1-r-idx) * activeness)

print(ans)
        

Measured memory_bytes: 100412
#include <iostream>

using namespace std;

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

    int N;
    cin >> N;

    int inarow = 0;

    for(int i = 0; i < N; i++){
        int x, y;
        cin >> x >> y;
        if(x == y)inarow++;
        else inarow = 0;
        if(inarow == 3){
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";


}

Measured memory_bytes: 3700
import java.io.*;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try {
			BufferedReader reader = new BufferedReader(
					new InputStreamReader(System.in));
			long n, m, result = 0;
			int ind;
			String str;
			
			str = reader.readLine();
			ind = str.indexOf(" ");
			n = Long.parseLong(str.substring(0, ind));
			m = Long.parseLong(str.substring(ind+1));
			
			if(n==1) {
				if(m==1) {
					result = 1;
				}else {
					result = m-2;
				}
			}else if(n == 2) {
				result = 0;
			}else {
				if(m==1) {
					result = n-2;
				}else if(m==2) {
					result = 0;
				}else {
					result = (n-2)*(m-2);
				}
			}
			System.out.println(result);
		}
		catch (Exception e) {
			
		}
	}

}


Measured memory_bytes: 20948
//Feet don't fail me now
//Take me to the finish line
//Oh, my heart, it breaks every step that I take
//But I'm hoping at the gates, they'll tell me
//that IOI gold is mine
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define no_answer {cout << "NO"; exit(0);}
#define vectors vector<vector<llong> >
#define FOR(i, start, finish, k) for(llong i = start; i <= finish; i += k)

const long long MXN = 2e5 + 10;
const long long MNN = 1e4 + 520;
const long long MOD = 10007;
const long long INF = 1e18;
const long long OO = 1e9;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

char ch[210][210];
llong b[210][210];
int n, clr[MXN];
vector<int> g[MXN];
bool ok = 1;

void dfs(int x, int color){
    clr[x] = color;
    for(int i = 0; i < g[x].size(); i++){
        int to = g[x][i];
        if(clr[to] == 0){
            dfs(to, -color);
        }
        if(clr[to] == color){
            ok = 0;
        }
    }
}

int main(){
    ios;
    cin >> n;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            cin >> ch[i][j];
            if(ch[i][j] == '1') b[i][j] = 1;
            else{
                if(i != j) b[i][j] = 1e9;
            }
            if(b[i][j] == 1) g[i].pb(j);
        }
    }
    dfs(1, 1);
    if(ok == 0) return cout << -1, 0;
    for(int k = 1; k <= n; k++){
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++){
                b[i][j] = min(b[i][j], b[i][k] + b[k][j]);
            }
        }
    }
    llong ans = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            ans = max(ans, b[i][j]);
        }
    }
    cout << ans + 1;
}


/*
 010110
 101001
 010100
 101000
 100000
 010000
 1 2
 1 4
 1 5
 2 3
 2 6
 3 4
 */


Measured memory_bytes: 5504
#include <bits/stdc++.h>
#define maxN 100002
using namespace std;

int n, m;
vector < int >  V[maxN];

int frt, bck;
bool in[maxN];

deque < int > path;

void dfs(int x, int ty)
{
    for (int y : V[x])
        if (!in[y])
        {
            in[y] = 1;
            if (ty)
                path.push_back(y);
            else
                path.push_front(y);
            dfs(y, ty);
            break;
        }
}

int main()
{
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= m; ++ i)
    {
        int x, y;
        scanf("%d %d", &x, &y);
        if (i == 1)
        {
            frt = x;
            bck = y;
            path.push_back(x);
            path.push_back(y);
            in[x] = in[y] = 1;
        }
        V[x].push_back(y);
        V[y].push_back(x);
    }
    dfs(frt, 0);
    dfs(bck, 1);

    printf("%d\n", path.size());
    while (!path.empty())
    {
        printf("%d ", path.front());
        path.pop_front();
    }

    return 0;
}


Measured memory_bytes: 10624