akhauriyash/Code-Regression huggingface dataset:
import java.io.*;

public class Main{
    public static void main(String[] args){
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        
        try{
            String line;
            line = reader.readLine();
            String[] data = line.split(" ",3);
            int a = 0, b = 0, c = 0;
            a = Integer.parseInt(data[0]);
            b = Integer.parseInt(data[1]);
            c = Integer.parseInt(data[2]);

            int max = 0, mid = 0, min = 0;

            if(a <= b && a <= c){
                min = a;
                if(b <= c){
                    mid = b;
                    max = c;
                }else{
                    mid = c;
                    max = b;
                }
            }else if(b <= a && b <= c){
                min = b;
                if(a <= c){
                    mid = a;
                    max = c;
                }else{
                    mid = c;
                    max = a;
                }
            }else if(c <= a && c <= b){
                min = c;
                if(a <= b){
                    mid = a;
                    max = b;
                }else{
                    mid = b;
                    max = a;
                }
            }
            System.out.println(min + " " + mid + " " + max);
        }catch(NumberFormatException e){
            System.out.println(e);
        }catch(IOException e){
            System.out.println(e);
        }
    }
}


Measured memory_bytes: 24316
object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  val a = readLine.trim.toList
  val b = readLine.trim.toList
  val aTree = parseAll(a).get
  val bTree = parseAll(b).get
  println(
    aTree.merge(bTree)
  )
  sealed trait BinaryTree {
    def merge(that: BinaryTree): BinaryTree
  }
  case class Node(value: Int, left: BinaryTree, right: BinaryTree) extends BinaryTree {
    override def toString: String = s"($left)[$value]($right)"

    override def merge(that: BinaryTree): BinaryTree = {
      that match {
        case Leaf ⇒ Leaf
        case Node(v, l, r) ⇒ Node(value + v, left.merge(l), right.merge(r))
      }
    }
  }
  case object Leaf extends BinaryTree {
    override def toString: String = ""

    override def merge(that: BinaryTree): BinaryTree = Leaf
  }
  def parseAll(arg: List[Char]): Option[BinaryTree] = {
    parse(arg) match {
      case (n, Nil) ⇒ Some(n)
      case _ ⇒ None
    }
  }
  def parse(arg: List[Char]): (BinaryTree, List[Char]) = {
    def readValue(arg: List[Char], res: Int = 0): (Int, List[Char]) = {
      arg match {
        case h::t if h.isDigit ⇒ readValue(t, res * 10 + h.asDigit)
        case _ ⇒ (res, arg)
      }
    }
    arg match {
      case '('::t ⇒ parse(t) match {
        case (left, ')'::'['::t) ⇒ readValue(t) match {
          case (value, ']'::'('::t) ⇒ parse(t) match {
            case (right, ')'::t) ⇒ (Node(value, left, right), t)
            case _ ⇒ ???
          }
          case _ ⇒ ???
        }
        case (left, ')'::Nil) ⇒ (left, Nil)
        case _ ⇒ ???
      }
      case _ ⇒ (Leaf, arg)
    }
  }
  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}
/*
 */


Measured memory_bytes: 44880
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod 			1000000007
#define tc(t) 			int t;cin >> t;while(t--)
#define for0(i , n)		for(int i=0;i<n;i++)
#define loop(i , a, b)	for(int i=a;i<=b;i++)
#define endl 			'\n'
#define inf 			1e18
#define fi 				first
#define se 				second

int XX[8] = { +1, +1, +1, 0, 0, -1, -1, -1};
int YY[8] = { +1, 0, -1, +1, -1, +1, 0, -1};
int dx[4] = { -1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};


char a[1001][1001];
vector<vector<int>> dp(1001, vector<int>(1001, -1));
int n, m;

int countPaths(int i, int j) {
	if (i > n or j > m or a[i][j] == '#') return 0;
	if (i == n && j == m) {
		return 1;
	}

	if (dp[i][j] != -1) return dp[i][j];

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

signed main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("input.txt" , "r" , stdin);
	freopen("output.txt" , "w" , stdout);
#endif

	cin >> n >> m;

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cin >> a[i][j];
		}
	}

	cout << countPaths(1, 1);

	return 0;
}

Measured memory_bytes: 12600
import math

a,b,h,m = map(int,input().split())

def clock_to_minutes(h, m):
  minutes = m
  minutes += h*60
  return minutes

angular_speed_A = 360/12/60
angular_speed_B = 6

angle = abs((angular_speed_A - angular_speed_B)*clock_to_minutes(h,m)%360)

ans = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(angle)))

print(ans)


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

#define int long long

vector<int> vec;

