akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))

#define INF 1000000000

int array_min_max(int* p, int n,bool f)  //f: true→min false→max
{
	int tmp;

	if (f)
		tmp = INF;
	else
		tmp = 0;

	for (int i = 0; i < n; i++)
	{
		if (f)
		{
			if (p[i] < tmp)
				tmp = p[i];
		}
		else
		{
			if (p[i] > tmp)
				tmp = p[i];
		}
	}
	return tmp;
}

int main()
{
	int N;
	int V[20];
	int C[20];
	double P[20];
	int cnt = 0;
	int V2[20];
	int C2[20];

	int X=0, Y=0;

	scanf("%d", &N);

	for (int i = 0; i < N; i++)
	{
		scanf("%d", &V[i]);
		X += V[i];
	}
	for (int i = 0; i < N; i++)
	{
		scanf("%d", &C[i]);
		Y += C[i];
	}

	for (int i = 0; i < N; i++)
		P[i] = (double)V[i] / (double)C[i];

	double tmp;

	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < N-i-1; j++)
		{
			if(P[j]>P[j+1])
			{
				tmp = P[j];
				P[j] = P[j+1];
				P[j+1] = tmp;

				tmp = V[j];
				V[j] = V[j + 1];
				V[j+1] = tmp;

				tmp = C[j];
				C[j] = C[j + 1];
				C[j+1] = tmp;
			}
		}
	}

	int max = X - Y;

	for (int i = 0; i < N; i++)
	{
		//printf("-----%d---\n", max);

		if ((X - V[i]) - (Y - C[i]) > max)
		{
			max = (X - V[i]) - (Y - C[i]);
			X -= V[i];
			Y -= C[i];
		}
		else
			break;
	}

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

	//for (int i = 0; i < N; i++)
	//	printf("%f ", P[i]);

	//printf("\n");

	//for (int i = 0; i < N; i++)
	//	printf("%d ", C[i]);
}

Measured memory_bytes: 128
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

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



class ERemOfSumIsNum {
public:
    int dy[4]={-1,1,0,0};
    int dx[4]={0,0,1,-1};

	void solve(std::istream& in, std::ostream& out) {
        ll N, K;
        // vector<ll> factorSum = vector<ll>(N, 0);
        unordered_map<ll, ll> d;
        in >> N >> K;
        ll fsum = 0;
        vector<ll> fuctorSum(N+1);
        fuctorSum[0]=0;
        REP(i, N) {
            ll a;
            in >> a;
            fsum += a;
            ll key = fsum - (i+1);
            key %= K;
            fuctorSum[i+1]=key;
        }

        ll ans = 0;
        REP(i, N+1) {
            auto idx = N - i;
            auto f = fuctorSum[idx];
            if (K <= i) {
                d[fuctorSum[idx + K]]--;
            }
            ans += d[fuctorSum[idx]];
            d[f]++;
        }
        out << ans << endl;
	}
};


