akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int max = 0;
		ArrayList<Integer> numbers = new ArrayList<>();
		for(int i =0;i<4;i++){
			numbers.add(sc.nextInt());
		}
		for(int i =0;i<3;i++){
			max = Math.max(max, numbers.get(i));
		}
		numbers.set(numbers.indexOf(max), max*(int)Math.pow(2, numbers.get(3)));
		int sum = 0;
		for(int i =0;i<3;i++){
			sum += numbers.get(i);
		}
		System.out.println(sum);
	}

}


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

namespace ITP1_6_D
{
    class Program
    {
        public static void Main()
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var n = int.Parse(line[0]); //width of a = 3
            var m = int.Parse(line[1]); //height of a and b 4
            var a = new int[n, m]; //new 2d array A with width 3, height 4
            var b = new int[m]; //new 1d array B with height 4
                                //array input for i values
            for (int i = 0; i < n; i++)
            {
                string[] yvalue = Console.ReadLine().Trim().Split(' ');
                //array input for j values
                for (int j = 0; j < m; j++)
                    a[i, j] = int.Parse(yvalue[j]);
            }
            //array input for j values of array b
            for (int i = 0; i < m; i++)
                b[i] = int.Parse(Console.ReadLine().Trim());
            //multiplication process for each value of array A to array B
            for (int i = 0; i < n; i++)
            {
                var product = 0;
                for (int j = 0; j < m; j++)
                    product += a[i, j] * b[j];
                Console.WriteLine(product);
            }
            Console.ReadLine();
        }
    }

}



Measured memory_bytes: 17936
/*COMPETITIVE PROGRAMMING C++ TEMPLATE */
 
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>
#include <climits>
#include <iomanip>
 
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n"
#define MOD 1000000007
 
const long double PI = 3.141592653589793236L;
 
typedef long long int ll;
typedef long double ld;

using namespace std;

void solve()
{
    int x;
    cin >> x;

    if(x >= 30)
    {
        cout << "Yes\n";
        return;
    }

    cout << "No\n";
    
}

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

    int T = 1;
    //cin >> T;

    while (T--)
    {
        solve();
    }
    
    return 0;
}



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

template<class T>
ll part(const T& s,int l, int r){return s[r] - s[l];};

ll a[100050],s[100050],p[100050];

int main(){
  int N,K; cin>>N>>K;
  for(int i=0;i<N;i++) cin>>a[i];
  for(int i=0;i<N;i++) s[i+1] = s[i] + a[i];
  for(int i=0;i<N;i++) {
    if(a[i] > 0) p[i+1] = p[i] + a[i];
    else p[i+1] = p[i];
  }
  ll ans = 0;
  for(int i=0;i+K<=N;i++){
    ll tmp = part(p,0,i) + part(p,i+K,N);
    ll b = part(s,i,i+K);
    if(b > 0) tmp += b;
    if(ans < tmp) ans = tmp;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 2560
C = [list(map(int, input().split())) for i in range(3)]
A = [0 for i in range(3)]
B_cand=[[0 for i in range(3)] for i in range(3)]

A[0] = min(C[0])
A[1] = min(C[1])
A[2] = min(C[2])

for i in range(3):
    for j in range(3):
        B_cand[i][j] = C[i][j] - A[i]

if (B_cand[0] == B_cand[1] == B_cand[2]):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
import java.io.*;
import java.util.*;
import java.lang.reflect.Array;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.Stack;


class Main {
	public static void main(String[] a) throws IOException {
		Scanner scan = new Scanner(System.in);
		int first = scan.nextInt();
		int second = scan.nextInt();
		
		double tsubo = (first*second)/3.305785;
		
		System.out.println(tsubo);
		
 }
}

Measured memory_bytes: 26368
// All Heil Fire Lord Zuko

#include <bits/stdc++.h>
using namespace std ;

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

#define _sz(x) (int)x.size()
#define F first
#define S second
#define PB push_back

#define debug(x) cerr << #x << " = " << "\n"

typedef long long ll ;
typedef long double ld ;
typedef pair<ll , ll> pll ;

const int N = 5 * 1000 + 19 ;
const int inf = 1e9 + 19 ;
const ll INF = 1e18 + 19 ;

ll r ;

int main() {
      ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ;
      cin >> r ;
      cout << r * r ;
      return 0;
}

/* THINGS TO CHECK */

// Runtime -> Checked
// Overflows -> Checked
// Time Complexity -> n + m
// Memory Complexity -> OK

/* READ PROBLEM STATEMENT CAREFULLY */


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <chrono>
using namespace std::chrono;
using namespace std;
#define fr(x,i,n) for(int x = i; x < n; ++x)
#define fb(x,i,n) for(int x = i; x >= n; --x)
#define pr pair<int,int>
#define ll long long int
const int mod=1e9+7;
/*    auto start = high_resolution_clock::now();
    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop - start);
    cout << "\nduration="<<duration.cnt()/1e6 << endl;
*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    int a[n+1],b[n+1];
    fr(i,1,n+1){
        a[i]=b[i]=0;
    }
    fr(i,2,n+1)
    cin>>a[i];
    fr(i,2,n+1)
    b[a[i]]++;
    fr(i,1,n+1)
    cout<<b[i]<<endl;
}


Measured memory_bytes: 5216
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{

   ll n,k;
   cin>>n>>k;
   ll arr[n+5]={0};
   for(int i=0;i<n;i++)
   {
       cin>>arr[i];
   }
   ll dis=0;
   for(int i=0;i<n;i++)
   {
       ll x=min(arr[i],k-arr[i]);
       dis+=2*x;
   }
   cout<<dis<<endl;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL n,pw[20],num,tmp;
string ans;

int main()
{
	pw[0]=1;
	repn(i,12) pw[i]=pw[i-1]*26;
	cin>>n;
	tmp=0;
	repn(i,12)
	{
		tmp+=pw[i];
		//cout<<tmp-n<<endl;
		if(tmp>=n)
		{
			tmp-=pw[i];
			n-=tmp;
			num=i;
			break;
		}
	}
	//cout<<num<<endl;
	//cout<<n<<endl;
	for(int i=num-1;i>=0;i--)
	{
		tmp=0;
		int tmp2=0;
		rep(j,26)
		{
			tmp+=pw[i];
			if(tmp>=n) break;
			tmp2++;
		}
		ans.pb(tmp2+'a');
		//cout<<i<<' '<<n<<' '<<tmp2<<endl;
		n-=tmp2*pw[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#define Free -1
#define NotFree 1
#define N 8
#define M 16

void putQ(int);
void printB(void);

int B[N][N];
int BG[N],Btate[N],Brn[M],Bln[M]; /* Brn=左上から右下,Bln=右上から左下 */

int main()
{
  int k,i,j,n,m;

  scanf("%d",&k);

  for(i=0;i<N;i++){
    Btate[i] = BG[i] = Free;
    for(j=0;j<N;j++){
      B[i][j] = 0;
    }
  }

  for(i=0;i<M;i++){
    Brn[i] = Bln[i] = Free;
  }

  for(i=0;i<k;i++){
    scanf("%d%d",&n,&m);
    B[n][m] = 1;
  }

  putQ(0);

  return 0;
}

void putQ(int i)
{
  int j;

  if(i == N){
    printB();
    return;
  }

  for(j=0;j<N;j++){
    if(Btate[j]==NotFree || Brn[i-j+(N-1)]==NotFree || Bln[i+j]==NotFree) conti\
nue;
    BG[i] = j; /* i行j列目にQを入れる */
    Btate[j] = Brn[i-j+(N-1)] = Bln[i+j] = NotFree;
    putQ(i+1);
    BG[i] = Btate[j] = Brn[i-j+(N-1)] = Bln[i+j] = Free;
  }
}

void printB()
{
  int i,j;

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(B[i][j]){
        if(BG[i]!=j) return;
      }
    }
  }

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(BG[i]==j) printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}


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

