akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const long long int INF =  100000000000000000;
vector<vector<long long int>> d;
void warshall_floyd(int N) {
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            for(int k = 0; k < N; k++) {
                if(d[j][i] != INF && d[i][k] != INF)
                d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
            }
        }
    }
}
int main() {
    int V, E;
    cin >> V >> E;
    d.assign(V, vector<long long int>(V, INF));
    for(int i = 0; i < V; i++) {
        d[i][i] = 0;
    }
    for(int i = 0; i < E; i++) {
        int s, t, cost;
        cin >> s >> t >> cost;
        d[s][t] = cost;
    }
    warshall_floyd(V);
    for(int i = 0; i < V; i++) {
        if(d[i][i] < 0) {
            cout << "NEGATIVE CYCLE" << endl;
            return 0;
        }
        d[i][i] = 0;
    }
    for(int i = 0; i < V; i++) {
        for(int j = 0; j < V; j++) {
            if(d[i][j] == INF) {
                cout << "INF";
            } else {
                cout << d[i][j];
            } 
            if(j != V - 1) {
                cout << " ";
            }
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3212
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;

public class Main {


  private static void solve() {
    int k = ni();
    int[] dp = new int[k];

    Deque<Integer> q = new ArrayDeque<>();
    q.add(1);
    Arrays.fill(dp, Integer.MAX_VALUE);
    dp[1] = 0;
    while (q.size() > 0) {
      int v = q.poll();
      int u1 = v * 10 % k;
      int u2 = (v + 1) % k;
      if (dp[u1] > dp[v]) {
        dp[u1] = dp[v];
        q.addFirst(v * 10 % k);
      }
      if (dp[u2] > dp[v] + 1) {
        dp[u2] = dp[v] + 1;
        q.addLast((v + 1) % k);
      }
    }
    System.out.println(dp[0]+1);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 25044
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<ll,ll>
#define vi(x) vector<x>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;

signed main()
{
    fast;
   
    ll n,i,j,k;
    cin>>n>>k;
    ll p[n+2];
    for(i=0;i<n;i++) cin>>p[i];
    ll dp[n+2]={0};
    dp[0] = 0;
    for(i=1;i<n;i++)
    {
    	dp[i] = LONG_MAX;
    	for(j=1;j<=k;j++)
    	{
    		if(i-j >=0) dp[i] = min(dp[i] , dp[i-j] + abs(p[i] - p[i-j]));
    		else break;
    	}
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<string>
//#include<sstream>
using namespace std;
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rep2(i,b) for(ll i=0;i<b;i++)
#define repl(i,a,b) for(ll i=a;i<=b;i++)
#define FastRead ios_base::sync_with_stdio(0);cin.tie(0)
set<int>p;
int main()
{
    int n;
    cin>>n;
    rep2(i,n)
    {
        int x;
        cin>>x;
        p.insert(x);
    }
    cout<<p.size()<<endl;
    return 0;
}

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

int main(){
  char S[4];
  int n,a,b,c,d;

  scanf("%s",&S);

  n = atoi(S);

  d=n%10;
  c=(n%100-d)/10;
  b=(n%1000-c-d)/100;
  a=n/1000;
  
  if(a==b || b==c || c==d){
    printf("Bad");
  }
  else{
    printf("Good");
  }
  
}

Measured memory_bytes: 128
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    S = input()
    T = input()

    ans = 10000

    for i in range(len(S) - len(T) + 1):
        sub = 0
        for j in range(len(T)):
            if S[i + j] != T[j]:
                sub += 1

        ans = min(ans, sub)

    print(ans)


main()


Measured memory_bytes: 68220
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout<<#x<<" "<<x<<"\n";
#define lli long long int
long long int mod= 1000000007,modd=998244353;
int32_t main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);  cout.tie(0);
   char  c;
   cin>>c;
   if(c>=97 && c<=122)
    cout<<"a"<<"\n";
   else
    cout<<"A"<<"\n";

   return 0;
}//main


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



#define         MOD       1000000007
inline void normal(LL &a)
{
    a %= MOD;
    (a < 0) && (a += MOD);
}
inline LL modMul(LL a, LL b)
{
    a %= MOD, b %= MOD;
    normal(a), normal(b);
    return (a*b)%MOD;
}
inline LL modAdd(LL a, LL b)
{
    a %= MOD, b %= MOD;
    normal(a), normal(b);
    return (a+b)%MOD;
}
inline LL modSub(LL a, LL b)
{
    a %= MOD, b %= MOD;
    normal(a), normal(b);
    a -= b;
    normal(a);
    return a;
}
inline LL modPow(LL b, LL p)
{
    LL r = 1;
    while(p)
    {
        if(p&1)
            r = modMul(r, b);
        b = modMul(b, b);
        p >>= 1;
    }
    return r;
}
inline LL modInverse(LL a)
{
    return modPow(a, MOD-2);
}
inline LL modDiv(LL a, LL b)
{
    return modMul(a, modInverse(b));
}

int main()
{
    LL n,a,b,fin1,fin2,i,j;

    cin>>n>>a>>b;


    LL ans = modPow(2ll,n);
    ans = modSub(ans,1ll);
//cout<<ans<<endl;
    fin1 = fin2 = 1;

    for(i=1; i<=a; i++)
    {
         fin1 = modMul(fin1,modMul(n-i+1,modInverse(i)));
    }
    for(i=1; i<=b; i++)
    {
         fin2 = modMul(fin2,modMul(n-i+1,modInverse(i)));
    }

    fin1 = modAdd(fin1,fin2);

    ans  = modSub(ans,fin1);

    cout<<ans<<endl;

}


Measured memory_bytes: 256
// C - Successive Subtraction

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1000000007;
// using mint = modint1000000007;
// const ll MOD = 998244353;
// using mint = modint998244353;

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

	priority_queue<ll, vector<ll>, greater<ll>> positive;
	priority_queue<ll> negative;
	stack<ll> zero;

	for (int i=0; i<N; i++) {
		ll A;
		cin >> A;

		if (A > 0) positive.push(A);
		else if (A < 0) negative.push(A);
		else zero.push(A);
	}

	vector<pair<ll, ll>> ansVec;
	ll x, y;

	while(positive.size() + negative.size() + zero.size() > 2) {
		if (negative.size() == 0 && zero.size() == 0) {
			x = positive.top();
			positive.pop();
			y = positive.top();
			positive.pop();
		} else if (positive.size() == 0 && zero.size() == 0) {
			x = negative.top();
			negative.pop();
			y = negative.top();
			negative.pop();
		} else if (negative.size() == 0 && zero.size() > 0) {
			x = zero.top();
			zero.pop();
			y = positive.top();
			positive.pop();
		} else if (positive.size() == 0 && zero.size() > 0) {
			x = zero.top();
			zero.pop();
			y = negative.top();
			negative.pop();
		} else if (positive.size() > 1) {
			x = negative.top();
			negative.pop();
			y = positive.top();
			positive.pop();
		} else {
			x = positive.top();
			positive.pop();
			y = negative.top();
			negative.pop();
		}

		ansVec.push_back(make_pair(x, y));

		if (x - y > 0) positive.push(x - y);
		else if (x - y < 0) negative.push(x - y);
		else zero.push(0);
	}

	if (positive.size() == 2) {
		y = positive.top();
		x = positive.top();
	} else if (negative.size() == 2) {
		x = negative.top();
		y = negative.top();
	} else if (zero.size() == 2) {
		x = 0;
		y = 0;
	} else if (positive.size() == 1 && negative.size() == 1) {
		x = positive.top();
		y = negative.top();
	} else if (positive.size() == 1 && zero.size() == 1) {
		x = positive.top();
		y = 0;
	} else {
		x = 0;
		y = negative.top();
	}

	ansVec.push_back(make_pair(x, y));

	cout << x - y << endl;

	for (auto ans : ansVec) {
		cout << ans.first << " " << ans.second << endl;
	}

	return 0;
}

Measured memory_bytes: 7264
#include<stdio.h>
     
    int main(){
        int X,A,B,temp=0,save;
        scanf("%d",&X);
        scanf("%d",&A);
        scanf("%d",&B);
     
        if(X>=(A+B) && X<=10000 && A<=1000 && B<=1000 && X>=1 && A>=1 && B>=1){
     
        temp=X-A;
        save=temp%B;
        printf("%d",save);
     }
     return 0;
    }

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int ans,mi1,mi2,mi3;
int main() {
	int k,s;
	cin>>k>>s;
	mi1=min(s,k);
	for(int i=mi1;i>=0;i--){
		mi2=min(s-i,k);
		for(int j=mi2;j>=0;j--){
			mi3=min(s-i-j,k);
			for(int l=mi3;l>=0;l--){
					if(i+j+l==s){
						ans++;
					}
					if(i+j+l<s){
						break;
					}
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    string S; 
    std::cin >> S;
    if(S[5] == '0' && (  S[6] == '1' || S[6] == '2' || S[6] == '3' || S[6] == '4' )  ){
        std::cout << "Heisei" << std::endl;
    }else{
        std::cout << "TBD" << std::endl;
    }
}

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

int main()
{
	const string table[] = {
		"pon",
		"pon",
		"hon",
		"bon",
		"hon",
		"hon",
		"pon",
		"hon",
		"pon",
		"hon"
	};

	int N;
	cin >> N;
	cout << table[N % 10];
}

Measured memory_bytes: 3104
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
from functools import reduce
import sys
import math
import bisect
import random
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return list(map(float, sys.stdin.readline().split()))
def LS():return sys.stdin.readline().split()
def SR(n): return [sys.stdin.readline()[:-1] for i in range(n)]
def IR(n): return [int(sys.stdin.readline()) for i in range(n)]
def LIR(n): return [list(map(int, sys.stdin.readline().split())) for i in range(n)]
def LSR(n): return [list(map(list, sys.stdin.readline().split())) for i in range(n)]
_gcd = lambda x, y: _gcd(y, x%y) if (x%y) else y
_lcm = lambda x, y: x*y // _gcd(x, y)
def gcd(*numbers):
    return reduce(_gcd, numbers)
def lcm(*numbers):
    return reduce(_lcm, numbers)
sys.setrecursionlimit(1000000)
INF = float('inf')
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

d = defaultdict(int)

N = I()
S = SR(N)

for s in S:
    d[str(sorted(s))] += 1

ans = 0
for key in d.keys():
    value = d[key]
    if value >= 2 :
        ans += value*(value-1)//2
    
print(ans)

Measured memory_bytes: 89564
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define NIL -1
typedef long long ll;
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll MOD = 1000000007;

void solve() {

    ll n, result, divide;
    cin >> n;
    result = 0;
    
    if(n % 2 != 0) {
        cout << result << endl;
        return;
    } else {
        divide = 10;
        while( n / divide) {
            result += n / divide;
            divide *= 5;
        }
    }
    cout << result << endl;
    return;
}

int main() {
    solve();
    return 0;

}

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

int gcd(int a,int b) {
    while(b) {
        a %= b;
        swap(a,b);
    }
    return a;
}

int main() {
    long long a,b,g;
    cin >> a >> b;
    g = gcd(a,b);
    cout << (a*b)/g << endl;
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use {
    itertools::Itertools,
    proconio::{fastout, input, marker::*},
    std::cmp::*,
    std::collections::*,
    std::io::Write,
    std::ops::*,
};

macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

#[fastout]
fn main() {
    input! {
        mut s:Bytes,
    }
    let n = s.len();
    if s[0] == b'0' || s[n - 1] == b'1' {
        println!("-1");
        return;
    }
    for i in (0..).take_while(|&i| i < n - 2 - i) {
        if s[i] != s[n - 2 - i] {
            println!("-1");
            return;
        }
    }
    let s = s
        .iter()
        .map(|&b| b as usize - b'0' as usize)
        .collect::<Vec<usize>>();
    println!("{} {}", n - 1, n);
    let mut p = n - 2;
    for v in (0..n - 2).rev() {
        println!("{} {}", v + 1, p + 1);
        if s[v] == 1 {
            p = v;
        }
    }
}


Measured memory_bytes: 3044
a, b, c = [],[],[]
ans = "No"
num = [[0, 1, 2],[3, 4, 5],[6, 7, 8],[0, 3, 6],[1, 4, 7],[2, 5, 8],[0, 4, 8],[2, 4, 6]]
for _ in range(3):
    n = list(map(int,input().split()))
    for i in range(3):
        a.append(n[i])
        
n = int(input())
for j in range(n):
    b.append(int(input()))
    
for k in range(9):
    for l in b:
        if a[k] == l:
            c.append(int(k))

for m in range(8):
    q = 0
    for p in range(3):
        if num[m][p] in c:
            q += 1
    if q == 3:
        ans = "Yes"
print(ans)

Measured memory_bytes: 9256
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(N: int, A: "List[int]"):
    A.sort(reverse=True)
    ret = 0
    #tmp = [A[0], A[1]]
    #for i in range(2, N):
    #    ret

    ret += A[0]
    cnt = 1
    i = 1
    while cnt < N - 1:
        #print(cnt, i, A[i])
        ret += A[i]
        cnt += 1
        if cnt % 2 == 1:
            i += 1
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


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

vector<int> di = {0, 0, -1, 1};
vector<int> dj = {1, -1, 0, 0};

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

    int h,w;
    cin >> h >> w;

    int si, sj;
    cin >> si >> sj;
    int ti, tj;
    cin >> ti >> tj;
    --si, --sj, --ti, --tj;

    vector<string> field(h);
    rep(i,h) cin >> field[i];

    const int INF = 1e9;
    vector<vector<int>> dist(h, vector<int>(w, INF));
    deque<pair<int,int>> q;

    dist[si][sj] = 0;
    q.emplace_back(si, sj);

    while(!q.empty()) {
        int f = q.front().first;
        int s = q.front().second;
        q.pop_front();
        int d = dist[f][s];

        rep(i, 4) {
            int ni = f + di[i];
            int nj = s + dj[i];
            if(ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
            if(field[ni][nj] == '#') continue;
            if(dist[ni][nj] <= d) continue;
            dist[ni][nj] = d;
            q.emplace_front(ni,nj);
        }

        for(int ai = -2; ai <= 2; ++ai) {
            for(int aj = -2; aj <= 2; ++aj) {
                int bi = f + ai;
                int bj = s + aj;
                if(bi < 0 || bi >= h || bj < 0 || bj >= w) continue;
                if(field[bi][bj] == '#') continue;
                if(dist[bi][bj] <= d+1) continue;
                dist[bi][bj] = d+1;
                q.emplace_back(bi, bj);
            }
        }
    }
    int ans = dist[ti][tj];
    if(ans == INF) ans = -1;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

static const double pi = 3.141592653589793;

double Cos(double D)
{
    return cos(pi/180 * D);
}

int main()
{
    double A,B,H,M;
    cin >> A >> B >> H >> M;

    printf("%13.9f",sqrt(A*A + B*B - 2.0 * A * B * Cos(min(H*30 - M*5.5,360-H*30 + M*5.5))));

    return 0;
}

Measured memory_bytes: 4224
//In the name of God
//SMani24
#include<bits/stdc++.h>
using namespace std;

int n, a;
map<int, int> cnt;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		cnt[a]++;
		if (cnt[a] > 1) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}


Measured memory_bytes: 9600
//拓展欧几里得 
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ll long long
inline int read()
{
	int s=0,w=1;register char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-') w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') { s=(s<<1)+(s<<3)+(ch^48);ch=getchar();}
	return s*w;
}
int ans[10005];
inline int fun(int x,int y,int z)
{
	return x*x+y*y+z*z+x*y+x*z+y*z;
}
int main()
{
	int n=read();
	f(i,1,n){
		if(fun(i,i,i)>n) break;
		f(j,i,n){
			if(fun(i,j,j)>n) break;
			f(k,j,n){
				int z=fun(i,j,k);
				if(z>n) break;
				if(i!=j&&j!=k) ans[z]+=6;
				if((i==j&&j!=k)||(i!=j&&j==k)) ans[z]+=3;
				if(i==j&&j==k) ans[z]+=1;
			}
		}
	}
	f(i,1,n) printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 3688
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int k = scanner.nextInt();
		int s = scanner.nextInt();
		scanner.close();

		int count = 0;

		for (int x = 0; x <= k; x++) {
			for (int y = 0; y <= k; y++) {
				int z = 0;
				if(x + y < s && s - (x + y) <= k) {
					z = s - (x + y);
				}
				if (x + y + z == s) {
					// System.out.printf("%d, %d, %d\n", x, y, z);
					count++;
				}
			}
		}

		System.out.println(count);

	}

}


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

int main(){
    int n; cin >> n;
    int F[50];
    
    F[0]=F[1]=1;
    for (int i=2; i<=n; i++) F[i]=F[i-1]+F[i-2];
    
    cout << F[n] << endl;
    return 0;
}


Measured memory_bytes: 3112
<?php

fscanf(STDIN, '%d %d', $r, $c);
$arr = array_fill(0, $c, 0);

for ($i = 0; $i < $r; $i++) {
    $line = trim(fgets(STDIN));
    $row = explode(' ', $line);
    $sum = 0;

    foreach ($row as $j => $n) {
        $sum += $n;
        $arr[$j] += $n;
    }

    $row[] = $sum;
    printf("%s\n", implode(' ', $row));
}

$sum = array_sum($arr);
$arr[] = $sum;
printf("%s\n", implode(' ', $arr));

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

int main() {
  int n;
  int r2w = 0;    // R->Wの数
  int w2r = 0;    // W->Rの数
  int n_change; // 交換する回数
  std::string s;
  
  std::cin >> n >> s;


  for (int i = 0; i < n; i++)
    if (s[i] == 'R') r2w++; // 赤の数でaを初期化(交換回数は赤の数)

  // 境界を一番左においた時の交換回数
  n_change = std::max(r2w, w2r);

  // はじめの完成形はすべて白. 境界を左から右に移動させ左から赤色していく
  for (int i = 0; i < n; i++) {
    if (s[i] == 'R') r2w--; // a(R->W)が一つ減る
    else w2r++;             // b(W->R)が増える

    // 最小の交換回数を更新
    int now = std::max(r2w, w2r);
    n_change = std::min(now, n_change);
  }

  std::cout << n_change << std::endl;
 
  return 0;
}

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


    if len(A) == 1 and A[0] == 1:
        print(0)
        exit()

    set_A = set(A)
    set_B = set()
    t = 1
    for i in range(1, len(A)):
        if not i in set_A:
            break
        if i in set_B:
            continue
        set_B.add(i)
        t += 1
    if t == 1:
        print(-1)
        exit()

    ans = 0
    tt = 1
    for a in A:
        if a == tt:
            tt += 1
            ans += 1
        else:
            pass

    print(len(A)-ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 42552
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

n,q = map(int,input().split())
t = [[] for _ in range(n+1)]
for _ in range(n-1):
  a,b = map(int,input().split())
  t[a].append(b)
  t[b].append(a)
cnt = [0]*(n+1)
for _ in range(q):
  p,x = map(int,input().split())
  cnt[p] += x
def csum(now,bef):
  for i in t[now]:
    if i != bef:
      cnt[i] += cnt[now]
      csum(i,now)
csum(1,0)
print(*cnt[1:])

Measured memory_bytes: 230932
#include <bits/stdc++.h>
using namespace std;
 
typedef unsigned long long ll;
typedef std::pair<int, int> P;
 
#define frep(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) frep(i, 0, (n))
#define rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define all(i, x) for(typeof(x.begin()) i = x.begin(); i != x.end(); i++)
#define pb push_back
 
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int MAX = 100010;
const int INF = 1e9;
const int MOD = 1000000007;
const string END = "\n";

void solve(){
	int n, y; cin >> n >> y;
	y /= 1000;
	rep(i, n+1){
		int sum = y;
		sum -= i * 10;
		rep(j, n+1-i){
			int sum2 = sum;
			sum2 -= j * 5;
			if(n == i + j + sum2){
				cout << i << " " << j << " " << sum2 << END;
				return;
			}
		}
	}
	cout << -1 << " " << -1 << " " << -1 << END;
}
 
int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	solve();
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
using namespace std;
typedef long long ll;
struct P {
	ll pos, time;
};
struct T {
	ll time, place;
};
struct B {
	ll to, time;
};
vector<B>e[100001];
ll a[100001];
T b[100001];
const ll inf = 80000000000000000;
bool  operator<(P a, P b) { return a.time < b.time; }
bool  operator>(P a, P b) { return a.time > b.time; }
int main() {
	ll n, m, x;
	cin >> n >> m >> x;
	for (ll i = 1; i <= n; i++) {
		cin >> a[i];
		b[i].time = inf;
		b[i].place = inf;
	}
	for (ll i = 0; i < m; i++) {
		ll u1, u2, u3;
		cin >> u1 >> u2 >> u3;
		e[u1].push_back(B{ u2,u3 });
		e[u2].push_back(B{ u1,u3 });
	}
	priority_queue<P, vector<P>, greater<P>>p;
	p.push(P{ 1,0 });
	b[1] = T{ 0,x };
	while (!p.empty()) {
		P t = p.top(); p.pop();
		ll o = t.pos;
		for (ll i = 0; i < (ll)e[o].size(); i++) {
			ll h = b[o].place;
			ll maxh = a[o] - e[o][i].time;
			if (maxh >= 0) {
				ll cost = b[o].time + e[o][i].time;
				ll h2 = h - e[o][i].time;
				if (h2<0) {
					cost += (0 - h2);
					h2 = 0;
				}
				if (h2 > a[e[o][i].to]) {
					cost += (h2 - a[e[o][i].to]);
					h2 = a[e[o][i].to];
				}
				if (b[e[o][i].to].time > cost) {
					b[e[o][i].to].time = cost;
					b[e[o][i].to].place = h2;
					p.push(P{ e[o][i].to,b[e[o][i].to].time });
				}
			}
		}
	}
	if (b[n].time == inf) {
		cout << -1 << endl;
	}
	else {
		if (b[n].place < a[n]) {
			b[n].time += (a[n] - b[n].place);
		}
		cout << b[n].time << endl;
	}
}

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

int main() {
  int N, M, X;
  cin >> N >> M >> X;
  int r = 0;
  int l = 0;
  for (int i = 0; i < M; ++i) {
    int A;
    cin >> A;
    if (A < X) {
      ++r;
    } else {
      ++l;
    }
  }
  cout << min(r, l) << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.nio.CharBuffer;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        int r = scanner.nextInt();
        writer.println(r * r);
        writer.close();
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }


        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        private void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        private char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        private String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

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

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

        private double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

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

int main(void){
    int N ,K;
    cin >> N >> K;
    
    double ans=0;
    if(N >= K)ans+=1.0*(N-K+1)/N;
    
    for(int i=1;i<=min(K-1,N);i++){
        int cnt = 0;
        int x = i;
        while(x < K){
            x = 2*x;
            cnt++;
        }
        ans += 1.0/pow(2,cnt)/N;
    }
    cout << fixed;
    cout << setprecision(9) << ans << endl;

    
    
    
}


Measured memory_bytes: 384
#include <iostream>
#include <atcoder/all>
using namespace std;using z=long;z N,Q,i,a,w,e,r;int main(){cin>>N>>Q;atcoder::fenwick_tree<z> b(N);for(;i<N;i++){cin>>a;b.add(i,a);}while(Q--){cin>>w>>e>>r;if(w)cout<<b.sum(e,r)<<endl;else b.add(e,r);}}

Measured memory_bytes: 8236
// Problem : D - I hate Factorization
// Contest : AtCoder - AtCoder Beginner Contest 166
// URL : https://atcoder.jp/contests/abc166/tasks/abc166_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 1e4+500;
bool sieve[N+5];

void help()
{
    
    for(int i=2;i*i<=N;++i)
    {
        if(!sieve[i])
        {
            for(int j = i*i;j<=N;j+=i)
            {
                sieve[j] = true;
            }
        }
    }
}
int give(int x)
{
	int ans = 1;
	for(int i=1;i<=5;++i)
	ans*=x;
	return ans;
}

signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
    	int n;
    	cin>>n;
		for(int i=0;i<N;++i)
		{
			for(int j=0;j<=i;++j)
			{
				if(give(i)-give(j)==n)
				{
					cout<<i<<" "<<j;
					return 0;
				}
			}
		}
		for(int i=0;i<N;++i)
		{
			for(int j=0;j<=i;++j)
			{
				if(give(i)-give(-j)==n)
				{
					cout<<i<<" "<<-j;
					return 0;
				}
			}
		}
		
		    	
    }
    return 0;
}



Measured memory_bytes: 3576
#include <stdio.h>
int main(void) {
    int num,i,j,place,key;
    char card[101];
    while (scanf("%d",&num)!=EOF&&num!=0) {
        int count[10]={0};
        scanf(" %s",card);
        place=0;
        for (i=0; i<100; i++) {
            switch (card[i]) {
                case 'M':
                    count[i%num]++;
                    break;
                case 'S':
                    place+=count[i%num]+1;
                    count[i%num]=0;
                    break;
                case 'L':
                    count[i%num]+=place+1;
                    place=0;
                    break;
            }
        }
        for (i=0; i<num; i++) {
            for (j=0; j<num-i-1; j++) {
                if (count[j]>count[j+1]) {
                    key=count[j];
                    count[j]=count[j+1];
                    count[j+1]=key;
                }
            }
        }
        for (i=0; i<num; i++) {
            if (i) printf(" ");
            printf("%d",count[i]);
        }
        printf(" %d\n",place);
    }
    return 0;
}

Measured memory_bytes: 608
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = (int)3e5;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}


int main(void){
  ll x,y;cin>>x>>y;
  if((x+y)%3 != 0){
    cout<<0<<endl;
    return 0;
  }
  ll n = (x+y)/3;
  x -= n;
  y -= n;
  if(x<0 || y<0){
    cout<<0<<endl;
    return 0;
  }
  cout<<nCr(x+y, x)<<endl;
  return 0;
}


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

using namespace std;

typedef long long ll; 
typedef long double ld;

int main() {
	
	// make input and output more efficient
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	
	
	// to read whole line
	//string s;
	//getline(cin, s);
	
	int N, K;
	
	cin >> N >> K;
	
	int p[N];
	
	for(int i = 0;i < N; i++) {
		cin >> p[i];
	}
	
	sort(p, p+N);
	
	int answer = 0;
	for(int i = 0; i<K; i++) {
		answer += p[i];
	}
	
	cout << answer << "\n";
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    int happy = (n / 500) * 1000 + ((n % 500) / 5) * 5;
    cout << happy << endl;
    return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> height(n), good_obs(n, 1);
    int a, b;
    int h;

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

    for (int j = 0; j < m; j++){
        cin >> a >> b;
        a--;
        b--;

        if (height[a] < height[b]){
            good_obs[a] = 0;
        }
        else if(height[a] > height[b]){
            good_obs[b] = 0;
        }
        else{
            good_obs[a] = 0;
            good_obs[b] = 0;
        }
    }

    cout << accumulate(good_obs.begin(), good_obs.end(), 0) << endl;

    return 0;
}

Measured memory_bytes: 3616
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String [] s_arr = sc.nextLine().split("");
        String [] t_arr = sc.nextLine().split("");
        
        //sの文字列長文loopして全部同じかどうかをチェックする
        boolean flg = true;
        for (int i=0;i<s_arr.length;i++){
            if (s_arr[i].equals(t_arr[i])){
                //
            }else{
                flg = false;
            }
        }
        
        if (flg){
            System.out.println("Yes");    
        }else{
            System.out.println("No");    
        }

    }
}


Measured memory_bytes: 35620
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
const long long MOD = (ll)1e9+7;
const long long MAX = (ll)420;

vector<ll> dp(MAX);
vector<ll> A;
vector<ll> B;


// Pow
long long Pow[MAX][MAX];
long long GetPow(long long k, long long l) {
   if(!Pow[k][l]) Pow[k][l] = (GetPow(k,l-1)*k)%MOD;
   return Pow[k][l];
}

void Update(int i) {
   vector<ll> dp1(MAX,0);
   rep(j,0,MAX) {
      ll tmp = 0;
      ll now = 1;
      // tmp = pow(A[i],j);
      rep(l,A[i],B[i]+1) {
         // tmp += pow(l,j);
         tmp += GetPow(l,j);
         tmp %= MOD;
      }
      rep(k,0,MAX-j) {
         dp1[j+k] += dp[k] * tmp;
         dp1[j+k] %= MOD;
      }
   }
   swap(dp1,dp);
   return;
}

int main(void) {
   ll N,C;
   cin>>N>>C;
   A.resize(N);
   B.resize(N);

   rep(i,0,N) cin>>A[i];
   rep(i,0,N) cin>>B[i];
   dp[0] = 1;
   rep(i,0,MAX) rep(j,0,MAX) Pow[i][j] = 0;
   rep(i,0,MAX) Pow[i][0] = 1;



   rep(i,0,N) Update(i);
   cout<<(dp[C]+MOD)%MOD<<endl;


   return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<lint, pii> plp;
typedef pair<lint, int> pli;

typedef struct SegTree{
  int n;
  vector<pli> node;
  lint initv;
  
  SegTree(int n_, lint initv_){
    n = 1;
    while(n < n_) n *= 2;
    node.resize(n*2-1);
    initv = initv_;
    rep(i, n*2-1) node[i] = make_pair(initv, -1);
  }
  
  void update(int i, pair<lint, int> x){
    i += n - 1;
    node[i] = x;
    while(i > 0){
        i = (i-1) / 2;
        if(node[i*2+1].fi <= node[i*2+2].fi) node[i] = node[i*2+1];
        else node[i] = node[i*2+2];
    }
  }
  
  pli getmin(int a, int b, int i, int l, int r){
    if(r<=a || b<=l) return make_pair(initv, -1);
    if(a<=l && r<=b) return node[i];
    auto pl = getmin(a, b, i*2+1, l, (l+r)/2);
    auto pr = getmin(a, b, i*2+2, (l+r)/2, r);
    if(pl.fi <= pr.fi) return pl;
    return pr;
  }
}SegTree;

typedef struct UnionFindTree{
    vector<int> par;
    
    UnionFindTree(int n){
        par.resize(n, -1);
    }
    
    int find(int x){
        if(par[x] < 0) return x;
        return par[x] = find(par[x]);
    }
    
    int size(int x){
        return -par[find(x)];
    }
    
    bool unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return false;
        if(size(x) < size(y)) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    bool same(int x, int y){
        return find(x) == find(y);
    }
}UF;

int main(){
    int n;
    lint d;
    scanf("%d%lld", &n, &d);
    pli a[n];
    rep(i, n){
        lint t;
        scanf("%lld", &t);
        a[i] = make_pair(t, i);
    }
    sort(a, a+n);
    SegTree st_l(n, 1e18);
    SegTree st_r(n, 1e18);
    vector<plp> E;
    rep(i, n){
        pli p_l = st_l.getmin(0, a[i].se+1, 0, 0, st_l.n);
        st_l.update(a[i].se, pli(a[i].fi + (lint)(n-a[i].se) * d, i));
        pli p_r = st_r.getmin(a[i].se, n, 0, 0, st_r.n);
        st_r.update(a[i].se, pli(a[i].fi + (lint)a[i].se * d, i));
        if(p_l.se >= 0) E.push_back(plp(a[p_l.se].fi + a[i].fi + (lint)abs(a[i].se - a[p_l.se].se) * d, pii(a[i].se, a[p_l.se].se)));
        if(p_r.se >= 0) E.push_back(plp(a[p_r.se].fi + a[i].fi + (lint)abs(a[i].se - a[p_r.se].se) * d, pii(a[i].se, a[p_r.se].se)));
    }
    UF uf(n);
    lint ans = 0;
    sort(E.begin(), E.end());
    for(plp e: E){
        if(uf.same(e.se.fi, e.se.se)) continue;
        ans += e.fi;
        uf.unite(e.se.fi, e.se.se);
    }
    printf("%lld\n", ans);
}

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

typedef long long ll;
typedef pair<int, int> P;

int MOD = 1e9 + 7;
ll INF = 1e18;

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

int main(){
    int h, w, n; cin>>h>>w>>n;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin>>a[i];
    }

    int num=0;
    int c[110][110];
    for(int i=0; i<w; i++){
        if(i % 2 == 0){
            for(int j=0; j<h; j++){
                c[j][i]=num+1;
                a[num]--;

                if(a[num] == 0){
                    num++;
                }
            }
        }
        else{
            for(int j=h-1; j>=0; j--){
                c[j][i]=num+1;
                a[num]--;

                if(a[num] == 0){
                    num++;
                }
            }
        }
    }

    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(j == w-1){
                cout << c[i][j];
            }
            else{
                cout << c[i][j] << " ";
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();
		if(A + B > 2 * C) {
			if(A > 2 * C && B > 2 * C) {
				System.out.println(Math.max(X, Y) * C * 2);
			} else if(A > 2 * C) {
				if(X > Y) {
					System.out.println(X * C * 2);
				} else {
					System.out.println(X * C * 2 + (Y - X) * B);
				}
			} else if(B > 2 * C){
				if(X > Y) {
					System.out.println(Y * C * 2 + (X - Y) * A);
				} else {
					System.out.println(Y * C * 2);
				}
			} else {
				if(X > Y) {
					System.out.println(Y * C * 2 + (X - Y) * A);
				} else {
					System.out.println(X * C * 2 + (Y - X) * B);
				}
			}
		} else {
			System.out.println(A * X + B * Y);
		}
	}
}


Measured memory_bytes: 23380
#include<stdio.h>
#define mod 1000000007
#define ll long long
ll n,k;
ll ans[100010];
ll quickpow(ll a,ll b){
	ll ans=1;
	while(b!=0){
		if(b%2==1)ans=(ans%mod*a%mod)%mod;
		b=b/2;
		a=(a%mod*a%mod)%mod;
	} 
	return ans;
}
int main(){
	scanf("%lld %lld",&n,&k);
	for(ll i=k;i>=1;i--){
		ans[i]=quickpow(k/i,n);
		for(ll j=(ll)2*i;j<=k;j=j+i){
			ans[i]=(ans[i]-ans[j]+mod)%mod;
		}
	}
	ll res=0;
	for(ll i=1;i<=k;i++){
		res=(res+i*ans[i])%mod;
	}
	printf("%lld\n",res);
}

Measured memory_bytes: 2508
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,i,j;
    string s;
    cin>>n>>m;
    for (i=1;i<=n;i++)
    {
        for (j=1;j<=m;j++)
        {
            cin>>s;
            if (s=="snuke")
            printf("%c%d\n",'A'+j-1,i);
        }
    }
    return 0;
}

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

template <typename T>
struct Dijkstra {
  struct Edge {
    int to;
    T cost;
  };
  vector<int> prev;
  vector<vector<Edge>> g;
  Dijkstra() {}
  Dijkstra(int n) : prev(n), g(n) {}

  void addEdge(int u, int v, T w) {
    g[u].push_back({v, w});
    g[v].push_back({u, w});
  }
  vector<T> build(int s) {
    vector<T> dist(g.size(), -1);
    prev.assign(g.size(), -1);
    using Node = pair<T, int>;
    priority_queue<Node, vector<Node>, greater<Node>> pq;
    pq.push({dist[s] = 0, s});

    while (!pq.empty()) {
      auto d = pq.top().first;
      auto u = pq.top().second;
      pq.pop();
      if (dist[u] < d) continue;
      for (auto&& v : g[u]) {
        if (dist[v.to] < 0 || dist[v.to] > dist[u] + v.cost) {
          dist[v.to] = dist[u] + v.cost;
          prev[v.to] = u;
          pq.push({dist[v.to], v.to});
        }
      }
    }
    return dist;
  }
  vector<int> getPath(int t) {
    vector<int> path;
    for (; t != -1; t = prev[t]) path.push_back(t);
    reverse(begin(path), end(path));
    return path;
  }
};

vector<int> color;
vector<int> c;
Dijkstra<int> g;
int p = 0;

void dfs(int s) {
  if (color[s] != -1) return;
  color[s] = 0;
  for (auto&& t : g.g[s]) {
    dfs(t.to);
  }
  color[s] = c[p++];
}

int main() {
  int n;
  cin >> n;
  g = Dijkstra<int>(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g.addEdge(a, b, 1);
  }
  c.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    c[i]--;
  }
  sort(begin(c), end(c));
  auto d1 = g.build(0);
  int s = -1, mx1 = 0;
  for (int i = 0; i < n; i++) {
    if (d1[i] > mx1) {
      mx1 = d1[i];
      s = i;
    }
  }
  color.assign(n, -1);
  dfs(s);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    sum += c[i] + 1;
  }
  cout << sum - (c[n - 1] + 1) << endl;
  for (int i = 0; i < n; i++) {
    cout << color[i] + 1 << ((i == n - 1) ? '\n' : ' ');
  }
}


