akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long int
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;

struct edge { int to, cost; };

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

signed main()
{
   int N; cin >> N;
   V<int> a(N);
   for (int i = 0; i < N; i++) {
      cin >> a[i];
   }

   sort(a.begin(), a.end());
   if (a[N-1] - a[0] == 0) {
      if (a[0] == N-1 || a[0] <= N/2) {
         cout << "Yes" << endl;
         return 0;
      }
   }
   if (a[N-1] - a[0] == 1) {
      int A = lower_bound(a.begin(), a.end(), a[N-1]) - a.begin();
      int B = N - A;
      if (A+1 <= a[0]+1 && a[0]+1 <= A+B/2) {
         cout << "Yes" << endl;
         return 0;
      }
   }
   cout << "No" << endl;

   return 0;
}


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

int main(){
 int a, b, c, d;
 cin >> a >> b >> c >> d;
 int xd = c - a;
 int yd = d - b;
 int x_3 = c - yd;
 int y_3 = d + xd;
 int x_4 = x_3 - xd;
 int y_4 = y_3 - yd;
 cout << x_3 << ' ' << y_3 << ' ' << x_4 << ' ' << y_4 << '\n';
}


Measured memory_bytes: 3644
n,k,*a=map(int,open(0).read().split())
b=[-1]*(n+1)
b[1]=0
c=a[0]
d=[0]*min(k+1,10**7)
d[0]=1
for i in range(1,k+1):
    d[i]=c
    if b[c]!=-1:
        # print(i,c,b[c])
        print(d[b[c]+(k-b[c])%(i-b[c])])
        exit()
    b[c]=i    
    c=a[c-1]
print(d[-1])  

Measured memory_bytes: 102220
#include <bits/stdc++.h>
using namespace std;
#define Me3za() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);srand(time(NULL))
#define endl "\n"
int n;
int arr[100005];
int mem[100005];
long long solve(int i,int cur){
if(i>=n)return 1e9;
//cout<<i<<" "<<cur<<endl;
if(mem[i]!=-1)return mem[i];
long long ch1=solve(i+1,arr[i+1])+abs(cur-arr[i+1]);
long long ch2=0;
if(i+2<=n)ch2=solve(i+2,arr[i+2])+abs(cur-arr[i+2]);
return mem[i]=min(ch1,ch2);
}
int main() {
Me3za();
cin>>n;
for(int i=0;i<n;i++){
    cin>>arr[i];
}
memset(mem,-1,sizeof mem);
cout<<solve(0,arr[0]);
}



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

int nil=-1;

struct Node{
	int p,l,r;
};
//pはparent,lはleftchild,rはrightchild

Node T[10000];
int n;

void preParse(int u){
	if(u==nil) return;
	cout<<" "<<u;
	preParse(T[u].l);
	preParse(T[u].r);
}

void inParse(int u){
	if(u==nil) return;
	inParse(T[u].l);
	cout<<" "<<u;
	inParse(T[u].r);
}

void postParse(int u){
	if(u==nil) return;
	postParse(T[u].l);
	postParse(T[u].r);
	cout<<" "<<u;
}

int main(){
	cin>>n;
	int u,l,r,root;
	for(int i=0;i<n;i++) T[i].p=nil;
	for(int i=0;i<n;i++){
		cin>>u>>l>>r;
		T[u].l=l;
		T[u].r=r;
		if(l!=nil) T[l].p=u;
		if(r!=nil) T[r].p=u;
	}
	for(int i=0;i<n;i++) if(T[i].p==nil) root=i;

	cout<<"Preorder"<<endl;
	preParse(root);
	cout<<endl;
	cout<<"Inorder"<<endl;
	inParse(root);
	cout<<endl;
	cout<<"Postorder"<<endl;
	postParse(root);
	cout<<endl;

	return 0;


}



Measured memory_bytes: 3020
'''input
3 5
1 2 1
2 3 0
'''
# connected components
from sys import stdin, setrecursionlimit


# main starts
a, b, k = list(map(int, stdin.readline().split()))

if a > k:
    a -= k
else:
    k -= a
    a = 0
    if b < k:
        b = 0
    else:
        b -= k

print(a, b)


Measured memory_bytes: 38384
#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 ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

using ll = long long int;
using P = pair<int,int>;

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

const ll INF=(ll)1e19;
//const int INF=(1<<30);
//const int INF=(1<<29);

int main(){
  VI a(3);
  REP(i,3)cin >> a[i];
  sort(ALL(a));
  cout << (a[0]+a[1]==a[2] ? "Yes" : "No") << endl;
}



Measured memory_bytes: 256
n = gets.to_i

def lcs(x, y)
  m = x.size
  n = y.size
  c = []
  maxl = 0

  x.unshift(nil)
  y.unshift(nil)

  (0..m).each do |i|
    c[i] = []
    c[i][0] = 0
  end
  (1..n).each do |i|
    c[0][i] = 0
  end

  (1..m).each do |i|
    (1..n).each do |j|
      if x[i] == y[j]
        c[i][j] = c[i - 1][j - 1] + 1
      else
        c[i][j] = [c[i - 1][j], c[i][j - 1]].max
      end
      maxl = [maxl, c[i][j]].max
    end
  end
  maxl
