akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>

int main(){

	int num, limit;

	while(std::cin >> num >> limit){

		if(num == 0 && limit == 0) break;

		std::vector<int> price;
		int sum_price = 0;
		//input
		for(int i = 0; i < num; ++i){
			int buf;
			std::cin >> buf;
			sum_price += buf;
			price.push_back(buf);
		}
		//sort
		std::sort(price.begin(),price.end(),std::greater<int>());
		//discount
		int discount = 0;
		int in_bag = 0;
		
		for(auto itr = price.begin(); itr != price.end(); ++itr){
			++in_bag;
			if(in_bag == limit){
				discount += *itr;
				in_bag = 0;
			}
		}

		std::cout << sum_price - discount << std::endl;
	}
	return 0;
}
	

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

using namespace std;
int main()
{
     long long a,b,c,d;
     cin >> a>> b >> c >>d;
    long long temp =   (c*d)/__gcd(c,d) ;

    long long div1 = ((a-1)/c) +((a-1)/d)-((a-1)/temp);
    long long div2 =(b/c) +(b/d)-(b/temp);
//    cout << b/c << " " << b/d << " " << b/temp << endl;
   long long rs = (b-a+1)-(div2-div1);
   cout << rs << endl;





}


Measured memory_bytes: 256
def solve():
    S = input()
    N = len(S)
    part1 = S[:(N-1)//2]
    part2 = S[(N+3)//2-1:]

    if isKaibun(part1) and isKaibun(part2) and isKaibun(S):
        print('Yes')
    else:
        print('No')

def isKaibun(S):
    for i in range(len(S)//2):
        if S[i] != S[-i-1]:
            return False
    return True

if __name__ == '__main__':
    solve()

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

int main(){

    int n,b,f,r,v;
    int buildings[4][3][10];
    cin >> n;

    for(int i=0;i<4;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<10;k++){
                buildings[i][j][k] = 0;
            }
        }
    }

    for(int i=0;i<n;i++){
        cin >> b >> f >> r >> v;
        buildings[b-1][f-1][r-1] += v;
    }

    for(int i=0;i<4;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<10;k++){
                if(k==0)cout << " ";
                cout << buildings[i][j][k];
                if(k!=9)cout << " ";
            }
            cout << endl;
        }
        if(i!=3)cout << "####################" << endl;
    }

}


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

public class Main{
    
    public static void main(String[] arg){
        Scanner scan =new Scanner(System.in);
        int n=scan.nextInt();

        ArrayList<Integer> W = new ArrayList<Integer>();

        for(int i=0;i<n;i++){
            W.add(scan.nextInt());
        }

        int sum=0;
        for(Integer temp:W){
            sum+=temp;
        }

        int sumk=0;
        int min=Math.abs(sum-2*W.get(0));
        int diffk;

        for(int j=0;j<n-1;j++){
            
            sumk=0;
            for(int k=0;k<=j;k++){
                sumk+=W.get(k);
            }

            diffk=Math.abs(sum-2*sumk);

            if( diffk < min) min=diffk;

        }
        System.out.print(min);
        
  



    }
}

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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second

ll mod = 2019 , dp[3][2022];

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

    string s;
    cin >> s;
    ll n = s.size();
    s = ' '+s;

    ll tn = 1 , num=0 , cur , ans=0;
    map<ll,ll> mp;
    for(int i=n; i>0; i--)
    {
        cur = (tn*(s[i]-'0') + num)%mod;
        ans += mp[cur];
        num = cur;
        if (num==0) ans++;

        mp[num]++;
        tn *= 10;
        tn %= mod;
    }
    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 3672
N, M = map(int, input().split())
E = [[] for _ in range(N)]
for _ in range(M):
  a, b = map(int, input().split())
  E[a - 1].append(b - 1)
  E[b - 1].append(a - 1)
V = [0] * N
V[0] = 1
P1 = []
P2 = []
s = 0
def pathfind(s):
  P = []
  for _ in range(N):
    P.append(str(s + 1))
    for t in E[s]:
      if V[t]:
        continue
      s = t
      V[t] = 1
      break
    else:
      break
  return P
P1 = pathfind(0)
P2 = pathfind(0)
P = P1[len(P1):0:-1] + P2
print(len(P))
print(' '.join(P))

Measured memory_bytes: 31304
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int a[] = new int[26];
        for (int i = 0; i < s.length(); i++) {
            a[s.charAt(i) - 'a'] += 1;
        }
        for (int i = 0; i < 26; i++) {
            if (a[i] == 0) {
                System.out.println((char)(i + 'a'));
                System.exit(0);
            }
        }
        System.out.println("None");
    }
}


Measured memory_bytes: 25044
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;