Measured memory_bytes: 1280
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define enld endl

int main() {
	lint N;
	cin >> N;
	vector<lint>A(N);
	rep(i, N) {
		cin >> A[i];
	}
	bool ok = true;
	rep(i, N) {
		if (A[i] % 2 == 0 && (A[i] % 3 != 0 && A[i] % 5 != 0)) {
			ok = false;
		}
	}
	if (ok) {
		cout << "APPROVED" << endl;
	}
	else {
		cout << "DENIED" << endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
int i,h,m,s;
scanf("%d",&i);

h = i / 3600;
m = (i-h*3600)/60;
s = (i-h*3600-m*60);


printf("%d:%d:%d\n",h,m,s);

return 0;
}

Measured memory_bytes: 1816
use std::vec::Vec;
use std::cmp::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

const MOD: u64 = 1_000_000_000 + 7;

fn main() {
    let (n, k) = {
      let v: Vec<usize> = read_vec();
      (v[0], v[1])
    };

    let mut dp: Vec<Vec<u64>> = vec![vec![0; 2001]; 2001];
    let l = dp[0].len();
    dp[1][1] = 1;

    for i in 0..l {
      dp[i][0] = 1;
    }

    for i in 2..l {
      for j in 1..i+1 {
        dp[i][j] = dp[i-1][j-1] % MOD + dp[i-1][j] % MOD;
      }
    }

    for i in 1..k+1 {
      println!("{}", (dp[k-1][k-i] * dp[n-k+1][i]) %MOD);
    }
}


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


int main(){
    ll a, b,c;
    cin>>a>>b>>c;
    if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
      cout << 0 << endl;
    } else {
        cout<<min(min(a*b, a*c), b *c)<<endl;
    }
}


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

//#define int long long
#define DEBUG 0
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) if(DEBUG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DEBUG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
using pii = pair<int, int>; using vi = vector<int>;
static const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
static const int MOD = (int)(1e9 + 7);

int n;
bool isinrange(int x, int y) {
	return x >= 0 && x < n&&y >= 0 && y < n;
}

signed main() {
	for (; cin >> n && n;) {
		vector<string>  a(n);
		rep(i, 0, n)cin >> a[i];

		int ans = 0;
		int di[] = { 0, 1, 1, 1 };
		int dj[] = { 1, 0, 1, -1 };
		rep(i, 0, n)rep(j, 0, n) {
			rep(k, 0, 4) {
				int ii = i, jj = j;
				int cnt = 0;
				while (a[ii][jj] == '1') {
					cnt++;
					ans = max(ans, cnt);
					ii += di[k];
					jj += dj[k];
					if (!isinrange(ii, jj))break;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3112