end

(0...n).each do |i|
  s1 = gets.chomp
  s2 = gets.chomp
  puts lcs(s1.chars, s2.chars)
end


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


int main(){
  string x;
  cin >> x;
  int n=x.size();
  stack<char> s;
  for(int i=0;i<n;++i){
    if(x[i]=='S'){
      s.push(x[i]);
    }else if(x[i]=='T'){
      if(s.empty()){
        s.push(x[i]);
      }else if(s.top()=='S'){
        s.pop();
      }else if(s.top()=='T'){
        s.push(x[i]);
      }
    }
  }

  cout << s.size() << endl;
  return 0;
}


Measured memory_bytes: 644
#include<iostream>

using namespace std;

int main(){
	int x,a,b,xa,xb;
	cin>>x>>a>>b;
	xa=x-a;
	if(xa<0) xa*=-1;
	xb=x-b;
	if(xb<0) xb*=-1;
	if(xa>=xb) cout<<"B"<<endl;
	else cout<<"A"<<endl;
	return 0;
}

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

main() {
  int A, B, C, D; cin >> A >> B >> C >> D;
  int ans = (max(B, D) - min(A, C)) - (abs(A - C) + abs(B - D));
  cout << ( (ans < 0) ? 0 : ans ) << endl;
}


Measured memory_bytes: 256
while True:
  a, op, b = map(str, input().split())
  a = int(a)
  b = int(b)
  if op == '?':
    break
  if op == '+':
    print(a + b)
  if op == '-':
    print(a - b)
  if op == '*':
    print(a * b)
  if op == '/':
    print(a // b)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;
 
ll N, A[100000], B[100000], C[100000];
 
int main(void) {
  cin >> N;
  REP(i, 0, N) cin >> A[i];
  REP(i, 0, N) cin >> B[i];
  REP(i, 0, N) cin >> C[i];
 
  sort(A, A + N);
  sort(B, B + N);
  sort(C, C + N);
 
  vector<ll> cnt(100000, 0);
  ll k = 0;
  REP(j, 0, N) {
    while(k < N && C[k] <= B[j]) k++;
    cnt[j] = N - k;
  }
  for(ll j = N - 1; j > 0; j--) cnt[j - 1] += cnt[j];
 
  ll ans = 0;
  ll j = 0;
  REP(i, 0, N) {
    while(j < N && B[j] <= A[i]) j++;
    ans += cnt[j];
  }
 
  cout << ans << endl;
}


Measured memory_bytes: 3328
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();
      	int b[]=new int[a];
      int sum=0;
      	for(int i=0;i<a;i++){b[i]=scan.nextInt();sum+=b[i];}
      int c=scan.nextInt();
      for(int i=0;i<c;i++){
      int x=scan.nextInt();
      int y=scan.nextInt();
      System.out.println(sum-b[x-1]+y);
      }
}
}


Measured memory_bytes: 23124
import java.util.*;
import static java.lang.System.*;

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    Scanner sc = new Scanner(in);
    int N = sc.nextInt();
    Integer A[] = new Integer[N+2];
    A[0] = 0;
    for(int i=1; i<N+1; i++) A[i] = sc.nextInt();
    A[N+1] = 0;
    Integer B[] = new Integer[N+1];
    int sum = 0;
    for(int i=0; i<N+1; i++){
      B[i] = Math.abs(A[i+1] - A[i]);
      sum += B[i];
    }
    int ans;
    for(int i=1; i<N+1; i++){
      ans = sum - B[i-1] - B[i] + Math.abs(A[i+1] - A[i-1]);
      out.println(ans);
    }
    
  }

  public static int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
  }
}

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

namespace A
{
    class Program
    {
        public static void Main(string[] args)
        {
            var s = ReadLine();

            Console.WriteLine((s[0] == s[1] && s[0] == s[2] && s[1] == s[2]) ? "No" : "Yes");
            ReadLine();
        }

        /// <summary>
        /// コンビネーション
        /// </summary>
        /// <param name="n"></param>
        /// <param name="m"></param>
        /// <returns></returns>
        static int nCm(int n, int m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            return n * nCm(n - 1, m - 1) / m;
        }

        /// <summary>
        /// stringを一文字ずつintにキャストして配列に変換します。
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static int[] StringCharArrayIntArray(string str)
        {
            List<int> b = new List<int>();
            for (int i = 0; i < str.Length; i++) {
                b.Add( int.Parse(str[i].ToString()));
            }
            return b.ToArray();
        }

        public static string ReadLine()
        {
            return Console.ReadLine();
        }

        public static int ReadLineInt()
        {
            return int.Parse(Console.ReadLine());
        }

        public static string[] ReadLineStringSplit(char a = ' ')
        {
            return ReadLine().Split(a).ToArray();
        }

        public static int[] ReadLineIntSpilit(char a = ' ')
        {
            return ReadLine().Split(a).Select(x => int.Parse(x)).ToArray();
        }
    }
}