int main(){
    int A[3];
    for(int i=0;i<3;++i){
        cin >> A[i];
    }
    int sum=0;
    for(int i=0;i<3;++i){
        sum+=A[i];
    }
    if(sum<=21){
        cout << "win";
    }
    else{
        cout << "bust";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>        ////べき乗を使うのに必要
using namespace std;

//int S の桁数を求める関数 dig
int dig(long long S) {
  int ans = 0;
  while (true) {
    S /= 10;
    ans++;
    if (S==0) 
      break;
  }
  return ans;  
}

//0スタートのフィボナッチ数列
long long num(int x) {
  if (x==0)
    return 1;
    
  int ans = 1;
  for (int i=0; i<x; i++) {
    ans += num(i);
  }
  return ans; 
}

long long sum_n(long long S, int n) {
  if (n==0)
    return S/pow(10,dig(S)-1);
  
  long long sum = 0;
  for (int i=1; i<n+1; i++) {
    long long a = pow(10,dig(S)-n-1);
    long long b = S/a;
    long long c = pow(10,n-i+1);
    sum += num(i-1)*(b%c);
  }
  long long sumsum = 0;
  for (int i=0; i<n; i++) {
    sumsum += sum_n(S,i);
  }
  return sum + sumsum + S/pow(10,dig(S)-n-1);
}

int main() {
  long long S;
  cin >> S;
  
  cout << sum_n(S,dig(S)-1) << endl;
}

Measured memory_bytes: 256
n,w=map(int,input().split())
value=[]
wt=[]
for i in range(n):
    a,b=map(int,input().split())
    wt.append(a)
    value.append(b)
dp=[[0 for i in range(sum(value)+1)] for j in range(n+1)]
for i in range(sum(value)+1):
    dp[0][i]=1000000000000
for j in range(n+1):
    dp[j][0]=0
for i in range(1,n+1):
    for j in range(1,sum(value)+1):
        if value[i-1]<=j:
            dp[i][j]=min(wt[i-1]+dp[i-1][j-value[i-1]],dp[i-1][j])
        else:
            dp[i][j]=dp[i-1][j]
for i in range(sum(value),-1,-1):
    if dp[-1][i]<=w:
        print(i)
        break


Measured memory_bytes: 167856
#include<bits/stdc++.h>
 
using namespace std;
 
#define ull unsigned long long
#define LL long long int
#define pii pair<int,int>
#define mp make_pair
#define pb(x) push_back(x)
#define F(i,a,n) for(int i=(a);i<(n);++i)
#define FD(i,a,n) for(int i=(a);i>=(n);--i)
#define FE(it,x) for(it=x.begin();it!=x.end();++it)
#define V(x) vector<x>
#define S(x) scanf("%d",&x)
#define Sl(x) scanf("%llu",&x)
#define M(x,i) memset(x,i,sizeof(x))
#define fr first
#define se second
#define MOD 1000000007

int main() {
	long long a,b;
	cin >> a >> b;
	int ans = 0;
	while(a <= b){
		ans++;
		a = a + a;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>

using namespace std;

int main() {
    int x0, y0, x1, y1, x2, y2;
    cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2;
    x1 -= x0; x2 -= x0;
    y1 -= y0; y2 -= y0;
    int si = abs(x1*y2 - x2*y1),
        ai = x1*x1 + y1*y1,
        bi = x2*x2 + y2*y2,
        ci = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1);
    double h = sqrt((double)si*si / max({ai, bi, ci})),
           s = si,
           a = sqrt(ai),
           b = sqrt(bi),
           c = sqrt(ci);
    cout << setprecision(15) << s / (a + b + c + 2*h) << '\n';
    return 0;
}

Measured memory_bytes: 256
import collections
import heapq
def main():

    N, M = map(int, input().split())
    S = input()
    h = []
    w = []
    heapq.heappush(h, [0, N])
    heapq.heappush(w, [0, N])
    for i in range(N-1, -1, -1):
        if S[i] == '0':
            while h:
                n, p = heapq.heappop(h)
                if p-i <= M:
                    heapq.heappush(h, [n+1, i])
                    heapq.heappush(w, [n+1, i])
                    heapq.heappush(h, [n, p])
                    break
            if len(h) == 0: return -1
        # print(h)

    ans = []
    n, p = heapq.heappop(w)
    # print(h)
    while w:
        m, q = heapq.heappop(w)
        if m == n + 1:
            ans.append(p-q)
            n = m
            p = q
    return " ".join(map(str, ans[::-1]))

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

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

C = []
for i in range(len(A)):
    C.append(B[i] - A[i])

if sum(C) > 0:
    print(-1)

else:
    ans = 0
    dif = 0
    for i in C:
        if i > 0:
            ans += 1
            dif += i

    for i in sorted(C):
        if dif <= 0:
            break

        ans += 1
        dif += i

    print(ans)

Measured memory_bytes: 18396
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
 
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define gap cout<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(int i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
ll n,k;
const int mod=1000000007;
int main(){
    
    cin>>n>>k;
    
  ll pre[100008];
   ll pre2[100008];
   ll arr[100008];
    FOR(i,1,n){
        cin>>arr[i];
    }
   
    //cout<<"SDefes"<<endl;
    fo(i,100008) {pre[i]=0; pre2[i]=0;}
    ll counter=min(k,arr[1]);
    FOR(i,0,counter){
        pre[i]=1;
        //dbg(pre[i]);
    }
    //dbg(pre[10]);
    //cout<<"SDefes"<<endl;
    pre2[0]=pre[0];
  
    FOR(i,1,k){
        pre2[i]=(pre2[i-1]+pre[i])%mod;
    }
    ll big;
    FOR(i,2,n){
        
        counter=counter+arr[i];
        counter=min(counter,k);
        //dbg2(i,counter);
 
        FOR(j,0,counter){
            big=j-arr[i];
            //dbg(big);
            if(big>0){big--; pre[j]=(pre2[j]-pre2[big]+mod)%mod; }
            else pre[j]=pre2[j];
            //dbg2(j,pre[j]);
        }
        FOR(nn,counter+1,k) pre[nn]=0;
        pre2[0]=pre[0];
        FOR(ii,1,k){
 
         pre2[ii]=(pre2[ii-1]+pre[ii])%mod;
        }
 
 
    }
    cout<<pre[k]<<endl;
 
 
 
 
 
 
}

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

int main(void) {
    int N, M;
    std::cin >> N >> M;
    vector< int > s(M), c(M);
    for (int i = 0; i < M; i++) {
        cin >> s[i] >> c[i];
    }
    char n[3];
    for (int i = 0; i < 3; i++) {
        n[i] = 0;
    }
    for (int i = 0; i < M; i++) {
        if (s[i] > N) {
            printf("-1\n");
            return 0;
        } else if (n[s[i] - 1] != 0 && n[s[i] - 1] != c[i] + '0') {
            printf("-1\n");
            return 0;
        }
        n[s[i] - 1] = c[i] + '0';
    }
    for (int i = 0; i < N; i++) {
        if (n[i] == 0) {
            if (N > 1 && i == 0) {
                n[i] = '1';
            } else {
                n[i] = '0';
            }
        }
    }
    if (n[0] == '0' && N > 1) {
        printf("-1\n");
        return 0;
    }
    for (int i = 0; i < N; i++) {
        printf("%c", n[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <climits>
#include <tuple>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int,int> T;




int bit[100003],n;
int sum(int i){
    int s=-1;
    while(i>0){
        s=max(bit[i],s);
        i-=i&-i;
    }
    return s;
}
void add(int i,int x){
    while(i<=n){
        bit[i]=max(bit[i],x);
        i+=i&-i;
    }
}
int main(){
    int n;
    cin>>n;
    int res=0;
    for(int i=0;i<n;i++){
        int tmp;
        cin>>tmp;
        while(tmp%2==0){
            res++;
            tmp/=2;
        }}
    cout<<res<<endl;
        
}


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

using namespace std;

int main( ) {
    ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t,n;
	t = 1;
	while(t--) {
	 cin >> n;
	 if(n < 1200)
	  cout << "ABC" << endl;
	 else
	  cout << "ARC" << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(void){
int n,i,sum;
while(1){
scanf("%d",&n);
if(!n)
break;
sum=0;
for(i=1;i*i<=n;i++){
if(n%i==0){
sum+=i;
sum+=n/i;
}
if(i*i==n)
sum-=i;
}
sum-=n;
if(n==sum)
puts("perfect number");
else if(n>sum)
puts("deficient number");
else
puts("abundant number");
}
return 0;
}

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

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

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

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  string s;
  int w;
  cin >> s >> w;

  int cur = 0;
  while (cur < s.size()) {
    cout << s[cur];
    cur += w;
  }
  cout << endl;

  return 0;
}


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


int main(){
    int n;
    int ma=0;
    map<string,int> mp;
    cin >> n;
    rep(i,n){
        string s;
        cin >> s;
        mp[s]++;
    }
    for (auto &p:mp){
        ma=max(ma,p.second);
    }
    vector<string> a;
    for(auto &p:mp){
        if(p.second==ma){
            a.emplace_back(p.first);
        }
    }
    sort(a.begin(),a.end());
    
    for (auto &q:a){
        cout << q << endl;
    }

    


    return 0;
}

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

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

    vector<long long int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    if(a[n-1] >= a[0] + 2){
        cout << "No" << endl;
        return 0;
    }

    int unique = upper_bound(a.begin(),a.end(),a[0]) - a.begin();
    if((n - unique == 0 && a[0] != n-1 && a[0] > (n-1+1)/2)
    ||  n - unique == 1// by definition of "unique"
    || (n - unique >= 2 && a[0] + 1 > unique + (n - unique) / 2)
    || (n - unique >= 2 && a[0]     < (unique - 1) + 1)){
        cout << "No" << endl;
        return 0;
    }

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

Measured memory_bytes: 4064
import kotlin.math.max

//

fun main() {
    abc124d()
}

fun abc124d() {
    val (n, k) = readLine()!!.split(" ").map { it.toInt() }
    val s = readLine()!!
    val table = List(2) { IntArray(n + 1) { 0 } }
    val startZero = s[0] == '0'
    var z = 0
    var o = 0
    var performZero = startZero
    for (c in s) {
        if (c == '0') {
            if (!performZero) {
                // 連続する1が途切れたので1のindexをすすめる
                performZero = true
                o++
            }
            table[0][z]++
        } else {
            if (performZero) {
                // 連続する0が途切れたので、ゼロのindexをすすめる
                performZero = false
                z++
            }
            table[1][o]++
        }
    }
    var count = 0
    for (i in 0 until k) {
        count += table[0][i] + table[1][i]
        if (table[0][i] == 0 && table[1][i] == 0) break
    }
    if (!startZero) {
        count += table[1][k]
    }
    var maxCount = count
    for (i in k until n - k) {
        if (table[0][i] == 0 && table[1][i] == 0) break
        count -= table[0][i - k]
        count -= if (startZero) {
            if (i - k - 1 >= 0) table[1][i - k - 1] else 0
        } else {
            table[1][i - k]
        }
        count += table[0][i]
        count += if (startZero) table[1][i] else table[1][i + 1]
        maxCount = max(count, maxCount)
    }
    println(maxCount)
}

Measured memory_bytes: 40640
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

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

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int n;
    cin >> n;

    vs32 a(n);
    rep (i, n) cin >> a[i];

    s64 ans = 0;
    s64 sum = 0, sumx = 0;
    int r = 0;
    rep (l, n)
    {
        while (r < n && (sum + a[r]) == (sumx ^ a[r]))
        {
            sum += a[r];
            sumx ^= a[r];
            ++r;
        }

        ans += r - l;
        sum -= a[l];
        sumx ^= a[l];
    }

    cout << ans << "\n";
    return 0;
}



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

int main() {
    string w;
    cin >> w;
    int f[27] = {};
    REP(i,w.length()){
        f[w[i]-'a']++;
    }
    REP(i,27){
        if(f[i]%2==1){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


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

using namespace std;
#define int long long


signed main(){
	int n,a,b;
	cin>>n>>a>>b;
	int ans=0;
	
	if(abs(b-a)%2==0){
		ans=abs(b-a)/2;
	}else{
		ans=min(a-1,n-b)+(abs(b-a)+1)/2;
	}
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;(i)--)
#define rrep1(i,n) for(int i=((int)(n));i>0;(i)--)
#define sz(c) ((int)(c).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int> > PP;
const int MAX=1e5+10;
const ll INF=1e18;

int N;
ll a[405];
ll sum[405];
void input(){
    cin>>N;
    rep(i,N) cin>>a[i];
    rep1(i,N)sum[i]=sum[i-1]+a[i-1];
}

ll dp[405][405];
ll dfs(int l, int r){
    if(dp[l][r]!=INF)return dp[l][r];
    if(l==r){
        dp[l][r]=0;
        return 0;
    }
  	if(r==l+1){
      	dp[l][r]=0;
      	return 0;
    }
    ll tmp=INF;
    for(int i=l+1; i<r; i++){
        tmp=min(tmp, dfs(l,i)+dfs(i,r));
    }
    tmp+=sum[r]-sum[l];
    dp[l][r]=tmp;
    return tmp;
}  

ll ans;
void solve(){
    rep(i,N+1)rep(j,N+1)dp[i][j]=INF;
    ans=dfs(0,N);
}

void output(){
    cout<<ans;
}

int main(){
    input();
    solve();
    output();
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    ll s;
    cin >> s;
    ll base = 1000000000;
    ll a = base;
    ll c = (s+base-1)/base;
    ll b = ((s%base)==0) ? 0 : base-s%base;
    ll d = 1;
    

    cout << "0 0 ";
    cout << a << " " << d << " " << b << " " << c << endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<cmath>
using namespace std;
int main(void){
    int k,t;
    cin >> k>>t;
    int ans=0;
    int bef;
    int usually=0;
    vector<int> kind;
    for(int i=0;i<t;i++){
        cin >> bef;
        kind.push_back(bef);

    }
    sort(kind.begin(),kind.end(),greater<int>());
    usually=max(kind.at(0)-1-(k-kind.at(0)),0);
    cout << usually << endl;

    
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;

template<class monoid>
struct LazySegmentTree
{
  using F=function<monoid(monoid,monoid)>;
private:
    int n;
    vector<ll> node, lazy;
    F f;
    monoid m1;


public:
    LazySegmentTree(int sz,F fun,monoid m1):f(fun),m1(m1)
    {
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1,m1);
        lazy.resize(2*n-1, 0);
    }
    void eval(int k, int l, int r)
    {
      if(lazy[k] != 0)
      {
        node[k] += lazy[k];//ここ
        if(r - l > 1)
        {
          lazy[2*k+1] += lazy[k];//ここ
          lazy[2*k+2] += lazy[k];//ここ
        }
        lazy[k] = 0;
      }
    }

    void add(int a, int b, monoid x, int k=0, int l=0, int r=-1)
    {
      if(r < 0) r = n;
      eval(k, l, r);
      if(b <= l || r <= a) return;
      if(a <= l && r <= b)
      {
          lazy[k] += x;//ここ
          eval(k, l, r);
      }
      else
      {
          add(a, b, x, 2*k+1, l, (l+r)/2);
          add(a, b, x, 2*k+2, (l+r)/2, r);
          node[k] = f(node[2*k+1],node[2*k+2]);
      }
    }

    monoid query(int a, int b, int k=0, int l=0, int r=-1)
    {
      if(r < 0) r = n;
      if(b <= l || r <= a) return 0;
      eval(k, l, r);
      if(a <= l && r <= b) return node[k];
      monoid vl = query(a, b, 2*k+1, l, (l+r)/2);
      monoid vr = query(a, b, 2*k+2, (l+r)/2, r);
      return f(vl,vr);
    }
};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m;
  cin>>n>>m;
  vector<vector<pair<int,int>>>sec(n+1);
  rep(i,m)
  {
    ll l,r,a;
    cin>>l>>r>>a;
    sec[r].push_back({l,a});
  }
  LazySegmentTree<ll> st(n+1,[](ll a,ll b){return max(a,b);},0);
  repi(i,1,n+1)
  {
    auto no=st.query(i,i+1);
    auto ne=-no;
    ne+=st.query(0,i);
    st.add(i,i+1,ne);
    for(auto p:sec[i])
    {
      st.add(p.first,i+1,p.second);
    }
  }
  ll res=st.query(0,n+1);
  chmax(res,0LL);
  cout<<res<<endl;


  return 0;

}


Measured memory_bytes: 19456
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define loop(i, r, n) for (int i = (r); i < (n); i++)
#define pb push_back
#define all(in) in.begin(),in.end()

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

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

const ll INF = 1ll<<60;

int main(){
    ll n, m; cin >> n >> m;
    vector<vector<ll>> dp(m+1,vector<ll>(1ll<<n,INF)); dp[0][0] = 0;
    rep(i,m){
        ll a, b; cin >> a >> b;
        ll count = 0;
        rep(i,b){
            ll c; cin >> c; c--;
            count |= 1<<c;
        }
        rep(j,1ll<<n){
            chmin(dp[i+1][j],dp[i][j]);
            chmin(dp[i+1][j|count],dp[i][j]+a);
        }
    }
    if(dp[m][(1ll<<n)-1] == INF) cout << -1 << endl;
    else cout << dp[m][(1ll<<n)-1] << endl;
    return 0;
}

Measured memory_bytes: 35380
#include<vector>
#include <iostream>
#include<string>
#include <complex>
#include <algorithm>
#include<string>

using namespace std;

int main(){
    int a[3];

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

    sort(a, a + 3);

    cout << a[2] * 10 + a[1] + a[0] << endl;
}

Measured memory_bytes: 3596
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

n,x=map(int, input().split())
p_list=list(map(int, input().split()))
p_list.append(x)
p_list=sorted(p_list)

df_list=[]
for j in range(len(p_list)-1):
  df_list.append(p_list[j+1]-p_list[j])

if n==1:
  print(df_list[0])
else:
  print(gcd_list(df_list))

Measured memory_bytes: 16280
import numpy as np
N = int(input())
A_str = input()
A_str_list = A_str.split()
A = np.array([int(A_str_list[i]) for i in range(N)])
sum = 0
mod = 1000000007
res = np.cumsum(A)
res = [np.mod((res[-1]-res[i]), mod) for i in range(N)]
# print(res)
for i in range(N):
    sum += np.mod(res[i]*A[i], mod)
print(np.mod(sum, mod))

Measured memory_bytes: 55244
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < N; i++)
int main(void){
 int n;
 cin >> n;
 vector<int> a(n+5);
 vector<int> b(n+5);
 vector<int> c(n+4);
  rep(i,n){
    cin >> a.at(i);
  }
  rep(i,n){
    cin >> b.at(i);
  }
  rep(i,n-1){
    cin >> c.at(i);
  }
  int x = 0;
  rep(i,n){
    int y = a.at(i);
    x += b.at(y-1);

    if(a.at(i+1) - a.at(i) == 1){
    x += c.at(y - 1);
    }
  }
  cout << x << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()


using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;



int main(){
    int n;
    cin >> n;
    map<int, int> mp;
    rep(i, n){
        int a;
        cin >> a;
        mp[a]++;
    }
    vector<int> v;
    int res = 0, cnt = 0;
    for(auto m : mp){
        if(m.second % 2 == 1){
            res++;
        }
        else {
            cnt++;
        }
    }
    if(cnt % 2 == 0)res += cnt;
    else res += cnt / 2 * 2;
    cout << res << endl;
}



Measured memory_bytes: 4992
#include "iostream"
#include "algorithm"
using namespace std;

int main()
{
	int a[3];
	for (int i = 0; i < 3; i++)
	{
		cin >> a[i];
	}
	sort(a, a + 3);
	for (int i = 0; i < 3; i++)
	{
		cout << a[i];
		if (i != 2)
		{
			cout << " ";
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3144
# frozen_string_literal: true
require 'thread'

n, Q = gets.split.map(&:to_i)
ab = (n - 1).times.map { gets.split.map { |e| e.to_i - 1 } }.sort_by { |e| e[0] }
px = Q.times.map { gets.split.map(&:to_i) }

s = Array.new(n) { 0 }

px.each do |e|
  p = e[0]
  x = e[1]
  s[p - 1] += x
end

d = Array.new(n) { false }
h = Hash.new { [] }
ab.each do |e|
  a = e[0]
  b = e[1]
  unless h[a].empty?
    h[a].push b
  else
    h[a] = [b]
  end
  unless h[b].empty?
    h[b].push a
  else
    h[b] = [a]
  end
end

q = Queue.new

q.push 0

loop do
  break if q.empty?

  a = q.pop
  d[a] = true
  h[a].each do |b|
    next if d[b]

    s[b] += s[a]
    q.push b
  end
end

puts s.join(' ')


Measured memory_bytes: 66468
#include <bits/stdc++.h>
using namespace std;
int main() {
        int n, s[111];
        cin >> n;
        for(int i = 1; i <= n; ++i)
                cin >> s[i];
        s[n+1] = 0;
        sort(s+1, s+2+n);
        int ans = 0;
        for(int i = 1; i <= n+1; ++i) ans += s[i];
        for(int i = 1; i <= n+1; ++i)
                if ((ans - s[i])%10 != 0) {
                        cout << ans-s[i] << endl;
                        return 0;
                }
        cout << 0 << endl;
}

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

int main() {
int r;
cin>>r;
for(int j=0;j<r;j++){
int x0,y0;
cin>>x0>>y0;
int a[x0+1][y0+1];
for(int q=0;q<x0+1;q++){
	for(int w=0;w<y0+1;w++){
		a[q][w]=0;
	}
}


a[0][0]=1;
int nn;
cin>>nn;
int yoko[x0][y0+1];
int tate[x0+1][y0];

for(int q=0;q<x0;q++){
	for(int w=0;w<y0+1;w++){
		yoko[q][w]=0;
	}
}
for(int q=0;q<x0+1;q++){
	for(int w=0;w<y0;w++){
		tate[q][w]=0;
	}
}




for(int kk=0;kk<nn;kk++){
int x1,x2,y1,y2;
	cin>>x1>>y1>>x2>>y2;
	if(x1==x2){
		if(y1>y2){
			y2=y2+1;
			y1=y1-1;
		}
		tate[x1][y1]=1;
	}
	if(y1==y2){
		if(x1>x2){
			x2=x2+1;
			x1=x1-1;
		}
		yoko[x1][y1]=1;
	}
}
	for(int l=1;l<=x0;l++){
		if(yoko[l-1][0]==1){
			a[l][0]=0;
		}
		else{
			a[l][0]=a[l-1][0];
		}
	}
	for(int l=1;l<=y0;l++){
		if(tate[0][l-1]==1){
			a[0][l]=0;
		}
		else{
			a[0][l]=a[0][l-1];
		}
	}

	
	for(int xx=1;xx<=x0;xx++){
		for(int yy=1;yy<=y0;yy++){
			if(yoko[xx-1][yy]!=1){
				a[xx][yy]=a[xx][yy]+a[xx-1][yy];
			}
			
			
			if(tate[xx][yy-1]!=1){
				a[xx][yy]=a[xx][yy]+a[xx][yy-1];
			}
		}
	}

if(a[x0][y0]!=0){
cout<<a[x0][y0]<<endl;
}
else{
	cout<<"Miserable Hokusai!"<<endl;
}
}
	return 0;
}

Measured memory_bytes: 1164
integer N,M
integer,allocatable,dimension(:,:)::A
logical,allocatable,dimension(:)::SPORTS
integer,allocatable,dimension(:)::CONTESTANTS
integer ans,preans
read*,N,M
allocate(A(N,M))
do i=1,N
  read*,A(i,:)
end do

allocate(SPORTS(M),CONTESTANTS(M))
SPORTS=.TRUE.

ans=huge(ans)

do i=1,M
  CONTESTANTS=0
  do j=1,N
    do k=1,M
      if(SPORTS(A(j,k)))then
        CONTESTANTS(A(j,k))=CONTESTANTS(A(j,k))+1
        exit
      endif
    end do
  end do
  preans=maxval(CONTESTANTS)
  do j=1,M
    if(CONTESTANTS(j)==preans)then
      SPORTS(j)=.FALSE.
      exit
    endif
  end do
  ans=min(ans,preans)
end do

print"(I0)",ans

end

Measured memory_bytes: 512
import fractions
n = int(input())
a = list(map(int,input().split()))
gcd_a = fractions.gcd(a[0],a[1])
for i in range(2,n):
  gcd_a = fractions.gcd(gcd_a,a[i])
  if gcd_a == 1:
    break
print(gcd_a)

Measured memory_bytes: 88300
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const ll INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
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(a>b){a=b;return 1;}return 0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

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



Measured memory_bytes: 764
/*package whatever //do not write package name here */

import java.io.*;
import java.util.*;
class Main {
	public static void main (String[] args) {
		Scanner input = new Scanner(System.in);
		
		int n = input.nextInt();
		int m = input.nextInt();
		
		boolean flag = false;
		for(int i=1;i<=10000000;i++)
		{
		    if((int)Math.floor(0.08*i)==n&&(int)Math.floor(0.1*i)==m){
		        System.out.println(i);
		        flag = true;
		        break;
		    }
		    else
		        flag = false;
		}
		if(!flag)
		    System.out.println(-1);
		
	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <algorithm>
#include <ctime>
#include <limits>
#include <cmath>


using namespace std;

//  ||
// \

int main() {

	int a = 0, b = 0, c = 0, sum = 0, cnt = 0;
	cin >> a >> b >> c;
	for(int i = 0; i < c; i++) {
		if(a > b) {
			break;
		}	
		else {
			sum = sum + a;
			if(sum <= b) {
				cnt++;
			}
			else {
				break;
			}
		}
	}
	cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#
import sys
import math
import numpy as np
import itertools


# ひとつ入力
n = int(input())
# n行複数列の数をリストに
ab = [[int(i) for i in input().split()] for i in range(n)] 


#print(ab)

# ソート　キーは0
ab = sorted(ab, key=lambda x:x[1])
t=0
for i in range(n):
    t += ab[i][0]
    if ab[i][1]<t:
        print('No')
        exit()

print('Yes')



Measured memory_bytes: 51740
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
#include<bitset>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e16
using namespace std;
typedef pair<ll, ll> P;

ll bit[20];
ll p[20];
ll n, m;

ll dfs(ll level, ll mask) {
	if (level == n) {
		ll num = 0;
		
		for (ll i = 0;i < m;i++) {
			ll num = 0;
			for (ll j = 0;j < n;j++) {
				if ((bit[i]>>j)&1) {
					if ((mask>>j)&1) {
						num++;
					}
				}
			}
			if (num % 2 != p[i])return 0;
		}
		return 1;
	}
	else {
		return dfs(level + 1, mask + (1 << level)) + dfs(level + 1, mask);
	}
}


int main(void) {
	ll k, s;
	
	cin >> n >> m;

	for (int i = 0;i < m;i++) {
		cin >> k;
		for (int j = 0;j < k;j++) {
			cin >> s;
			bit[i] += 1 << (s - 1);
		}
	}
	for (int i = 0;i < m;i++)cin >> p[i];
	cout << (ll)dfs(0, 0) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T&a,T b){if(a>b){a=b;return 1;}return 0;}
using ll = long long;
using P = pair<int,int>;

int n,k,m;
//string s,t;
int s[100005],c[100005];

int main() {
  cin >> n >> m;
  rep(i,m) cin >> s[i] >> c[i], s[i]--;
  rep(i,1000){
    string t=to_string(i);
    if(t.size()!=n) continue;
    bool ok=true;
    rep(j,m)if(t[s[j]]!=c[j]+'0') ok=false;
    if(ok){
      cout << t << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int T = sc.nextInt();
    int A = sc.nextInt();
    int[] H = new int[N];
    double min = 100000L;
    int ansIndex = -1;
    for(int i = 0; i < N; i++){
      H[i] = sc.nextInt();
      double tmp = Math.abs(A - T + H[i] * 0.006);
      if(min > tmp){
        min = tmp;
        ansIndex = i;
      }
    }
    System.out.println(ansIndex + 1);
  }
}

Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  string w;
  cin >> w;
  int ans=0;
  if(w=="END_OF_TEXT") return 0;
  
  transform(w.begin(), w.end(), w.begin(), ::toupper);
  while(true){
    string s;
    cin >> s;
    if(s=="END_OF_TEXT") break;
    transform(s.begin(), s.end(), s.begin(), ::toupper);
    if(s==w) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3152
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


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


const int MAX_N = 100010;

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	VE a(n); rep(i, n)cin >> a[i];
	map<int, int>mp;
	rep(i, n)mp[a[i]]++;
	vector<int>ans;
	for (auto itr = mp.begin(); itr != mp.end(); itr++) {
		if (itr->second >= 4) {
			ans.push_back(itr->first);
			ans.push_back(itr->first);
		}
		else if (itr->second >= 2) {
			ans.push_back(itr->first);
		}
		else {
			
		}
	}
	if (ans.size() <= 1) {
		cout << 0 << endl; return 0;
	}
	sort(ALLR(ans));
	cout << ans[0] * ans[1] << endl;
	return 0;
}

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

#define ll long long
#define ull unsigned long long 
#define endl '\n'
#define pii pair<int, int>
#define all(a) a.begin(),a.end()

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

    int d = a[0], cnt=1;
    for(int i=1; i<n; ++i){
        if(a[i] <= d){
            cnt++;
            d=a[i];
        }
    }
    cout << cnt;
}

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

using namespace std;
typedef long long ll;
const ll INF = 1e10;
const ll MOD = 1e9 + 7;

int N;
vector<int> A;
vector<int> ans;

int main(){
    cin >> N;
    A.resize(N + 1);
    ans.resize(N + 1);
    for (int i = 1; i <= N; i++) { cin >> A[i]; ans[i] = -1; }

    // decide from N-1 to 0
    int count = 0;
    for (int j = N; j >= 1; j--) {
        if (j * 2 > N) {
            ans[j] = A[j] % 2 == 0 ? 0 : 1;
            if (ans[j] == 1)
                count++;
        } else {
            // cout << "not implemented for " << j << endl;
            int sum = 0;
            for (int f = 2; f <= INF; f++) {
                int k = j * f;
                if (k > N)
                    break;
                sum += ans[k];
            }
            if (sum % 2 == 0 && A[j] == 1) {
                ans[j] = 1;
                count++;
            } else if (sum % 2 == 1 && A[j] == 0) {
                ans[j] = 1;
                count++;
            } else {
                ans[j] = 0;
            }
            // cout << "  sum of values = " << sum << ", ans[j] = " << ans[j] << endl;
        }
    }

    cout << count << endl;
    for (int i = 1; i <= N; i++) {
        if (ans[i] == 1)
            cout << i << endl;
    }
    return 0;
}


Measured memory_bytes: 2432
import sys
n, D, a = map(int, input().split())
tg = []
for _ in range(n):
    x, h = map(int, sys.stdin.readline().split())
    c = h // a
    if h % a > 0:
        c+=1
    tg.append([x, c])

class BIT:
    def __init__(self, n):
        self.n = n
        self.N = 1 << n.bit_length()
        self.data = [0] * (self.N +1)

    def add(self, i, x):
        while i <= self.N:
            self.data[i] += x
            i += i & -i

    def sum(self, i):
        total = 0
        while i > 0:
            total += self.data[i]
            i -= i&-i
        return total

    def search(self, w):
        if w <= 0:
            return 0
        x = 0
        k = self.N >> 1
        while k > 0:
            if x+k <= self.N and self.data[x+k] < w:
                w -= self.data[x+k]
                x += k
            k = k >> 1
        return x+1

    def len(self):
        return self.data[self.N]

tg = sorted(tg, key=lambda x:x[0])
bit = BIT(n+2)
result = 0
ind = 0
for i in range(n):
    c = tg[i][1] - bit.sum(i+1)
    d = tg[i][0]
    if c <= 0:
        continue
    result += c
    wd = d + 2*D
    if ind < i:
        ind = i
    for j in range(ind, n):
        if tg[j][0] <= wd:
            ind = j
        else:
            break
    bit.add(i+1, c)
    bit.add(ind+2, -c)
print(result)

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

/***typededfs***/
typedef long long ll;
typedef long double ldb;

/***defines***/
#define M1 1000000007
#define M2 998244353
#define F first
#define S second
#define pb push_back
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define forz(i,n) for(int i=0;i<(n);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define rforz(i,n) for(int i=(n-1);i>=0;i--)
#define rfore(i,a,b) for(int i=(a);i>=(b);i--)
#define test int T; cin>>T; while(T--)

ll knapsaack(int n,int W,ll w[],ll v[]){
      ll dp[n+1][W+1]{};
      //fore(i,0,W){dp[1][i]=0;}
      dp[1][w[1]] = v[1];
      fore(i,2,n){
            fore(j,0,W){
                  dp[i][j] = dp[i-1][j];
                  if(j-w[i]>=0)
                  dp[i][j] = max(dp[i][j],v[i]+dp[i-1][j-w[i]]);
            }
      }
      
      return *max_element(dp[n],dp[n]+W+1);
}

int main(){ 
      FASTIO;
      int n,W;
      cin>>n>>W;
      ll w[n+1],v[n+1];
      fore(i,1,n){
            cin>>w[i]>>v[i];
      }
      cout<<knapsaack(n,W,w,v);
      //approach 1
      //dp(n,w) = max(dp(n-1,w) , v[n]+dp(n-1,w-w[n]))
      //dp(0,x) = 0
      //w>=0
      //dp(i,w) = sum of weigths is exaclty w
      //dp(i,w) = v[i] + dp(i-1,w-w[i]) , dp(i-1,w)
}


Measured memory_bytes: 82508
N = int(input())
A = [int(i) for i in input().split()]
 
absA = []
for i in range(N):
    absA.append(abs(A[i]))

cnt = 0
for i in range(N):
    if A[i] <= 0:
        cnt += 1
    
if cnt % 2 == 0:
    ans = sum(absA)
else:
    ans = sum(absA) - min(absA) * 2

print(ans)

Measured memory_bytes: 14412
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include <fstream>
using namespace std;
typedef long long ll;
const ll INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int mod = 1e9+7;
const int maxn = 200005;
ll T,n,m;
const int fact[10] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880};
int p[20];
int q[20];
int main() {
	int a[20];
	a[1] = 1;
	for(int i=2;i<9;i++)
		a[i] = a[i-1]*i;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>p[i];
	for(int i=0;i<n;i++)
		cin>>q[i];
	int cnt1=0,cnt2=0;
    for (int i = 0; i < n; ++i) {
        int cnt = 0; // 在 i 之后，比 i 还小的有几个
        for (int j = i + 1; j < n; ++j)
            if (p[i] > p[j]) ++cnt;
        cnt1 += cnt * fact[n - i - 1];
    }
	for (int i = 0; i < n; ++i) {
        int cnt = 0; // 在 i 之后，比 i 还小的有几个
        for (int j = i + 1; j < n; ++j)
            if (q[i] > q[j]) ++cnt;
        cnt2 += cnt * fact[n - i - 1];
    }
	cout<<abs(cnt1-cnt2)<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int h[1500001]={},w[1500001]={},n,m,i,j,p[1500],k;
int main(){
 while(1){
   cin>>n>>m;if(n==0)break;
   for(i=0;i<n;i++){
    cin>>p[i];
    for(j=i,k=0;j>=0;j--)k+=p[j],h[k]++;
   }
   n=k;
   for(i=0;i<m;i++){
     cin>>p[i];
     for(j=i,k=0;j>=0;j--)k+=p[j],w[k]++;
   }
   if(k<n)k=n;
   n=0;
   for(i=1;i<=k;i++)n+=h[i]*w[i],h[i]=w[i]=0;
   cout<<n<<endl;
  }
 return 0;
}

Measured memory_bytes: 7248
#include "bits/stdc++.h"
using namespace std;

#define long

long double eps = 0.00000001;

int N, K;
vector<long double> X, Y, C;

pair<pair<long double, long double>, pair<long double, long double> > CLI(long double A, long double B, long double C, long double X1, long double Y1, long double R) {
	long double L = A * A + B * B;
	long double K = A * X1 + B * Y1 + C;
	long double D = L * R * R - K * K;
	long double Ds = sqrt(D);
	long double ApL = A / L;
	long double BpL = B / L;
	long double XC = X1 - ApL * K;
	long double YC = Y1 - BpL * K;
	long double XD = BpL * Ds;
	long double YD = ApL * Ds;
	return { {XC - XD, YC + YD}, {XC + XD, YC - YD} };
}

pair<pair<long double, long double>, pair<long double, long double> > CCI(long double X1, long double Y1, long double R1, long double X2, long double Y2, long double R2) {
	long double A = X1 - X2;
	long double B = Y1 - Y2;
	return CLI(A, B, 0.5 * ((R1 - R2) * (R1 + R2) - A * (X1 + X2) - B * (Y1 + Y2)), X1, Y1, R1);
}

long double Dist(long double X1, long double Y1, long double X2, long double Y2) {
	return sqrt((X1 - X2) * (X1 - X2) + (Y1 - Y2) * (Y1 - Y2));
}

bool check(long double T) {
	for (int i = 0; i < N; i++) {
		int COUNT = 0;
		for (int j = 0; j < N; j++) {
			if (Dist(X[i], Y[i], X[j], Y[j]) * C[j] <= T + eps) COUNT++;
		}
		if (COUNT >= K) return true;
	}
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			if (Dist(X[i], Y[i], X[j], Y[j]) > T / C[i] + T / C[j] + eps) continue;
			pair<pair<long double, long double>, pair<long double, long double> > Ps = CCI(X[i], Y[i], T / C[i], X[j], Y[j], T / C[j]);
			int COUNT = 0;
			for (int k = 0; k < N; k++) {
				if (Dist(Ps.first.first, Ps.first.second, X[k], Y[k]) * C[k] <= T + eps) COUNT++;
			}
			if (COUNT >= K) return true;
			COUNT = 0;
			for (int k = 0; k < N; k++) {
				if (Dist(Ps.second.first, Ps.second.second, X[k], Y[k]) * C[k] <= T + eps) COUNT++;
			}
			if (COUNT >= K) return true;
		}
	}
	return false;
}

int main() {
	cin >> N >> K;
	X.resize(N), Y.resize(N), C.resize(N);
	for (int i = 0; i < N; i++) cin >> X[i] >> Y[i] >> C[i];
	if (K == 1) {
		cout << 0 << endl;
		return 0;
	}
	long double L = 0.0, R = 200000.0;
	for (int i = 0; i < 50; i++) {
		long double MID = (L + R) / 2;
		check(MID) ? R = MID : L = MID;
		if (L + eps > R) break;
	}
	printf("%.12lf\n", L);
}

Measured memory_bytes: 256