int nasu(int s, int t){
	if(s == t) return 0;
	
	for(int i = vec.size()-1;i >= 0;i--){
		if(s % vec[i] == 0 && s + vec[i] <= t) return nasu(s + vec[i], t) + 1;
	}
}

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

	int tmp = 1;
	while(tmp <= 1000000000){
		vec.push_back(tmp);
		tmp *= 2;
	}
	
	for(int i = 0;i < n;i++){
		int s, t;
		cin >> s >> t;
		cout << nasu(s, t) << endl;
	}

	return 0;
}
		


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

class Program
{
    static void Main(string[] args)
    {

        //入力
        string[] HW = Console.ReadLine().Split(' ');
        int H = int.Parse(HW[0]);
        int W = int.Parse(HW[1]);

        string[] S = new string[H];
        for (int i = 0; i < H; i++)
        {
            S[i] = Console.ReadLine();
        }


        int[,] Left = new int[2100, 2100];
        int[,] Right = new int[2100, 2100];
        int[,] Up = new int[2100, 2100];
        int[,] Down = new int[2100, 2100];

        // 前処理
        for (int i = 0; i < H; ++i)
        {
            int cur = 0;
            string tmp = S[i];
            for (int j = 0; j < W; ++j)
            {
                if (tmp[j] == '#')
                {
                    cur = 0;
                }
                else
                {
                    ++cur;
                }
                Left[i, j] = cur;
            }
        }

        for (int i = 0; i < H; ++i)
        {
            int cur = 0;
            string tmp = S[i];
            for (int j = W - 1; j >= 0; --j)
            {
                if (tmp[j] == '#')
                {
                    cur = 0;
                }
                else
                {
                    ++cur;
                }
                Right[i, j] = cur;
            }
        }

        for (int j = 0; j < W; ++j)
        {
            int cur = 0;

            for (int i = 0; i < H; ++i)
            {
                string tmp = S[i];
                if (tmp[j] == '#')
                {
                    cur = 0;
                }
                else
                {
                    ++cur;
                }
                Up[i, j] = cur;
            }
        }

        for (int j = 0; j < W; ++j)
        {
            int cur = 0;

            for (int i = H - 1; i >= 0; --i)
            {
                string tmp = S[i];
                if (tmp[j] == '#')
                {
                    cur = 0;
                }
                else
                {
                    ++cur;
                }
                Down[i, j] = cur;
            }
        }

        //集計
        int ans = 0;
        for (int i = 0; i < H; ++i)
        {
            string tmp = S[i];
            for (int j = 0; j < W; ++j)
            {
                if (tmp[j] == '#')
                {
                    continue;
                }
                ans = Math.Max(ans, Left[i, j] + Right[i, j] + Up[i, j] + Down[i, j] - 3);
            }
        }

        Console.WriteLine(ans);
    }

}


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

