akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;
	int MOD = 10000;
	
	void run() {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt(), k = sc.nextInt();
		
		int[][][] dp = new int[n+1][4][3];
		int[] ks = new int[n+1];
		for(int i=0;i<k;i++) {
			int a = sc.nextInt(), b = sc.nextInt();
			for(int j=0;j<3;j++){
				ks[a] = b;
			}
		}
//		debug(ks);
		dp[0][0][0] = 1;
		for(int i=1;i<=n;i++) {
			if( ks[i] != 0) {
				for(int h=0;h<4;h++) {
					if( h != ks[i] ) for(int l=0;l<3;l++) 
						dp[i][ks[i]][1] = ( dp[i-1][h][l] + dp[i][ks[i]][1] ) % MOD;
					else for(int l=1;l<3;l++) 
						dp[i][ks[i]][l] = ( dp[i-1][ks[i]][l-1] + dp[i][ks[i]][l] ) % MOD;
				}
			}
			else {
				for(int j=1;j<4;j++) for(int h=0;h<4;h++) if( j != h ){
					for(int l=0;l<3;l++) dp[i][j][1] = ( dp[i-1][h][l] + dp[i][j][1] ) % MOD;
				}
				for(int j=1;j<4;j++) {
					for(int l=2;l<3;l++) dp[i][j][l] = ( dp[i-1][j][l-1] + dp[i][j][l] ) % MOD;
				}
			}
		}
//		for(int[][] a: dp) debug(a);
		int ans = 0;
		for(int i=0;i<4;i++) for(int j=0;j<3;j++) ans = (ans + dp[n][i][j]) % MOD;
		System.out.println(ans);
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 19708
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define forn(i,n) for(ll i=0; i<(n); i++)
#define fori(i,k,n) for(ll i=k; i<(n); i++) 
 
int t;
 
void solve(){
	ll n, k;
	cin >> n >> k;
	n %= k;
	cout << min(n, k-n);
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	t = 1;
	while(t--)
		solve();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
#define rep1(i,n) for (ll i=1; i<=(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";
ll mod = 1000000007;

int main(){
  ll a,b,c,k; cin >> a >> b >> c >>k;
  cout << min(a, k)-((k-a-b)>0? min(k-a-b,c) : (ll)0);
  return 0;
}

Measured memory_bytes: 3616
n = int(input())
X = list(map(int, input().split()))

s = sum(X)
p = s // n
# print(p)
ans = 100100100100
for j in range(-5, 6):
    tmp = 0
    for i in range(n):
        tmp += (X[i] - p+j)**2
    if ans > tmp:
        ans = tmp
print(ans)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vl = vector<ll>;  // long longの1次元の型に vl という別名をつける
using vvl = vector<vl>; // long longの2次元の型に vvl という別名をつける
int MOD = 1000000007; //10^9 + 7

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// 無限大の値
const ll  LINF = 1LL << 60;
const int iINF = 1 << 29;

int main(void){
  int a, b, c, d;
  cin >> a >> b >> c >> d; 
  cout << (a * b > c * d ? a * b : c * d) << endl;
}

Measured memory_bytes: 3616
n = int(input())
w_list = list(map(int,input().split()))
sum_w = sum(w_list)
temp_sum = 0
dif = sum_w
for i in range(n):
    if abs(sum_w - temp_sum*2) > abs(sum_w - temp_sum*2 - w_list[i]*2):
        temp_sum += w_list[i]
        dif = w_list[i]
        #print(temp_sum)
    else:
        break 
if abs(temp_sum) == abs(sum_w - temp_sum):
    print(0)
else:
    print(abs(sum_w - temp_sum*2))

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
//max_element


int ya[10000010];


signed main()
{
	int N;
	cin >> N;

	ya[1] = 0;
	for (int i = 2; i <= N; i++)
	{
		int cur = i;
		while (cur <= N)
		{
			ya[cur]++;
			cur += i;
		}
	}

	int ans = 0;
	for (int i = 1; i <= N; i++)
	{
		ans += i * (ya[i] + 1);
	}

	cout << ans << endl;
}



Measured memory_bytes: 81736
n, k = gets.chomp.split(" ").map{|i| i.to_i}
d = gets.chomp.split(" ").map{|i| i.to_s}
for i in n...1000000
  ok = true
  i.to_s.chars{|c|
    if d.include?(c)
      ok = false
      break
    end
  }
  if ok
    puts i
    exit
  end
end


Measured memory_bytes: 1788
using System;
using System.Collections.Generic;
using System.Linq;

namespace abc079_c
{
    class Program
    {
        static void Main(string[] args)
        {
            var ABCDs = GetStr();
            var ABCD = new List<int>();
            foreach(var c in ABCDs) 
                ABCD.Add(int.Parse(c.ToString()));

            for (int i = 0; i <= 1; i++) 
                for (int j = 0; j <= 1; j++)
                    for (int k = 0; k <= 1; k++)
                    {
                        int r = ABCD[0];
                        r += i == 0 ? ABCD[1] : -1 * ABCD[1];
                        r += j == 0 ? ABCD[2] : -1 * ABCD[2];
                        r += k == 0 ? ABCD[3] : -1 * ABCD[3];
                        if (r == 7)
                        {
                            Console.WriteLine(ABCD[0] + (i == 0 ? "+" : "-") + ABCD[1] + (j == 0 ? "+" : "-") + ABCD[2] + (k == 0 ? "+" : "-") + ABCD[3] + "=7");
                            return;
                        }
                    }
        }

        public static string GetStr() => Console.ReadLine();
        public static int GetInt() => int.Parse(Console.ReadLine());
        public static long GetLong() => long.Parse(Console.ReadLine());
        public static double GetDouble() => double.Parse(Console.ReadLine());
        public static decimal GetDecimal() => decimal.Parse(Console.ReadLine());

        public static List<string> GetStrList() => Console.ReadLine().Split(' ').ToList();
        public static List<int> GetIntList() => Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
        public static List<long> GetLongList() => Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
        public static List<double> GetDoubleList() => Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToList();
        public static List<decimal> GetDecimalList() => Console.ReadLine().Split(' ').Select(x => decimal.Parse(x)).ToList();

    }
}


Measured memory_bytes: 11220
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    char a[100];
    int n,i,sum,max;
    sum=0;max=0;
    scanf("%d",&n);
    getchar();
    for(i=0;i<n;i++)
    {
        scanf("%c",&a[i]);
    }
    for(i=0;i<n;i++)
    {
        if(a[i]=='D') sum=sum-1;
        else sum=sum+1;
        if(sum>max) max=sum;

    }
    printf("%d",max);
    return 0;
}

Measured memory_bytes: 128
ABCD = input()
A, B, C, D = (int(ABCD[i]) for i in range(4))
op = ['+', '-']
for i in range(2):
    if i == 0:
        W = A + B
    else:
        W = A - B
    for j in range(2):
        if j == 0:
            X = W + C
        else:
            X = W - C
        for k in range(2):
            if k == 0:
                Y = X + D
            else:
                Y = X - D
            if Y == 7:
                print(A, op[i], B, op[j], C, op[k], D, '=7', sep='')
                exit()


Measured memory_bytes: 3188
MOD = 10 ** 9 + 7
MAX = 200000 + 5
fact = [1 for _ in range(MAX)]
finv = [1 for _ in range(MAX)]
for i in range(2, MAX):
    fact[i] = fact[i - 1] * i % MOD
    finv[i] = pow(fact[i], MOD-2, MOD)

def comb(n: int, k: int) -> int:
    if n < k or n < 0 or k < 0:
        return 0
    return (fact[n] * finv[k] % MOD) * finv[n-k] % MOD

n, m, k = map(int, input().split())

ans = 0
for i in range(n):
    for j in range(m):
        a = j * (j+1) // 2
        b = (m-1-j) * (m-1-j+1) // 2
        ans += (a + b) * i + m * (i*(i+1)//2) + a
        ans %= MOD

ans *= comb(n*m-2, k-2)
ans %= MOD

print(ans)


Measured memory_bytes: 19056
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<cmath>
using namespace std;
typedef long long ll;
#define N 100005
int main()
{
    int n,m,i,j,k,l;
    int T,unit;
    int z,y,x1,y1;
    int ans1=0,ans2=0;
    int n1,n2;
    char x[105];
    scanf("%s",&x);
    for(i=0;i<strlen(x);i++)
    {
        if(i%2==0&&x[i]=='L'||i%2==1&&x[i]=='R')
        {
            ans1=1;
            break;
        }
    }
        if(ans1)
            printf("No\n");
        else
            printf("Yes\n");
    return 0;
}


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

template<typename T>
istream& operator >> (istream& istr, vector<T>& v){
    for(T& x: v) istr >> x;
    return istr;
}

template<typename T, typename U>
istream& operator >> (istream& istr, pair<T,U>& p){
    istr >> p.first >> p.second;
    return istr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<T>& v){
    if(!v.empty()){
        ostr << v.front();
        for(auto itr = ++v.begin(); itr != v.end(); itr++)
            // ostr << *itr;
            ostr << " " << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, pair<T,U>& p){
    // ostr << p.first << p.second;
    // ostr << p.first << ", " << p.second;
    ostr << "(" << p.first << ", " << p.second << ")";
    return ostr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<vector<T>>& vv){
    if(!vv.empty()){
        ostr << vv.front();
        for(auto itr = ++vv.begin(); itr != vv.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, vector<pair<T,U>>& vp){
    if(!vp.empty()){
        ostr << vp.front();
        for(auto itr = ++vp.begin(); itr != vp.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

typedef long long ll;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<double> vd;
// vll v(n); v[i]=x;
typedef vector<vll> vvll;
typedef vector<vc> vvc;
typedef vector<vd> vvd;
// vvll v(m,vll(n)); v[i][j]=x;
typedef pair<ll,ll> pll;
typedef pair<double,double> pd;
typedef vector<pll> vpll;
typedef vector<pd> vpd;
// vpll v(n); v[i]=make_pair(x,y); v[i].first/second;
// v.front() : v[0]
// v.back()  : v[v.size()-1]

#define PI 3.1415926535897932
#define EPS 1e-12
#define INF ((ll)1e+12)
#define REP(i,n) for(ll i=0; i<(n); i++)
#define RREP(i,n) for(ll i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=(a); i<=(b); i++)
#define FORR(i,a,b) for(ll i=(b); i>=(a); i--)
#define fix(x) cout << fixed << setprecision(x)
#define dump(x) cout << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()

template<typename T> T sum(vector<T>& v){return accumulate(all(v), (T)0);}
template<typename T> inline void sort(vector<T>& v){sort(all(v));}
template<typename T> inline void rsort(vector<T>& v){sort(all(v), greater<T>());}
template<typename T> inline void chmin(T& a, T b){if(a>b) a=b;}
template<typename T> inline void chmax(T& a, T b){if(a<b) a=b;}

int main(){
    ll n, ans = 0;
    cin >> n;
    vll a(n);
    map<ll, ll> l;

    cin >> a;
    REP(i,n) l[i+1+a[i]]++;
    // for(auto& [key, val] : l) cout << key << "=>" << val << endl;
    REP(i,n){
        if(l[i+1-a[i]]>0) ans += l[i+1-a[i]];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 27448
/*Shivam Bhalla */
/* f2016941@pilani.bits-pilani.ac.in */



#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iostream>
#include <string>
#include <cmath>
#include <cassert>
#include <bits/stdc++.h>
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;
long long maxv = 1e9;

int main()
{
  int N;
  cin>>N;
  int A;
  int maxi=INT_MIN;
  int total=0;
  for(int i=0;i<N;i++){
    cin>>A;
    total+=A;
    if(A>maxi)
      maxi=A;
  }
  if(total-maxi>maxi)
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
class Simple
{
    //////////////////////////////
    void Solve() {
        //input
        var a = io.String;
        var b = io.String;
        //cal
        var num = int.Parse(a + b);
        var f = (int)Math.Pow((int)Math.Sqrt(num), 2) == num;
        //ret
        Console.WriteLine(f ? "Yes" : "No");
    }
    //////////////////////////////
    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) { new Simple().Stream(); }
    void Stream() { Solve(); io.writeFlush(); }
}
class SimpleIO
{
    string[] nextBuffer;
    int BufferCnt;
    char[] cs = new char[] { ' ' };
    StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    public SimpleIO() {
        nextBuffer = new string[0];
        BufferCnt = 0;
        Console.SetOut(sw);
    }
    public string Next() {
        if (BufferCnt < nextBuffer.Length)
            return nextBuffer[BufferCnt++];
        string st = Console.ReadLine();
        while (st == "")
            st = Console.ReadLine();
        nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        BufferCnt = 0;
        return nextBuffer[BufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void writeFlush() { Console.Out.Flush(); }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    string S;
    cin >> S;
    int N = S.length();

    int right = N-1;
    while(right >= 0){
        if(right >= 5 && S.substr(right - 5, 6) == "eraser"){
            right -= 6;
        }
        else if(right >= 4 && S.substr(right - 4, 5) == "erase"){
            right -= 5;
        }
        else if(right >= 6 && S.substr(right - 6, 7) == "dreamer"){
            right -= 7;
        }
        else if(right >= 4 && S.substr(right - 4, 5) == "dream"){
            right -= 5;
        }
        else {
            printf("NO\n");
            return 0;
        }


    }

    printf("YES\n");
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
using ll = long long;
using ii = pair<int, int>;

vector<int> G[100001];
ii DP[100001][11];

int main() {
    if (fopen("in", "r")) freopen("in", "r", stdin), freopen("out", "w", stdout);
    ios_base::sync_with_stdio(0), cin.tie(0);

    int N, M; cin >> N >> M;
    while (M--) {
        int a, b; cin >> a >> b;
        G[a].push_back(b), G[b].push_back(a);
    }

    int Q; cin >> Q;
    for (int i = 0; i < Q; ++i) {
        int v, d, c; cin >> v >> d >> c;
        DP[v][d] = max(ii(i, c), DP[v][d]);
    }

    for (int d = 10; d > 0; --d)
        for (int u = 1; u <= N; ++u)
            for (int v : G[u]) DP[v][d-1] = max(DP[u][d], DP[v][d-1]);

    for (int u = 1; u <= N; ++u) {
        ii ans(0, 0);
        for (int d = 0; d <= 10; ++d) ans = max(DP[u][d], ans);
        cout << ans.s << '\n';
    }
}

Measured memory_bytes: 17652
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



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

  sort(a.begin(), a.end());
  vector<pair<int, int>> ans;
  int res1 = a[0], idx1 = lower_bound(a.begin(), a.end(), 0) - a.begin();
  chmax(idx1, 1);
  FOR(i, idx1, n - 1) {
    ans.push_back({res1, a[i]});
    res1 -= a[i];
  }
  int res2 = a[n - 1], idx2 = lower_bound(a.begin(), a.end(), 0) - a.begin();
  chmin(idx2, n - 1);
  FOR(i, 1, idx2) {
    ans.push_back({res2, a[i]});
    res2 -= a[i];
  }
  ans.push_back({res2, res1});
  int sum = res2 - res1;
  cout << sum << endl;
  rep(i, n - 1) cout << ans[i].first << ' ' << ans[i].second << endl;


  
  return 0;
}

Measured memory_bytes: 3188
N = int(input())
m = N % 10
if m == 2 or m == 4 or m == 5 or m == 7 or m == 9:
  ret = 'hon'
elif m == 0 or m == 1 or m == 6 or m == 8:
  ret = 'pon'
else:
  ret = 'bon'
  
print(ret)

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

int main(){
	int a,b,c,d,e;
  	cin >> a >> b >> c >> d >> e;
  	if (a==0){
    	cout << 1 << endl;
      return 0;
    }
  	else if (b==0){
    	cout << 2 << endl;
      return 0;
    }
  	else if (c==0){
    	cout << 3 << endl;
      return 0;
    }
  	else if (d==0){
    	cout << 4 << endl;
      return 0;
    }
  	else if (e==0){
    	cout << 5 << endl;
      return 0;
    }
}

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

int main()
{
  long long n, k, s = 0;
  cin >> n >> k;
  long long a[n];
  for(long long i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for(long long i = 0; i < n - k; i++) s += a[i];
  cout << s;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 1010
 
struct Point{
  double x,y;
  Point(){}
  Point(double x,double y) : x(x),y(y) {}
};
 
int N,X,Y;
vector<int> G[MAX];
 
double getDist(Point &a,Point &b){
  return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));
}
 
void init(){
  for(int i = 0 ; i < MAX ; i++){
    G[i].clear();
  }  
}
 
void solve(){
  int d[MAX] = {0};
  queue<int> Q; Q.push(0);
  bool can = true;
  
  while(!Q.empty()){
    int v = Q.front(); Q.pop();
    for(int i = 0 ; i < (int)G[v].size() ; i++){
      int to = G[v][i];
      if(d[to] == 0){
        d[to] = d[v] + 1;
        if(v > 0 && X > Y){
          can = false;
          break;
        }
        Q.push(to);
      }
    }
    if(!can){ break; }
  }
  
  if(can){
    cout << *max_element(d+1,d+N+1)*X << endl;
  }else{
    cout << "You're always welcome!" << endl;
  }
}
 
int main(){
  int Tc;
  cin >> Tc;
  while(Tc--){
    init();
    Point sp;
    vector<Point> p;
    cin >> N >> X >> Y;
    cin >> sp.x >> sp.y;
    p.resize(N);
    for(int i = 0 ; i < N ; i++){
      cin >> p[i].x >> p[i].y;
      if(getDist(sp,p[i]) <= 10){
        G[0].push_back(i+1);
      }
    }
    for(int i = 0 ; i < N ; i++){
      for(int j = 0 ; j < N ; j++){
        if(i == j){ continue; }
        if(getDist(p[i],p[j]) <= 50){
          G[i+1].push_back(j+1);
        }
      }
    }
    solve();
  }
  return 0;
}

Measured memory_bytes: 5316
N,M = map(int,input().split())

a = 0
b = M+1

for i in range(M//2):
    a += 1
    b -= 1
    print(a,b)

a = M
b = 2*M+2

for i in range((M+1)//2):
    a += 1
    b -= 1
    print(a,b)


Measured memory_bytes: 9180
#include<bits/stdc++.h>
using namespace std;
int n , m , res;
int dx[4] = {-1,+1,0,0};
int dy[4] = {0,0,-1,+1};
int op[1005][1005];
char c[1005][1005];
queue<pair<int,int > > q; 
bool check(int x, int y){
	return (x >= 1 && x <= n && y >= 1 && y <= m);
}
int main(){
	cin >> n >> m;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j ++){
			cin >> c[i][j];
			op[i][j] = -1;
			if(c[i][j] == '#'){
				q.push({i,j}), op[i][j] = 0;
			}
		}
	}
	while(q.size()){
		int x = q.front().first;
		int y = q.front().second;
		q.pop();
		for(int i = 0; i < 4; i ++)
			if(op[x + dx[i]][y + dy[i]] == -1 && (check(x + dx[i] , y + dy[i]))){
				q.push({x + dx[i],y + dy[i]});
				op[x + dx[i]][y + dy[i]] = op[x][y] + 1; 
			}
	} 
	for(int i = 1; i <= n; i ++){
		for(int j = 1; j <= m; j ++){
			res = max(res , op[i][j]);
		}
	}
	cout << res << "\n";
}

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

int main(){
    int N;
    cin >> N;
    int H[N];
    for(int i = 0; i < N; i++) cin >> H[i];
    
    int ans = 0;
    
    for(int i = 1; i < N; i++){
        if(H[i-1] - H[i] >= 0){
            ans += H[i-1] - H[i];
        }else{
            ans = 0;
        }if(ans >= 2){
            cout << "No" << "\n";
            return 0;
        }
    }
        cout << "Yes" << "\n";
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  bool flag1 = false,flag2 = false,flag3 = true;
  if(s[0] == 'A'){
    flag1 = true;
    s[0] = 'a';
  }
  for(int i=2 ;i<s.size()-1 ;i++){
    if(s[i] == 'C'){
      flag2 = true;
      s[i] = 'c';
      break;
    }
  }
  for(int i=0 ;i<s.size() ;i++){
    if(isupper(s[i])){
      flag3 = false;
    }
  }
  cout << (flag1&&flag2&&flag3?"AC":"WA") << endl;
}

Measured memory_bytes: 256
//
//  main.cpp
//  Sumo
//
//  Created by Hashizo on 2019/06/01.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

int main(int argc, const char * argv[]) {
    char s[16];
    int loss = 0;
    memset(s,'o',sizeof(s));
    
    cin >> s;

    REP(i,15){
        if(s[i] =='x'){
            loss++;
        }
    }

    
    if (loss < 8) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    
    return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll Inf = 1e18;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

vector<vector<int> > g;
vector<int> c;

void dfs(int s = 0, int p = -1) {
    rep (i, g[s].size()) {
        int v = g[s][i];
        if (v == p) continue;
        c[v] += c[s];
        dfs(v, s);
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n, q;
    cin >> n >> q;
    g.resize(n);
    c = vector<int>(n);
    rep (i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    rep (i, q) {
        int p, x;
        cin >> p >> x;
        c[p - 1] += x;
    }
    dfs();
    rep (i, n) {
        cout << c[i];
        if (i < n - 1) cout << " ";
        else cout << endl;
    }
    
    return 0;
}



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

#define M 1000000007
#define pb emplace_back
#define f first
#define s second
#define rep(i, st, ed) for(ll i=st; i<ed; ++i)
#define repn(i, st, ed) for(ll i=st; i<=ed; ++i)
#define repb(i, ed, st) for(ll i=ed; i>=st; --i)
#define all(v) v.begin(),v.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define PI acosl(-1.0)
#define mp(a, b) make_pair(a, b)
#define eps 1e-9

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vec;
typedef vector<pll> vecp;
typedef map<ll, ll> mpll;


const int N = 1e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << to_string(H) << endl;
  debug_out(T...);
}
#define LOCAL 3
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:" << endl, debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif



void solve()
{
    ll n;
    cin>>n;
    bool f = true;
    rep(i, 0, n){
    	ll x;
    	cin>>x;
    	if(x%2 == 0){
    		if(x%3 != 0 && x%5 != 0) f = false;
    	}
    }
    if(f) cout<<"APPROVED"<<endl;
    else cout<<"DENIED"<<endl;
}


int main()
{
    ll Tests = 1;
    //cin>>Tests;
    while(Tests--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
"""

石の数が最大の内数字が大きいものから取り除いていくのが最適？

前にあるできるだけ数が多いものに譲っていく

優先度付きキューでaが大きい方からpopしていく？

numが現在より小さい→以降する
そうでない = 現在のnumよりは低いが次のnumよりは大きい
→次のnumが確定した瞬間に差分を計算して定常減少用に入れる

最後は残りを全部1に入れて終わり
"""
import heapq

N = int(input())

ans = [0] * N

a = list(map(int,input().split()))

q = []

for i,na in enumerate(a):

    heapq.heappush(q,[-1 * na , i])

nowa , nowi = heapq.heappop(q)
nowa *= -1
always = 0
tempq = [nowa]

for i in range(N-1):

    nexa , nexi = heapq.heappop(q)
    nexa *= -1

    if nexi > nowi:
        tempq.append(nexa)

    else:
        nowpl = always * (nowa - nexa)

        for j in tempq:
            nowpl += j - nexa

        always += len(tempq)
        tempq = [nexa]

        ans[nowi] += nowpl

        nowa = nexa
        nowi = nexi

ans[0] = sum(a) - sum(ans)

print ("\n".join(map(str,ans)))

Measured memory_bytes: 99252
/*
      author : nishi5451
      created: 11.08.2020 20:44:38
*/

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


int main(){
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(),a.end());
    cout << abs(a[1]-a[0]) + abs(a[2]-a[1]) << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,sum=0;
	cin>>n;
	int w[n];
	for(int i=0;i<n;i++)
		cin>>w[i];
	int mini = 1e9;
	int sum1 = 0;
	for(int i=0;i<n;i++)
	{
		sum1+=w[i];
		int sum2 = 0;
		for(int j=n-1;j>i;j--)
		{
			sum2+=w[j];
		}
		mini = min(mini,abs(sum1-sum2));
	}
	cout<<mini<<endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main{ // 

	public static void main(String args[]) {
		ConsoleScanner cin = new ConsoleScanner();
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	static long now() {
		return System.currentTimeMillis();
	}

	static void trace(Object... objects) {
		assert null != System.out.format("trace:%s\n", Arrays.deepToString(objects));
	}

	private static void solve(ConsoleScanner cin, PrintWriter cout) {
		// assert solve(1) == 1;

		int n = cin.nextInt();

		int[] a = new int[n];
		for (int i = 0; i < a.length; i++)
			a[i] = cin.nextInt();

		long start = now();

		long ans = solve(n, a);
		cout.println(ans);

		trace("elapsed", now() - start);
	}

	private static long solve(int n, int[] a) {
		Arrays.sort(a);
		long ans = 1;
		long sides = 0;
		for (int i = n - 2; i >= 0; i--) {
			if (a[i] != a[i + 1])
				continue;
			sides += 2;
			ans *= a[i];
			i -= 1;
			if (sides == 4)
				break;
		}
		if (sides == 4)
			return ans;
		else
			return 0;
	}

	static class ConsoleScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			try {
				while (!st.hasMoreElements())
					st = new StringTokenizer(br.readLine());
				return st.nextToken();
			} catch (IOException e) {
				throw new AssertionError(e);
			}
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}

}


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

int main(){
  int n;
  cin >> n;
  vector<pair<pair<string,int>,int>> pairs(n);
  //multimap<string, int> mp;
  //multimap<int, string, greater<int>> mmp;
  string s;
  int tmp;
  for(int i=0; i<n; i++){
    cin >> s >> tmp;
    pairs.at(i) = make_pair(make_pair(s,-1*tmp),i+1);
    //mp[make_pair(tmp,s)] = i+1;
    //mmp.insert(make_pair(tmp,s));
  }
  sort(pairs.begin(),pairs.end());
  for(auto const& entry: pairs){
    cout << entry.second << endl;
  }
}
  
  


Measured memory_bytes: 256
def solve(price, usable):
  ans = price
  usable_set = set(usable)
  while True:
    ans_set = {int(i) for i in list(str(ans))}
    if ans_set <= usable_set:
      return ans
    ans += 1

if __name__ == "__main__":
  n,k = map(int,input().split())
  d_list = [int(i) for i in input().split()]

  usable = [int(i) for i in range(10) if i not in d_list]
  print(solve(n, usable))


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

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

	bool e[26];

	for (int i = 0; i < 26; i++)
	{
		e[i] = false;
	}
	for (int i = 0; i < s.size(); i++)
	{
		if (e[s[i] - 97])
		{
			cout << "no" << endl;
			return 0;
		}
		e[s[i] - 97] = true;
	}
	cout << "yes" << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{

	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		int a[] = new int[3];
		for (int i = 0; i < a.length; i++)
			a[i] = in.nextInt();

		for (int i = a.length - 1; i > 0; i--)
		{
			for (int j = i - 1; j >= 0; j--)
			{
				if (a[j] > a[i])
				{
					int temp = a[i];
					a[i] = a[j];
					a[j] = temp;
				}
			}
		}

			for (int q = 0; q < a.length-1; q++)
		{
			System.out.print(a[q] + " ");
		}
		System.out.println(a[a.length-1]);


	}

}

Measured memory_bytes: 26332
#include <bits/stdc++.h>
#define pr pair<long long int, long long int>
using namespace std;
long long int mod = 1e9 + 7;

int main()
{
    long long int n;
    cin >> n;
    if(n % 2 == 0)
        cout << n / 2 << endl;
    else
        cout << (n + 1) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e2 + 10;
int cnt[N * 100];
int a[N];
int p[N][11];
void init()
{
	for (int i = 1; i < N * 100; i++)
	{
		cnt[i] = cnt[i >> 1] + (i & 1);
	}
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	init();
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		int o = 0;
		for (int j = 0; j < 10; j++)
		{
			int x;
			cin >> x;
			o = o << 1 | x;
		}
		a[i] = o;
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 0; j <= 10; j++)
		{
			cin >> p[i][j];
		}
	}
	int ans = -INF;
	for (int o = 1; o < (1 << 10); o++)
	{
		int tot = 0;
		for (int j = 1; j <= n; j++)
		{
			tot += p[j][cnt[a[j] & o]];
		}
		ans = max(ans, tot);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main() {
	ll a,b,c;
	cin>>a>>b>>c;
	cout << c/a*b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int a, b, x;
  cin >> x >> a >> b;
  if(b<=a){
    cout << "delicious\n";
  }
  else if(b-a <= x){
    cout << "safe\n";
  }
  else{
    cout << "dangerous\n";
  }
}

Measured memory_bytes: 256
n,w=map(int,input().split())
val=[]
we=[]
for i in range(n):
  a,b=map(int,input().split())
  we.append(a)
  val.append(b)
dp=[[0 for _ in range(w+1)]for _ in range(n+1)]
for i in range(n+1):
  for j in range(w+1):
    if i==0 or j==0:
      continue
    if we[i-1]>j:
      dp[i][j]=dp[i-1][j]
    else:
      dp[i][j]=max(dp[i-1][j],val[i-1]+dp[i-1][j-we[i-1]])
print(dp[n][w])


Measured memory_bytes: 171912
#include <iostream>
#include <vector>
#include <cmath>

int ans = 10000;
int n;
std::string s;

int main() {
    std::string s;
    std::cin >> s;
    for (int i = 0; i + 2 < s.size(); i++) {
        int x = std::stoi(s.substr(i, 3));
        int res= std::abs(x - 753);
        if (res < ans) {
            ans = res;
        }
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

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


Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
int ans[1050],prime[1050];

int main()
{
	int n;
	memset(prime,0,sizeof(prime));
	prime[1] = 1;
	for(int i = 2;i < 35;i++)
	{
		if(!prime[i])
		for(int j = i*i;j < 1050;j=i+j)
		{
			prime[j] = 1;
		}
	}
	while(~scanf("%d",&n))
	{
		memset(ans,0,sizeof(ans));
		for(int i = 2;i <= n;i++)
		{
			if(prime[i])
			{
				int m = i;
				for(int j = 2;j < i;)
				{
					if(prime[j]){
						j++;continue;
					} 
					if(m%j==0)
					{
						ans[j]++;
						m = m/j;
					}
					else j++;
					if(!prime[m])
					{
						ans[m]++;
						break;
					}
				}
			}
			else ans[i]++;
		}
		long long sum = 1;
		for(int i = 2;i <= n;i++)
		{
			sum = sum*(ans[i]+1)%1000000007;
		}
		printf("%lld\n",sum);
	}
return 0;
}

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

int main() {
	// your code goes here
	int n,d,count = 0;
	cin >> n >> d;
	for (int i = 0; i < n;i++) {
	    double x,y;
	    cin >> x >> y;
	    if (sqrt (pow(x,2) + pow (y,2)) <= d) {
	        count++;
	    }
	}
	cout << count << endl;
}


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

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

int nums[5];
int k;

int main() {
  scanf("%d %d %d %d %d %d", &nums[0], &nums[1], &nums[2], &nums[3], &nums[4], &k);
  bool flag = false;
  REP(i, 5) {
    for (int j = i + 1; j < 5; j++){
      if (nums[j] - nums[i] > k) flag = true;
    }
  }
  if (flag) {
    printf(":(\n");
  } else {
    printf("Yay!\n");
  }
  
  return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    int d = n % 10;
    if (d == 3) {
        cout << "bon";
    }
    else if (d == 0 || d == 1 || d == 6 || d == 8) {
        cout << "pon";
    }
    else {
        cout << "hon";
    }
    //cout << "Output sentence"; 
    return 0;
}
/*
mod = int(1e9+7)
def add(a, b):
    c = a + b
    if c >= mod:
        c -= mod
    return c

def main():
    #N, K = map(int,raw_input().split())
    n = int(raw_input())
    
    d = n % 10
    
    if d == 3:
        print('bon')
    elif d == 0 or d == 1 or d == 6 or d == 8:
        print('pon')
    else:
        print('hon')
        
    
main()
*/

Measured memory_bytes: 3532
//{Headers
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<algorithm>
#include<list>
#include<queue>
#include<deque>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<bitset>

using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
#define mp(x,y) make_pair(x,y)
typedef long long ll;
//}

const int MAXN=10,INF=0x3f3f3f3f;
int N,M,g[MAXN][MAXN];

void init(){
    memset(g,INF,sizeof g);
    for(int i=0;i<MAXN;i++) g[i][i]=0;
}

void solve(){
    for(int k=0;k<N;k++) for(int i=0;i<N;i++) for(int j=0;j<N;j++)
        g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
    int ans=-1,ansT=INF;
    for(int i=0;i<N;i++){
        int sum=0;
        for(int j=0;j<N;j++) sum+=g[i][j];
        if(sum<ansT){
            ans=i;
            ansT=sum;
        }
    }
    printf("%d %d\n",ans,ansT);
}

int main(void){
//    freopen("in.txt","r",stdin);
    int a,b,c;
    while(~scanf("%d",&M) && M!=0){
        init();
        N=1;
        for(int i=0;i<M;i++){
            scanf("%d%d%d",&a,&b,&c);
            N=max(N,1+max(a,b));
            g[a][b]=g[b][a]=c;
        }
        solve();
    }
    return 0;
}

/*
Sample Input
6
0 1 80
1 2 20
0 2 60
2 3 50
3 4 60
1 4 90
2
0 1 1
1 2 1
0
Output for the Sample Input
2 240
1 2
*/



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

int main(){
  ll n;
  cin>>n;
  double p[n+1];
  for(ll i=1; i<=n; i++){
    cin>>p[i];
  }
  double dp[n+1][n+1];
  memset(dp,0.0, sizeof(dp));
  dp[0][0]=1.0;
  for(ll i=1; i<=n; i++){
    for(ll j=0; j<=i; j++){
      if(j==0){
        dp[i][j] = dp[i-1][j]*(1.0-p[i]);
      }
      else{
        dp[i][j] = dp[i-1][j]*(1.0-p[i]) + dp[i-1][j-1]*p[i];
      }
    }
  }
  double ans=0.0;
  for(ll i = (n+1)/2; i<=n; i++){
    ans += dp[n][i];
  }
  cout<<std::setprecision(10) <<ans<<"\n";
  return 0;
}


Measured memory_bytes: 74008
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    if (N == 1){
      System.out.println("Hello World");
    }
    else if (N == 2){
      int A = sc.nextInt();
      int B = sc.nextInt();
      System.out.println(A + B);
    }
  }
}

Measured memory_bytes: 23380
#import<cstdio>
#define k 1024
#define r(a) for(int i=0;i<a;i++)
#define s(a) scanf("%d",a);
#define m(a,b) a=a<b?a:b
int w,n,m,c[k],d[k],p[k];main(){s(&n)s(&m)r(n)s(d+i)r(m)s(c+i)r(n)p[i]=1e9;r(m*n)w=i%n,m(p[w],p[w+1]+c[i/n]*d[n-w-1]);printf("%d\n",p[0]);}

Measured memory_bytes: 1036
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  [n, x, t] <- getIntList
  let ans = (n+x-1) `div` x * t
  print ans


Measured memory_bytes: 3676
#include <bits/stdc++.h>
#include <variant>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n;
  cin>>n;
  --n;
  ll p = 1;
  ll cnt = 0;
  while (true) {
    p *= 26;
    ++cnt;
    if (n < p) {
      string ans = "";
      REP(i,cnt) {
        ans += n % 26 + 'a';
        n /= 26;
      }
      reverse(ALL(ans));
      cout<<ans<<endl;
      return 0;
    }
    n -= p;
  }
  return 0;
}


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

long long L,A,B,M;

template<class K>
vector<vector<K>> matmul(const vector<vector<K>> &A,const vector<vector<K>> &B){
    vector<vector<K>> C(A.size(),vector<K>(B[0].size(),K()));
    for (int i=0;i<A.size();++i)
        for (int j=0;j<B[0].size();++j)
            for (int k=0;k<B.size();++k)
                C[i][j]=(C[i][j]+A[i][k]*B[k][j]%M)%M;
    return C;
}

template<class K>
vector<vector<K>> matpow(vector<vector<K>> A,long long n){
    vector<vector<K>> res(A.size(),vector<K>(A.size(),K()));
    for (int i=0;i<A.size();++i) res[i][i]=K(1);
    while(n){
        if (n&1) res=matmul(res,A);
        A=matmul(A,A); n>>=1;
    }
    return res;
}

int digit(long long n){
    int res=0;
    while(n>0){n/=10; ++res;}
    return res;
}

long long modpow(long long a,long long n){
    long long res=1;
    while(n>0){
        if (n&1) res=res*a%M;
        a=a*a%M; n>>=1;
    }
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> L >> A >> B >> M;
    vector<pair<long long,int>> ds;
    ds.emplace_back(1,digit(A));
    for(int i=digit(A)+1;;++i){
        long long n=((long long)pow(10,i-1)-A+B-1)/B+1;
        if (L<n) break;
        if (digit(A+(n-1)*B)!=i) continue;
        ds.emplace_back(n,i);
        if (i==18) break;
    }
    ds.emplace_back(L+1,19);
    int s=ds.size();
    long long ans=0;
    vector<vector<long long>> po(3,vector<long long>(3))
                        ,cal={{1,1,0},{0,1,1},{0,0,1}}
                        ,init={{0},{1},{B%M}}
                        ,result(3,vector<long long>(1));
    for (int i=0;i<s-1;++i){
        long long n=ds[i+1].first-ds[i].first,d=ds[i].second;
        cal[0][0]=modpow(10,d);
        po=matpow(cal,n);
        init[0][0]=ans,init[1][0]=(A%M+(ds[i].first-1)*B%M)%M;
        ans=matmul(po,init)[0][0];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
package main

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

func main() {
	fsc := NewFastScanner()

	N := fsc.NextInt()
	var A []int
	for i := 0; i < N; i++ {
		A = append(A, fsc.NextInt())
	}
	sort.Ints(A)
	fmt.Println(A[len(A)-1] - A[0])
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1024)
	return &FastScanner{r: rdr}
}
func (s *FastScanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *FastScanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *FastScanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *FastScanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *FastScanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *FastScanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

//Max,Min
func IntMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func Int64Max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func Float64Max(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

func IntMin(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func Int64Min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}
func Float64Min(a, b float64) float64 {
	if a > b {
		return b
	}
	return a
}

//Gcd
func IntGcd(a, b int) int {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return IntGcd(b, a%b)
}
func Int64Gcd(a, b int64) int64 {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return Int64Gcd(b, a%b)
}

func IntAbs(a int) int {
	if a < 0 {
		a *= -1
	}
	return a
}

func Int64Abs(a int64) int64 {
	if a < 0 {
		a *= -1
	}
	return a
}


Measured memory_bytes: 640
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    int n; cin>>n;
    vector<int> l(n);
    rep(i,n) cin>>l[i];
    sort(al(l));
    int sum=0;
    rep(i,n-1) sum+=l[i];
    cout<<(sum>l[n-1] ? "Yes" : "No");
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b;
	scanf("%d ",&a);
	scanf("%d",&b);
	if(a<b){
		printf("a < b\n");
	}
	else if(a>b){
		printf("a > b\n");
	}
	else{
		printf("a == b\n");
	}
	return 0;
}



Measured memory_bytes: 2060