Measured memory_bytes: 11092
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys, math, bisect, random, itertools
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A(s):

    # たぶん嘘解法です
    def fake():

        def pri(n, x):
            for i in range(2, int(math.sqrt(n))):
                if n % i == 0 and n // i <= x:
                    return [i, n // i]
            return [1, n]

        x = int(math.sqrt(s))
        if s < 10 ** 9:
            print(0, 0, 0, s, 1, 0)
            return
        while 1:
            X = x ** 2
            if X - s < 0:
                x += 1
                continue
            b = pri(X - s, x)
            if b:
                print(0, 0, x, int(b[0]), int(b[1]), x)
                return
            x += 1
        return

    # 本解答
    v = 10 ** 9
    y = -s % v
    x = (s + y) // v
    print(0, 0, v, 1, y, x)
    return


#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return



#Solve
if __name__ == '__main__':
    A(II())


Measured memory_bytes: 39280
import java.math.BigInteger;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		
		Scanner sc = new Scanner(System.in);
		
		int num = sc.nextInt();
		
		for(int i=0; i<num; i++){
			BigInteger x = sc.nextBigInteger();
			BigInteger y = sc.nextBigInteger();
			BigInteger sum = x.add(y);
			
			if (sum.toString().length()<=80) {
				System.out.println(sum);
			}
			else{
				System.out.println("overflow");
			}
		}
	}
}

Measured memory_bytes: 18448
#include<iostream>
using namespace std;
int main()
{
	int h1,m1,h2,m2,s;
	cin>>h1>>m1>>h2>>m2>>s;
	if(h1>h2) 
	{
		cout<<"0";
		return 0;
	}
	if(m1>m2)
	{
		h2--;
		m2+=60;
	}
	int temp=(h2-h1)*60+m2-m1-s;
	if(temp>0) cout<<temp;
	else cout<<"0";
	return 0;
}

Measured memory_bytes: 3636
from sys import stdin
def main():
  N = int(input())
  Wlist = list(map(int, stdin.readline().rstrip().split()))
  
  diffMin = -1
  for i in range(N):
    S1 = sum(Wlist[0:i+1])
    S2 = sum(Wlist[i+1:N])
    
    diff = abs(S2-S1)
    if diffMin < 0 or diff < diffMin:
      diffMin = diff
    elif diff > diffMin:
      break
      
  print(diffMin)   

input = lambda: stdin.readline()
main()


Measured memory_bytes: 3060
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public static String process(TestCase testCase) {
        final int N = testCase.N;
        final int X = testCase.X;
        final List<Integer> x = testCase.x;

        final int num = x.stream()
                .map(xi -> Math.abs(X - xi))
                .reduce(Main::gcd)
                .orElseThrow(() -> new IllegalArgumentException("x is empty"));
        return String.valueOf(num);
    }

    private static int gcd(int a, int b) {
        if (b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    }

    // Util func

    public static void main(String[] args) {
        TestCase testCase = readFromInput();

        final String result = process(testCase);

        output(result);
    }

    private static TestCase readFromInput() {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int X = sc.nextInt();
        final List<Integer> x = IntStream.range(0, N).mapToObj(i -> sc.nextInt()).collect(Collectors.toList());

        return new TestCase(N, X, x);
    }

    private static void output(String result) {
        System.out.println(result);
    }

    public static class TestCase {
        final int N;
        final int X;
        final List<Integer> x;

        public TestCase(int N, int X, List<Integer> x) {
            this.N = N;
            this.X = X;
            this.x = x;
        }
    }
}


Measured memory_bytes: 61800
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <complex>

int add_num(std::vector<long long int> &BIT, long long int N_MAX, long long int index, long long int d);
long long int cumulative_sum(std::vector<long long int> &BIT, long long int r);

int main(){

  // prepare BIT
  long long int N_MAX = 1LL<<19; // aproximately
  std::vector<std::vector<long long int> > BIT_table(26, std::vector<long long int>(N_MAX));

  std::vector<long long int> ans;

  // read problem
  long long int N, Q, tmp, tmp1, tmp2;
  char ctmp;
  std::string S;
  std::vector<long long int> I, L, R;
  std::vector<char> C;

  scanf("%lld", &N);
  std::cin >> S;
  scanf("%lld", &Q);

  for(long long int i = 0; i < N; i++){
    add_num(BIT_table[(long long int)S[i] - 'a'], N_MAX, i, 1);
  }

  for(long long int i = 0; i < Q; i++){
    scanf("%lld", &tmp);
    if(tmp == 1){
      scanf("%lld %c", &tmp1, &ctmp);
      I.push_back(tmp1);
      C.push_back(ctmp);
      
      // change count
      add_num(BIT_table[(long long int)S[tmp1-1] - 'a'], N_MAX, tmp1-1, -1);
      add_num(BIT_table[(long long int)ctmp - 'a'], N_MAX, tmp1-1, 1);
      // change letter
      S[tmp1-1] = ctmp;
    }
    else{
      scanf("%lld%lld", &tmp1, &tmp2);
      L.push_back(tmp1);
      R.push_back(tmp2);
      tmp = 0;
      for(long long int j = 0; j < 26; j++){
        if(cumulative_sum(BIT_table[j], tmp2-1) - cumulative_sum(BIT_table[j], tmp1-2) > 0){
          tmp++;
        }
      }
      ans.push_back(tmp);
    }
  }

  std::cerr << "Answer:" << std::endl;
  for(long long int i = 0; i < ans.size(); i++){
    std::cout << ans[i] << std::endl;
  }
  
  /*std::cerr << "N: " << N << std::endl;
  std::cerr << "S: " << S << std::endl;
  std::cerr << "Q: " << Q << std::endl;
  std::cerr << "Q1" << std::endl;
  for(long long int i = 0; i < I.size(); i++){
    std::cerr << I[i] << " " << C[i] << std::endl;
  }
  std::cerr << "Q2" << std::endl;
  for(long long int i = 0; i < L.size(); i++){
    std::cerr << L[i] << " " << R[i] << std::endl;
  }*/
  return 0;
  
}