int main(){
    string s,ans="";
    cin >> s;
    int n;
    n=s.length();
    for(int i=0;i<n;++i){
        if(s[i]=='0') ans+='0';
        if(s[i]=='1') ans+='1';
        if(s[i]=='B' && ans.empty()==false) {
            int l=ans.length();
            ans.erase(l-1);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int A, B; cin >> A >> B; A--; B--;

  int H = 49, W = 98;
  char m[H][W]; rep(i, H) rep(j, W/2) { m[i][j]='#'; m[i][j+W/2]='.';}
  rep(i, A){
    int px = i/((W-2)/4), py = i%((W-2)/4); 
    m[2*px+1][2*py+1] = '.';
  }
  rep(i, B){
    int px = i/((W-2)/4), py = i%((W-2)/4); 
    m[2*px+1][2*py+1+W/2] = '#';
  }

  cout << H << " " << W << endl;
  rep(i, H) { rep(j, W) { cout << m[i][j]; } cout << endl; }
  return 0;
}

Measured memory_bytes: 256
import sys
import math


def main():
    N, D = [int(s) for s in sys.stdin.readline().strip().split()]
    X = []
    for i in range(N):
        Xi = [int(s) for s in sys.stdin.readline().strip().split()]
        X.append(Xi)

    sqrts = set()
    sqrts.add(0)

    ans = 0
    for i in range(N-1):
        for j in range(i+1, N):
            dist_sq = sum([(X[i][k] - X[j][k]) ** 2 for k in range(D)])
            if dist_sq in sqrts:
                ans += 1
            else:
                if math.floor(math.sqrt(dist_sq)) == math.ceil(math.sqrt(dist_sq)):
                    ans += 1
                    sqrts.add(dist_sq)
    print(ans)


if __name__ == '__main__':
    main()



Measured memory_bytes: 38512
#include <stdio.h>
#include <vector>

using namespace std;

struct Node {
	Node() {
		s = p = -1;
		h = d = noc = 0;
	}
	int p, s, d, noc, h;
	vector<int> children;
};

void depth(Node nodes[], int root) {
	for (int i = 0; i < nodes[root].noc; i++) {
		nodes[nodes[root].children[i]].d = nodes[root].d + 1;
		depth(nodes, nodes[root].children[i]);
	}
}

void height(Node nodes[], int h, int p) {
	nodes[p].h = max(nodes[p].h, h + 1);
	if (nodes[p].p != -1) height(nodes, h + 1, nodes[p].p);
}

int main() {
	int n, id, left, right, root;
	scanf("%d", &n);
	Node nodes[n];

	for (int i = 0; i < n; i++) {
		scanf("%d %d %d", &id, &left, &right);
		if (left != -1) {
			nodes[id].children.push_back(left);
			nodes[id].noc++;
			nodes[left].p= id;
		}
		if (right != -1) {
			nodes[id].children.push_back(right);
			nodes[id].noc++;
			nodes[right].p = id;
		}
		if (left != -1 && right != -1) {
			nodes[left].s = right;
			nodes[right].s = left;
		}
	}

	for (root = 0; root < n; root++) {
		if (nodes[root].p == -1) break;
	}

	if (n > 1){
		depth(nodes, root);
		for (int i = 0; i < n; i++) {
			if (nodes[i].noc == 0) height(nodes, 0, nodes[i].p);
		}
	}
	for (int i = 0; i < n; i++) {
		printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d,"
			, i, nodes[i].p, nodes[i].s, nodes[i].noc, nodes[i].d, nodes[i].h);
		if (nodes[i].p == -1) {
			printf(" root\n");
		}
		else if (nodes[i].noc== 0) {
			printf(" leaf\n");
		}
		else {
			printf(" internal node\n");
		}
	}
}



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

int main()
{
	int64_t n, k, q;
	cin >> n >> k >> q;
	vector<int64_t> as(q);
	for (auto &&a : as)
	{
		cin >> a;
		a--;
	}

	vector<int64_t> bs(n, 0);
	vector<bool> cs(n, true);

	for (int64_t i = 0; i < q; i++)
	{
		if (k - i + bs[as[i]] <= 0)
		{
			cs[as[i]] = false;
		}
		bs[as[i]]++;
	}

	for (int64_t i = 0; i < n; i++)
	{
		if (!cs[i])
		{
			continue;
		}
		if (k - q + bs[i] <= 0)
		{
			cs[i] = false;
		}
	}

	for (auto &&c : cs)
	{
		cout << (c ? "Yes" : "No") << endl;
	}

	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
#define int long long
typedef long long ll;
using namespace std;

const int N = 222222;
int cnt[10][10];
int n;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    rep(a, 1, n) {
        string s = to_string(a);
        cnt[s[0] - '0'][a % 10]++;
    }
    int ans = 0;
    rep(b, 1, n) {
        string s = to_string(b);
        ans += cnt[b % 10][s[0] - '0'];
    }
    cout << ans << endl;
    return 0;
}


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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n;
  std::cin >> n;
  std::vector<int64_t> h(n);
  std::cin >> h;

  int64_t ans = 0;
  int64_t tmp = 0;

  for (int64_t i = 1; i < n; i++) {
    if (h[i] <= h[i - 1]) {
      tmp++;
    } else {
      ans = std::max(ans, tmp);
      tmp = 0;
    }
  }
  ans = std::max(ans, tmp);
  tmp = 0;

  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 1024
def calc_divisiors(x):
    divisors=[]
    for i in range(1,x+1):
        if x % i == 0:
            divisors.append(i)
    return divisors

a,b,k = map(int,input().split())
a_divisiors = calc_divisiors(a)
b_divisiors = calc_divisiors(b)
# print(a_divisiors,b_divisiors)
l = list(set(a_divisiors)&set(b_divisiors))
l.sort(reverse=True)
# print(l)
print(l[k-1])

Measured memory_bytes: 38384
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <string>
#include <algorithm>
using namespace std;
const int maxn = 1e2 + 10;
int n, k, v[maxn] = {0};

int Take(int Left, int Right){
    int a = k - (Left + Right);
    //cout << Left << ' ' << Right << " test: " << k - (Left + Right) << endl;
    vector <int> Q;
    for(int i = 0; i < Left; i++){Q.push_back(v[i]);}
    for(int j = n - 1; j >= 0 && Right > 0; j--, Right--){Q.push_back(v[j]);}
    sort(Q.begin(), Q.end());
    int anw = 0;
    //cout << a << endl;
    //for(int i = 0; i < Q.size(); i++){
        //cout << Q[i] << ' ';
    //}
    //cout << endl;
    int i = 0;
    for(i = 0; i < Q.size(); i++){
        if(i < a && Q[i] < 0){continue;}
        anw += Q[i];
    }
    //for(; i < Q.size(); i++){anw += Q[i];}
    //cout << k << ' ' << a << " anw: " << anw << endl;
    //cout << endl;
    return anw;
}

int main(){
    scanf("%d%d", &n, &k);
    int value = 0, r = min(n, k);
    for(int i = 0; i < n; i++){scanf("%d", &v[i]);}
    int anw = 0;
    for(int i = 0; i <= r; i++){
        for(int j = r - i; j >= 0; j--){
            anw = max(anw, Take(i, j));
        }
    }
    printf("%d", anw);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int n,k,x,y,s=0,i;
    scanf("%d%d%d%d",&n,&k,&x,&y);
    for(i=0;i<n&&i<k;i++)s+=x;
    for(i=k;i<n;i++)s+=y;
    printf("%d",s);
    return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-

import math


def isPrime(x):
    if x == 2:
        return True
    if x < 2 or x % 2 == 0:
        return False
    for i in range(3, int(math.sqrt(x)) + 1):
        if x % i == 0:
            return False
    return True


if __name__ == '__main__':

    n = int(input())
    cnt = 0
    for _ in range(n):
        x = int(input())
        if isPrime(x):
            cnt += 1

    print(cnt)



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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

int n;

int main() {
    cin >> n;
    cout << n * n * 3 << endl;
    return 0;
}


Measured memory_bytes: 3624
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ACantWaitForHoliday solver = new ACantWaitForHoliday();
        solver.solve(1, in, out);
        out.close();
    }

    static class ACantWaitForHoliday {
        PrintWriter out;
        InputReader in;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            String st = n();
            String[] arr = new String[]{"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
            int i = 0;
            for (i = 0; i < 7; i++) {
                if (arr[i].equals(st)) {
                    pn(7 - i);
                }
            }

        }

        String n() {
            return in.next();
        }

        void pn(long zx) {
            out.println(zx);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new UnknownError();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}



Measured memory_bytes: 22228
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

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

  if (cnt[0] == n) {
    cout << 1 << endl;
    return 0;
  }
  
  lint ans = cnt[0];
  if (cnt[1] > cnt[2]) {
    swap(cnt[1], cnt[2]);
  }
  
  ans += cnt[1] + min(cnt[1] + 3, cnt[2]);
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 4672
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws NumberFormatException 
	 */
	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] tmpArray = br.readLine().split(" ");
		double r = Double.parseDouble(tmpArray[0]);
//		int b = Integer.parseInt(tmpArray[1]);
//		int c = Integer.parseInt(tmpArray[2]);
//		int y = Integer.parseInt(tmpArray[3]);
//		int r = Integer.parseInt(tmpArray[4]);
		
		
		System.out.printf("%f %f", Math.PI*r*r, Math.PI*2*r);
		/*
		int i = 1;
		while(true){
			String[] tmpArray = br.readLine().split(" ");
			int a = Integer.parseInt(tmpArray[0]);
			int b = Integer.parseInt(tmpArray[1]);
			if(a == 0 && b == 0){
				break;
			}
			if(a > b){
				int tmp = a; 
				a = b;
				b = tmp;
			}
			System.out.println(a + " "+b);
			
		}*/

		//		int[] array = new int[3];
//		array[0] = a; array[1] = b; array[2] = c;
//
//		Arrays.sort(array);
//		System.out.printf("%d %d %d\n", array[0], array[1], array[2]);
		/*
		if(a < b && b < c){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}*/
	}

}

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