int main() {
    ios::sync_with_stdio(false);
	ERemOfSumIsNum solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 10056
#include <iostream>
#include <cmath>
#include <queue>
int main(){
  int N;
  std::cin >> N;
  
  std::priority_queue<int> q;
  
  for(int i=0;i<N;++i){
    int score;
    std::cin >> score;
    q.push(score);
  }
  
  int alice=0;
  int bob=0;
  while(!q.empty()){
  	alice += q.top();
    q.pop();
    if(q.empty()){
      break;
    }
  	bob += q.top();
    q.pop();
  }
  
  std::cout << alice - bob << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma comment(linker, "/stack:200000000")
using namespace std;
#define F first
#define S second
#define EB emplace_back
#define MP make_pair
#define all(o) (o).begin(), (o).end()
#define mset(m,v) memset(m,v,sizeof(m))
#define fr(i,n) for(lli i=0;i<(n);++i)
#define rep(i,a,b) for(lli i=a;i<=b;++i)
#define per(i,a,b) for(lli i=a;i>=b;i--)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b))) 
#define sz(x) (lli)(x).size()
#define endl '\n'
typedef long long lli;        typedef long double ld;
typedef pair<lli,lli> ii;     typedef vector<lli> vi;
typedef vector<ii> vii;       typedef vector<vi> graph;
long long MOD=1000000007;     long double EPS=1e-9;
#ifndef ONLINE_JUDGE
#define debarr(a,n)cerr<<#a<<":";for(int i=0;i<n;i++)cerr<<a[i]<<" ";cerr<<endl;
#define debmat(mat,row,col)cerr<<#mat<<":\n";for(int i=0;i<row;i++){for(int j=0;j<col;j++)cerr<<mat[i][j]<<" ";cerr<<endl;}
#define pr(...)dbs(#__VA_ARGS__,__VA_ARGS__)
template<class S,class T>ostream &operator<<(ostream &os,const pair<S,T> &p){return os<<"("<<p.first<<","<<p.second<<")";}
template<class T>ostream &operator<<(ostream &os,const vector<T> &p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>ostream &operator<<(ostream &os,const set<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>ostream &operator<<(ostream &os,const multiset<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class S,class T>ostream &operator<<(ostream &os,const map<S,T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>void dbs(string str,T t){cerr<<str<<":"<<t<<"\n";}
template<class T,class...S>void dbs(string str,T t,S... s){int idx=str.find(',');cerr<<str.substr(0,idx)<<":"<<t<<",";dbs(str.substr(idx+1),s...);}
#else
#define pr(...){}
#define debarr(a,n){}
#define debmat(mat,row,col){}
#endif
lli binpow(lli b,lli p,lli mod){lli ans=1;b%=mod;for(;p;p>>=1){if(p&1)ans=ans*b%mod;b=b*b%mod;}return ans;}

void pre(){

}

void solve(){
    int n;cin>>n;
    string s,t;
    cin>>s>>t;
    fr(i,n){
        cout<<s[i]<<t[i];
    }
    cout<<endl;
}

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //cout<<fixed<<setprecision(15);
    //clock_t begin = clock();
    pre();lli _t=1;//cin>>_t;
    for(lli i=1;i<=_t;i++){
        //cout<<"Case #"<<i<<": ";
        solve();
    }
    // clock_t end = clock();double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;cerr << elapsed_secs;
}

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

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

    stack<char> stk;
    int cnt = 0;
    REP(i, SZ(s)) {
        if (s[i] == 'm') {
            if (stk.empty()) cnt++;
            stk.push(s[i]);
        } else if (s[i] == 'e') {
            stk.push(s[i]);
        } else if (s[i] == 'w') {
            if (stk.empty()) {
                cout << "Rabbit" << endl;
                goto END;
            }
            char c2 = stk.top();
            stk.pop();
            if (stk.empty()) {
                cout << "Rabbit" << endl;
                goto END;
            }
            char c1 = stk.top();
            stk.pop();
            if (c1 == 'm' && c2 == 'e') {
            } else {
                cout << "Rabbit" << endl;
                goto END;
            }
        }
    }
    if (stk.empty() && cnt == 1) {
        cout << "Cat" << endl;
    } else {
        cout << "Rabbit" << endl;
    }
END: {}
}

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

from collections import deque

n = int(input())
word = deque()

for i in range(n):
    command = list(map(int, input().split()))
    if command[0] == 0:
        word.append(command[1])
    elif command[0] == 1:
        print('{0}'.format(word[command[1]]))
    elif command[0] == 2:
        word.pop()



Measured memory_bytes: 13812
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextInt();
		long a = sc.nextInt();
		long b = sc.nextInt();

		if (b <= a)System.out.println("delicious");
		else if (b <= a + x) System.out.println("safe");
		else System.out.println("dangerous");
	}
}

Measured memory_bytes: 21844
package main

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

// 参考: https://mickey24.hatenablog.com/entry/bufio_scanner_line_length
const (
	// 初期バッファサイズ
	initialBufSize = 10000
	// バッファサイズの最大値。Scannerは必要に応じこのサイズまでバッファを大きくして各行をスキャンする。
	// この値がinitialBufSize以下の場合、Scannerはバッファの拡張を一切行わず与えられた初期バッファのみを使う。
	maxBufSize = 100000000
)

// stringToInt はstring型のスライスをint型のスライスにキャストする関数
func stringToInt(tSlice []string) (rSlice []int) {
	for _, str := range tSlice {
		num, _ := strconv.Atoi(str)
		rSlice = append(rSlice, num)
	}
	return
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	// 何も指定しないままスキャンすることもできるが、
	// 一行の長さが一定以上になると自動的にスキャンがストップするので、
	// 最小、最大バッファサイズを指定してスキャンを継続させる
	buf := make([]byte, initialBufSize)
	scanner.Buffer(buf, maxBufSize)

	scanner.Scan()
	var braveStr string = scanner.Text()
	brave, _ := strconv.Atoi(braveStr)

	scanner.Scan()
	var monsterRemain []int = stringToInt(strings.Split(scanner.Text(), " "))

	scanner.Scan()
	var canKill []int = stringToInt(strings.Split(scanner.Text(), " "))

	var killedTotal int = 0
	for i := 0; i < brave; i++ {
		// 勇者iが街iのモンスターを全員倒せるなら
		if canKill[i] >= monsterRemain[i] {
			// 勇者iの倒せる数から、街iのモンスターを引く
			canKill[i] -= monsterRemain[i]
			// 街iのモンスターを全員倒し、トータルに加算
			killedTotal += monsterRemain[i]
			monsterRemain[i] = 0
		} else {
			// 倒せるだけ倒し、トータルに加算
			monsterRemain[i] -= canKill[i]
			killedTotal += canKill[i]
			// 倒し切ったので、残力を0に
			canKill[i] = 0
		}

		// fmt.Println("1ターン終了後の残気:", canKill[i])

		// まだ倒せるんなら、街i+1のモンスターも倒せるだけ倒す！
		if canKill[i] > 0 {
			// 勇者iが街i+1のモンスターを全員倒せるなら
			if canKill[i] >= monsterRemain[i+1] {
				// 街i+1のモンスターを全員倒し、トータルに加算
				killedTotal += monsterRemain[i+1]
				monsterRemain[i+1] = 0
			} else {
				// 倒せるだけ倒し、トータルに加算
				monsterRemain[i+1] -= canKill[i]
				killedTotal += canKill[i]
				// 倒し切ったので、残力を0に
				canKill[i] = 0
			}
		}

		// fmt.Println("\n現在の勇者番号:", i)
		// fmt.Println("現在の残っているモンスター:", monsterRemain)
		// fmt.Println("現在の勇者の残気:", canKill)
		// fmt.Println("現在の倒したモンスター数:", killedTotal)
	}

	fmt.Println(killedTotal)
	// fmt.Println("\n現在の残っているモンスター:", monsterRemain)
	// fmt.Println("現在の勇者の残気:", canKill)
}

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

using namespace std;

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

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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 <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)
//blue>green>red
int main(){
    int red,blue,green,k;
    cin>>red>>green>>blue>>k;
    rep(i,k){
        if(green<=red){
            green*=2;
        }else if(blue<=green){
            blue*=2;
        }
        //cout<<red<<" "<<green<<" "<<blue<<endl;
        if(red<green&&green<blue){
            cout<<"Yes"<<endl;
            //cout<<red<<" "<<green<<" "<<blue<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

//a=97,z=122

Measured memory_bytes: 3624
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

  public static void main(String[] args) {
    try (Scanner sc = new Scanner(System.in);) {
      int N = sc.nextInt();
      int M = sc.nextInt();

      Map<Long, Long> tMap = new TreeMap<>();
      for (int i = 0; i < N; i++) {
        long price = sc.nextInt();
        long left = sc.nextInt();
        if (tMap.containsKey(price)) {
          tMap.put(price, tMap.get(price) + left);
        } else {
          tMap.put(price, left);
        }
      }

      long ans = 0;
      for (Map.Entry<Long, Long> entry : tMap.entrySet()) {
        long buy = Math.min(M, entry.getValue());
        ans += buy * entry.getKey();
        M -= buy;
        if(M <= 0) {
          break;
        }
      }

      System.out.println(ans);
    }
  }
}

Measured memory_bytes: 98568
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector<int> b(n, 0);

	for (int i = n; i >= 1; i--) {
		int tmp = 0;
		for (int j = i+i; j <= n; j += i) {
			tmp += b[j-1];
		}
		if (tmp % 2 == a[i-1]) {
			b[i-1] = 0;
		} else {
			b[i-1] = 1;
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans += b[i];
	}
	cout << ans << endl;
	for (int i = 0; i < n; i++) {
		if (b[i])
			cout << i+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 4680
#include<stdio.h>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 100005
#define ll long long

int n,i;
ll x,g;

ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
 
int main()
{
	scanf("%d",&n);
	scanf("%lld",&x);
	for(i=1;i<n;i++){
		scanf("%lld",&g);
		x/=gcd(g,x);
		x*=g;
	}printf("%lld\n",x);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int c[2][1<<17];
int n;
main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int a;cin>>a;
		c[i%2][a]++;
	}
	vector<pair<int,int> >a,b;
	for(int i=1;i<=100000;i++)
	{
		if(c[0][i]>0)a.push_back(make_pair(n/2-c[0][i],i));
		if(c[1][i]>0)b.push_back(make_pair(n/2-c[1][i],i));
	}
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	if(a[0].second!=b[0].second)
	{
		cout<<a[0].first+b[0].first<<endl;
	}
	else
	{
		cout<<min(a[0].first+(b.size()>1?b[1].first:n/2),(a.size()>1?a[1].first:n/2)+b[0].first)<<endl;
	}
}


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

using namespace std;

int gcd(int a, int b) {
  return a ? gcd(b % a, a) : b;
}

int main() {
  int n, k;
  int g = 0, ma = 0;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    ma = max(ma, a);
    g = gcd(g, a);
  }
  if ((k % g) == 0 && k <= ma)
    puts("POSSIBLE");
  else
    puts("IMPOSSIBLE");
  return 0;
}

Measured memory_bytes: 256
// include
#include <iostream>

// using namespace 
using namespace std;

// typedef
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int, int> PII;

// macro
#define REP(index, num) for (auto index = 0; index < num; index++)
#define FOR(index, num) for (auto index = 1; index <= num; index++)

#define MAX_HEIGHT 60
#define MAX_WIDTH 60
#define INF (int)1e9

// global
int N;
int H, W;

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

  cout << (N - H + 1) * (N - W + 1) << endl;

}


Measured memory_bytes: 256
using System;

namespace AOJ.Volume5
{
    public class SchoolRoad
    {
        public static int Main()
        {
            while (true)
            {
                var input = Console.ReadLine().Split(' ');
                int a = int.Parse(input[0]);
                int b = int.Parse(input[1]);
                if (a == 0 && b == 0) { break; }

                // ?????????
                var map = new int[a + 1, b + 1];
                for(int i = 0; i <= a; i++)
                {
                    for(int j = 0; j <= b; j++) { map[i, j] = 0; }
                }
                // ??\?????´??????????????????
                int n = int.Parse(Console.ReadLine());
                for(int i = 0; i < n; i++)
                {
                    input = Console.ReadLine().Split(' ');
                    int x = int.Parse(input[0]);
                    int y = int.Parse(input[1]);
                    map[x, y] = -1;
                }
                // ???????¨????
                map[1, 1] = 1;
                for(int i = 1; i <= a; i++)
                {
                    for(int j = 1; j <= b; j++)
                    {
                        if (i == 1 && j == 1) { continue; }
                        if (map[i, j] == -1) { continue; }
                        map[i, j] = (map[i - 1, j] < 0 ? 0 : map[i - 1, j]) +
                            (map[i, j - 1] < 0 ? 0 : map[i, j - 1]);
                    }
                }
                Console.WriteLine(map[a, b]);
            }
            return 0;
        }
    }
}

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

void fail(){
    cout << -1 << endl;
    exit(0);
}

int main(){
    int N;
    cin >> N;
    vector<int64_t> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    int64_t ans = 0, now = 0;
    for(int i=N-1; i>=0; i--){
        if(now < A[i]){
            if(A[i] > i) fail();
            now = A[i];
            ans += now;
        }else if(now > A[i]){
            fail();
        }
        if(now > 0) now--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
int a,b,c,d;
cin >> a >> b >> c >> d;
if((abs(a-b)<=d&&abs(b-c)<=d)||abs(a-c)<=d) cout <<"Yes" << endl;
else cout << "No" << endl;
}

Measured memory_bytes: 256
s = input()

flag = True


for i in range(len(s)):
    if((i+1)%2== 0):
        if(s[i] == 'L' or s[i] == 'U' or s[i] == 'D'):
            pass
        else:
            flag = False

    else:
        if(s[i] == 'R' or s[i] == 'U' or s[i] == 'D'):
           pass
        else:
            flag = False


if(flag == True):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
def collatz(n):
  if n % 2 == 0:
    return int(n/2)
  else:
    return 3 * n + 1

A = [int(input())]
i = 1
while True:
  x = collatz(A[-1])
  if x in A:
    print(i + 1)
    break
  else:
    A.append(x)
    i += 1



Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)

/*
#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>
*/

int main() {
    int N;
    cin >> N;
    vector<int> A(N);

    REP(i, 0, N){
        int p;
        cin >> p;
        A[i] = p;
    }
        
    int select = N/2;

    vector<vector<long>> DP(select, vector<long>(3, 0));
    REP(i, 0, 3) DP[0][i] = A[i];
    if(N % 2){
        REP(i, 1, select){
            DP[i][0] = DP[i-1][0] + A[i * 2];
            DP[i][1] = max(DP[i-1][0] + A[i * 2 + 1], DP[i-1][1] + A[i * 2 + 1]);
            long temp =  max(DP[i-1][0] + A[i * 2 + 2], DP[i-1][1] + A[i * 2 + 2]);
            DP[i][2] = max(temp, DP[i-1][2] + A[i * 2 + 2]);
        }
    }else{
        REP(i, 1, select){
            DP[i][0] = DP[i-1][0] + A[i * 2];
            DP[i][1] = max(DP[i-1][0] + A[i * 2 + 1], DP[i-1][1] + A[i * 2 + 1]);
        }
    }
    long ans = 0-__LONG_MAX__;
    REP(i, 0, 2+ N % 2)ans = max(ans, DP[select-1][i]);
    cout << ans << endl;
}

Measured memory_bytes: 9592
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
template<typename A, size_t NNN, typename T>
void Fill(A (&array)[NNN], const T &val){
    fill( (T*)array, (T*)(array+NNN), val );
}
#define INF 1e9+7
#define LLINF 1e18+7
ll MOD=1e9+7;
#define N 3000000
ll n,m,k;
ll a[N];
ll b[N];
ll dp[N][2];
vec G[N];
template<typename T>
struct BIT{
    vector<T> data;

    BIT(int size){
        data.assign(++size,0);
    }
    T query(int k){
        T ret=0;
        for(++k;k>0;k-=k&-k) ret=max(data[k],ret);
        return (ret);
    }
    void add(int k,T x){
        for(++k;k<data.size();k+=k&-k)data[k]=max(data[k],x);
    }
};
ll c[N];
int main(){
    n=in();
    rep(i,n)a[i]=in();
    rep(i,n)c[i]=in();
    BIT<ll> b(N);
    rep(i,n){
        ll ret=b.query(a[i]);
        b.add(a[i],ret+c[i]);
    }
    cout<<b.query(n);
    return 0;
}

Measured memory_bytes: 98944
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

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

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A.at(i);

    set<int> se;
    REP(i, N) {
        if (se.find(A[i]) == se.end()) {
            se.insert(A[i]);
        } else {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 10368
h,w,a,b=map(int,input().split())
flag=0
for i in range(h):
    if 0<=i<b: flag=1
    else: flag=0
    for j in range(w):
        if flag:
            if 0<=j<a: print(0,end="")
            else: print(1,end="")
        else:
            if 0<=j<a: print(1,end="")
            else: print(0,end="")
    print()

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

ans = N - 1 if N != 2 else 0
for i in range(2, int(N ** 0.5) + 1):
    if N % i == 0:
        a = N // i
        b = i
        if N // (a-1) == N % (a-1):
            ans += a-1
        if N // (b-1) == N % (b-1):
            ans += b-1

print(ans)



Measured memory_bytes: 40300
// https://atcoder.jp/contests/abc177/tasks/abc177_e

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "string"
#include "unordered_set"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
template <typename T>
using VV = V<V<T>>;
using VVL = VV<ll>;
template <typename T>
using VVV = VV<V<T>>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
using asc_pq = priority_queue<T, V<T>, greater<T>>;

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

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

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

string PC = "pairwise coprime";
string SC = "setwise coprime";
string NC = "not coprime";

VPL factorize(ll n) {
  VPL res;

  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0) continue;

    auto r = PL(i, 0);

    while (n % i == 0) {
      n /= i;
      r.second++;
    }

    res.push_back(r);
  }

  // sqrt(n) 以上の素因数は高々一つ
  if (n != 1) res.emplace_back(n, 1);

  return res;
}

void solve() {
  ll N;
  cin >> N;

  V<int> as(N);
  rep(i, N) cin >> as[i];

  unordered_set<int> facts;

  bool is_pc = true;

  for (int a : as) {
    VPL fact = factorize(a);

    for (PL pa : fact) {
      auto [fact, _] = pa;

      if (facts.count(fact)) {
        is_pc = false;
        break;
      }

      facts.insert(fact);
    }

    if (!is_pc) break;
  }

  if (is_pc) drop(PC);

  ll gcd_v = as[0];

  rep(i, N) { gcd_v = gcd(gcd_v, as[i]); }

  if (gcd_v == 1) drop(SC);
  drop(NC);
}


Measured memory_bytes: 7128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char>cvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
int main()	{
  int n;
  cin>>n;
  vector<int>w(n);
  int ans=300;
  rep(i,n) cin>>w[i];
  rep(i,n){
    int sum1=0,sum2=0;
    rep(j,i+1){
      sum1+=w[j];
    }
    for(int j=i+1;j<n;j++){
      sum2+=w[j];
    }
    ans=min(ans,abs(sum2-sum1));
  }
  cout<<ans<<endl;
    
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,o;
ll dp[3009][3009],a[3009];
ll bt(int l,int r)
{
    if(l==r)
    {
        if(n%2)return a[l];
        else return -a[l];
    }
    if(dp[l][r]!=-1)return dp[l][r];
    if((r-l+1)%2==o)
    {
        dp[l][r]=max(bt(l+1,r)+a[l],bt(l,r-1)+a[r]);
    }
    else
    {
        dp[l][r]=min(bt(l+1,r)-a[l],bt(l,r-1)-a[r]);
    }
    return dp[l][r];
}
int main()
{
    cin>>n;
    memset(dp,-1,sizeof(dp));
    if(n%2)o=1;
    for(int i=0;i<n;i++)cin>>a[i];
    cout<<bt(0,n-1);
}


Measured memory_bytes: 71168
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=510;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int n;
int a[maxn];
int b[maxn];
int c[maxn];
int d[maxn];
int can[maxn][maxn];
int vis[maxn];
int linker[maxn];
bool dfs(int x)
{
    repd(i,1,n)
    {
        if(can[x][i]&&vis[i]==0)
        {
            vis[i]=1;
            if(linker[i]==0||(dfs(linker[i])))
            {
                linker[i]=x;
                return 1;
            }
        }
    }
    return 0;
}
int main()
{
    //freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
    //freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
    gbtb;
    cin>>n;
    repd(i,1,n)
    {
        cin>>a[i]>>b[i];
    }
    repd(i,1,n)
    {
        cin>>c[i]>>d[i];
    }
    repd(i,1,n)
    {
        repd(j,1,n)
        {
            if(a[i]<c[j]&&b[i]<d[j])
            {
                can[i][j]=1;
            }
        }
    }
    int ans=0;
    repd(i,1,n)
    {
        memset(vis,0,sizeof(vis));
        if(dfs(i))
        {
            ans++;
        }
    }
    cout<<ans<<endl;
//    repd(i,1,n)
//    {
//        cout<<linker[i]<<endl;
//    }
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



Measured memory_bytes: 512
from collections import defaultdict
n, a = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
x = list(map(lambda x:x - a, x))
dic = defaultdict(int)
dic[0] = 1
for i in x:
    for j, k in list(dic.items()):
        dic[j + i] = dic.get(j + i, 0) + k
print(dic[0] - 1)

Measured memory_bytes: 9560
#include <stdio.h>

int main(void)
{
	int n,b,i;
	scanf("%d",&n);
	b=1;
	for(i=1;i<=100;i++){
	if(n<b){
	printf("%d\n",b/2);
	break;
	}
	b=b*2;
	}
	return 0;
}



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

#define MOD_1_000_000_007 (1000000007LL)
#define LINF (1LL<<60)
#define rep(i, n)   for (long long i = 0; i <  (long long)(n); i++)
#define rep1(i, n)  for (long long i = 1; i <  (long long)(n); i++)
#define rep2(i, n)  for (long long i = 2; i <  (long long)(n); i++)
#define rep0c(i, n) for (long long i = 0; i <= (long long)(n); i++)
#define rep1c(i, n) for (long long i = 1; i <= (long long)(n); i++)
#define rep2c(i, n) for (long long i = 2; i <= (long long)(n); i++)
#define repc0(n, i) for (long long i = (long long)(n); i >= 0; i--)
#define repc1(n, i) for (long long i = (long long)(n); i >= 1; i--)
#define repc2(n, i) for (long long i = (long long)(n); i >= 2; i--)

namespace solver {
  using namespace std;
  typedef long long ll;

  ll K;

  void init() {
    scanf("%lld", &K);
  }

  ll gcd(ll a, ll b) {
    if(a<b) return gcd(b, a);
    else if(a%b) return gcd(b, a%b);
    else return b;
  }

  void solve() {
    ll ans = 0;
    rep1c(a, K) rep1c(b, K) rep1c(c, K) {
      ans += gcd(gcd(a, b), c);
    }
    printf("%lld\n", ans);
  }
}

int main() {
  solver::init();
  solver::solve();
  return 0;
}

Measured memory_bytes: 3824
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int i, number_n, number_l, temp, sum = 0, min;
    number_n = Integer.parseInt(sc.next());
    number_l = Integer.parseInt(sc.next());
    int[] score = new int[number_n];
    for(i = 0; i < number_n; i++) {
      score[i] = number_l + i;
      sum += score[i];
    }
    min = Math.abs(score[0]);
    temp = score[0];
    for(i = 0; i < number_n; i++) {
      if(Math.abs(score[i]) < min) {
        min = Math.abs(score[i]);
        temp = score[i];
      }
    }
    System.out.println(sum - temp);
  }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
int main() {
  string s,t;
  cin>>s>>t;
  
  vector<vector<int>>dp(s.size()+1,vector<int>(t.size()+1));
  rep(i,s.size()){
    rep(j,t.size()){
      if(s.at(i)==t.at(j)){
        dp[i+1][j+1]=dp[i][j]+1;
      }
      else{
        dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);     
      }
    }
  }
  int i=s.size();
  int j=t.size();
  string ans="";
  while(i>0&&j>0){
    if(s[i-1]==t[j-1]){
      ans=s.at(i-1)+ans;
      i--;
      j--;
    }
    else{
      if(dp[i][j-1]>dp[i-1][j]){
        j--;
      }
      else{
        i--;
      }
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 35584
#include <iostream>
using namespace std;
int main()
{
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a<c) a=c;
  if(b>d) b=d;
  if(b-a>0)
  {
    cout<<b-a<<endl;
  }else{
    cout<<"0"<<endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int a[] = new int[n+2];
		a[0]=0;
		for(int i=1;i<n+1;i++) {
			a[i]=sc.nextInt();
		}
		a[n+1]=0;
		int sum=0;
		for(int i=1;i<n+2;i++) {
			sum+=Math.abs(a[i-1]-a[i]);
		}
		for(int i=1;i<n+1;i++) {
			int num = sum;
			num -=Math.abs(a[i-1]-a[i])+Math.abs(a[i]-a[i+1]);
			num += Math.abs(a[i-1]-a[i+1]);
			System.out.println(num);
		}
	}
}

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

int n, k;
int h[100005] = {0};
int dp[100005] = {0};

int solve();

int main() {
  cin >> n;
  k = 2;
  for(int i = 0; i < n; ++i) cin >> h[i];
  cout << solve() << endl;
  return 0;
}

int solve() {
  for(int i = 1; i < n; ++i) dp[i] = 2000000000;
  for(int i = 0; i < n; ++i) {
    for(int j = 1; j + i < n && j <= k; ++j) {
      int cost = max(h[i] - h[i + j], h[i + j] - h[i]);
      dp[i + j] = min(dp[i + j], dp[i] + cost);
    }
  }
  return dp[n - 1];
}

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

int main(){
    int n; 
    string s;
    cin >> n >> s;
    char c = '#';
    int ans = 0;
    rep(i,s.size()){
        if(c == s.at(i)) continue;
        c = s.at(i);
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3700
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N, K = read_ints()
    A = [a-1 for a in read_ints()]
    distance = [-1]*N
    i = 0
    k = K
    while k > 0:
        if distance[i] != -1:
            cycle_length = K-k-distance[i]
            k %= cycle_length
            if k == 0:
                break
        else:
            distance[i] = K-k
        i = A[i]
        k -= 1
    return i+1


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 32368
#include<iostream>
using namespace std;
const int MAX = 100000;

int parent(int i){
	return i / 2;
}

int left(int i){
	return 2 * i;
}

int right(int i){
	return 2 * i + 1;
}

int main(){
	int H, A[MAX + 1];  //数组起点为 1
	
	cin >> H;
	for(int i = 1; i <= H; i++) cin >> A[i];
	
	for(int i = 1; i <= H; i++){
		cout << "node " << i << ": key = " << A[i] << ", ";
		if(parent(i) >= 1) cout << "parent key = " << A[parent(i)] << ", ";
		if(left(i) <= H) cout << "left key = " << A[left(i)] << ", ";
		if(right(i) <= H) cout << "right key = " << A[right(i)] << ", ";
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3056
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let m: usize = input();
    let a: Vec<Vec<char>> = (0..n)
        .map(|_| input::<String>().chars().collect())
        .collect();
    let b: Vec<Vec<char>> = (0..m)
        .map(|_| input::<String>().chars().collect())
        .collect();

    let mut ok = false;
    for i in 0..n - m + 1 {
        for j in 0..n - m + 1 {
            let mut temp = true;
            for k in 0..m {
                for l in 0..m {
                    if a[i + k][j + l] != b[k][l] {
                        temp = false;
                    }
                }
            }
            if temp {
                ok = temp;
            }
        }
    }

    println!("{}", if ok { "Yes" } else { "No" });
}


Measured memory_bytes: 4352
#include <stdio.h>
#define UNDER_E 0
#define E 1
#define D 2
#define C 3
#define B 4
#define A 5
#define AA 6
#define AAA 7
void print_rank(int rank){
	printf(
			"%s\n",
			rank == AAA ? "AAA":
			rank == AA  ? "AA" :
			rank == A   ? "A"  :
			rank == B   ? "B"  :
			rank == C   ? "C"  :
			rank == D   ? "D"  :
			rank == E   ? "E"  :
			              "NA"
		);
}

int main(void){
	double time500,time1000;
	int rank500,rank1000;
	while(scanf("%lf%lf",&time500,&time1000) != EOF){
		if(time500 < 35.50){
			rank500 = AAA;
		}else if(time500 < 37.50){
			rank500 = AA;
		}else if(time500 < 40.00){
			rank500 = A;
		}else if(time500 < 43.00){
			rank500 = B;
		}else if(time500 < 50.00){
			rank500 = C;
		}else if(time500 < 55.00){
			rank500 = D;
		}else if(time500 < 70.00){
			rank500 = E;
		}else{
			rank500 = UNDER_E;
		}
		if(time1000 < 71.00){
			rank1000 = AAA;
		}else if(time1000 < 77.00){
			rank1000 = AA;
		}else if(time1000 < 83.00){
			rank1000 = A;
		}else if(time1000 < 89.00){
			rank1000 = B;
		}else if(time1000 < 105.00){
			rank1000 = C;
		}else if(time1000 < 116.00){
			rank1000 = D;
		}else if(time1000 < 148.00){
			rank1000 = E;
		}else{
			rank500 = UNDER_E;
		}
		if(rank1000 >= rank500){
			print_rank(rank500);
		}else{
			print_rank(rank1000);
		}
	}
	return 0;
}

Measured memory_bytes: 0
// 2017/07/18 Tazoe

#include <iostream>
#include <algorithm>
using namespace std;

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

	int p[5000];
	for(int i=0; i<N; i++){
		cin >> p[i];
	}

	int min_sum = 20000;

	for(int I=0; I<=p[0]; I++){
		int q[5000];
		for(int i=0; i<N; i++){
			q[i] = p[i];
		}

		int sum = I;
		q[0] -= I;

		for(int i=0; i<=N-2; i++){
			if(q[i]<=0)
				continue;

			sum += q[i]*2;
			q[i+1] -= q[i];
		}

		if(q[N-1]>0){
			sum += q[N-1];
		}

		min_sum = min(min_sum, sum);
	}

	cout << min_sum << endl;

	return 0;
}

Measured memory_bytes: 3120
import java.io.InputStream;
import java.io.PrintStream;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int n = sc.nextInt();
		int m = sc.nextInt();

		int[][] x = new int[n][2];

		for (int i = 0; i < n; i++) {
			x[i][0] = sc.nextInt();
			x[i][1] = sc.nextInt();
		}

		Arrays.sort(x, new Comparator<int[]>() {
			@Override
			public int compare(int[] o1, int[] o2) {
				return Integer.compare(o1[0], o2[0]);
			}

		});

		BigDecimal ans = new BigDecimal(0);
		int y = 0;

		for (int i = 0; y < m; i++) {
			BigDecimal a = new BigDecimal(x[i][0]);

			// a * min(x[i][1], m-y)
			a = a.multiply(new BigDecimal(Math.min(x[i][1], m - y)));
			ans = ans.add(a);

			y += x[i][1];

		}
		out.println(ans);

		sc.close();

	}

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

}


Measured memory_bytes: 94312
// 

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <stack>

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

using namespace std;

int main(){
  map<string, bool> m;
  int n;
  cin >> n;
  string s, ns;
  cin >> s;
  m[s] = true;
  for(int i = 0; i < n - 1; i++){
    cin >> ns;
    if(m.find(ns) == m.end() && s[s.length() - 1] == ns[0]){
      m[ns] = true;
      s = ns;
      continue;
    }else{
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
// Why am I so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

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

#define fi first
#define se second

using namespace std;

typedef long long ll;

const int MAXN = (int)1e5 + 5;

vector<int> adj[MAXN];

int dp[MAXN];

int n;

bool cmp(int a, int b) {
	return dp[a] > dp[b];
}

void dfs(int v) {
	for (int to : adj[v]) {
		dfs(to);
	}

	sort(all(adj[v]), cmp);
	dp[v] = adj[v].size();
                   
    for (int i = 0, to; i < adj[v].size(); ++i) {
    	to = adj[v][i];
    	dp[v] = max(dp[v], dp[to] + i + 1);
    }
}

void solve() {                   
	scanf("%d", &n);

    for (int i = 2, x; i <= n; ++i) {
    	scanf("%d", &x);
    	adj[x].pb(i);
    }

    dfs(1);
	printf("%d\n", dp[1]);
}

int main() {    
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 10752
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	// ?????????????????°???????????????????????°?????£?¨???????
	// ????????\????????????????????????????????????????????????????????¨
	void doIt( ) {
		Scanner sc = new Scanner(System.in);
		int race = 3,ninzu = 8;
		Person[][] playersArray =  new Person [race][ninzu];
		//??????????????\???
		for(int i = 0;i < race;i++){
			for(int k = 0;k < ninzu;k++){
				playersArray[i][k] = new Person(sc.nextInt(),sc.next());
			}
		}
		//System.out.println(Arrays.toString(playersArray[0]));
		//?????????????????????
		for(int i = 0;i < 3;i++)Arrays.sort(playersArray[i]);
		//System.out.println(Arrays.toString(playersArray[0]));

		//?????¬??????1???2????????????
		for(int i = 0;i < race;i++){
			for(int k = 0;k < 2;k++){
				System.out.println(playersArray[i][k]);
			}
		}
		//3?????\????????????
		Person[] ThreeArray =  new Person [3*2];
		for(int i = 0;i < race;i++){
			for(int k = 2;k < 4;k++){
				ThreeArray[i*2+k-2] = playersArray[i][k];
			}
		}
		//System.out.println(Arrays.toString(ThreeArray));
		Arrays.sort(ThreeArray);
		//3?????\????????????
		for(int i = 0;i < 2;i++)System.out.println(ThreeArray[i]);

	}
	public static void main(String [ ] args) {
		new Main( ) . doIt( );
	}
	class Person implements Comparable<Person>{
		int num;
		String time;
		Person(int num, String time) {
			this.num = num;
			this.time = time;
		}
		@Override
		public String toString() {
			return num + " " + time;
		}
		@Override
		public int compareTo(Person p) {
			return time.compareTo(p.time);
		}
	}
}

Measured memory_bytes: 26064
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		long N = long.Parse(str[0]);
		long M = long.Parse(str[1]);
		long A = long.Parse(str[2]);
		long ans = N+M+A;
		if(ans>=22){
			Console.WriteLine("bust");
		} else {
			Console.WriteLine("win");
		}
	}
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin>>S;
    int m=1000;
    int keta=S.size();
    for(int i=0;i<keta-2;i++){
        int a=(S[i]-'0')*100+(S[i+1]-'0')*10+(S[i+2]-'0');
        if(abs(a-753)<m){m=abs(a-753);}
    }
    cout<<m<<endl;
}

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

using namespace std;
#define int long long

signed main() {
    //ios::sync_with_stdio(0);
    //cin.tie(0);
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<int> r(a);
    for(auto& el : r){
        cin >> el;
    }
    sort(begin(r), end(r), [](int a, int b){ return a > b;});
    vector<int> g(b);
    for(auto& el : g){
        cin >> el;
    }
    sort(begin(g), end(g), [](int a, int b){ return a > b;});
    vector<int> v(x+y+c);
    for(int i = 0; i < c; ++i){
        cin >> v[i];
    }
    for(int i = c; i < c+x; ++i){
        v[i] = r[i-c];
    }
    for(int i = c+x; i < c+x+y; ++i){
        v[i] = g[i-c-x];
    }
    sort(begin(v), end(v),[](int a, int b){ return a > b;});
    int res = 0;
    for(int i = 0; i < x+y; ++i){
        res += v[i];
    }
    cout << res << endl;
}

Measured memory_bytes: 3968
#include <iostream>

int main()
{
	int n;
	std::cin >> n;
	int min = 1e9;
	int max = -1e9;
	for(int i = 0; i < n; i++){
		int a;
		std::cin >> a;
		if(a < min) min = a;
		if(a > max) max = a;
	}
	std::cout << (max - min) << std::endl;
	return 0;
}


Measured memory_bytes: 256
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

//macro
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define EPS (1e-8)
#define equals(a,b)(fabs((a)-(b))<EPS)

using ll = long long;
using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vvll = vector<vll>;
//func
template<typename A, typename T>void assign2d(A&arr, ll H, ll W, T t) { arr.resize(H); REP(i, H) arr[i].assign(W, t); }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); REP(i, n)os << v[i] << (i == n - 1 ? "" : " "); return os; }
template <class T = int> inline T IN() { T x; cin >> x; return x; }
template<class T> inline void OUT(const T &x) { cout << x << "\n"; }
void YESNO(bool c) { OUT(c ? "YES" : "NO"); };
void YesNo(bool c) { OUT(c ? "Yes" : "No"); };
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); /*cout << fixed << setprecision(6);*/ } } pre__;

int main() {
	int X, T;
	cin >> X >> T;
	int ans = X - T;
	if (ans < 0)ans = 0;
	OUT(ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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; }

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};


signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    int X,N; cin >> X >> N;
    VI P(N);
    int ex[110] = {};
    REP(i,N){
        cin >> P[i];
        ex[P[i]]++;
    }
    int ans = -1;
    int cost = 1000;
    REP(i,110){
        if(ex[i]) continue;
        if(cost > abs(X-i)){
            cost = abs(X-i);
            ans = i;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 3628