int main() {
    string O, E;
    cin >> O >> E;

    int T = O.size();
    int U = E.size();

    for (int i = 0; i < U; i++) {
        cout << O.at(i);
        cout << E.at(i);
    }

    if (T > U) {
        cout << O.at(T -1);
    }
}

Measured memory_bytes: 256
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<string>
#include<cctype>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
const int maxn = 100 + 8;

int n;
int a[maxn];
int v,j;
void see(int a[])
{
    for(int i = 0; i < n; ++i){
        if(i) printf(" ");
        printf("%d",a[i]);
    }
    printf("\n");
    return;
}

int main()
{
    memset(a,0,sizeof a);
    scanf("%d",&n);
    for(int i = 0; i < n; ++i){
        scanf("%d",&a[i]);
    }

    see(a);

    for(int i = 1; i < n; ++i){
        v = a[i];
        j = i-1;
        while(j >= 0 && a[j] > v){
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = v;
        see(a);
    }

}

Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, m, n) for(ll i = m; i > n; i--)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define lmax(x, y) max<ll>(x, y)
#define lmin(x, y) min<ll>(x, y)
#define tmax(x, y, z) lmax((x), lmax((y), (z)))
#define tmin(x, y, z) lmin((x), lmin((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
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;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
// struct edge{ ll from, to, cost; };
// struct edge{ ll to, cost; };
// using Graph = vector<vector<ll>>;  // 重み無し
// using Graph = vector<edge>;  // 辺
// using Graph = vector<vector<edge>>;  // 重み付き
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};


int main(){
    ll a, b, c , d; cin >> a >> b >> c >> d;
    cout << lmax(a*c, tmax(a*d, b*c, b*d)) << endl;
}


Measured memory_bytes: 3632
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define case(i) cout<<"Case #"<<i<<": "
using namespace std;
typedef long long int ll;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 4e18;

ll gcd(int a, int b) {
	while (a && b) {
		if (a < b) swap(a, b);
		a %= b;
	}
	return max(a,b);
}

bool isPrime(int N)
{
	if (N <= 1) return false;
	if (N == 2) return true;
	if (N % 2 == 0) return false;
	for (int i = 3; i * i <= N; i += 2)
		if (N % i == 0) return false;
	return true;
}