int add_num(std::vector<long long int> &BIT, long long int N_MAX, long long int index, long long int d){
  index ++;
  while(index < N_MAX){
    BIT[index-1] += d;
    index += (index & -index);
  }
  
  return 0;
}

long long int cumulative_sum(std::vector<long long int> &BIT, long long int r){
  // sum of no elements
  if(r == -1){
    return 0;
  }
  
  r++;
  long long int sum = 0;
  while(r > 0){
    sum += BIT[r-1];
    r -= (r & -r);
  }
  
  return sum;
}


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

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using ull = unsigned long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vvs = vector<vs>;
using vc = vector<char>;
using vvc = vector<vc>;
using ii = pair<int,int>;
using vii = vector<ii>;
using vvii = vector<vii>;
using dd = pair<double, double>;
using vdd = vector<dd>;
using vvdd = vector<vdd>;
using Mii = map<int,int>;
using vMii = vector<Mii>;

#define fi first
#define se second
#define INF INT_MAX
#define mod(a,m) (a%m+m)%m
#define PB push_back
#define MP make_pair

vvi memo, v;

int dp(int day, int act) {
	int n = v.size();
	if(day == n) return 0;
	int& ans = memo[day][act];
	if(ans != -1) return ans;
	ans = v[day][act] + max(dp(day + 1, (act + 1)%3), dp(day + 1, (act + 2)%3));
	return ans;
}

int main(){
//	cout.setf(ios::fixed);
//	cout.precision(4);
	int n;
	while (cin >> n) {
		v = vvi(n, vi(3));
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < 3; ++j) {
				cin >> v[i][j];
			}
		}
		memo = vvi(n, vi(3, -1));
		int ans = 0;
		for (int i = 0; i < 3; ++i) ans = max(ans, dp(0, i));
		cout << ans << '\n';
	}
}




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

int main()
{
  int N, M;
  int a, b;
  long long res=0;

  priority_queue<pair<int, int> > q1;
  priority_queue<int> q2;
  
  cin >> N >> M;
  rep(i,N) {
    cin >> a >> b;
    q1.push(make_pair(-a,b));
  }

  for(int i=1; i<=M; i++){// from 1-day before the day M to the day 1.
    while(!q1.empty() && -q1.top().first <= i){
      q2.push(q1.top().second);
      q1.pop();
    }
    if(!q2.empty()){
      res+=(long long)q2.top();
      q2.pop();
    }
  }
  
  cout << res << endl;
}

Measured memory_bytes: 1908
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPr(i, n) for(int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for(int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for(int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
    cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
    int x12345;                                                                \
    cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
const long long MOD = 1e9 + 7;

///////////////////////////////////////////////
// for template
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;
}
///////////////////////////////////////////////
/// ⸜( ⌓̈ )⸝ ///
int main() {
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll ans = max({a*c,a*d,b*c,b*d});
    cout << ans << endl;
}

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

// #include <boost/algorithm/string/join.hpp>
// using boost::algorithm::join;
//
// #include "boost/multi_array.hpp"
// boost::multi_array<int, 3> dp;
// dp.resize(boost::extents[10][9][8]);
//
// #include <boost/multiprecision/cpp_dec_float.hpp>  // quite slowly
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision; // mp::log10
// using bigint = boost::multiprecision::cpp_int;
// using rational = mp::cpp_rational;  // double d = static_cast<double>(r);

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

//constexpr ll MOD = 1e9+7;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/4;
constexpr int INF=inf<int>;
constexpr ll LINF=inf<ll>;

#define Sort(x) sort(begin(x),end(x))
#define Reverse(x) reverse(begin(x),end(x))
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ull<<(n))
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,(v).size())

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
#define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int main(int argc, char** argv) {
  int N;
  cin >> N;

  vi A(N);
  vll counts(N+1);
  for (auto& a : A) {
    cin >> a;
    counts[a]++;
  }

  ll z = 0;
  for (auto c : counts) {
    z += c*(c-1)/2;
  }

  //cerr << "z " << z <<endl;

  REP(i, N) {
    const int a = A[i];
    ll c = counts[a];
    ll ret = z;
    if (c>=2) {
      ret -= c-1;
    }

    cout << ret << endl;;
  }

  return 0;
}

