akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#define int long long
using namespace std;

signed main() {
  int N, A, B; cin >> N >> A >> B;
  int x[100010];
  int cost = 0;
  for(int i = 0; i < N; ++i) {
    cin >> x[i];
    if(i != 0) cost += min(A * (x[i] - x[i-1]), B);
  }
  cout << cost << endl;
  return 0;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n, m, l;
        n = scan.nextInt();
        m = scan.nextInt();
        l = scan.nextInt();
        int a[][] = new int[n][m];
        int b[][] = new int[m][l];
        for(int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                a[i][j] = scan.nextInt();
            }
        }
        for(int i = 0; i < m; i++) {
            for (int j = 0; j < l; j++) {
                b[i][j] = scan.nextInt();
            }
        }
        long c[][] = new long[n][l];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < l; j++){
                for(int k = 0; k < m; k++){
                    c[i][j] += a[i][k] * b[k][j];
                }
            }
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < l; j++){
                System.out.print(c[i][j]);
                if(j == l - 1) System.out.println();
                else System.out.print(" ");
            }
        }
    }
}



Measured memory_bytes: 53100
#include <bits/stdc++.h>
using namespace std;
int main(void){

    int a, b;
    char op;
    cin >> a >> op >> b;

    //*
    if(op == '+'){
        cout << a + b << endl;
    } else {
        cout << a - b << endl;
    }
    //*/
    
    //cout << a.at(0) << b.at(0) << c.at(0) << endl;

    return 0; 
}