int n, m;

vector <int> num[1000007];

int x[1000007];
int y[1000007];
int com[1000007];

vector <int> graf[1000007];

int odl[1000007];

priority_queue < pair <int,int> > dij;
int v;

int ko(int v, int u)
{
    return (v<=n && u>n);
}

bool mniej(int a, int b)
{
    return com[a]<com[b];
}

int main()
{
    scanf("%d%d", &n, &m);
    for (int i=1; i<=m; i++)
    {
        scanf("%d%d%d", &x[i], &y[i], &com[i]);
        graf[x[i]].push_back(n+i);
        graf[y[i]].push_back(n+i);
        graf[n+i].push_back(x[i]);
        graf[n+i].push_back(y[i]);

        num[x[i]].push_back(i);
        num[y[i]].push_back(i);
    }
    for (int i=1; i<=n; i++)
    {
        sort(num[i].begin(), num[i].end(), mniej);
        for (int j=1; j<(int)num[i].size(); j++)
        {
            if (com[num[i][j]]==com[num[i][j-1]])
            {
                graf[num[i][j]+n].push_back(num[i][j-1]+n);
                graf[num[i][j-1]+n].push_back(num[i][j]+n);
            }
        }
    }
    dij.push(make_pair(-1, 1));
    while(!dij.empty())
    {
        v=dij.top().second;
        if (odl[v])
        {
            dij.pop();
            continue;
        }
        odl[v]=-dij.top().first;
        dij.pop();
        for (int i=0; i<graf[v].size(); i++)
            dij.push(make_pair( -odl[v]-ko(v, graf[v][i]) , graf[v][i] ));
    }
    printf("%d\n", odl[n]-1);
    return 0;
}