int main() {
	int n; cin >> n;
	vector<int> a(n + 1),ans;
	int g = 0;
	rep(i, 0, n + 1) {
		cin >> a[i];
		g = gcd(g, abs(a[i]));
	}
	int h = g;
	rep(i, 2, sqrt(g) + 1) {
		if (g % i == 0 && isPrime(i)) {
			ans.push_back(i);
			while(g%i==0)g /= i;
		}
	}
	if (g != 1) ans.push_back(g);
	rep(i, 0, n + 1) a[i] /= h;
	rep(p, 0, n + 2) {
		if (isPrime(p) && a[n] % p == 0) {
			vector<int> f = a;
			rep(j, 0, n + 1 - p) {
				f[j+p-1] += f[j];
				f[j] = 0;
			}
			int cnt = 0;
			rep(i, 0, n) {
				if (f[i]%p == 0) cnt++;
			}
			if (cnt==n) ans.push_back(p);
		}
	}
	sort(ans.begin(), ans.end());
	ans.erase(unique(ans.begin(), ans.end()), ans.end());
	rep(i, 0, ans.size()) cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 384
package main

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

func main() {
	a := readf()
	b := readf()
	h := readf()
	m := readf()
	fmt.Fprintln(os.Stderr, "hoge")
	fmt.Println(math.Sqrt(a*a + b*b - 2*a*b*math.Cos(diff(360*(h/12)+30*(m/60), 360*(m/60))*math.Pi/180)))
}

func diff(a, b float64) float64 {
	if a > b {
		return a - b
	}
	return b - a
}

// IO---------------------------------------------------

func readi() (n int) {
	fmt.Scan(&n)
	return
}

func readf() (n float64) {
	fmt.Scan(&n)
	return
}

func reads() (n string) {
	fmt.Scan(&n)
	return
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func readSlice() []string {
	return strings.Split(readLine(), " ")
}

func atoi(a []string) (b []int) {
	b = make([]int, len(a))
	for i := range a {
		b[i], _ = strconv.Atoi(a[i])
	}
	return
}

func atof(a []string) (b []float64) {
	b = make([]float64, len(a))
	for i := range a {
		b[i], _ = strconv.ParseFloat(a[i], 64)
	}
	return
}

func readSlice2(n int) (a []int, b []int) {
	a = make([]int, n)
	b = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

func readFloatSlice2(n int) (a []float64, b []float64) {
	a = make([]float64, n)
	b = make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

func yesOrNo(b bool) {
	if b {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}

func yesorNO(b bool) {
	if b {
		fmt.Println("YES")
		return
	}
	fmt.Println("NO")
}

func yesorno(b bool) {
	if b {
		fmt.Println("yes")
		return
	}
	fmt.Println("no")
}

// calc---------------------------------------------------

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

func ave(a []int) (ave int) {
	for i := 0; i < len(a); i++ {
		ave += a[i]
	}
	ave /= len(a)
	return
}

func eq(a []string, b []string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] != b[i] {
			return false
		}
	}
	return true
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func max(a ...int) int {
	max := a[0]
	for i := 1; i < len(a); i++ {
		if max < a[i] {
			max = a[i]
		}
	}
	return max
}

func min(a ...int) int {
	min := a[0]
	for i := 1; i < len(a); i++ {
		if min > a[i] {
			min = a[i]
		}
	}
	return min
}

func mid(a []int) int {
	sort.Ints(a)
	return a[len(a)/2]
}

func sum(a []int) (ans int) {
	for i := range a {
		ans += a[i]
	}
	return
}


Measured memory_bytes: 1856
from functools import reduce

N = int(input())
N_list = [int(x) for x in list(str(N))]

N_ = []
for i in N_list:
    if i == 1:
        i = 9
    elif i == 9:
        i = 1
    N_.append(i)

new_N = int(reduce(lambda x,y: x+y, [str(x) for x in N_]))

print(new_N)    


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

int main() {
  int N,M;
  cin >> N >> M;
  vector<pair<int,int>> P(M);
  for(int k=0;k<M;k++){
    cin >> P[k].first >> P[k].second;
  }
  bool check=true;
  int ans=-1;
  for(int i=0;i<pow(10,N);i++){
    check=true;
    if(N>1&&i<pow(10,N-1)){
      check = false;
    }
      
    for(int j=0;j<M;j++){
      if(P[j].first==1){
        
        if(N>1&&P[j].second==0){
          check = false;
        }else if(int(i/pow(10,N-1)) != P[j].second){
          check = false;
        }
        
      }else if(P[j].first==2){
        
         if(N==2 && P[j].second != (i%10)){
          check = false;
        }else  if(N==3 && P[j].second != (i%100)/10){
          check = false;
        }
        
      }else if(P[j].first==3){
        
        if(P[j].second != i%10){
          check =false;
        }
        
      }
    }
    if(check){
      ans = i;
      break;
    }

  }   
  
  cout << ans <<endl;
  
}



Measured memory_bytes: 384
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long X = in.nextLong();
        HashMap<Long, Long> nums = new HashMap<>();
        for (long i = -200; i <= 200; i++) {
            nums.put((long)Math.pow(i, 5), i);
        }
        for (long i : nums.keySet()) {
            if (nums.containsKey(i - X)) {
                System.out.println(nums.get(i) + " " + nums.get(i - X));
                break;
            }
        }
    }
}


Measured memory_bytes: 38992
#include<string>
#include<iostream>
using namespace std;
int main(){
  int a[1010],i;
  string s,t;
  cin >> s >> t;
  for(i=0;i<1000;i++){
    a[i]=0;
  }
  for(i=0;i<s.size();i++){
    if(a[t[i]]==0){
      a[t[i]]=s[i];
    }
    else if(a[t[i]]!=s[i]){
      printf("No\n");
      return 0;
    }
  }
  for(i=0;i<1000;i++){
    a[i]=0;
  }
  for(i=0;i<s.size();i++){
    if(a[s[i]]==0){
      a[s[i]]=t[i];
    }
    else if(a[s[i]]!=t[i]){
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}

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

int main(){
    int A,B,C,D;
    int price = 0;
    cin >> A;
    cin >> B;
    cin >> C;
    cin >> D;
    price += min(A,B);
    price += min(C,D);
    cout << price << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

ll a[100005],b[100005],c[100005];
ll dp[100005][3];

int main(){
    ll N; cin >> N;
    rep(i,N) cin >> a[i] >> b[i] >> c[i];

    for(int i=0;i<3;i++) dp[0][i] = 0;
    for(int i=0;i<N;i++){
        dp[i+1][0] = max({dp[i+1][0],dp[i][1]+a[i],dp[i][2]+a[i]});
        dp[i+1][1] = max({dp[i+1][1],dp[i][0]+b[i],dp[i][2]+b[i]});
        dp[i+1][2] = max({dp[i+1][2],dp[i][0]+c[i],dp[i][1]+c[i]});
    }

    cout << max({dp[N][0],dp[N][1],dp[N][2]}) << endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define pii make_pair
int ceil(int a, int b) { if(a%b==0) return a/b; else return a/b+1; }
bool checkbit(int pos, int mask) { return mask&(1<<pos); }
int turnon(int pos, int mask) { return mask|(1<<pos); }

main()
{
    int n;
    cin>>n;
    if(n>=30) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3632
import heapq
N = int(input())
A = list(map(int, input().split()))
R = [a for a in A[:N]]
M = [a for a in A[N:2*N]]
B = [-a for a in A[2*N:3*N]]
res_R = [0] * (N + 1)
res_B = [0] * (N + 1)
res_R[0] = sum(R)
res_B[N] = -sum(B)
heapq.heapify(R)
heapq.heapify(B)
for i in range(N):
    heapq.heappush(R, M[i])
    a = heapq.heappop(R)
    res_R[i+1] = res_R[i] + M[i] - a
    heapq.heappush(B, -M[N-i-1])
    a = heapq.heappop(B)
    res_B[N-i-1] = res_B[N-i] + M[N-i-1] + a
print(max(r - b for r, b in zip(res_R, res_B)))

Measured memory_bytes: 37212
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
const int mod = 1e9 + 7;
typedef pair<lint, lint> pi;

int dp[10005];
int n;

int main(){
	cin >> n;
	dp[0] = 1;
	for(int i=0; i<n; i++){
		int x;
		cin >> x;
		for(int j=10000; j>=x; j--) dp[j] |= dp[j-x];
	}
	for(int i=10000; i>=0; i--){
		if(i%10 != 0 && dp[i]){
			cout << i << endl;
			return 0;
		}
	}
	puts("0");
}


Measured memory_bytes: 256
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}

function Main(input) {
  input = myconv(input,3);
  var N = myconv(input[0],4)[0];
  var M = myconv(input[0],4)[1];
  input.shift();
  var list = new Array(N).fill(0);
  for(var i = 0; i < M; i++){
    var tmp = myconv(input[i],4);
    list[tmp[0]-1]++;
    list[tmp[1]-1]++;
  }
  myout(list.join("\n"));
}

Main(myin());


Measured memory_bytes: 7372
#include <iostream>
#include <cmath>

using namespace std;
#define int long long

signed main() {
  int N;
  cin >> N;
  
  if (N % 2 == 1) {
    cout << 0 << endl;
    return 0;
  }
  
  int ret = 0;
  int tmp;
  int k = 1;
  do {
    tmp = N / (2 * ((int)pow(5, k)));
    int tmp2 = N / (2 * ((int)pow(5, k+1)));
    if (tmp > 0) {
      ret += k * (tmp - tmp2);
    }
    k++;
  } while (tmp > 0);
  
  cout <<ret << endl;
  return 0;
}

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

int main(){
    ll D;
    cin >> D;
    vector<ll> c(26), t(D), last(26, -1);
    vector< vector<ll> > s(365, vector<ll> (26));
    rep(i, 0, 26) cin >> c[i];
    rep(i, 0, D){
        rep(j, 0, 26) cin >> s[i][j];
    }
    srand((unsigned int)time(NULL));
    rep(i, 0, D){
        t[i] = (ll) (rand() % 26);
    }
    ll M = 1e6;
    vector<ll> rec(26, 0);
    /*
    vector<ll> d(M), q(M), rec(26, 0);
    rep(i, 0, M){
        d[i] = (ll) (rand() % D);
        q[i] = (ll) (rand() % 26);
    }
    */
    ll res = 0;
    rep(d, 0, D){
        res += s[d][t[d]];
        last[t[d]] = d;
        rep(j, 0, 26) {
            res -= c[j] * (d - last[j]);
            rec[j] += c[j] * (d - last[j]);
        }
    }
    vector<ll> median(D);
    rep(i, 0, D){
        auto cp = s[i];
        sort(cp.begin(), cp.end());
        median[i] = cp[3*D/4];
    }
    // t[d[m]] := 0 - 25
    rep(m, 0, M){
        ll prev_res = res;
        // ll d = (ll) (rand() % D);
        ll d = m % D;
        // ll q = (ll) (rand() % 26);
        ll q = m % 26;
        if(s[d][q] < median[d]) continue;
        res -= s[d][t[d]];
        res += s[d][q];
        res += rec[t[d]];
        res += rec[q];
        ll tdrec = 0, qrec = 0;
        ll lst = -1;
        rep(i, 0, D){
            if(i != d && t[i] == t[d]){
                lst = i;
            }
            res -= c[t[d]] * (i - lst);
            // rec[t[d[m]]] +=  c[t[d[m]]] * (i - lst);
            tdrec +=  c[t[d]] * (i - lst);
        }
        lst = -1;
        rep(i, 0, D){
            if(i == d || t[i] == q){
                lst = i;
            }
            res -= c[q] * (i - lst);
            // rec[q[m]] += c[q[m]] * (i - lst);
            qrec += c[q] * (i - lst);
        }
        if(res > prev_res){
            rec[t[d]] = tdrec;
            rec[q] = qrec;
            t[d] = q;
        }else{
            res = prev_res;
        }
        // cout << res << endl;
    }
    rep(i, 0, D) cout << t[i]+1 << endl;
    return 0;
}

Measured memory_bytes: 3720
while True:
  x,y,s=map(int,input().split())
  if x==0 and y==0 and s==0:
    break
  A=[]
  B=[]
  for i in range(1,s):
    a=int(i*(100+x)/100)
    for j in range(i,s):
      b=int(j*(100+x)/100)
      if a+b==s:
        A.append(i)
        B.append(j)
      if (a+b)>s:
        break
  kumi=[]
  for i in range(len(A)):
    c=int(A[i]*(100+y)/100)
    d=int(B[i]*(100+y)/100)
    #print(c,d)
    goukei=c+d
    kumi.append(goukei)
  print(max(kumi))


Measured memory_bytes: 5604
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

#define MAX_N	(100)
#define MAX_M	((MAX_N * (MAX_N + 1)) / 2)

#define MAX_W	(10000)

/* typedef */

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

struct Edge {
  int ai, bi, wi;
};

/* global variables */

int n, m;

Edge edges[MAX_M];
int uft[MAX_N];

/* subroutines */

bool operator<(const Edge e0, const Edge e1) {
  return e0.wi < e1.wi;
}

int root(int i) {
  while (i != uft[i]) i = uft[i];
  return i;
}

bool spanning() {
  int r0 = root(0);
  for (int i = 1; i < n; i++)
    if (root(i) != r0) return false;
  return true;
}

int check_rec(int k) {
  if (k >= m) return MAX_W + 1;

  Edge& ek = edges[k];
  int ra = root(ek.ai);
  int rb = root(ek.bi);

  int uw;

  if (ra == rb)
    uw = check_rec(k + 1);
  else {
    uft[rb] = ra;

    if (spanning())
      uw = ek.wi;
    else
      uw = check_rec(k + 1);

    uft[rb] = rb;
  }

  return uw;
}

int check() {
  int min_dw = MAX_W + 1;

  for (int i = 0; i < n; i++) uft[i] = i;

  for (int i = 0; i < m; i++) {
    Edge& ei = edges[i];
    int lw = ei.wi;
    int uw;
    
    uft[ei.bi] = ei.ai;

    if (spanning())
      uw = ei.wi;
    else
      uw = check_rec(i + 1);
    
    uft[ei.bi] = ei.bi;

    if (uw <= MAX_W) {
      int dw = uw - lw;
      if (min_dw > dw) min_dw = dw;
    }
  }
  
  return min_dw;
}

/* main */

int main() {
  for (;;) {
    cin >> n >> m;
    if ((n | m) == 0) break;

    for (int i = 0; i < m; i++) {
      cin >> edges[i].ai >> edges[i].bi >> edges[i].wi;
      edges[i].ai--;
      edges[i].bi--;
    }
    sort(edges, edges + m);
    //for (int i = 0; i < m; i++)
    //printf("%d: [%d,%d,%d]\n", i, edges[i].ai, edges[i].bi, edges[i].wi);

    int min_dw = check();

    cout << (min_dw > MAX_W ? -1 : min_dw) << endl;
  }

  return 0;
}

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



int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);    
    
    int health, A;
    cin >> health >> A;
    if (A > health)
      cout << 1 << endl;
    else{
      double res = health / (A * 1.0);
      cout << ceil(res) << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
typedef pair<pll, lint> ppl;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(const T a, const T b){return a>=0 ? a/b : (a+1)/b-1;}
template<class T> T div_ceil(const T a, const T b){return a>=0 ? (a-1)/b+1 : a/b;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100000010;

int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    ppl p[n];
    rep(i, n){
        lint x, y, z;
        scanf("%lld%lld%lld", &x, &y, &z);
        p[i] = {{x, y}, z};
    }

    lint ans = -INF;
    rep(s1, 2)rep(s2, 2)rep(s3, 2){
        lint sg1 = s1*2-1, sg2 = s2*2-1, sg3 = s3*2-1;
        auto f = [&](const ppl &a){return a.fi.fi*sg1 + a.fi.se*sg2 + a.se*sg3;};
        sort(p, p+n, [&](const ppl &a, const ppl &b){return f(a) > f(b);});
        lint tmp = 0;
        rep(i, m) tmp += p[i].fi.fi*sg1 + p[i].fi.se*sg2 + p[i].se*sg3;
        chmax(ans, tmp);
    }
    printf("%lld\n", ans);
}

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

int main()
{
    string S;
    ll K;

    cin >> K;
    cin >> S;

    if(S.length() <= K) {
        cout << S;
    } else {
        cout << S.erase(K) << "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define li long
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pli pair<li,li>
#define pll pair<ll,ll>
#define pb push_back
#define fori(i,k,n) for(int i = k;i<n; i++)
#define rfori(i,k,n) for(int i = k; i>=n; i--)
#define tc int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
} 
class dsu{
    public:
    unordered_map<int,int> p,sz;
    void make_set(int x)
    {
        p[x] = x;
        sz[x]+=1;
    }
    int find(int x)
    {
        if(x == p[x])return x;
        return p[x] = find(p[x]);
    }
    void merge(int a,int b)
    {
        a = find(a);
        b = find(b);
        if(a == b)return;
        if(sz[a]<sz[b])swap(a,b);
        p[b] = a;
        sz[a]+=sz[b];
        sz.erase(b);
    }
};
template<class T>
T power(T a,T b){
    T res = (T)1;
    while(b>0){
        if(b&1)res = (res*a);
        b>>=1;
        a*=a;
    }
    return res;
}


int kmp(string s){
    vector<int> lps(s.size(),0);
    for(int i = 1; i<lps.size(); ++i){
        int prev_index = lps[i-1];
        while(prev_index>0&&s[i]!=s[prev_index]){
            prev_index = lps[prev_index-1];
        }
        lps[i] = prev_index+(s[i] == s[prev_index]?1:0);
    }
    return lps[lps.size()-1];
}

int main()
{
    fastio();
    int k;cin>>k;
    set<ll> st = {1,2,3,4,5,6,7,8,9};
    vector<ll> a;
    while(a.size()<k){
        a.pb(*st.begin());
        st.erase(st.begin());
        string z = to_string(a.back());
        if(z.back() == '9'){
            st.insert(stoll(z+"9"));
            st.insert(stoll(z+"8"));
        }
        else if(z.back() == '0'){
            st.insert(stoll(z+"1"));
            st.insert(stoll(z+"0"));
        }
        else{
            string phi;
            phi+=z;
            int c = z.back()-'0';
            string d = to_string(c-1);
            string e = to_string(c+1);
            string f = to_string(c);
            st.insert(stoll(phi+d));
            st.insert(stoll(phi+e));
            st.insert(stoll(phi+f));
        }
    }
    cout<<a[k-1]<<"\n";
}


Measured memory_bytes: 9972
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  // const int64_t L = static_cast<int64_t>(T.length());
  vector<int64_t> A(6);
  for (int64_t i = 1; i <= 5; ++i) {
    cin >> A[i];
    if (A[i] == 0) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 3564
n,k = map(int,input().split())

p = [int(x) for x in input().split()]

sum1 = sum(p[:k])
num = k-1
max1 = sum1

for i in range(k,n):
    sum1 = sum1 - p[i-k] + p[i]
    if sum1 >= max1:
        max1 = sum1
        num = i
    #print(max1,sum1,i)

sum2 = sum(p[num-k+1:num+1])

def goukei(j):
    return 1/2 * j * (j+1)

print(float((goukei(sum2)-goukei(k-1))/(sum2 -k +1)))


Measured memory_bytes: 32260
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k,r,s,p;cin >> n >> k >> r >> s >> p;
  string t;cin >> t;
  int ans=0;
  vector<int> c(k);
  for(int i=0;i<n;i++){
    if(i<k){
      if(t[i]=='r'){
        ans+=p;
      }
      if(t[i]=='s'){
        ans+=r;
      }
      if(t[i]=='p'){
        ans+=s;
      }
      c[i]=true;
    }
    else{
      if(t[i]!=t[i-k]){
        if(t[i]=='r'){
        ans+=p;
      }
      if(t[i]=='s'){
        ans+=r;
      }
      if(t[i]=='p'){
        ans+=s;
      }
        c[i%k]=true;
      }
      else{
        if(c[i%k]){
          c[i%k]=false;
        }
        else{
          if(t[i]=='r'){
        ans+=p;
      }
      if(t[i]=='s'){
        ans+=r;
      }
      if(t[i]=='p'){
        ans+=s;
      }
        c[i%k]=true;
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 768
#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>;

const int mod = 1000000007;
struct mint {
    ll x;
    mint(ll x=0):x( (x%mod + mod) % mod ) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ( (x += a.x) >= mod ) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ( ( x += mod - a.x) >= mod ) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        ( x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main() {
    int n;
    cin >> n;
    int zeros = 0;
    map< pair<ll,ll>, P> mp;
    rep(i,n) {
        ll x, y, g;
        cin >> x >> y;
        if (x == 0 && y == 0) {
            zeros++;
            continue;
        }
        g = __gcd(x,y);
        x /= g;
        y /= g;
        if (y < 0) x = -x, y = -y;
        if (y == 0 && x < 0) x = -x, y = -y;
        bool rot90 = (x <= 0);
        if (rot90) {
            ll tmp = x;
            x = y, y = -tmp;
        }
        if(rot90) mp[{x,y}].first++;
        else mp[{x,y}].second++;
    }
    mint ans = 1;
    for (auto p : mp) {
        int s = p.second.first;
        int t = p.second.second;
        mint cur = 1;
        cur += mint(2).pow(s) - 1;
        cur += mint(2).pow(t) - 1;
        ans *= cur;
    }
    ans -= 1;
    ans += zeros;
    cout << ans << endl;
    return 0;
}

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

int main(){
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int> v(n);	
	map<int,int> impares;
	map<int,int> pares;
	for(int i = 0; i< n; i++){
		cin >>v[i];		
	}
	for(int i = 0; i< n; i+=2){
		pares[v[i]]++;
	}
	for(int i = 1; i< n; i+=2){
		impares[v[i]]++;
	}
	int ma = -1;
	int ma2 = -1;
	int mp,mi; 
	for(auto p: pares){		
		if(ma<=p.second){
			ma = max(ma,p.second);
			mp = p.first;
		}
	}
	for(auto p: impares){
		if(ma2 <= p.second){
			ma2 = max(ma2,p.second);
			mi = p.first;
		}
	}
	int ama = -1;
	int ama2 = -1;
	pares[mp] = -1;
	impares[mi] = -1;
	for(auto p: pares){
		ama = max(ama,p.second);
	}
	for(auto p: impares){
		ama2 = max(ama2,p.second);
	}
	
	if(n-ma2-ma == 0 && v[0] == v[1]) 
		cout<<ma2<<'\n';
	else if(mi == mp){
		if(ma2<ma){
			cout<< n-ma-ama2<<'\n';
		}
		else if(ma2>ma){
			cout<< n-ma2-ama<<'\n'; 
		}
		else{
			int a = max(ama,ama2);
			cout<<n-ma-a<<'\n';
		}
	}
	else cout<<n-ma2-ma<<'\n';
}


Measured memory_bytes: 5376
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)

    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]

    def Unite(self, x, y):
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        if(x == y):
            return
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1

    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    def Count(self, x):
        return -self.root[self.Find_Root(x)]


n, m = map(int, input().split())
ab = []
for i in range(m):
    a, b = map(int, input().split())
    ab.append([a, b])

all_ptn = n * (n - 1) // 2
num = 0
ret = [str(all_ptn)]

uni = UnionFind(n)
for i in range(1, m):
    a, b = ab[-i]
    prev_a = uni.Count(a)
    prev_b = uni.Count(b)
    if not uni.isSameGroup(a, b):
        uni.Unite(a, b)
        now_ab = uni.Count(a)
        cnt = now_ab * (now_ab - 1) // 2 - (prev_a * (prev_a - 1)) // 2 - \
            (prev_b * (prev_b - 1)) // 2
        num += cnt
    ret.append(str(all_ptn - num))

ret.reverse()

print('\n'.join(ret))


Measured memory_bytes: 31728
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

template<typename T> void chmax(T &a, T b) { a = std::max(a, b); }
template<typename T> void chmin(T &a, T b) { a = std::min(a, b); }
template<typename T> void chadd(T &a, T b) { a = a + b; }

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}
}

int main() {

  int n;
  cin >> n;
  vector<vector<int>> a(n, vector<int>(n - 1));
  rep(i, n)rep(j, n - 1) {
    int tmp; cin >> tmp; a[i][j] = tmp - 1;
  }

  vector<int> mNum(n, 0);
  int sum = 0;
  int ans = 0;

  vector<bool> used(n, false);
  int dest = n * (n - 1);

  queue<int> que;
  rep(i, n) que.push(i);
  int prevMoveNum = n;

  while (sum != dest) {
	int moveNum = 0;
	rep(i, n) used[i] = (mNum[i] == n - 1);
	rep(i, prevMoveNum) {
	  int p = que.front(); que.pop();
	  if (used[p]) continue;
	  int op = a[p][mNum[p]];
	  if (used[op])continue;

	  if (a[op][mNum[op]] != p) continue;

	  mNum[p]++; mNum[op]++;
	  used[p] = used[op] = true;
	  moveNum += 2;
	  que.push(p); que.push(op);
	}

	if (!moveNum) {
	  ans = -1;
	  break;
	}
	prevMoveNum = moveNum;
	ans++;
	sum += moveNum;
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

int ans, nr, N, K, dp[10009], dv[10009], mod = 1e9 + 7;

int add (int x, int y) {int ans = x + y; if (ans >= mod) ans -= mod; return ans;}
int substract (int x, int y) {if (x >= y) return x - y; return x - y + mod;}
int mul (int x, int y) {return 1LL * x * y % mod;}

int pow (int a, int b)
{
    int p = 1;
    for (int i=0; (1<<i) <= b; i++)
    {
        if (b & (1 << i)) p = mul (p, a);
        a = mul (a, a);
    }
    return p;
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d", &N, &K);
for (int i=1; i * i<=N; i++)
    if (N % i == 0)
        dv[++nr] = i;
for (int i=nr; i>=1; i--)
    if (dv[i] * dv[i] != N)
        dv[++nr] = N / dv[i];
for (int i=1; i<=nr; i++)
{
    dp[i] = pow (K, (dv[i] + 1) / 2);
    for (int j=1; j<i; j++)
        if (dv[i] % dv[j] == 0)
            dp[i] = substract (dp[i], dp[j]);
    int coef = dv[i];
    if (coef % 2 == 0) coef /= 2;
    ans = add (ans, mul (dp[i], coef));
}
printf ("%d\n", ans);
return 0;
}


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

#define REP(i, n) for(int i = 0; i != n; ++i)
#define REPR(i, n) for(int i = n - 1; i != -1; --i)
#define FOR(i, a, b) for(int i = a; i != b; ++i)
#define RBF(i, n) for(auto &i : n)
#define ABS(n) (n < 0 ? -n : n)
#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#define IN(n) (cin >> n)
#define OUT(n) (cout << n << "\n")
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main() {
    int N;
    IN(N);
    vector<double> v(N);
    REP(i, N) IN(v[i]);
    sort(v.begin(), v.end());
    REP(i, N - 1) {
        v[i + 1] = (v[i] + v[i + 1]) / 2;
    }
    OUT(v[N - 1]);
}

Measured memory_bytes: 256
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;

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

    Int n;
    cin >> n;
    map<Int, Int> m;
    vector<Int> a(n);
    for (Int i = 0; i < n; i++) {
        cin >> a[i];

        m[a[i]]++;
    }

    Int all = 0;
    for (auto &&e : m) {
        all += e.second * (e.second - 1) / 2;
    }

    for (Int i = 0; i < n; i++) {
        cout << all - (m[a[i]] * (m[a[i]] - 1) / 2) + ((m[a[i]] - 1) * (m[a[i]] - 2) / 2) << endl;
    }

    return 0;
}


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

int main(){
  int n;
  int a[30];

  while(cin >> n ,n){
    for(int i=0;i<n;i++)cin >> a[i];

    int ans = 30000000;
    for(int i=0;i<(1<<n);i++){
      int A=0,B=0;
      for(int j=0;j<n;j++){
	if((i>>j)&1)A += a[j];
	else B += a[j];
      }
      ans = min(ans,abs(A-B));
    }
    cout << ans << endl;
  }
}

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

int main(){
  int N;
  cin >> N;
  vector<pair<long long,long long>> H(N);
  for(int i=0; i<N; i++){
    long long A, B;
    cin >> A >> B;
    H[i].first= A + B;
    H[i].second= A;
  }
  sort(H.begin(), H.end());
  reverse(H.begin(), H.end());
  long long ans=0;
  for(int i=0; i<N; i++){
    if(i%2==0) ans+=H[i].second;
    else ans+=H[i].second - H[i].first;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
n = int(input())
a = list(map(int, input().split()))
odd = 0
ans = 0
b = []
for i in range(n):
    b.append(abs(a[i]))
b.sort()
ans = sum(b)
if 0 in a:
    print(ans)
else:
    for i in range(n):
        if a[i] < 0:
            odd += 1
    if odd % 2 == 0:
        print(ans)
    else:
        print(ans - 2*b[0])

Measured memory_bytes: 14332
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N, M = map(int, input().split())
    MOD = 10 ** 9 + 7
    if abs(N - M) >= 2:
        print(0)
        return

    ans = 1
    if abs(N - M) == 1:
        for i in range(1, M + 1):
            ans *= i
            ans %= MOD
        for i in range(1, N + 1):
            ans *= i
            ans %= MOD
    else:
        for i in range(1, N + 1):
            ans *= i
            ans %= MOD
        for i in range(1, N + 1):
            ans *= i
            ans %= MOD
        ans *= 2

    print(ans % MOD)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3952
N = int(input())
A = list(map(int, input().split()))

dp = [[0] * 2 for i in range(N)]
dp[0][0] = 0
dp[0][1] = A[0]
dp[1][0] = 0
dp[1][1] = max(A[0:2])
for i in range(2, N-1):
    if i%2 == 0:
        dp[i][0] = max(dp[i-1][1], dp[i-2][0] + A[i])
        dp[i][1] = dp[i-2][1] + A[i]
    else:
        dp[i][0] = max(dp[i-1][0], dp[i-2][0] + A[i])
        dp[i][1] = max(dp[i-1][1], dp[i-2][1] + A[i])
#print(dp)

if N%2 == 0:
    ans = max(dp[N-2][1], dp[N-3][1] + A[N-1])
else:
    ans = max(dp[N-2][1], dp[N-3][0] + A[N-1])
print(ans)


Measured memory_bytes: 112560
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll a, b, k;

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

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

void maxHeapify(int a[], int h, int i) {
    int left = 2 * i;
    int right = 2 * i + 1;
    int largest;

    if (left <= h && a[left] > a[i]) {
        largest = left;
    } else {
        largest = i;
    }
    if (right <= h && a[right] > a[largest]) {
        largest = right;
    }

    if (largest != i) {
        swap(a[i], a[largest]);
        maxHeapify(a, h, largest);
    }
}

int main() {
    int h, a[MAX+1];

    cin >> h;
    for (int i = 1; i <= h; i++) cin >> a[i];

    for (int i = h / 2; i >= 1; i--) maxHeapify(a, h, i);

    for (int i = 1; i <= h; i++) {
        cout << " " << a[i];
    }
    cout << endl;
}



Measured memory_bytes: 5044
#include<iostream>
using namespace std;
int main()
{
	int a,b,c;
	cin >> a >> b >> c;
  	int t = a;
  	a = b;
  	b = t;
  	t = a;
  	a = c;
  	c = t;
  	cout << a << " " <<b << " "<< c; 
}

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

int main(){
    int n;
    cin >> n;
    if(n < 105){
        cout << "0";
        return 0;
    }
    int count = 1;
    for(int i = 107; i <= n; i+=2){
        int c = 0;
        for(int j = 1; j <= i; j++){
            if(i%j == 0)
                c++;
        }
        if(c == 8)
            count++;
    }
    cout << count;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <algorithm>
using namespace std;

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

    cout << n-k +1;
}
    // for (int i = 0; i < ; i++){
        
    // }


Measured memory_bytes: 256