Measured memory_bytes: 3500
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    abc = map(int, input().split())
    a, b, c = sorted(abc)
    if (b - a) % 2 == 0:
        print((2 * c - a - b) // 2)
    else:
        print((2 * (c + 1) - a - b - 1) // 2 + 1)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 38256
#define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

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

static const double eps = 1e-8;

bool isPrime[10000001];

int main(){

	fill((bool*)isPrime,(bool*)isPrime+10000001,true);
	isPrime[0] = isPrime[1] = false;
	
	for(int i=2;i*i<=10000000;i++){
		if(isPrime[i]){
			for(int j=i+i;j<=10000000;j+=i){
				isPrime[j] = false;
			}
		}
	}

	int n;
	while(~scanf("%d",&n)){
		if(n==0) break;
		int res=-1;
		for(int i=n;i>=13;i--){
			if(isPrime[i] && isPrime[i-2]
			&& isPrime[i-6] && isPrime[i-8]){
				res = i;
				break;
			}
		}

		printf("%d\n",res);

	}
}

Measured memory_bytes: 12924
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ss second
#define ff first
#define N 200005
#define inf 1000000009
#define ll long long
#define pii pair<int,int>
#define sz(a) int(a.size())
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int n,k,a[N];
int b = 1;
int in[N];

int main(){
	scanf("%d%d",&n,&k);
	for(int i = 1;i <= n;i++) scanf("%d",&a[i]);
	while(b == 1 and k){
		memset(in,0,sizeof(in));
		for(int i = 1;i <= n;i++){
			int l = max(1,i-a[i]);
			int r = min(n,i + a[i]);
			in[l]++;
			in[r + 1]--;
		}
		b = 0;
		for(int i = 1;i <= n;i++){
			in[i] += in[i-1];
			a[i] = in[i];
			if(a[i] != n) b = 1;
		}
		k--;
	}
	for(int i = 1;i <= n;i++)
		printf("%d ",a[i]);
}


Measured memory_bytes: 5328
#include <stdio.h>

int main()
{
	int i, j;
	for (i = 9; i; i--)
	{
		for (j = 9; j; j--)
		{
			printf("%1dx%1d=%d\n", (10 - i), (10 - j), (10 - i)*(10 - j));
		}
	}

	return 0;
}


Measured memory_bytes: 2048
#include<iostream>
using namespace std;
int n,a[100];
main()
{
    while(cin>>n,n)
    {
        for(int i=0;i<n;i++)cin>>a[i];
        int c=32,i=0;
        while(c)
        {
            c-=(c-1)%5;
            cout<<c<<endl;
            c-=(a[i]>c?c:a[i]);
            cout<<c<<endl;
            i=(i+1)%n;
        }
    }
}


Measured memory_bytes: 3084
from math import ceil

D, G = map(int, input().split())
ps, cs = [], []
for _ in range(D):
    p, c = map(int, input().split())
    ps.append(p)
    cs.append(c)

ans = 1000
for pat in range(2 ** D):
    score = 0
    num = 0
    for i in range(D):
        if pat & (1 << i):
            score += 100 * (i + 1) * ps[i] + cs[i]
            num += ps[i]
        else:
            iRest = i

    if score < G:
        n = ceil((G - score) / (100 * (iRest + 1)))
        if n >= ps[iRest]: continue
        num += n

    ans = min(ans, num)

print(ans)


Measured memory_bytes: 3064
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    S, T = map(str, input().split())
    print(T + S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 66156
function main(input) {
  const lines = input.split('\n');
  lines.pop();
  lines.forEach(line => {
    const s = line.split(' ');
    const a = parseInt(s[0], 10),
      b = parseInt(s[1], 10);
    console.log(fn(a, b));
  });
}

function fn(a, b) {
  return Math.max(
    a - b,
    a + b,
    a * b
  );
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21064
#include <bits/stdc++.h>
using namespace std;
long long int INF= 1e17+5;
void cmp(long long int & val1, long long int val2){
	if(val1>=val2 ){
      val1=val2;
	}
}
int main(){

  	int n;
  	cin>>n;
  	vector<long long int> inp(n);
  	vector<long long int> prefix_sums(n+1);
  	for(int i=0;i<n;i++) {
  		cin>>inp[i];
  		prefix_sums[i+1]=prefix_sums[i]+inp[i];
  	}
  	//tc[i][j] denotes the total cost incurred to combine slimes from i...j	
  	vector<vector<long long int>> tc( n+1, vector<long long int>(n+1, INF));
    for(int j=0;j<n;j++){
    	if((j-1)>=0)
           cmp(tc[j-1][j], inp[j-1]+inp[j]);
    	for(int i=(j-2);i>=0;i--){	
           	 cmp(tc[i][j], prefix_sums[j]- prefix_sums[i]+inp[j]+tc[i][j-1]);
           	 cmp(tc[i][j], prefix_sums[j+1]-prefix_sums[i+1]+inp[i]+tc[i+1][j]);
    		for(int k=i+1;k<(j-1);k++)
               cmp(tc[i][j], prefix_sums[j+1]-prefix_sums[i]+tc[i][k]+tc[k+1][j]);
    	}     
    }
    
    cout<<tc[0][n-1]<<endl;

	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;

const int mod = 1e9+7;
int h,w;
vector<string> a;
int dp[1100][1100]={0};

void add(int &a,int b){
    a+=b;
    if(a>=mod) a-=mod;
}

int main(){
    cin>>h>>w;
    a.resize(h);
    rep(i,h) cin>>a[i];
    
    dp[0][0]=1;
    rep(i,h){
        rep(j,w){
            if(i+1<h && a[i+1][j]=='.') add(dp[i+1][j],dp[i][j]);
            if(j+1<w && a[i][j+1]=='.') add(dp[i][j+1],dp[i][j]);
        }
    }
    cout << dp[h-1][w-1] <<endl;
    return 0;
}


Measured memory_bytes: 5632
package main

import (
	"fmt"
)

func main() {
	var s string
	var k int

	fmt.Scan(&s, &k)

	n := len(s)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = int(s[i] - '0')
	}

	/*
		dp[i][j][ok]
		i桁目まで確定
		j個の非0を使用済み
		ok: この時点でN以下であることが確定しているかどうか
	*/
	dp := [101][4][2]int{}
	dp[0][0][0] = 1

	for i := 0; i < n; i++ {
		for j := 0; j < 4; j++ {
			for ok := 0; ok < 2; ok++ {
				for d := 0; d <= 9; d++ {
					ni, nj, nok := i+1, j, ok
					if d != 0 {
						nj++
					}
					if nj > k {
						continue
					}
					if ok == 0 {
						if d > a[i] {
							continue
						}
						if d < a[i] {
							nok = 1
						}
					}
					dp[ni][nj][nok] += dp[i][j][ok]
				}
			}
		}
	}
	fmt.Println(dp[n][k][0] + dp[n][k][1])
}


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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var k = int.Parse(Console.ReadLine());
        var s = Console.ReadLine().Trim();

        Console.WriteLine(s.Length <= k ? s : s.Substring(0, k) + "...");
    }
}


Measured memory_bytes: 27392
#include <bits/stdc++.h>
using std::cin;
using std::cout;

const int N = 4054, mod = 998244353;
typedef std::bitset <N> bitset;

bitset GCD(bitset A, bitset B) {
	int dA = N - 1, dB = N - 1;
	for (; ; ) {
		for (; dA >= 0 && !A.test(dA); --dA);
		for (; dB >= 0 && !B.test(dB); --dB);
		if (!(~dA && ~dB)) return A | B;
		dA < dB ? B ^= A << (dB - dA) : A ^= B << (dA - dB);
	}
}

int main() {
	int i, n, deg, ans = 0; bitset t, d, X;
	cin >> n >> X >> d;
	for (i = 1; i < n; ++i) cin >> t, d = GCD(d, t);
	for (deg = N - 1; deg >= 0 && !d.test(deg); --deg);
	assert(~deg);
	for (i = N - 1; i >= deg; --i) ans = (ans * 2 + X.test(i)) % mod;
	for (n = N - 1, t = X; ; t ^= d << (n - deg)) {
		for (; n >= deg && !t.test(n); --n);
		if (n < deg) break;
	}
	for (++ans, i = deg - 1; i >= 0; --i)
		if (t.test(i)) {ans -= !X.test(i); break;}
	cout << ans % mod << '\n';
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;

inline int xor32()
{
  static int y = 2463534242;
  y = y ^ (y << 13); y = y ^ (y >> 17);
  return(y = y ^ (y << 5));
}

struct Node {
  int Value;
  int SubTreeSize;
  Node *Lch, *Rch;

  int RMQ;

  Node(int V):Value(V), SubTreeSize(1), RMQ(V) {
    Lch = (Node *)NULL;
    Rch = (Node *)NULL;
  };
};
inline int Count(Node *t)
{
  if(t == (Node *)NULL) return(0);
  else return(t -> SubTreeSize);
}
inline int Sum(Node *t)
{
  if(t == (Node *)NULL) return(INF);
  else return(t -> RMQ);
}

inline Node *Update(Node *t)
{
  t -> SubTreeSize = Count(t -> Lch) + Count(t -> Rch) + 1;
  t -> RMQ = min(Sum(t -> Lch), min(Sum(t -> Rch), t -> Value));
  return(t);
}
inline void Push(Node *t) 
{
}

inline Node *MakeRoot(int value)
{
  return(new Node(value));
}

Node *Merge(Node *l, Node *r)
{
  Push(l), Push(r);
  if(l == (Node *)NULL) return(r);
  if(r == (Node *)NULL) return(l);
  int Left  = l -> SubTreeSize;
  int Right = r -> SubTreeSize;
  if(rand() % (Left + Right) < Left) { // ???(left)??????
    l -> Rch = Merge(l -> Rch, r);
    return(Update(l));
  } else {                              // ???(right)??????
    r -> Lch = Merge(l, r -> Lch);
    return(Update(r));
  }
}
  
pair< Node*, Node* > Split(Node *t, int k) // [0, k), [k, n)
{
  if(t == (Node *)NULL) return(make_pair((Node *)NULL, (Node *)NULL));
  Push(t);
  if(k <= Count(t -> Lch)) { // ?????´?????????
    pair< Node *, Node *> s = Split(t -> Lch, k);
    t -> Lch = s.second;
    return(make_pair(s.first, Update(t)));
  } else {                   // ?????´?????????
    pair< Node *, Node *> s = Split(t -> Rch, k - Count(t -> Lch) - 1);
    t -> Rch = s.first;
    return(make_pair(Update(t), s.second));
  }
}

Node *Insert(Node *root, int pos, int value)
{
  Node *p = MakeRoot(value);
  pair< Node *, Node *> s = Split(root, pos);
  return(Merge(Merge(s.first, p), s.second));
}
Node *Erase(Node *root, int pos)
{
  pair< Node *, Node *> s = Split(root, pos);
  pair< Node *, Node *> t = Split(s.second, 1);
  delete t.first;
  return(Merge(s.first, t.second));
}

void Dump(Node *root)
{
  if(root == (Node *)NULL) return;
  cout << "(";
  Dump(root -> Lch);
  cout << "" << root -> Value << "";
  Dump(root -> Rch);
  cout << ")";
}

int main()
{
  Node *root = NULL;
  int n, q, a, x, y, z;
  scanf("%d %d", &n, &q);
  for(int i = 0; i < n; i++) {
    scanf("%d", &a);
    root = Insert(root, i, a);
  }
  while(q--) {
    scanf("%d %d %d", &x, &y, &z);
    if(x == 0) {
      ++z;
      pair< Node *, Node *> a, b, c;
      c = Split(root, z);
      b = Split(c.first, z - 1);
      a = Split(b.first, y);
      root = Merge(Merge(Merge(a.first, b.second), a.second), c.second);
    } else if(x == 1) { 
      ++z;
      pair< Node *, Node *> p, q;
      p = Split(root, y);
      q = Split(p.second, z - y);
      printf("%d\n", Sum(q.first));
      root = Merge(p.first, Merge(q.first, q.second));
    } else {
      root = Erase(root, y);
      root = Insert(root, y, z);
    }
  }
}

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

Measured memory_bytes: 128
#include <bits/stdc++.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 pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int t[101];
int main(){
    int n,m,p,x;
    cin>>n;
    int sum=0;
    rep(i,n){
        cin>>t[i];
        sum+=t[i];
    }
    cin>>m;
    rep(i,m){
        cin>>p>>x;
        cout<<sum-t[p-1]+x<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;

int main() {

    int n, digit = 0;
    cin >> n;

    int smp = n;
    while(smp!=0){
        smp /= 10;
        digit++;
    }
    
    ll score = 0;
    int tmp;

    for (int i = digit; i > 0; i--) {
        tmp = 1;
        if(i % 2 == 0) {
            for (int j = 1; j < i-1; j++) {
                tmp *= 10;
            }
            score += tmp*9;
        }
    }

    if(digit % 2 == 1){
        tmp = 1;
        for (int i = 1; i < digit; i++) {
            tmp *= 10;
        }

        score += (n - tmp + 1);
    }

    cout << score << endl;
    

}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int n, v[50], i, j, t;
  double sum = 0;
  
  scanf("%d", &n);
  
  for(i = 0; i < n; i++)
    scanf("%d", &v[i]);
  
  for(i = 0; i < n - 1; i++)
  {
    for(j = n - 1; i < j; j--)
    {
      if(v[j] < v[j - 1])
      {
        t = v[j];
        v[j] = v[j - 1];
        v[j - 1] = t;
      }
    }
  }
  
  sum = v[0];
  for(i = 1; i < n; i++)
  {
    sum = (sum + v[i])/2.0;
  }
  
  printf("%lf\n", sum);
  return 0;
}

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

int main(){
    int n, k;
    int h[100005];
    cin >> n >> k;
    for(int i = 0; i < n; i++) cin >> h[i];

    sort(h, h+n);
    int diff_max = INT_MAX;
    for(int i = 0; i <= n-k; i++)
    {
        int diff = h[i+k-1] - h[i];
        if (diff_max > diff) diff_max = diff;
    }
    cout << diff_max << endl;
    return 0;
}


Measured memory_bytes: 640
"use strict"
function main(arg) {
    let data = arg.trim().split("\n")
    data.shift()
    let list = {
        'AC': 0,
        'WA': 0,
        'TLE': 0,
        'RE': 0,
    }
    for (let i = 0; i < data.length; i++) {
        let l = data[i]
        list[l]++
        // console.log(l)
    }
    console.log(`AC x ${list['AC']}`)
    console.log(`WA x ${list['WA']}`)
    console.log(`TLE x ${list['TLE']}`)
    console.log(`RE x ${list['RE']}`)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main(){
    int x,y;
    cin>>x>>y;
    while(!(x==0&&y==0)){
        if(x<y){
            cout<<x<<" "<<y<<endl;
        }
        else {
            cout<<y<<" "<<x<<endl;
        }
        cin>>x>>y;
    }
}


Measured memory_bytes: 3076
n=int(input())
num=[0]*4
for i in range(n):
    s=input()
    if s=="AC":
        num[0]+=1
    elif s=="WA":
        num[1]+=1
    elif s=="TLE":
        num[2]+=1
    elif s=="RE":
        num[3]+=1
print("AC","x",str(num[0]))
print("WA","x",str(num[1]))
print("TLE","x",str(num[2]))
print("RE","x",str(num[3]))


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

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

	vector<long long> a(n);
	for (long long i = 0; i < n; i++) cin >> a[i];

	sort(a.begin(), a.end(), greater<int>());
	
	long long d_f = 0;
	long long index;
	for (long long i = 1; i < n; i++) {

		if (a[i - 1] == a[i] && d_f == 0) {
			d_f = a[i];
			index = i;
			break;
		}
	}

	long long d_s = 0;
	for (long long i = index + 2; i < n; i++) {

		if (a[i - 1] == a[i] && d_s == 0) {
			d_s = a[i];
			break;
		}	
	}

	long long ans = d_f * d_s;

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

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

#define ll long long
#define F(i,m,n) for(ll i=m;i<n;i++)
#define Fr(j,n,m) for(ll j=n;j>=m;j--)
#define vll vector<ll>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vpll vector< pll >
#define tlll tuple < ll ,ll,ll >
/*-------------------------------------*---------------------------------------*/

#define godspeed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout << #x << "=" << x << endl
#define cout_array(a) cout<<#a<<"=";for(auto x: a){ cout<<x<<" ";}cout<<endl

ll gcd(ll a,ll b){
    return (b?gcd(b,a%b):a);
}
const ll MAX_PRIME = 1e9+7;
const ll INF = 1e18;


/*I NEED YOU TO WORK FOR TWO HOURS ON THIS NO MATTER WHAT....THE RESULT DOESN'T MATTER.....ITS ALL ABOUT YOUR EFFORTS.
---------------------------------------------------------------------------------------------------------------------*/

ll fast_pow(ll x,ll y,ll z){
    if(y==0)return 1%z;
    else if(y==1)return x%z;
    if(y%2==0){
        ll res = fast_pow(x,y/2,z);
        return (res*res)%z;
    }
    else{
        ll res = fast_pow(x,y/2,z);
        ll temp = (res*res)%z;
        return ((x%z)*temp)%z;
    }
}

int main() {
    godspeed
    ll n;
    cin>>n;
    vll a(n);
    ll max_h = 0;
    ll ans = 0;
    F(i,0,n){
        cin>>a[i];
        max_h = max(a[i],max_h);
        ans+=max_h-a[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4760
//{{{
#include <bits/stdc++.h>
using namespace std;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
#define foreach(x,a) for(auto &x:a)
typedef long long ll;
const int MOD = 1e9+7;
//}}}

int main(){
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int mx = a;
	mx = max(mx, b);
	mx = max(mx, c);
	int ans = a + b + c - mx;
	rep(i, k) mx *= 2;
	ans += mx;
	cout << (ans) << endl;
	return 0;
}


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

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 101010
#define DEBUG_OUT true

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


template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


//BELOW
//-----CODE------//


void solve(void)
{
  int n,m;
  cin>>n>>m;
  map<int,int> mp;
  for (int i = 0; i < n; i++)
  {
    int x;cin>>x;
    mp[x] += 1;
  }
  vector<int> cnt(m),pr(m);
  for (auto &&x : mp)
  {
    cnt[x.first%m] += x.second;
    pr[x.first%m] += x.second/2*2; 
  }
  int res = 0;
  for (int i = 0; i < m; i++)
  {
    int j = (m - i)%m;
    if(i == j) res += cnt[i]/2;
    else if( i < j)
    {
      int k = min(cnt[i],cnt[j]);
      res += k;
      res += min(cnt[i] - k ,pr[i])/2;
      res += min(cnt[j] - k ,pr[j])/2;
    }
  }
  cout<<res<<endl;
  return;
  
  
  

  

  

  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 11092
file = File.exist?('in.in') ? File.new('in.in','r') : STDIN
n = file.gets.chomp.to_i

data = Array.new(n)
dp = Array.new(n) { Array.new(3, 0) }
n.times do |i|
  data[i] = file.gets.chomp.split.map(&:to_i)
end

dp[0][0] = data[0][0]
dp[0][1] = data[0][1]
dp[0][2] = data[0][2]

for i in 1...n
  dp[i][0]=[dp[i-1][1], dp[i-1][2]].max + data[i][0]
  dp[i][1]=[dp[i-1][0], dp[i-1][2]].max + data[i][1]
  dp[i][2]=[dp[i-1][0], dp[i-1][1]].max + data[i][2]
end

puts dp.last.max

Measured memory_bytes: 15868
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

S = gets.chomp
T = gets.chomp

ss = S.split('')
tt = T.split('')

count = 0
ss.each.with_index do |s, i|
  count += 1 if s != tt[i]
end

puts count


Measured memory_bytes: 35048
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}} End

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

    int x, a, b; cin >> x >> a >> b;
    cout << (abs(x - a) < abs(x - b) ? 'A' : 'B') << "\n";

    return 0;
}


Measured memory_bytes: 256
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

#define sq(x) ((x)*(x))

ll INF = 1LL << 60;

ll MOD = 1000000007LL;

struct edge {
    int to; ll dist;
    edge() {} ~edge() {}
    edge(int to, ll dist): to(to), dist(dist) {}
};

struct state {
    int v; ll cost;
    state() {} ~state() {}
    state(int v, ll cost): v(v), cost(cost) {}
    bool operator < (const state& o) const { return cost > o.cost; }
};

int N, M, S, T;
vector<vector<edge>> graph;
vector<tuple<int, int, int>> edges;

vector<ll> min_cost;
vector<ll> num;

void calc(int start, int goal) {
    fill(begin(min_cost), end(min_cost), INF);
    fill(begin(num), end(num), 0);

    min_cost[start] = 0;
    num[start] = 1;

    priority_queue<state> pq;
    pq.emplace(start, 0);
    while (!pq.empty()) {
        state s = pq.top(); pq.pop();
        if (min_cost[s.v] < s.cost) continue;
        for (int i = 0; i < graph[s.v].size(); ++i) {
            edge& e = graph[s.v][i];
            ll cost = s.cost + e.dist;
            if (cost < min_cost[e.to]) {
                min_cost[e.to] = cost;
                num[e.to] = num[s.v];
                pq.emplace(e.to, cost);
            } else if (cost == min_cost[e.to]) {
                num[e.to] = (num[e.to] + num[s.v]) % MOD;
            }
        }
    }
}

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> M >> S >> T;
    --S; --T;
    min_cost.resize(N);
    num.resize(N);
    graph.resize(N);
    for (int j = 0; j < M; ++j) {
        int u, v; ll d; cin >> u >> v >> d; --u; --v;
        graph[u].emplace_back(v, d);
        graph[v].emplace_back(u, d);
        edges.emplace_back(u, v, d);
    }

    calc(S, T);
    vector<ll> min_cost1 = min_cost;
    vector<ll> num1 = num;
    calc(T, S);
    vector<ll> min_cost2 = min_cost;
    vector<ll> num2 = num;

    ll dd = min_cost1[T];

    ll ans = sq(num1[T]) % MOD;
    for (int j = 0; j < N; ++j) {
        if (min_cost1[j] + min_cost2[j] == dd && min_cost1[j] == min_cost2[j]) {
            ans = (ans - sq(num1[j]*num2[j]%MOD)%MOD + MOD) % MOD;
        }
    }

    for (auto e : edges) {
        int u, v, d;
        tie(u, v, d) = e;
        if (min_cost1[u] > min_cost1[v]) swap(u, v);
        if (min_cost1[u] + d + min_cost2[v] == dd &&
                min_cost1[u] < (double) dd / 2 && min_cost2[v] < (double) dd / 2) {
            ans = (ans - sq(num1[u]*num2[v]%MOD)%MOD + MOD) % MOD;
        }
    }
    cout << ans << endl;



    return 0;
}


Measured memory_bytes: 21764
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

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

    int n;
    string s;
    cin >> n >> s;
    if (n % 2 == 1)
    {
        cout << "No" << endl;
        return 0;
    }
    rep(i, n / 2) if (s[i] != s[i + n / 2])
    {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	char taro[101]={0},hanako[101]={0};
	int tcnt=0,hcnt=0,len;
	int i,j;
	int n;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s %s",&taro,&hanako);
		if(taro[0]>hanako[0]){
			tcnt+=3;
		}else if(taro[0]<hanako[0]){
			hcnt+=3;
		}else if(taro[0]==hanako[0]){
			/*
			??????0???????????¨??????3????????????
			
			*/
			if(strlen(taro)>strlen(hanako)) len=strlen(taro);
			else len=strlen(hanako);
			for(j=0;j<len;j++){
				if(taro[j]>hanako[j]) {
					tcnt+=3;
					break;
				}
				else if(taro[j]<hanako[j]) {
					hcnt+=3;
					break;
				}else{
					if(len-1==j){
					tcnt++;
					hcnt++;
					break;}
				}
			}
			
			
		}
	}	
	printf ("%d %d\n",tcnt,hcnt);
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
# define    all(a)              a.begin(), a.end()
#define MOD (long long int )1e9+7
using namespace std;

typedef long long int ll;

// bool cmp(const pair<int, set<int>> a, const pair<int, set<int>> b) {
//     return a.second.size() > b.second.size();
// }

bool cmp(int a, int b) {

    return a > b;
}

// void printV(vector<int> nums) {
//     for (int i: nums) {
//         printf("%d ", i);// << " ";
//     }
//     printf("\n");
// }

void printV(vector<ll> nums) {
    for (ll i: nums) {
        printf("%lld ", i);// << " ";
    }
    printf("\n");
}



int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

bool valid(int i, int j, int n, int m) {
    if (i >= 0 && i < n && j >=0 && j < m)
        return true;
    else 
        return false;
}

ll dp[110][100010];

ll solve(int index, ll currweight, ll weight, vector<vector<int>> &nums, int n) {
    if (index == n)
        return 0;
    if (dp[index][currweight] != -1)
        return dp[index][currweight];
    ll res = solve(index+1, currweight, weight, nums, n);
    if (currweight+nums[index][0] <= weight) {
        res = max(res, nums[index][1] + solve(index+1, currweight+nums[index][0], weight, nums, n));
    }
    dp[index][currweight] = res;
    return res;
}


int main() {
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    // ios_base::sync_with_stdio(false);
    // cin.tie(0);cout.tie(0);
    // time_t start, end;
    // time(&start);
    int n, k;
    cin >> n >> k;
    vector<vector<int>> nums(n, vector<int>(2));
    for (int i=0; i<n; i++) cin >> nums[i][0] >> nums[i][1];
    memset(dp, -1, sizeof(dp));
    ll res = solve(0, 0, k, nums, n); 
    cout << res << endl;
    //l time(&end);
    // double time_taken = double(end - start);
    // cout << "Time Taken: " << fixed << time_taken << setprecision(5);
    // cout << " sec" << endl;
    return 0;
}


Measured memory_bytes: 89524
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main() {
  int n, m;
  cin >> n >> m;
  bool flag = false;
  string ans = "";
  for (int i = 0; i < n; i ++) ans += '0';
  if (n != 1) ans[0] = '1';
  for (int i = 0; i < m; i ++) {
    int s;
    char c;
    cin >> s >> c;
    s --;
    if (s == 0) {
      if (ans[s] != c && flag) {
        cout << -1 << endl;
        return 0;
      } else if (ans[s] == c) {
        continue;
      } else {
        ans[s] = c;
        flag = true;
      }
    }
    if (ans[s] != c && ans[s] != '0') {
      cout << -1 << endl;
      return 0;
    }

    ans[s] = c;
  }

  if (n == 1 && ans == "0") {
    cout << 0 << endl;
    return 0;
  }

  for (int i = 0; i < n; i ++) {
    if (ans[i] != '0') break;
    else {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	[ a, v ] <- readIntegers
	[ b, w ] <- readIntegers
	t <- readInteger
	let
		d = abs $ a - b
		v' = max 0 $ v - w
	putStrLn $ which "YES" "NO" $ d <= v' * t

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

using namespace std;
using ll = long long;

#define gc getchar
int getint() { unsigned int c; int x = 0; while (((c = gc()) - '0') >= 10) { if (c == '-') return -getint(); if (!~c) exit(0); } do { x = (x << 3) + (x << 1) + (c - '0'); } while (((c = gc()) - '0') < 10); return x; }
int getstr(char *s) { int c, n = 0; while ((c = gc()) <= ' ') { if (!~c) exit(0); } do { s[n++] = c; } while ((c = gc()) > ' ' ); s[n] = 0; return n; }
template<class T> inline bool chmin(T &a, T b) { return a > b ? a = b, 1 : 0; }
template<class T> inline bool chmax(T &a, T b) { return a < b ? a = b, 1 : 0; }

int n;
char in[1 << 20];

int main () {
    n = getstr(in);
    int res = n;
    for (auto i = 0; i < n - 1; ++i) {
        if (in[i] != in[i + 1]) {
            int need = max(i + 1, n - i - 1);
            chmin(res, need);
        }
    }
    cout << res << endl;
    return 0;
}




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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int  long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define pie 3.14159265358
#define mod2 998244353

void solve(){  
    int n,a,b;
    cin>>n;   
    map<int,int> m;
    rep(i,0,120){ 
        rep(j,i+1,120){
            a=pow(i,5);
            b=pow(j,5);
            if(b-a==n){cout<<j<<" "<<i; return;}
            if(b+a==n){cout<<j<<" -"<<i; return;}
        }
    }
} 

signed main(){
    IOS;
    int n=1; 
     // cin>>n; 
    rep(i,0,n)solve();
    
    return 0;
}

Measured memory_bytes: 4060
#include<stdio.h>

int main(void){
	int n;
	int max[3] = {9, 900, 90000};
	
	scanf("%d", &n);
	
	if(n < 10)
		printf("%d\n", n );
	else if(n<100)
		printf("%d\n", max[0] );
	else if(n<1000)
		printf("%d\n", max[0]+(n-99) );
	else if(n<10000)
		printf("%d\n", max[0]+max[1] );
	else if(n<100000)
		printf("%d\n", max[0]+max[1]+(n-9999) );
	else
		printf("%d\n", max[0]+max[1]+max[2] );

	return 0;
}


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

int main() {
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  a --; b --; c --; d --;
  int ans = (int)10e9;
  for(int w=1; w<=n; w++) {
    int man_ab = abs(a%w-b%w) + abs(a/w-b/w);
    int man_cd = abs(c%w-d%w) + abs(c/w - d/w);
    ans = min(ans, man_ab + man_cd);
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main()
{
    int x, a, b;
    cin>>x>>a>>b;
    if((a-b)>=0)
    {
        cout<<"delicious"<<endl;
    }
    else if(((x+a)-b)>=0)
    {
        cout<<"safe"<<endl;
    }
    else
    {
         cout<<"dangerous"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> arr;
  for (int i = 0; i < N; ++i) {
    int x;
    cin >> x;
    arr.push_back(x);
  }
  long long sum = 0;
  int max_value = 0;
  int Bi = 0;
  for (int i = 0; i < arr.size(); ++i) {
    max_value = max(max_value, arr[i]);
    Bi = max_value;
    sum += (Bi - arr[i]);
  }
  cout << sum << endl;
}

Measured memory_bytes: 4260
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

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

    if (S[0] == S[1] || S[1] == S[2] || S[2] == S[3]) {
        cout << "Bad" << endl;
    } else {
        cout << "Good" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
def actual(N, V):
    # 降順にソートして最後尾の小さい値から合成していく
    V.sort(reverse=True)

    while len(V) != 1:
        first_small = V.pop()
        second_small = V.pop()

        new_value = (first_small + second_small) / 2

        V.append(new_value)

    return V[0]

N = int(input())
V = list(map(int, input().split()))
print(actual(N, V))

Measured memory_bytes: 3060
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (N, M): (usize, usize) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };
    let (s, t): (Vec<usize>, Vec<usize>) = {
        let (mut s, mut t) = (vec![], vec![]);
        for _ in 0..M {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            s.push(iter.next().unwrap().parse().unwrap());
            t.push(iter.next().unwrap().parse().unwrap());
        }
        (s, t)
    };

    let G = {
        let mut G = vec![std::collections::HashSet::new(); N + 1];
        for i in 0..M { G[s[i]].insert(t[i]); }
        G
    };
    const INF: f64 = 1_000_000_000.0;
    let mut dp = vec![0.0; N + 1];
    let mut dp2 = vec![0; N + 1];
    dp[0] = -1.0;
    for i in (1..N).rev() {
        let mut k = 0;
        for &j in &G[i] {
            dp[i] += 1.0 + dp[j];
            if dp[j] > dp[k] { k = j; }
        }
        dp[i] /= G[i].len() as f64;
        if G[i].len() >= 2 { dp2[i] = k; }
    }

    let mut ans = INF;
    for k in 1..N {
        let mut dp3 = vec![0.0; N + 1];
        for i in (1..N).rev() {
            let mut m = 0;
            for &j in &G[i] { if !(i == k && j == dp2[i]) { dp3[i] += 1.0 + dp3[j]; m += 1; } }
            dp3[i] /= m as f64;
        }
        if ans > dp3[1] { ans = dp3[1]; }
    }

    println!("{}", ans);
}

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

#define ll long long

int coins[] = {100, 101, 102, 103, 104, 105};
int cnt[] = {1000000, 1000000, 1000000, 1000000, 1000000, 1000000};

int dp[6][100000];
int n;

int recur(int pos, int sum){
    if(sum == n) return 1;
    if(pos >= 6) return 0;

    if(dp[pos][sum] != -1) return dp[pos][sum];

    int ret1, ret2;
    ret1 = ret2 = 0;

    if(sum + coins[pos] <= n) ret1 = recur(pos, sum + coins[pos]);
    ret2 = recur(pos+1, sum);

    dp[pos][sum] = ret1 | ret2;
}

int main(){
    memset(dp, -1, sizeof(dp));

    n; cin >> n;

    if(n < 100){
        cout << 0 << endl;
        return 0;
    }

    if(recur(0, 0)) cout << 1 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 2688
#include<cstdio>
#include<map>
#include<utility>
#include<vector>
#include<queue>
#define INF 1000000
using namespace std;

struct edge{int to;long cost;};
typedef pair<int,int> P;

int V;
vector<edge> G[500000];
long d[500000];

void dijkstra(int s){
    priority_queue<P,vector<P>,greater<P> > que;
    fill(d,d+V,INF);
    d[s]=0;
    que.push(P(0,s));

    while(!que.empty()){
        P p=que.top(); que.pop();
        //printf("%d %d\n",p.first,p.second);
        int v=p.second;
        if(d[v]<p.first) continue;
        for(int i=0;i<G[v].size();i++){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}
int main(){
    int n,m,p,q,c,cnt=0;
    edge x;
    map<pair<int,int>,int> ma;
    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++){
        scanf("%d %d %d",&p,&q,&c);
        decltype(ma)::iterator a=ma.find(make_pair(p,c));
        if(a==ma.end()){
            ma.insert(make_pair(make_pair(p,c),n+cnt));
            x={n+cnt,1};
            G[p-1].push_back(x);
            x={p-1,0};
            G[n+cnt].push_back(x);
            cnt++;
        }
        decltype(ma)::iterator b=ma.find(make_pair(q,c));
        if(b==ma.end()){
            ma.insert(make_pair(make_pair(q,c),n+cnt));
            x={n+cnt,1};
            G[q-1].push_back(x);
            x={q-1,0};
            G[n+cnt].push_back(x);
            cnt++;
        }
        x={ma[make_pair(q,c)],0};
        G[ma[make_pair(p,c)]].push_back(x);
        x={ma[make_pair(p,c)],0};
        G[ma[make_pair(q,c)]].push_back(x);
    }
    V=n+cnt;
    dijkstra(0);
    if(d[n-1]==INF){
        printf("-1\n");
    }
    else{
        printf("%ld\n",d[n-1]);
    }
}

Measured memory_bytes: 72048
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define pb push_back
#define MOD 1000000007
#define INF 1000000000
#define EPS 0.0000000001
typedef long long ll;

ll n,q;
vector<vector<ll>> edge;
vector<ll> cost(n,0);
vector<bool> check(n);

void dfs(ll current){
    check[current]=true;
    for(ll next:edge[current]){
        if(check[next]){
            continue;
        }
        cost[next]+=cost[current];

        dfs(next);
    }
}

int main()
{
    cin>> n>>q;
    ll a,b,p,x;
    cost.resize(n);
    edge.resize(n);
    rep(i,n-1){
        cin>>a>>b;
        edge[a-1].pb(b-1);
        edge[b-1].pb(a-1);
    }
    rep(i,q){
        cin>>p>>x;
        cost[p-1]+=x;
    }
    check.resize(n);
    dfs(0);
    rep(i,n){
        cout<<cost[i]<<" ";
    }
    cout<<endl;
}


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


int main()
{
	int N,K;
	cin>>N>>K;
	vector<bool> sunuke(N,false);
	rep(cnt,K)
	{
		int d;
		cin>>d;
		rep(i,d)
		{
			int a;
			cin>>a;
			sunuke[a-1]=true;
		}
	}
	int ans=0;
	for(bool flag : sunuke)
	{
		if(!flag) ans++;
	}
	cout<<ans<<endl;
	return 0;
}


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


int main() {
    int64_t N;
    cin >> N;
    double d = sqrt(N);
    int64_t a = 0, b = 0;
    for (int i = 1; i <= d; ++i) {
        int64_t j = N / i;
        if (i * j == N) {
            a = i;
            b = j;
        }
    }
    int a_num = to_string(a).size();
    int b_num = to_string(b).size();
    int ans = max(a_num, b_num);
    cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    N, M, X = map(int, input().split())
    a = list(map(int, input().split()))
    if X < a[0] or a[M-1] < X:
        print(0)
        return
    else:
        for i in range(M):
            if X < a[i]:
                t = i
                break
        b = M - t
        f = t
        print(min(f, b))
main()

Measured memory_bytes: 9168
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();

        sc.close();

        long max = Math.min(a, b);
        long min = Math.max(a + b - n, 0);

        System.out.println(max + " " + min);
    }
}

Measured memory_bytes: 21716
import java.io.*;
import java.util.*;

public class Main
{
    PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok;

    public void go() throws IOException
    {
        ntok();
        int n = ipar();
        ArrayList<Vector> list = new ArrayList<>();
        for (int i = 0; i < n; i++)
        {
            ntok();
            list.add(new Vector(ipar(), ipar()));
        }
        Collections.sort(list);
        ArrayList<Vector> prefix = new ArrayList<>();
        Vector p = new Vector();
        prefix.add(new Vector(p));
        for (int i = 0; i < 2 * n; i++)
        {
            p.add(list.get(i%n));
            prefix.add(new Vector(p));
        }
        // out.println(list);
        // out.println(prefix);
        double best = 0;
        for (int i = 0; i < n; i++)
        {
            for (int e = 0; e <= n; e++)
            {
                Vector res = new Vector(prefix.get(i+e));
                res.subtract(prefix.get(i));
                if (Math.hypot(res.x, res.y) > best)
                {
                    best = Math.hypot(res.x, res.y);
                    // out.println("---- " + i + " " + (i+e));
                }
            }
        }
        out.println(best);

        out.flush();
        in.close();
    }

    private class Vector implements Comparable<Vector>
    {
        long x, y;
        double angle;

        public Vector()
        {
            this(0, 0);
        }

        public Vector(Vector other)
        {
            this(other.x, other.y);
        }

        public Vector(long x, long y)
        {
            this.x = x;
            this.y = y;
            angle = Math.atan2(y, x);
        }

        public void add(Vector v)
        {
            x += v.x;
            y += v.y;
        }

        public void subtract(Vector v)
        {
            x -= v.x;
            y -= v.y;
        }

        public long cross(Vector other)
        {
            return x * other.y - y * other.x;
        }

        public long dot(Vector other)
        {
            return x * other.x + y * other.y;
        }

        public int compareTo(Vector other)
        {
            return Double.compare(angle, other.angle);
        }

        public String toString()
        {
            return String.format("(%d %d)", x, y);
        }
    }

    public void ntok() throws IOException
    {
        tok = new StringTokenizer(in.readLine());
    }

    public int ipar()
    {
        return Integer.parseInt(tok.nextToken());
    }

    public long lpar()
    {
        return Long.parseLong(tok.nextToken());
    }

    public double dpar()
    {
        return Double.parseDouble(tok.nextToken());
    }

    public String spar()
    {
        return tok.nextToken();
    }

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


Measured memory_bytes: 23348
import sys
from fractions import gcd
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    A=list(map(int,input().split()))
    l=A[0]
    for x in A[1:]:
        l=l*x//gcd(l,x)
    ans=0
    for x in A:
        ans+=l//x
    print(ans%MOD)

if __name__ == '__main__':
    main()


Measured memory_bytes: 6072
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i< (n);i++)
using namespace std;
int main(){
    int n,t,ans = 0;
    cin >> n >> t;
    vector<pair<int,int>> v(n);
    rep(i,n) cin >> v[i].first >> v[i].second;
    sort(v.begin(),v.end());
    rep(i,n){
        if(v[i].second <= t) {
            ans = v[i].first;
            break;
        }
    }
    if(ans == 0) cout << "TLE\n";
    else cout << ans << endl;
}
/*abc114
int main(){
    int ans = 1e9;
    string s;
    cin >> s;
    int l = s.size();
    for(int i=0;i+2 < l;i++) {
        string c = s.substr(i,3);
        int n = stoi(c);
        int cl = abs(753-n);
        ans = min(ans,cl);
    }
    cout << ans << endl;
}*/
/*abc115
int main(){
    int n;
    cin >> n;
    vector<int> v(n,0);
    rep(i,n) cin >> v.at(i);
    sort(v.rbegin(),v.rend());
    v.at(0) /= 2;
    int ans = accumulate(v.begin(),v.end(),0);
    cout << ans << endl;   
}*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int a[1000005];
bool b[1000005];
int main(void){
	int s; cin>>s;
	a[0]=s; b[a[0]]=true;
	for(int i=1;i<1000005;i++){
		if(a[i-1]%2==0){
			a[i]=a[i-1]/2;
		}else{
			a[i]=a[i-1]*3+1;
		}
		//cout<<a[i]<<endl;
		if(b[a[i]]==true){
			cout<<i+1<<endl;
			return 0;
		}
		b[a[i]]=true;
	}
	
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>

using namespace std;

int main() {
  while (true) {
    int size[3];
    scanf("%d %d %d", size, size + 1, size + 2);
    if (size[0] == 0 && size[1] == 0 && size[2] == 0) { break; }
    sort(size, size + 3);
    int squared_chord = size[0] * size[0] + size[1] * size[1];

    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
      int radius;
      scanf("%d", &radius);
      int squared_diameter = 4 * radius * radius;
      puts(squared_diameter > squared_chord ? "OK" : "NA");
    }
  }

  return 0;
}

Measured memory_bytes: 1012