Measured memory_bytes: 74100
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  n, m = map(int, readline().split())
  A = list(int(readline()) for i in range(m))
  A.append(INF)
  dp = [0]*(n+1)
  dp[0] = 0
  j = 0
  if A[j] == 1:
    dp[1] = 0
    j += 1
  else:
    dp[1] = 1
  
  if n>=2:
    if A[j] == 2:
      dp[2] = 0
      j += 1
    else:
      dp[2] = dp[1] + 1
  
  if n>=3:
    for i in range(3, n+1):
      if A[j] == i:
        dp[i] = 0
        j += 1
      else:
        dp[i] = (dp[i-1]+dp[i-2])%MOD
  print(dp[n])
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 9980
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXLEN = 300000;

int len, base;
int ret[MAXLEN], nret;

void solve() {
	nret = 0;
	if (base == 1) {
		nret = (len + 1) / 2; REP(i, nret) ret[i] = 1;
	} else if (base % 2 == 0) {
		ret[nret++] = base / 2; FOR(i, 1, len) ret[nret++] = base;
	} else {
		int pref = 0;
		while (true) {
			// middle of {pref} and base times {(base^(len-pref)-1)/(base-1)}
			// as long as pref*(base-1)+1<base^(len-pref) then we can remove the large blocks from each side
			ll lhs = (ll)pref*(base - 1) + 1;  ll rhs = 1; REP(i, len - pref) if (lhs < rhs) break; else rhs *= base;
			if (!(lhs < rhs)) break;
			ret[nret++] = (base + 1) / 2; ++pref;
		}
		ll block = 1; REP(i, len - pref) block *= base; block = (block - 1) / (base - 1);
		ll sum = pref + base*block, idx = (sum - 1) / 2;
		//printf("base=%d,len=%d: pref=%d sum=%lld idx=%lld block=%lld\n", base, len, pref, sum, idx, block);
		if (idx < pref) {
			nret = idx + 1; REP(i, nret) ret[i] = (base + 1) / 2;
		} else {
			idx -= pref; ret[nret] = 1;
			while (idx >= block) idx -= block, ++ret[nret];
			++nret;
			while (idx != 0) {
				--idx; block = (block - 1) / base; ret[nret] = 1;
				while (idx >= block) idx -= block, ++ret[nret];
				++nret;
			}
		}
	}
}

void run() {
	scanf("%d%d", &base, &len);
	solve();
	REP(i, nret) { if (i != 0) printf(" "); printf("%d", ret[i]); } puts("");
}

void stress() {
	for (base = 1; base <= 10; ++base) for (len = 1; len <= 20; ++len) {
		solve();
		REP(i, nret) { if (i != 0) printf(" "); printf("%d", ret[i]); } puts("");
	}
}

int main() {
	run();
	//stress();
	return 0;
}


Measured memory_bytes: 3456
import java.util.*;
public class Main{
	static int maxOfVar(int k, String s){
		String[] alph = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
		int num = 0;
		int cnt = 0;
		for(int i=0; i<k; i++){
			cnt = 0;
			String x = s.substring(0,i);
			String y = s.substring(i);
			for(int j=0; j<26; j++){
				if(!x.equals(x.replaceAll(alph[j],"")) && !y.equals(y.replaceAll(alph[j],"")))cnt++;
			}
			if(num<cnt)num = cnt;
		}
		return num;
	}

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String S = sc.next();
		System.out.println(maxOfVar(n,S));
	}
}

Measured memory_bytes: 31444
#include<bits/stdc++.h>
using namespace std;
int n,k,i,j,now;
long long qdh[1005],ans,sp;
vector<long long> q;
int main(){
	cin>>n>>k;
	for(i=1;i<=n;i++)
	{
		cin>>qdh[i];
		qdh[i]+=qdh[i-1];
	}
	ans=0;
	for(i=0;i<n;i++)
		for(j=i+1;j<=n;j++)
			q.push_back(qdh[j]-qdh[i]);
	for(i=40;i>=0;i--)
	{
		ans+=((long long)1<<i);
		int cnt=0;
		for(j=0;j<=q.size();j++)
			if((q[j]&ans)==ans)
				cnt++;
		if(cnt<k)
			ans-=((long long)1<<i);
	}
	cout<<ans<<endl;
	return 0;
}

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

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

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

def main():
    n = int(input())
    d = map(int, input().split())
    arr = list(itertools.combinations(d,2))
    ans = 0
    for x, y in arr:
        ans += x*y
    print(ans)



if __name__ == '__main__':
        main()