/* vim: set expandtab shiftwidth=2 softtabstop=2 : */


Measured memory_bytes: 4992
#include <stdio.h>
#include <string.h>
#include <vector>

int main(void) {
  int i, j, x, y, n, f, be;
  bool d = false, ans_ud = false, ans_lr = false;
  std::vector<int> ud, lr;
  char s[8100];
  scanf("%s", s);
  n = strlen(s);
  scanf("%d%d", &x, &y);
  for(i = 0; i < n && s[i] != 'T'; ++i);
  f = be = i;
  for(i = f + 1; i < n; ++i) {
    if(s[i] == 'T') {
      if(d) lr.push_back(i - be - 1);
      else ud.push_back(i - be - 1);
      d = !d;
      be = i;
    }
  }
  if(f != n) {
    if(d) lr.push_back(n - be - 1);
    else ud.push_back(n - be - 1);
  }
  bool ar[18000];
  for(i = 0; i < 18000; ++i) ar[i] = false;
  ar[9000 + f] = true;
  for(i = 0; i < lr.size(); ++i) {
    bool ar2[18000];
    for(j = 0; j < 18000; ++j) ar2[j] = false;
    for(j = 0; j < 18000; ++j) {
      if(ar[j]) ar2[j - lr[i]] = ar2[j + lr[i]] = true;
    }
    for(j = 0; j < 18000; ++j) ar[j] = ar2[j];
  }
  if(ar[9000 + x]) ans_lr = true;
  for(i = 0; i < 18000; ++i) ar[i] = false;
  ar[9000] = true;
  for(i = 0; i < ud.size(); ++i) {
    bool ar2[18000];
    for(j = 0; j < 18000; ++j) ar2[j] = false;
    for(j = 0; j < 18000; ++j) {
      if(ar[j]) ar2[j - ud[i]] = ar2[j + ud[i]] = true;
    }
    for(j = 0; j < 18000; ++j) ar[j] = ar2[j];
  }
  if(ar[9000 + y]) ans_ud = true;
  if(ans_ud && ans_lr) printf("Yes");
  else printf("No");
  return 0;
}

Measured memory_bytes: 384
# include <algorithm>
# include <cassert>
# include <cctype>
# include <cstdio>
# include <cstdlib>
# include <cstring>
# include <cmath>
# include <iostream>
# include <map>
# include <queue>
# include <set>
# include <sstream>
# include <stack>
# include <string>
# include <vector>
# include <iomanip>
 
# define rep(i, n) for (int i = 0; i < (int)(n); i++)
# define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
# define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)
 
using namespace std;

int main(){
  int N,W;
  int v[30];
  int dp[50005] = {0};
  cin >> N >> W;
  rep(i, W){
    cin >> v[i];
  }
  rep(i,N+1){
  	dp[i] = i;
  }
  rep(i,W){
  	rep(j,N+1){
  		if ((j-v[i])>-1){
  			dp[j] = min(dp[j-v[i]]+1, dp[j]);
  		}
  	}
  }
  cout << dp[N] << endl;
}

Measured memory_bytes: 3268
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define pb push_back
#define fi first
#define se second
const int INF = 1e18+10;
using namespace std;

int N,K;
int A[200010],F[200010];

bool isOK(int index) {
    ll sum=0;
    rep(i,N){
        if(A[i]*F[i]>index){
            sum += (A[i]*F[i]-index+F[i]-1)/F[i];
        }
    }
    if(sum<=K) return true;
    else return false;
}
int binary_search() {
    int left = -1;
    int right = INF;
    while (right - left > 1) {
        int mid = left + (right - left) / 2;
        if (isOK(mid)) right = mid;
        else left = mid;
    }
    return right;
}

signed main() {
    cin >> N >> K;
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> F[i];
    sort(A,A+N);
    sort(F,F+N,greater<int>());
    cout << binary_search() << endl;
}

Measured memory_bytes: 3328
sx,sy,tx,ty=map(int,input().split())

way_1="U"*(ty-sy)+"R"*(tx-sx)
way_2="D"*(ty-sy)+"L"*(tx-sx)
way_3="L"+"U"*(ty-sy+1)+"R"*(tx-sx+1)+"D"
way_4="R"+"D"*(ty-sy+1)+"L"*(tx-sx+1)+"U"

print(way_1+way_2+way_3+way_4)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <bitset>
#include <queue>
#include <utility>
#include <functional>
#include <sstream>
using namespace std;
#define ll long long
 
int main(void){
    ll n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<ll> change;
    ll f,e;
    ll ans;
    for(ll i = 1; i < s.length(); i++){
        if(s[i-1]!=s[i])
            change.push_back(i);
    }
    ll rev = 0;
    if(change.size() < 2*k+1)
        ans = s.length()-1;
    else{
        for(ll i = 0; i < change.size()-2*k+1; i++){
            if(rev < max(rev, change[i+2*k-1]-change[i])){
                f = change[i]; e = change[i+2*k-1];
            }
            rev = max(rev, change[i+2*k-1]-change[i]);
        }
        ans = rev+1;
        for(ll i = 1; i <= f; i++){
            if(s[i-1]==s[i])
                ans++;
        }
        for(ll i = e; i < s.length(); i++){
            if(s[i-1]==s[i])
                ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1528
#include <stdio.h>

int main()
{
  int n;
  int i, j;
  int Ball[10];
  int left[10], right[10];
  int left_num, right_num;
  int flag;

  scanf("%d", &n);

  for (i = 0; i < n; i++) {

    for (j = 0; j < 10; j++)
      scanf("%d", &Ball[j]);

    for (j = 0; j < 10; j++) {
      left[j] = 0;
      right[j] = 0;
    }

    left_num = 0;
    right_num = 0;
    flag = 1;

    for (j = 0; j < 10; j++) {

      if (left_num == 0 || left[left_num - 1] < Ball[j]) {
        left[left_num] = Ball[j];
        left_num++;
      }

      else if (right_num == 0 || right[right_num - 1] < Ball[j]) {
        right[right_num] = Ball[j];
        right_num++;
      }

      else {
        flag = 0;
        break;
      }
    }

    if (flag)
      printf("YES\n");

    else
      printf("NO\n");
  }

  return 0;
}

Measured memory_bytes: 576
#include<bits/stdc++.h>
using namespace std;
int main()
{
	//freopen("input.txt", "r", stdin);
   // freopen("output.txt", "w", stdout);
    string a,b;
    int f=0;
    cin>>a>>b;
    for(int i=0;i<a.size();i++)
    {
    	if(a[i]!=b[i])
    	{
    		f=1;
    	
    	break;
    }
    }
    if(f==0&&b.size()==a.size()+1)
    	cout<<"Yes";
    else
    	cout<<"No";
    return 0;
}

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

int main(int argc, char const *argv[]) {
    int a, b, c;
    cin >> a >> b >> c;
    c = c - (a - b);

    if (c<0) cout << 0 << endl;
    else cout << c << endl;
    return 0;
}


Measured memory_bytes: 3604
using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            //Question1();
            //Question2();
            Question3();
        }

        private static void Question1()
        {
            var input = Console.ReadLine();
            char ans = input[0] <= 'Z' ? 'A' : 'a';
            Console.WriteLine(ans);
        }

        private static void Question2()
        {
            var inputA = Console.ReadLine().Split(' ');
            var inputP = Console.ReadLine().Split(' ');

            var N = int.Parse(inputA[0]);
            var K = int.Parse(inputA[1]);

            int[] p = new int[N];

            for (int i = 0; i < N; i++) p[i] = int.Parse(inputP[i]);

            List<int> val = new List<int>();
            foreach (var v in p) val.Add(v);

            val.Sort();
            var sum = 0;
            for (int i = 0; i < K; i++) sum += val[i];

            Console.WriteLine(sum);
        }

        private static void Question3()
        {
            var input = Console.ReadLine();
            long N = long.Parse(input);
            char[] alphabet = new[]
            {
                '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'
            };

            string ans = "";
            do
            {
                N = N - 1;
                long b = N % 26;
                N /= 26;
                ans = alphabet[b] + ans;
            } while (N > 0);
            
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 27544
#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <string>
#include <numeric>
#include <tuple>
#include <type_traits>

// template <typename Tp, size_t N>
// std::vector<Tp> make_vector_detail(std::vector<size_t>& sizes, typename std::enable_if<(N == 1), const Tp&>::type x) {
//   return std::vector<Tp>(sizes[0], x);
// }
// template <typename Tp, size_t N>
// auto make_vector_detail(std::vector<size_t>& sizes, typename std::enable_if<(N > 1), const Tp&>::type x) {
//   size_t size = sizes[N-1];
//   sizes.pop_back();
//   return std::vector<decltype(make_vector_detail<Tp, N-1>(sizes, x))>(size, make_vector_detail<Tp, N-1>(sizes, x));
// }

// template <typename Tp, size_t N>
// auto make_vector(const size_t(&sizes)[N], const Tp& x) {
//   std::vector<size_t> s(N);
//   for (size_t i = 0; i < N; ++i) s[i] = sizes[N-i-1];
//   return make_vector_detail<Tp, N>(s, x);
// }

intmax_t constexpr mod = 1e9+7;

int main() {
  char buf[131072];
  scanf("%s", buf);
  std::string L = buf;

  size_t N = L.length();
  // auto dp = make_vector<intmax_t>({N+1, 2}, 0);
  std::vector<std::vector<intmax_t>> dp(N+1, std::vector<intmax_t>(2));
  dp[0][1] = 1;
  for (size_t i = 0; i < N; ++i) {
    for (size_t j = 0; j <= 1; ++j) {
      // j for tightness
      for (int d = '0'; d <= '1'; ++d) {
        // d for digits
        if (j && L[i] < d) continue;
        size_t nj = j && (d == L[i]);
        if (nj) {
          if (d == '0') {
            (dp[i+1][nj] += dp[i][j]) %= mod;  // 00
          } else {
            (dp[i+1][nj] += 2 * dp[i][j]) %= mod;  // 10, 01
          }
        } else {
          if (d == '0') {
            (dp[i+1][nj] += dp[i][j]) %= mod;  // 00
          } else {
            (dp[i+1][nj] += 2 * dp[i][j]) %= mod;  // 10, 01
          }
        }
      }
    }
  }

  intmax_t res = (dp[N][0] + dp[N][1]) % mod;
  printf("%jd\n", res);
}


Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}
const int M = 2001;
int L[M][M]={0},R[M][M]={0}, U[M][M]={0}, D[M][M]={0}; 

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w; cin>>h>>w;
    vector<string> S(h);
    rep(i, h) cin>>S[i];

    // 上下・左右方向の累積和を求めておく
    for(int y=0; y<h; y++){
        int cur=0;
        for(int x=0; x<w; x++){
            if(S[y][x]=='#') cur = 0;
            else cur++;
            L[y][x] = cur;
        }
    }
    for(int y=0; y<h; y++){
        int cur = 0;
        for(int x=w-1; x>=0; x--){
            if(S[y][x]=='#') cur = 0;
            else cur++;
            R[y][x] = cur;
        }
    }
    for(int x=0; x<w; x++){
        int cur = 0;
        for(int y=0; y<h; y++){
            if(S[y][x]=='#') cur = 0;
            else cur++;
            U[y][x] = cur;
        }
    }
    for(int x=0; x<w; x++){
        int cur = 0;
        for(int y=h-1; y>=0; y--){
            if(S[y][x]=='#') cur = 0;
            else cur++;
            D[y][x] = cur;
        }
    }

    // 全探索
    int ans = 0;
    rep(i, h){
        rep(j, w){
            if(S[i][j]=='#') continue;
            int t = L[i][j]+R[i][j]+U[i][j]+D[i][j] - 3;
            ans = max(ans, t);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 67072
import java.util.Arrays;
import java.util.Scanner;

class Main{
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong(), K = sc.nextLong();
		long[] H = new long[200005];
		for(int i = 0; i < N; i++) {
			H[i] = sc.nextLong();
		}
		Arrays.sort(H);
		long sum = 0;
		if(N > K) {
			for(int i = (int)(200005 - K - 1); i >= 200005 - N; i--) {
				sum += H[i];
			}
		}
		System.out.print(sum);
		
		sc.close();
		
	}
}


Measured memory_bytes: 93144
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
   ll n,m;
   cin>>n>>m;
   ll ans=1;
   for(int i=m/n;i>=2;i--)
   {
       if(m%i==0)
       {
           ans=i;
           break;
       }
   }
   cout<<ans<<endl;
    return 0;
}


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

int f(int n) {
    if (n % 2 == 1) {
        return 0;
    } else {
        return f(n / 2) + 1;
    }
}

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

    int ans = 1;
    for (int i = 1; i <= n; i++) {
        if (f(i) > f(ans)) {
            ans = i;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define _ << " " <<
#define all(v) v.begin(), v.end()

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;

bool cmp(pair<string, int> a, pair<string, int> b) {
	if (a.first == b.first) return a.second > b.second;
	return a.first < b.first;
}

bool a[15][15];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, m;
	cin >> n >> m;
	int t[15];
	int p[15];
	for (int i = 0; i < m; i++) {
		int k; cin >> k;
		for (int j = 0; j < k; j++) {
			int l; cin >> l;
			a[i][l - 1] = true;
		}
	}
	int ans = 0;
	for (int i = 0; i < m; i++) cin >> p[i];
	for (int i = 0; i < (1 << n); i++) {
		for (int j = 0; j < m; j++) t[j] = 0;
		for (int j = 0; j < n; j++) {
			if (i & (1 << j)) {
				for (int k = 0; k < m; k++) {
					if (a[k][j]) t[k]++;
				}
			}
		}
		bool chk = true;
		for (int j = 0; j < m; j++) {
			if (t[j] % 2 != p[j]) chk = false;
		}
		if (chk) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<unistd.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ST first
#define ND second
#define ll long long
#define ld long double
using namespace std;
using namespace __gnu_pbds;
 
// replace ll with pair if multiset needed
typedef tree<pair<int,int>, null_type, greater<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ordered_set secik;
 
const ll INF = 1e9 + 9;
const ll MOD = 1e9 + 7;
const long long LINF = (ll)1e18 + 3;
 
// secik.insert({x, t++});
// secik.erase(secik.lower_bound({x,-1}));
// *secik.find_by_order(x)).first << "\n";
// secik.order_of_key(x)
 
//random_device device;
//mt19937 gener(device());
//uniform_int_distribution<int> gen(0,n-1);

const int SIZE = 3e3 + 3;

int dp[SIZE][SIZE];

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

	string s1,s2; cin >> s1 >> s2;

	for(int i = 1; i <= s1.size(); i++){
		for(int j = 1; j <= s2.size(); j++){
			if(s1[i-1] == s2[j-1]){
				dp[i][j] = dp[i-1][j-1] + 1;
			} else {
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	
	int i = s1.size(), j = s2.size();
	string result = "";
	while(i != 0 && j != 0){
		if(s1[i-1] == s2[j-1]){
			result += s1[i-1];
			i--;
			j--;
		} else if(dp[i-1][j] > dp[i][j-1]){
			i--;
		} else {
			j--;
		}
	}
	
	reverse(result.begin(),result.end());

	cout << result;







}

Measured memory_bytes: 35456
from math import factorial as f

N, P = list(map(int, input().split()))
A = list(map(int, input().split()))

num_odd = 0
num_even = 0
for i in range(N):
    if A[i] % 2 == 0:
        num_even += 1
    else:
        num_odd += 1

even_choice = 2**num_even

def c(n, k):
    return f(n)//(f(k)*f(n-k))

odd_choice = 0
for i in range(0, num_odd+1):
    if i % 2 == P:
        odd_choice += c(num_odd, i)

print(even_choice*odd_choice)


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define fastio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define display(v) for (auto x : v) cout << x << ", "
#define print(x) cout << (#x) << " = [ ";display(x); cout << "]\n"
#define endl '\n'
#define pb push_back
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
 
// DEBUG TEMPLATE by livw
void __print(int x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifdef INCLUDEWHENOFFLINE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


int main()
{
    fastio;
    
    int h, n;
    cin >> h >> n;
    vector <pair<int, int>> v;
    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        v.pb({a, b});
    }
    int dp[h + 1];
    dp[0] = 0;
    for (int i = 1; i <= h; i++)
    {
        dp[i] = 0;
        int num = i;
        int ans = 1e9;
        for (auto x : v)
        {
            if (x.first > num) 
            {
                ans = min(ans, x.second);
            }
            else ans = min(ans, x.second + dp[num - x.first]);
        }
        dp[i] = ans;
    }
    cout << dp[h];
    
    return 0;
}


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

int bubbleSort(int A[], int N){
    int sw = 0;
    bool flag = 1;
    for ( int i = 0; flag; i++ ){
        flag = 0;
        for (int j = N - 1; j >= i + 1; j-- ) {
            if ( A[j] < A[j - 1]) {
                swap(A[j], A[j - 1]);
                flag = 1;
                sw++;
            }
        }
    }
    return sw;
}

int main(){
    int A[100], N, sw;
    cin >> N;
    for (int i = 0; i < N ; i++)
        cin >> A[i];

    sw = bubbleSort(A, N);

    for ( int i = 0; i < N ; i++){
        if (i)
            cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << sw << endl;

    return 0;
}


Measured memory_bytes: 3092
N = int(input())

cake_price = 4
donut_price = 7

max_cake = N // cake_price
max_donut = N // donut_price

isJustN = False
if max_cake * cake_price == N or max_donut * donut_price == N:
    isJustN = True
else:
    for c in range(1, max_cake + 1):
        for d in range(1, max_donut + 1):
            total_price = cake_price * c + donut_price * d
            if total_price == N:
                isJustN = True
                break

Result = ''
Result = 'Yes' if isJustN == True else 'No'
print(Result)


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


 int main(){

  string s,t;
  cin>>s>>t;

  int n = s.length(); int k = t.length();
  int st = -1;

  for(int i=0;i<=n-k;i++)
  {

      bool flag = true;

      for(int j=0;j<k;j++){
         if(s[i+j] != t[j] && s[i+j] != '?'){
            flag  = false;
            break;
         }
      }

      if(flag  == true)
        st = i;

  }

  if(st == -1)
       cout<<"UNRESTORABLE\n";
  else{
      for(int i=st;i<st+k;i++){
        s[i] = t[i-st];
        for(int i=0;i<n;i++){
            if(s[i] == '?')
            s[i] = 'a';
      }
  }
     cout<<s<<endl;

  }

 return 0;
 }

Measured memory_bytes: 3600
//set many funcs template
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}

int main(void){
    long long i,j,k,n,a,x[131072],dp[64][4096]={0},r=0;
    dp[0][0]=1;
    scanf("%lld%lld",&n,&a);
    for(i=1;i<=n;i++){scanf("%lld",&x[i]);
        for(j=60;j>=0;j--){
            for(k=3600;k>=0;k--){
                dp[j+1][k+x[i]]+=dp[j][k];
            }
        }
    }
    for(i=1;i<=n;i++){
        r+=dp[i][a*i];
    }
    printf("%lld\n",r);
    return 0;
}

Measured memory_bytes: 3200
#include<iostream>
#include<algorithm>
using namespace std;
int a[100005],n,s=0,bj=0,k=1;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+n+1);
	for(int i=2;i<=n;i++)
	{
		if(a[i]==a[i-1])k=(k+1)%2;
		else bj+=k,k=1;
	}
	if(k%2)bj++;
	cout<<bj<<endl;
}

Measured memory_bytes: 640