Measured memory_bytes: 3060
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: i32 = read();
    let h: Vec<i32> = (0..n).map(|_| read()).collect();
    let mut max = 0;
    let mut ans = 0;
    for x in h {
        if max <= x {
            ans += 1;
            max = x;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}


int main(){
  double a,b,x; cin >> a >> b >> x;
  
  double d,radian,degree;
  if(x > a*a*b/2){
    d = (2*a*a*b-2*x)/(a*a);
    radian = atan(a/d);
    degree = radian * 180.0 /PI;
    degree = 90.0-degree;
  }else{
    d = 2*x/(a*b);
    radian = atan(b/d);
    degree = radian * 180.0 / PI;
  }
  
  printf("%.15f\n",degree);
 
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,vl>;
using vvl = vector<vector<ll>>;
ll INF=1LL<<60;
ll MOD=1000000007;



int main(){
    ll N;
    cin >> N;
    ll K;
    cin >> K;
    vector<ll> A(N+1,0);
    for(ll i=0;i<N;i++){
        cin>>A[i+1]
    ;}
    ll sum=1;
    Map m;
    for(ll i=0;i<=N;i++){
        sum+=A[i]-1;
        sum%=K;
        m[sum].emplace_back(i);
    ;}
    ll ans=0;
    for(auto p: m){
        for(ll i=0;i<p.second.size();i++){
            ans+=lower_bound(p.second.begin(), p.second.end(), p.second[i]+K)-1-i-p.second.begin()
        ;}
    ;}
    cout<<ans<<endl;
    return 0;
}


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

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

using namespace std;

int main() {
  while(1){
    int n;
    cin>>n;
    if(!n) break;
    vector<string> trr(n);
    REP(i,n) cin>>trr[i];
    vector<int> old(1000,-1);
    REP(i,n) {
      if (!i) continue;
      int dep = 0;
      while(trr[i][dep] == '.') ++dep;
      REP(j,dep) trr[i][j] = ' ';
      trr[i][dep-1] = '+';
      if (old[dep] != -1) {
        for (int j = old[dep] + 1; j < i; ++j) {
          trr[j][dep-1] = '|';
        }
      }
      old[dep] = i;
      for (int j=dep+1; j < 1000; ++j) old[j] = -1;
    }
    REP(i,n) cout << trr[i] << endl;
  }
  return 0;
}

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

using namespace std;

int main() {

	int n;

	cin >> n;

	vector<int> f(1+n,0);

	int lim = (int)sqrt(n - 2) - 1;

	for(long long x = 1; x <= lim; x++ ) {

		for(long long y = 1; y <= lim; y++) {

			for(long long z = 1; z <= lim; z++ ) {

				long long res = x*x + y*y + z*z + x*y + y*z + z*x;

				if(res <= n) {
					f[res]++;
				}
			}
		}
	}

	for(int i = 0; i < n; i++) {
		cout << f[i+1] <<'\n';
	}

	return 0;
}

Measured memory_bytes: 3536
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define V vector<int>
#define COUT(x) cout<<(x)<<endl
#define M map<int,int>
#define S set<int>
#define PQ priority_queue


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

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 50;

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<P>vec;
	rep(i, n) {
		int a; cin >> a;
		vec.push_back({ a,0 });
	}
	rep(i, n) {
		int a; cin >> a;
		vec.push_back({ a,1 });
	}
	sort(vec.begin(), vec.end());
	int ans = 1;
	int p = 0, e = 0;
	rep(i, 2 * n) {
		if (vec[i].second == 0) {
			if (e > p)ans *= (e - p); p++;
		}
		else {
			if (p > e)ans *= (p - e); e++;
		}
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  int n; cin >> n;
  vector<int> a(n);
  int q;
  ll sum = 0;
  vector<ll> num(110000, 0);
  rep(i, n){
    ll a; cin >> a;
    sum += a;
    num[a]++;
  }
  cin >> q;
  rep(i, q){
    ll b, c; cin >> b >> c;
    sum += (c - b) * num[b];
    num[c] += num[b];
    num[b] = 0;
    cout << sum << endl;
  }
  return 0;
}


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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

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

	if(b==1){
		cout<<0<<endl;
		return 0;
	}else if(a>=b){
		cout<<1<<endl;
		return 0;
	}

	int sum=a,ans=1;
	while(sum<b){
		ans++;
		sum=sum+a-1;
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


struct SCC{
    int n;
    vector<vector<int>> g,rg;
    vector<int> vs,cmp;
    vector<bool> used;
    SCC(int _n){
        n=_n;
        g=vector<vector<int>>(n);rg=g;
        cmp=vector<int>(n);used=vector<bool>(n);
    }
    void add_edge(int f, int t){
        g[f].push_back(t);
        rg[t].push_back(f);
    }
    int init(){
        rep(i,n)if(!used[i])dfs(i);
        int k=0;
        used=vector<bool>(n,false);
        per(i,n){
            if(!used[vs[i]]){
                rdfs(vs[i],k);
                k++;
            }
        }
        return k;
    }
    private:
    void dfs(int v){
        used[v]=true;
        rep(i,g[v].size()){
            if(!used[g[v][i]])dfs(g[v][i]);
        }
        vs.push_back(v);
    }
    void rdfs(int v, int k){
        used[v]=true;cmp[v]=k;
        rep(i,rg[v].size()){
            if(!used[rg[v][i]]){
                rdfs(rg[v][i],k);
            }
        }
    }
};

int main(){
    ll n,d;cin >> n >>d;
    SCC g(2*n);
    vl x(n),y(n);rep(i,n)cin >> x[i] >> y[i];
    rep(i,n){
        repl(j,i+1,n){
            if(abs(x[i]-x[j])<d){
                g.add_edge(i,j+n);
                g.add_edge(j,i+n);

            }
            if(abs(x[i]-y[j])<d){
                g.add_edge(i,j);
                g.add_edge(j+n,i+n);
            }
            if(abs(y[i]-x[j])<d){
                g.add_edge(i+n,j+n);
                g.add_edge(j,i);
            }
            if(abs(y[i]-y[j])<d){
                g.add_edge(i+n,j);
                g.add_edge(j+n,i);
            }
        }
    }
    g.init();
    bool ok=true;
    rep(i,n){
        if(g.cmp[i]==g.cmp[i+n])ok=false;
    }
    if(ok){
        cout << "Yes" <<endl;
        rep(i,n){
            if(g.cmp[i]>g.cmp[i+n])cout << x[i] <<endl;
            else cout << y[i] <<endl;
        }
    }
    else{
        cout << "No" <<endl;
    }
}


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

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var d = new int[n];
        for (int i = 0; i < n; i++)
        {
            d[i] = int.Parse(Console.ReadLine());
        }

        var left = new int[n + 1];
        for (int i = 0; i < n; i++)
        {
            left[i + 1] = Math.Max(left[i], d[i]);
        }

        var right = new int[n + 1];
        for (int i = n - 1; 0 <= i; i--)
        {
            right[i] = Math.Max(right[i + 1], d[i]);
        }

        for (int i = 0; i < n; i++)
        {
            Console.WriteLine(Math.Max(left[i], right[i + 1]));
        }
    }
}


Measured memory_bytes: 18772
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

// -------------------------------------------------------------------------------------



int main() {
  vector< vector<int> > c;
  c.assign(3, vector<int>(3, 0));
  rep(i, 3) {
    rep(j, 3) {
      cin >> c[i][j];
    }
  }

  int b1 = c[0][0], b2 = c[0][1], b3 = c[0][2];
  int a1 = 0, a2 = c[1][0]-b1, a3 = c[2][0]-b1;

  if(c[0][0] == a1 + b1
    && c[1][0] == a2 + b1
    && c[2][0] == a3 + b1
    && c[0][1] == a1 + b2
    && c[1][1] == a2 + b2
    && c[2][1] == a3 + b2
    && c[0][2] == a1 + b3
    && c[1][2] == a2 + b3
    && c[2][2] == a3 + b3
  ) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

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

int main()
{
    int H, W;
    cin >> H >> W;
    char a[H][W];

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> a[i][j];
        }
    }

    for(int i = 0; i < W + 2; i++){
        cout << "#";
    }
    cout << "" << endl;
    for(int i = 0; i < H; i++){
        cout << "#";
        for(int j = 0; j < W; j++){
            cout << a[i][j];
        }
        cout << "#" << endl;
    }

    for(int i = 0; i < W + 2; i++){
        cout << "#";
    }
    cout << "" << endl;
    

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long lli;
int main()
{
	lli a, b; cin >> a >> b;
	lli arr1[b + 50], arr2[b + 50], mx = 0;
	for(int i=0; i<b; i++)
	{
		cin >> arr1[i] >> arr2[i];
		mx = max(mx, arr1[i]);
	}
	lli dp[a + mx + 50];
	for(int i=0; i<=a + mx; i++)
		dp[i] = 2147483647;
	dp[0] = 0;
	for(int i=0; i < b; i++)
	{
		for(int j=arr1[i]; j <= a + mx; j++)
		{
			dp[j] = min(dp[j], dp[j - arr1[i]] + arr2[i]);
		}
	}
	lli ans = 2147483647;
	for(int i=a; i <= a + mx; i++)
		ans = min(ans, dp[i]);
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
   
#define MAXLEN 100000
    
     
int main( void ) 
{
    int n,q;
    int S[MAXLEN+1],T[MAXLEN+1];
    int i;
    int cnt;
    int lo,hi,m;
       
    scanf( "%d", &n ); 
    for( i=0; i<n; i++ ) {
        scanf( "%d", &S[i] ); 
    }
   
    scanf( "%d", &q); 
    for( i=0; i<q; i++ ) {
        scanf( "%d", &T[i] ); 
    }
    
    cnt=0;
    for( i=0; i<q; i++ ) {
		lo=0;
		m=n/2;
		hi=n;
		while( lo <= hi ) {
            if( T[i] == S[m] ) {
                cnt++;
                break;
            } else if( T[i] < S[m] ) {
            	hi=m-1;
            	m=(lo+hi)/2;            	
            } else {
            	lo=m+1;
            	m=(lo+hi)/2;            	
            }
        }
    }
 
    if( cnt ) {
        printf( "%d\n", cnt );
    } else {
        printf( "0\n" );
    }
   
    return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <iomanip>
#include <sstream>

int main(void)
{
    int64_t N;
    std::cin >> N;

    std::vector<int64_t> A(N);

    for (auto& a : A) {
        std::cin >> a;
    }

    std::vector<int64_t> sorted = A;

    std::sort(sorted.begin(), sorted.end(), std::greater<int64_t>());

    for (auto& a: A) {
        int64_t max = sorted.at(0);
        if (a == max) max = sorted.at(1);
        std::cout << max << std::endl;
    }

    return 0;
}

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

//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
//typedef unsigned long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
typedef pair<int, int> P;
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX / 100;
//const ll INF = (1ll << 31) - 1;
const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<ll> &s, ll a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> positions(m);
    rep(i, m) cin >> positions[i];
    sort(positions.begin(), positions.end());

    vector<int> dis;
    rep(i, m - 1)dis.push_back(positions[i + 1] - positions[i]);
    sort(dis.begin(), dis.end());
    int ans = 0;
    rep(i, m - n) ans += dis[i];
    cout << ans << endl;
}



Measured memory_bytes: 1276
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define upperlimit 1000100
#define INF 1000000100
#define INFL 1000000000000000100LL
#define eps 1e-8
#define endl '\n'
#define sd(n) scanf("%d",&n)
#define slld(n) scanf("%lld",&n)
#define pd(n) printf("%d",n)
#define plld(n) printf("%lld",n)
#define pds(n) printf("%d ",n)
#define pllds(n) printf("%lld ",n)
#define pdn(n) printf("%d\n",n)
#define plldn(n) printf("%lld\n",n)
#define REP(i,a,b) for(i=a;i<=b;i++)
#define mp make_pair
#define pb push_back
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define F first
#define S second
#define clr(a) memset(a,0,sizeof(a))
#define FILEIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);

using namespace std;

ll gcd(ll n1,ll n2){
    if(!n1)return n2;
    if(!n2)return n1;
    if(n1%n2==0)return n2;
    return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent){
    base%=mod;
    ll ans=1;
    while(exponent){
        if(exponent&1)ans=(ans*base)%mod;
        base=(base*base)%mod;
        exponent/=2;
    }
    ans%=mod;
    return ans;
}
int arr[upperlimit+1];
int main()
{
	int n,i,j,k;
	ll answer=0;
	sd(n);
	for(i=0;i<n;i++)sd(arr[i]);
	for(i=0;i<n;i++){
		if(arr[i]>i){
			pdn(-1);
			return 0;
		}
	}
	int ind=n-1;
	for(i=n-1;i>0;i--){
		if(i>ind && arr[i]<(i-ind)){
			pdn(-1);
			return 0;
		}
		if(arr[i]==arr[i-1]+1)answer++;
		else{
			ind=min(ind,i-arr[i]);
			answer+=arr[i];
		}
	}
	plldn(answer);
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define N 500009
using namespace std;
typedef long long ll;
map<ll,ll>m;
int main(void)
{
    //freopen("in.txt","r",stdin);

    ll n;
    cin>>n;
    for(ll i=1;i<n;i++)
    {
        ll a;
        cin>>a;
        m[a]++;
    }
    for(ll i=1;i<=n;i++) cout<<m[i]<<endl;

    //main();
    return 0;
}


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

int main() {
	long long N, K;
	cin >> N >> K;

/*	long long diff = abs(N - K);
	long long prev_diff = N;

	if(N % K == 0) {
		cout << 0 << endl;
		return 0;
	}

	bool flag = true;
	while(flag) {
		if(diff >= prev_diff)
			flag = false;
		else {
			prev_diff = diff;
			diff = abs(diff - K);
		}
	}
*/
	N %= K;
	if(N >= abs(N - K))
		cout << abs(N - K) << endl;
	else
		cout << N << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string a, b;
	while (cin >> a >> b)
	{
		int x = a.size();
		int y = b.size();
		if (x != y)
			cout << "No" << endl;
		else if (a == b)
			cout << "Yes" << endl;
		else
		{
			int flag = 0;
			for (int i = 0;i < x;i++)
			{
				string str = a;
				str[0] = a[x - 1];
				for (int i = 1;i <x;i++)
				{
					str[i] = a[i - 1];
				}
				if (str == b)
				{
					flag = 1;
					break;
				}
				a = str;
			}
			if (flag == 0)
				cout << "No" << endl;
			else
				cout << "Yes" << endl;
		}	
	}
	return 0;
}

Measured memory_bytes: 256