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

int main(){
	int a,b,c,digit;
	while(scanf("%d %d",&a, &b)!=EOF){
		digit=0;
		c=a+b;
		while(1){
			if(c/10==0) break;
			else{
				digit++;
				c/=10;
			}
		}
		printf("%d\n",digit+1);
	}
    return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N;
ll A[200010];
ll sum[200010];
int main(){
    cin>>N;
    for(ll i=0;i<N;i++){
        cin>>A[i];
    }
    sum[0]=A[0];
    for(ll i=1;i<N;i++){
        sum[i]=sum[i-1]+A[i];
    }
    ll ans=INF;
    for(ll cStart=2;cStart<=N-2;cStart++){
        ll bEnd=cStart-1;
        ll P=*lower_bound(sum,sum+bEnd+1,sum[bEnd]/2);
        ll Q=sum[bEnd]-P;
        ll P_=*(lower_bound(sum,sum+bEnd+1,sum[bEnd]/2)-1);
        ll Q_=sum[bEnd]-P_;
        if(max(P,Q)-min(P,Q) > max(P_,Q_)-min(P_,Q_)){
            P=P_;
            Q=Q_;
        }
        ll R=*lower_bound(sum+bEnd+1,sum+N,(sum[N-1]-sum[bEnd])/2+sum[bEnd])-sum[bEnd];
        ll S=sum[N-1]-sum[bEnd]-R;
        ll R_=*(lower_bound(sum+bEnd+1,sum+N,(sum[N-1]-sum[bEnd])/2+sum[bEnd])-1)-sum[bEnd];
        ll S_=sum[N-1]-sum[bEnd]-R_;
        if(max(S,R)-min(S,R) > max(S_,R_)-min(S_,R_)){
            S=S_;
            R=R_;
        }
        ans=min(ans,max({P,Q,R,S})-min({P,Q,R,S}));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3328
package main

import "fmt"

func main() {
  var priceA, priceB, priceAB, nA, nB, priceRemain int

  fmt.Scan(&priceA, &priceB, &priceAB, &nA, &nB)

  if priceA + priceB <= 2 * priceAB {
    fmt.Println(priceA * nA + priceB * nB)
    return
  }

  if nA > nB {
    if priceA >= priceAB * 2 {
      priceRemain = 2* priceAB
    } else {
      priceRemain = priceA
    }
    fmt.Println(priceAB * nB * 2 + priceRemain * (nA - nB))
    return
  } else {
    if priceB >= priceAB * 2 {
      priceRemain = 2 * priceAB
    } else {
      priceRemain = priceB
    }
    fmt.Println(priceAB * nA * 2 + priceRemain * (nB - nA))
    return
  }
}

Measured memory_bytes: 512
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, M;
    cin >> N >> M;
    vint p(M);
    vector<string> S(M);
    rep(i, M) {
        cin >> p[i] >> S[i];
    }
    vector<bool> is_ac(N + 1, false);
    vint wa_cnt(N + 1, 0);
    rep(i, M) {
        if (is_ac[p[i]] == false && S[i] == "WA") {
            wa_cnt[p[i]]++;
        }
        if (S[i] == "AC") {
            is_ac[p[i]] = true;
        }
    }
    ll ans_ac_cnt = 0;
    ll ans_wa_cnt = 0;
    REP(i, 1, N + 1) {
        if (is_ac[i] == true) {
            ans_ac_cnt++;
            ans_wa_cnt += wa_cnt[i];
        }
    }
    cout << ans_ac_cnt << " " << ans_wa_cnt << endl;
    return 0;
}

Measured memory_bytes: 6528
n = int(input())
c0, c1, c2, c3 = 0, 0, 0, 0

for i in range(n):
    s = input()
    if s == 'AC':
        c0 += 1
    elif s == 'WA':
        c1 += 1
    elif s == 'TLE':
        c2 += 1
    else:
        c3 += 1

print('AC x',c0)
print('WA x',c1)
print('TLE x',c2)
print('RE x',c3) 


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

using namespace std;
using ll = long long;

#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define REP(i,n) FOR(i, 0, n)
#define FORD(i,a,n) for(int i=(a); i>=(n); i--)
#define REPD(i,n) FOR(i, n, 0)

#define ALL(o) (o).begin(), (o).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;

const ll MOD = 1000000007;

int main() {
	ll n, m, tmp;
	cin >> n >> m;
	V<ll> v;

	ll cnt = 0;

	REP(i, n) {
		cin >> tmp;
		v.push_back(tmp);
		cnt+=tmp;
	}


	ll ans = 0;
	REP(i, n) {
		if(!(double(v[i]) < double(cnt)/double(4*m))) {
			ans++;
		}
	}

	if(ans >= m) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

}



Measured memory_bytes: 256
#include <cstdio>
#define NIL -1

struct Node {
    int parent, left, right;
};

int *D;
Node *T;

void print(int u) {
    printf("node %d: parent = %d, depth = %d, ", u, T[u].parent, D[u]);

    if (T[u].parent == NIL) { printf("root, "); }
    else if (T[u].left != NIL) { printf("internal node, "); }
    else { printf("leaf, "); }

    printf("[");
    for (int i = 0, c = T[u].left; c != NIL; i++, c = T[c].right) {
        if (i) { printf(", "); }
        printf("%d", c);
    }
    printf("]\n");
}

void setDepth(int u, int p) {
    D[u] = p;
    if (T[u].right != NIL) {
        setDepth(T[u].right, p);
    }
    if (T[u].left != NIL) {
        setDepth(T[u].left, p+1);
    }
}

int main() {
    int n;
    scanf("%d", &n);

    D = new int[n];
    T = new Node[n];

    for (int i = 0; i < n; i++) {
        T[i].parent = T[i].left = T[i].right = NIL;
    }

    for (int i = 0; i < n; i++) {
        int v, k;
        scanf("%d %d", &v, &k);
        for (int j = 0; j < k; j++) {
            int c, left;
            scanf("%d", &c);
            if (j == 0) { 
                T[v].left = c;
            } else {
                T[left].right = c;
            }
            left = c;
            T[c].parent = v;
        }
    }

    int root;
    for (int i = 0; i < n; i++) {
        if (T[i].parent == NIL) {
            root = i;
            break;
        }
    }

    setDepth(root, 0);

    for (int i = 0; i < n; i++) {
        print(i);
    }

    return 0;
}


Measured memory_bytes: 7372
#include <stdio.h>

using namespace std;

int main(){
	int m,f,r;
	char grade;
	while(true){
		scanf("%d %d %d",&m,&f,&r);
		if(m == -1 && f == -1 && r == -1) break;
		if(m == -1 || f == -1){
			grade = 'F';
		}else if(m+f >= 80){
			grade = 'A';
		}else if(m+f >= 65){
			grade = 'B';
		}else if(m+f >= 50){
			grade = 'C';
		}else if(m+f >= 30){
			grade = (r >= 50)? 'C':'D';
		}else{
			grade = 'F';
		}
		printf("%c\n",grade);
	}
}


Measured memory_bytes: 2644
#include<bits/stdc++.h>
using namespace std;
int read() {
	char c=getchar(); int x=0,f=1;
	while (c<'0' || c>'9') {
		if (c=='-') f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9') {
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
int main() {
	int n=read();
	int temp=n;
	int s=0;
	while (n>0) {
		s+=n%10;
		n/=10;
	}
	if (temp%s==0) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Linq;
using System.Text;
using static System.Math;

class MainClass
{

    public static void Main(string[] args)
    {
        var N = LnInt();
        var hash = new HashSet<long>(LnLngs());
        print(N == hash.Count ? "YES" : "NO");
    }

public static long SumAtoB(long a,long b){var length = b - a + 1;return (a + b) * (length / 2) + (length % 2 == 1 ? (a + b) / 2 : 0);}
public static long PowLite(long n, long p, int mod = (int)1e9 + 7){long ans = 1;long now = n;for (; p > 0; p >>= 1){if ((p & 1) == 1){ans *= now;ans %= mod;}now *= now;now %= mod;}return ans;}
public static void print(object obj) { Console.WriteLine(obj); }
public static long Gcd(long a, long b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } }
public static int Gcd(int a, int b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } }
public static int[] LnInts() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new int[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]); return ins; }
public static int LnInt() { var vs = Console.ReadLine().Trim(); return int.Parse(vs); }
public static long[] LnLngs() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new long[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = long.Parse(vs[i]); return ins; }
public static long LnLng() { var vs = Console.ReadLine().Trim(); return long.Parse(vs); }
public static string[] LnStrs() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return vs; }
public static string LnStr() { var vs = Console.ReadLine().Trim(); return vs; }
public static List<T[]> AllPermutation<T>(params T[] array) where T : IComparable{var a = new List<T>(array).ToArray();var res = new List<T[]>();res.Add(new List<T>(a).ToArray());var n = a.Length;var next = true;while (next){next = false;int i;for (i = n - 2; i >= 0; i--){if (a[i].CompareTo(a[i + 1]) < 0) break;}if (i < 0) break;var j = n;do{j--;} while (a[i].CompareTo(a[j]) > 0);if (a[i].CompareTo(a[j]) < 0){var tmp = a[i];a[i] = a[j];a[j] = tmp;Array.Reverse(a, i + 1, n - i - 1);res.Add(new List<T>(a).ToArray());next = true;}}return res;}}


Measured memory_bytes: 34652
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
using namespace std;
typedef long long ll;
const int N=200005;
int a[N];
int main()
{
	int n,k;scanf("%d%d",&n,&k);
	rep(i,1,n)scanf("%d",&a[i]);
	ll ans0=1,ans1=0;
	rep(i,1,n)
	{
		if(a[i]&1){ans0=ans1=ans0+ans1;}
		else{ans0*=2ll;ans1*=2ll;}
	}
	if(!k)printf("%lld\n",ans0);
	else printf("%lld\n",ans1);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#define max 100
#define inf 200000
#define N -1
#define White 0
#define Gray 1
#define Black 2

int a[max][max];
int d[max];
int pi[max];
int color[max];
int n;

void prim(){
  int u,i,v;
  int mincost;
  for(i=0;i<n;i++){
    color[i]=White;
    d[i]=inf;
    pi[i]=N;
  }
  d[0]=0;
  while(1){
    mincost = inf;
    for(i=0;i<n;i++){
      if(color[i] != Black && d[i] < mincost){
	mincost = d[i];
	u=i;
      }
    }
    if(mincost == inf)break;

    color[u] = Black;

    for(v=0;v<n;v++){
      if(color[v]!=Black && a[u][v]!=inf){
	if(a[u][v]<d[v]){
	  d[v] = a[u][v];
	  pi[v] = u;
	  color[v]=Gray;
	}
      }
    }
  }
}
	
  
int main(){
  int i,j,sum=0;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&a[i][j]);
      if(a[i][j]==N)a[i][j]=inf;
    }
    color[i] = White;
    d[i]=inf;
    pi[i] = N;
  }

  prim();
  for(i=0;i<n;i++){
    if(pi[i]!=N){
      sum+=a[i][pi[i]];
    }
  }
  printf("%d\n",sum);
  return 0;
}
      
	



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

int main() {
	string s;
	cin >> s;
 
	if (s[0] == 'A') {
		cout << "T"<<endl;
	}
	else if(s[0]=='C'){
		cout<<"G"<<endl;
	
	}
	else if (s == "G") {
		cout << "C" << endl;
	}
	else {
		cout << "A" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
# 2019-11-18 00:38:19(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# import re
# import heapq
# import array
# from scipy.misc import comb # (default: exact=False)
import numpy as np 

def main():
    n, k = [int(x) for x in sys.stdin.readline().split()]

    s = np.array(list(sys.stdin.readline().rstrip()), dtype='U1')
    # dtype=U1 : Unicode, 1-char string.

    happy_count = np.count_nonzero(s[:-1] == s[1:])
    # s[:-1] と s[1:] の各要素を比較してTrue/False のndarray(n-dimensional array を返す) 
    # np.count_nonzeroでcount(bool(elem) != False)を返す

    happy_count += 2 * k
    # every rotation make more two or one person happy.(editorial)

    happy_count = min(happy_count, n - 1)
    # finaly, at least one person is unhappy

    print(happy_count)

if __name__ == "__main__":
    main()



Measured memory_bytes: 14656
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, R: int, S: int, P: int, T: str):
    ans=0
    flag=[False]*N
    for i in range(N):
        if i<K:
            ans+=P if T[i]=='r' else S if T[i]=='p' else R
            flag[i]=True
    for i in range(K, N):
        if T[i]!=T[i-K] or (not flag[i-K]):
            ans+=P if T[i]=='r' else S if T[i]=='p' else R
            flag[i]=True
        
    print(ans)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    R = int(next(tokens))  # type: int
    S = int(next(tokens))  # type: int
    P = int(next(tokens))  # type: int
    T = next(tokens)  # type: str
    solve(N, K, R, S, P, T)

if __name__ == '__main__':
    main()


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

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

const int N = 4010;

int n; char s[N];
int a[N], cnt[3][N];

int main() { 
  scanf("%d %s", &n, s);
  for(int i = 0; i < n; i++) {
    if(s[i] == 'R') a[i + 1] = 0;
    else if(s[i] == 'G') a[i + 1] = 1;
    else a[i + 1] = 2;
    for(int k : {0, 1, 2})
      cnt[k][i + 1] = cnt[k][i];
    cnt[a[i + 1]][i + 1]++;
  }
  ll ans = 0;
  for(int i = 1; i <= n; i++) {
    for(int j = i + 1; j <= n; j++) if(a[i] != a[j]) {
      int k = 0;
      while(a[i] == k || a[j] == k) k++;
      int got = cnt[k][n] - cnt[k][j];
      if(j + (j - i) <= n && a[j + (j - i)] == k) 
        got--;
      ans += got;
    }
  } printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 3832
use std::io;

fn main() {
  let mut line = String::new();
  io::stdin().read_line(&mut line)
    .expect("failed to read line");
  let ss: Vec<i32> = line.trim().split_whitespace()
    .map(|e| e.parse().unwrap()).collect();

  if ss[0] < ss[1] && ss[1] < ss[2] {
    println!("Yes")
  } else {
    println!("No")
  }
}



Measured memory_bytes: 5024
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    int k;
    cin >> k;
    queue<ll> q;
    rep(i, 1, 10)
        q.push(i);
    k--;
    while(k--)
    {
        ll x = q.front();
        q.pop();
        if (x % 10 != 0)
            q.push(10*x + x%10 - 1);
        q.push(10*x + x%10);
        if (x % 10 != 9)
            q.push(10*x + x%10 + 1);
    }
    cout << q.front();
    return 0;
}

Measured memory_bytes: 5080
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define MIN(a,b) ((a) <= (b) ? (a) : (b))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort( ALL(v) )
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;


ll n,k;
ll arr[1000000]{};
int main()
{
   cin>>n>>k;
   for(int i = 0 ; i<n ; i++)scanf("%lld", arr+i);
    if(k>=n)
    {
        cout<<0<<endl;
        return 0;
    }
    sort(arr , arr+n);
    reverse(arr , arr+n);


    ull ans = 0 ;
    for(int i = 0 ; i < k  ; i++)arr[i] = 0;
    for(int i = k ; i<n ; i++)ans+=arr[i];


    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var r = long.Parse(Console.ReadLine());
            Console.WriteLine(r * r);
        }
    }
}


Measured memory_bytes: 13140
// AOJ 2543 Ancient Scrolls
// 2018.2.9 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char s[3][100005];
char ans[100005];
int t[5], dp[4];
int num[100005];
char v[100005][4];
  
void sort1(char *a)
{
	int i, j, k;
	char t;

	for (i = 0; i < 3; i++) {
		k = i;
		for (j = i+1; j < 4; j++) if (a[j] < a[k]) k = j;
		if (k != i) t = a[i], a[i] = a[k], a[k] = t;
	}
}

void sort2(int *a)
{
	int i, j, k;
	int t;

	for (i = 0; i < 2; i++) {
		k = i;
		for (j = i+1; j < 3; j++) if (a[j] < a[k]) k = j;
		if (k != i) t = a[i], a[i] = a[k], a[k] = t;
	}
}

int check()
{
	int i, j, f, ans;
	int r[3];

	for (i = 0; i < 3; i++) if (dp[i] < 0) return 0;
    r[0] = dp[0] - t[3];
	r[1] = dp[1] - t[2];
	r[2] = dp[2] - t[1];

	f = 0;
	for (i = 0; i < 3; i++) if (r[i] < 0) f++;
	if (f >= 2) return 0;
	for (i = 0; i < 3; i++) if (r[i] < 0) {
		for (j = 0; j < 3; j++) if (i != j) r[j] += r[i];
		r[i] = 0;
	}

	f = 0;
	for (i = 0; i < 3; i++) if (r[i] < 0) f++;
	if (f) return 0;
	sort2(r);
	r[0] += r[1];
	ans = (r[0]+r[2]) >> 1;
	if (ans > r[0]) ans = r[0];
	return ans >= t[0];
}  

int main()
{
	int l, d, i, j, k, a;
	char buf[15], *p;

	while (fgets(p=buf, 15, stdin) && *p != '0') {
		l = atoi(p); while (*p >= '0') p++; d = atoi(p+1);
		for (i = 0; i < 3; i++) {
			fgets(s[i], 100005, stdin), dp[i] = d;
		}

		memset(t, 0, sizeof(t));
		for (i = 0; i < l; i++) {
			a = 0;
			for (j = 0; j < 3; j++) for (k = j+1; k < 3; k++) {
				if (s[j][i] == s[k][i]) a += j+k;
			}
			if (a > 4) a = 4;
			num[i] = a, t[a]++;

			v[i][0] = 'A'; for (j = 0; j < 3; j++) v[i][j+1] = s[j][i];  
			sort1(v[i]);
		}

		for (i = 0; i < l; i++) {
			t[num[i]]--;
			for (j = 0; ; j++) {
				if (j == 4) goto ng;
				for (k = 0; k < 3; k++) if (s[k][i] != v[i][j]) dp[k]--;
				if (check()) { ans[i] = v[i][j]; break; }
				for (k = 0; k < 3; k++) if (s[k][i] != v[i][j]) dp[k]++;
			}
		}
		ans[l] = 0;
		puts(ans);
		continue;
ng:		puts("-1");
	}
	return 0;
}


Measured memory_bytes: 2836
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

const int N = 10010005;

struct open {
  int w, s, v;
  open(int w, int s, int v) : w(w), s(s), v(v) {}
}; vector <open> vec;

inline bool cmp(const open &a, const open &b) {
  return (a.w + a.s < b.w + b.s);
}

int n;
long long dp[N];

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    vec.push_back(open(x, y, z));
  }
  sort(vec.begin(), vec.end(), cmp);
  for (int i = 0; i < vec.size(); i++) {
    for (int j = vec[i].s; j >= 0; j--) {
      dp[j + vec[i].w] = max(dp[j + vec[i].w], dp[j] + vec[i].v);
    }
  }
  cout << *max_element(dp, dp + N) << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
  ll A,B,C,D,e,f;
  cin>>A>>B>>C>>D;
  e=A/D;
  f=C/B;
  if(A%D!=0){
    e+=1;
  }
  if(C%B!=0){
    f+=1;
  }
  if(f>e){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
  
  
  
}


Measured memory_bytes: 3636
local n, k = io.read("*n", "*n")
local t = {}
for i = 1, 100000 do
  t[i] = 0
end
for i = 1, n do
  local a, b = io.read("*n", "*n")
  t[a] = t[a] + b
end
local sum = 0
for i = 1, 100000 do
  sum = sum + t[i]
  if k <= sum then print(i) break end
end

Measured memory_bytes: 4276
#include <bits/stdc++.h>
  
using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

#define INF 1000000000

typedef long double Real;
#define EPS 1e-11
#define EQ(x) (-EPS<x && x<EPS)
typedef complex<Real> P;
Real dot(P a,P b){return real(conj(a)*b);}
Real cross(P a,P b){return imag(conj(a)*b);}

int n,m,g,d;
int mp[30][9];

bool calc(){
  int p = m;
  REP(i,d){
    if(p!=0 && mp[i][p-1]==1){
      --p;
    }else if(p!=n-1 && mp[i][p]==1){
      ++p;
    }
  }
  return p==g;
}

int main(){
  while(true){
    cin>>n;
    if(n==0)break;
    cin>>m>>g>>d;
    --m; --g;
    REP(i,d){
      int x;
      cin>>x;
      REPR(j,n){
        mp[i][n-1-j] = x%10;
        x/=10;
      }
    }
    if(calc()){
      cout<<0<<endl;
      continue;
    }
    bool flag = false;
    REP(i,d)REP(j,n-1){
      if(flag)break;
      if(mp[i][j]==1)continue;
      if(j!=0 && mp[i][j-1]==1)continue;
      if(j!=n-2 && mp[i][j+1]==1)continue;
      mp[i][j]=1;
      if(calc()){
        cout<<(i+1)<<" "<<(j+1)<<endl;
        flag = true;
      }
      mp[i][j]=0;
    }
    if(!flag) cout<<1<<endl;
  }
  return 0;
}

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

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

const int N = 4005;
int a[N], b[N], n1, n2, n, r_idx[N][2], dp[N][N], f[N][N], g[N][N];
vector <int> ind[N];

int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(0); cin.tie(0);

	cin >> n;
	for (int i = 1; i <= 2 * n; ++i) {
		char type; int x;
		cin >> type >> x;
		if (type == 'W') a[++n1] = x, r_idx[n1][0] = i;
		else b[++n2] = x, r_idx[n2][1] = i;
	}
	vector <ii> A(n + 5, {0, 0}), B(n + 5, {0, 0});
	A[0] = {N, N}; for (int i = n + 1; i <= n + 4; ++i) A[i] = {N, N};
	for (int i = 1; i <= n; ++i) {
		f[a[i]][r_idx[i][0]] = 1;
		A[i] = {a[i], r_idx[i][0]};
	}
	sort(A.begin() + 1, A.end());
	B[0] = {N, N}; for (int i = n + 1; i <= n + 4; ++i) B[i] = {N, N};
	for (int i = 1; i <= n; ++i) {
		g[b[i]][r_idx[i][1]] = 1;
		B[i] = {b[i], r_idx[i][1]};
	}
	sort(B.begin() + 1, B.end());
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= 2 * n; ++j) {
			f[i][j] += f[i - 1][j] + f[i][j - 1] - f[i - 1][j - 1];
			g[i][j] += g[i - 1][j] + g[i][j - 1] - g[i - 1][j - 1];
		}
	}
	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= n; ++j)
			dp[i][j] = N * N;
	}
	dp[0][0] = 0;
	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= n; ++j) {
			if (i + j == 0) continue;
			int ind1 = A[i].second, aa = A[i].first, ind2 = B[j].second, bb = B[j].first;
			int cost_a, cost_b; cost_a = cost_b = N;
			if (i != 0) cost_a = (i - 1 - f[i - 1][ind1]) + (j - g[j][ind1]);
			if (j != 0) cost_b = (i - f[i][ind2]) + (j - 1 - g[j - 1][ind2]);
			if (i != 0) dp[i][j] = dp[i - 1][j] + cost_a;
			if (j != 0) dp[i][j] = min(dp[i][j], dp[i][j - 1] + cost_b);
			// cerr << "dp[" << i << "][" << j << "] : " << dp[i][j] << endl;
		}
	}
	cout << dp[n][n] << endl;
	return 0;
}

Measured memory_bytes: 98560
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

int main() {
    int a,n=0;
  	cin >> a;
  	for(int i=1;i<(int)log10(a)+1; i=i+2){
    	n+=pow(10,i)-pow(10, i-1);
    }
  	if((((int)log10(a)+1)%2)!=0){
    	n+=a-pow(10, (int)log10(a))+1;
    }
	cout<<n;
  	return 0;
}

Measured memory_bytes: 640
A, B, C, K = map(int, input().split())
lst = []
sum = 0
if A <= K:
    sum += 1 * A
else:
    sum += 1 * K

k = K - (A + B)

if (C <= k) and (k > 0):
    sum += -1 * C
elif (C > k) and k > 0:
    sum += -1 * k

print(sum)

Measured memory_bytes: 61652
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	set<string> ws;
	string prevs;
	cin >> prevs;
	ws.insert(prevs);
	bool flag = true;
	--n;
	while( n-- ){
		string temp; cin >> temp;
		if( ws.count(temp) or prevs.back() != temp.front() ) flag = false;
		prevs = temp;
		ws.insert(temp);
	}
	if( flag ) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  double a, b, x, ans; cin >> a >> b >> x;
  const double PI=3.14159265358979323846;
  if(x < a * a * b / 2) ans = (atan(b / (x * 2 / a / b)) / PI) * 180;
  else ans = (atan((b * 2 - (x * 2 / a / a)) / a) / PI) * 180;
  cout << setprecision(15) << ans << endl;
  return 0;
}

Measured memory_bytes: 256
from math import sin, cos, pi, sqrt

A, B, H, M = map(int, input().split())
a = (30*H + 0.5*M)/180*pi
b = 6*M/180*pi
len_x = A*cos(a)-B*cos(b)
len_y = A*sin(a)-B*sin(b)
ans = sqrt(len_x**2+len_y**2)
print(ans)

Measured memory_bytes: 9508
#include<stdio.h>

using namespace std;

int final_board[8][8] = {{0,0,0,0,0,0,0,0},
                         {0,0,0,0,0,0,0,0},
                         {0,0,0,0,0,0,0,0},
                         {0,0,0,0,0,0,0,0},
                         {0,0,0,0,0,0,0,0},
                         {0,0,0,0,0,0,0,0},
                         {0,0,0,0,0,0,0,0},
                         {0,0,0,0,0,0,0,0}};

void deletePossibility(int tmp_board[8][8], int row, int column) {
    tmp_board[row][column] = 1;
    
    for(int i = 0; i < 8; i++) {
        if(i != column) {
            tmp_board[row][i] = -1;
        }
    }
    for(int i = 0; i < 8; i++) {
        if(i != row) {
            tmp_board[i][column] = -1;
        }
    }
    
    for(int r = row - 1, c = column + 1; r >= 0 && c <= 7; r--, c++) {
        tmp_board[r][c] = -1;
    }
    
    for(int r = row + 1, c = column + 1; r <=7 && c <= 7; r++, c++) {
        tmp_board[r][c] = -1;
    }
    
    for(int r = row - 1, c = column - 1; r >= 0 && c >= 0; r--, c--) {
        tmp_board[r][c] = -1;
    }
    
    for(int r = row + 1, c = column - 1; r <= 7 && c >= 0; r++, c--) {
        tmp_board[r][c] = -1;
    }
}

void func(int tmp_board[8][8], int num_of_putQ) {
    if(num_of_putQ == 8) {
        for(int i = 0; i < 8; i++) {
            for(int k = 0; k < 8; k++) {
                final_board[i][k] = tmp_board[i][k];
            }
        }
    }else {
        int row, column, count = 0;
        
        for(row = 0; row < 8; row++) {
            for(column = 0; column < 8; column++) {
                if(tmp_board[row][column] == 0) {
                    count++;
                }
            }
            if(count > 0) break;
        }
        if(row == 8 && column == 8) {
            //Do nothing
        } else {
            int tri_board[count][8][8];
            int index = 0;
            
            for(int a = 0; a < count; a++) {
                for(int b = 0; b < 8; b++) {
                    for(int c = 0; c < 8; c++) {
                        tri_board[a][b][c] = tmp_board[b][c];
                    }
                }
            }
            
            for(int i = 0; i < 8; i++) {
                if(tmp_board[row][i] == 0) {
                    deletePossibility(tri_board[index], row, i);
                    func(tri_board[index++], num_of_putQ + 1);
                }
            }
        }
    }
}

int main() {
    int k, row, column;
    int tmp_board[8][8];
    
    for(int i = 0; i < 8; i++) {
        for(int k = 0; k < 8; k++) {
            tmp_board[i][k] = 0;
        }
    }
    
    scanf("%d", &k);
    
    for(int i = 0; i < k; i++) {
        scanf("%d %d", &row, &column);
        deletePossibility(tmp_board, row, column);
    }
    
    func(tmp_board, k);
    
    for(int i = 0; i < 8; i++) {
        for(int p = 0; p < 8; p++) {
            if(final_board[i][p] == 1) {
                printf("Q");
            }else {
                printf(".");
            }
        }
        printf("\n");
    }
    
    return 0;
}


Measured memory_bytes: 2672
#include<iostream>

using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	
	if (a > b)
	{
		cout << "a > b" << endl;
	}
	else if (a < b)
	{
		cout << "a < b" << endl;
	}
	else
	{
		cout << "a == b" << endl;
	}



	return 0;
}


Measured memory_bytes: 3064
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int count = 0;

    String[] str1 = sc.next().split("");
    String[] str2 = sc.next().split("");

    for(int i=0; i<3; i++){
      if(str1[i].equals(str2[i])){
        count +=1;
      }
    }
    System.out.println(count);
  }

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<int, ull> piu;
typedef vector<vector<int>> matrix;

const ll INF = 1e18 + 123;
const ld EPS = 1e-9;
const int inf = 1e9 + 123;
const int MOD = 1e9 + 7;
const int N = 5e5 + 13;
const int M = 1e6 + 123;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a+3);
    if (a[0] == a[1] && a[2] != a[1]){
        cout << "Yes";
    }
    else if (a[1] == a[2] && a[0] != a[1]){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int, int>;

enum { END, START };

int time(string str) {
    int h = stoi(str.substr(0, 2));
    int m = stoi(str.substr(3, 2));
    int s = stoi(str.substr(6, 2));
    return 3600 * h + 60 * m + s;
}

void solve(int N) {
    priority_queue<Pair, vector<Pair>, greater<Pair>> que;
    for(int i = 0; i < N; ++i) {
        string s, e;
        cin >> s >> e;
        que.emplace(time(s), START);
        que.emplace(time(e), END);
    }
    int now = 0, ans = 0;
    while(!que.empty()) {
        auto t = que.top(); que.pop();
        if(t.second == START) now++;
        else now--;
        ans = max(ans, now);
    }
    cout << ans << '\n';
}

int main() {
    int N;
    while(cin >> N) {
        if(!N) break;
        solve(N);
    }
    return 0;
}



Measured memory_bytes: 3372
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#define gs(x, r) (r==0?0:x[r-1])
using namespace std;
#define INF (1 << 29)
typedef pair<int, int> P; 
typedef pair<int, P> F;
int xs[] = {-1, 0, 1, 0}, ys[] = {0, 1, 0, -1};

vector<int> input_djk(int z){
  int w, h, x ,y;
  scanf("%d%d%d%d", &w, &h ,&x ,&y);
  int dist[w][h], level[w][h];
  bool used[w][h];
  priority_queue<F, vector<F>, greater<F> > pq;
  x--,y--;
  for(int j = 0;j < h;j++){
    for(int i = 0;i < w;i++){
      scanf("%d", &level[i][j]);
      dist[i][j] = INF;
      used[i][j] = false;
    }
  }
  dist[x][y] = 1;
  used[x][y] = true;
  pq.push(F(1, P(x, y)));
  while(!pq.empty()){
    F tmp = pq.top();pq.pop();
    int tx = tmp.second.first, ty = tmp.second.second;
    if(dist[tx][ty] < tmp.first)continue;
    for(int i = 0;i < 4;i++){
      if(tx + xs[i] < 0 || tx + xs[i] >= w || ty + ys[i] < 0 || ty + ys[i] >= h || used[tx + xs[i]][ty + ys[i]])continue;
      tx += xs[i], ty += ys[i];
      if(dist[tx][ty] > max(tmp.first, level[tx][ty])){
	dist[tx][ty] = max(tmp.first, level[tx][ty]);
	used[tx][ty] = true;
	pq.push(F(dist[tx][ty], P(tx, ty)));
      }
      tx -= xs[i], ty -= ys[i];
    }
  }
  vector<int> res;
  for(int i = 0;i < w;i++)
    for(int j = 0;j < h;j++)
      res.push_back(dist[i][j]);
   
  sort(res.begin(), res.end());
  return res;
}


int solve(vector<int> a, vector<int> b, int r){
  int res = INF;
  for(int i = min(r,(int) a.size());i >= 0 && b.size() >= r - i;i--){
    res = min(res, gs(a, i) + gs(b, r - i));
  }
  return res;
}

int main(){
  while(true){
    int r;
    scanf("%d", &r);
    if(r == 0)return 0;
    vector<int> a, b;
    a = input_djk(0);
    b = input_djk(1);
    cout << solve(a, b, r) << endl;
  }
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL n, m;

int main() {
	cin >> n >> m;
	
	
	cout << (100 * (n - m) + 1900 * m) * (1 << m) << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int  ll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL) ; cout.tie(NULL);
 
int main() {
 
    fastio;
 
    string s,t,u= "";
    vector<vector<ll>> dp(3005 , vector<ll>(3005));
    
 
    cin >> s >> t;
 
    
 
    for(ll i = 0; i < sizeof(t); i++) dp[0][i] = 0;
    for(ll i = 0; i < sizeof(s); i++) dp[i][0] = 0;
 
   
 
    for(ll i = 1; i <= s.size(); i++)
    {
        for(ll j = 1; j <= t.size(); j++)
        {
            if(s[i-1] == t[j-1])
            {
                dp[i][j] = 1 + dp[i-1][j-1];
            }
            else dp[i][j] = max(dp[i-1][j] , dp[i][j-1]);
        }
    }
 
    ll i = s.size(), j = t.size(), p = dp[s.size()][t.size()];
    ll count = 0;
    while (i > 0 && j > 0)
    {
        if (s[i-1] == t[j-1])
        {
            u[p-1] = t[j-1];
            i--; j--;p--;count++;
        }
 
        else if (dp[i-1][j] > dp[i][j-1])
            i--;
        else
            j--;
    }
 
    
 
    for(ll i = 0; i < count; i++) cout << u[i];
 
    return 0;
}

Measured memory_bytes: 70912
#include <stdio.h>

int main(void)
{
	int ticket, m, i, sum;
	
	for (i = 0; i < 4; i++){
		scanf("%d%d", &ticket, &m);
		if (ticket == 1)sum = 6000 * m;
		else sum = (4000 - (1000 * (ticket - 2))) * m;
		printf("%d\n", sum);
	}
	
	return (0);
}

Measured memory_bytes: 600
h, w = map(int, input().split())
s = []
s.append('.' * (w + 2))
for _ in range(h):
    s.append('.' + input() + '.')
s.append('.' * (w + 2))


def count_bomb(i, j):
    ret = 0
    l = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]
    for dy, dx in l:
        if s[i + dy][j + dx] == '#':
            ret += 1

    return ret


for i in range(1, h + 1):
    for j in range(1, w + 1):
        if s[i][j] == '.':
            print(count_bomb(i, j), end='')
        else:
            pass
            print(s[i][j], end='')
    print()


Measured memory_bytes: 46936
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <cctype>
using namespace std;

typedef string::const_iterator State;
int expression(State &begin);

typedef string::const_iterator State;
int expression(State &begin);

int number(State &begin) {
	int ret = 0;
	for (; isdigit(*begin);) {
		ret *= 10;
		ret += *begin - '0';
		begin++;
	}
	return ret;
}
int factor(State &begin) {
	int ret;
	if (*begin == '(') {
		begin++;
		ret = expression(begin);
		begin++;
	}
	else {
		return number(begin);
	}
	return ret;
}
int term(State &begin) {
	int ret = factor(begin);
	for (;;) {
		if (*begin == '*') {
			begin++;
			ret *= factor(begin);
		}
		else if (*begin == '/') {
			begin++;
			ret /= factor(begin);
		}
		else break;
	}
	return ret;
}


int expression(State &begin) {
	int ret = term(begin);
	for (;;) {
		if (*begin == '+') {
			begin++;
			ret += term(begin);
		}
		else if (*begin == '-') {
			begin++;
			ret -= term(begin);
		}
		else break;
	}
	return ret;
}

int main() {
	int N;
	cin >> N;
	cin.ignore();
	for (int i = 0; i < N; i++) {
		string str;
		getline(cin, str);
		State s = str.begin();
		cout << expression(s) << endl;
	}
	return 0;
}

Measured memory_bytes: 3132
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
typedef long long ll;

int N, M;
vector<vector<int>> edge;

bool ischecked[100000];

void dfs(int pos) {
	for (int i = 0; i < edge[pos].size(); i++) {
		int next = edge[pos][i];
		if (!ischecked[next]) {
			ischecked[next] = true;
			dfs(next);
		}
	}
}

int main() {
	cin >> N >> M;
	edge.resize(N);
	for (int i = 0; i < M; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--, b--;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (!ischecked[i]) {
			ischecked[i] = true;
			ans++;
			dfs(i);
		}
	}
	cout << ans << endl;
	return 0;
}

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

void primeFactorize(vector<int> &ans, int n)
{
  for (int i = 2; i <= (int)sqrt(n); i++)
  {
    if (n % i == 0)
    {
      ans.push_back(i);
      primeFactorize(ans, n / i);
      return;
    }
  }
  ans.push_back(n);
}

int main()
{
  int n;
  cin >> n;
  vector<int> ans;
  primeFactorize(ans, n);
  cout << n << ":";
  rep(i, ans.size())
  {
    cout << " " << ans.at(i);
  }
  cout << endl;
}


Measured memory_bytes: 3160
from sys import stdin

def main():
    N, *LR = map(int, stdin.buffer.read().split())
    L, R = LR[::2], LR[1::2]

    max_l = max(L)
    min_r = min(R)

    ab = [(max(0, r - max_l + 1), -max(0, min_r - l + 1)) for l, r in zip(L, R)]
    ab.sort()

    mi = float("inf")
    ma = max(r - l + 1 for l, r in zip(L, R)) + max(0, min_r - max_l + 1)
    for i in range(N - 1):
        mi = min(mi, -ab[i][1])
        ma = max(ma, mi + ab[i + 1][0])

    print(ma)

main()


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


void solve(long long S, long long W){
    cout << (S <= W ? "unsafe" : "safe") << endl;

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long S;
    scanf("%lld",&S);
    long long W;
    scanf("%lld",&W);
    solve(S, W);
    return 0;
}


Measured memory_bytes: 3764
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextInt();
		long m = sc.nextInt();
		long ans;
		if (n >= 2 && m >= 2) {
			ans = (n - 2) * (m - 2);
		} else if (n == 1 && m == 1) {
			ans = 1;
		} else{
			ans = n * m - 2;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21972
/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/* libnum {{{*/
void amax(N, Args...)(ref N x, Args y) {
  x = x.max(y);
}
void amin(N, Args...)(ref N x, Args y) {
  x = x.min(y);
}
auto maxE(R)(R r) if (isInputRange!R) {
  ElementType!R x = r.front;
  r.popFront();
  foreach (y; r) x.amax(y);
  return x;
}
auto minE(R)(R r) if (isInputRange!R) {
  ElementType!R x = r.front;
  r.popFront();
  foreach (y; r) x.amin(y);
  return x;
}
/*}}}*/

/+---test
5
10 4 8 7 3
---+/
/+---test
7
4 4 5 6 6 5 5
---+/
/+---test
4
1 2 3 4
---+/

void main(string[] args) {
  readln;
  const H = readln.split.map!(to!long).array;

  auto dp = new long[H.length];
  dp[$-1] = 0;
  foreach_reverse (i; 0..H.length-1) {
    if (H[i] >= H[i+1]) dp[i] = dp[i+1] + 1;
  }
  dp.maxE.writeln;
}


Measured memory_bytes: 6216
import math
S = input()
like = 753
diff = 753
for i in range(len(S)-2):
#     print(i)
#     print(S[i:i+3])
    T = int(S[i:i+3])
    if math.fabs(like - T) < diff:
        diff = math.fabs(like - T)
print(int(diff))

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

using namespace std;

int main(){
    pair<int,int> sa;
    
    int a,b,c;
    cin>>a>>b>>c;
    sa.first=a-b;
    sa.second=b-c;
    
    for(int i=0;i<2;i++){
        pair<int,int> pre;
        cin>>a>>b>>c;
        pre.first=a-b;
        pre.second=b-c;
        
        if(pre!=sa){
            cout<<"No"<<endl;
            return 0;
        }
    }
    
    cout<<"Yes"<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    ll n, k;
    cin >> n >> k;
    vll p(n);
    for(ll i = 0; i < n; i++) cin >> p[i];
    sort(p.begin(), p.end());
    ll ans = 0;
    for(ll i = 0; i < k; i++) ans += p[i];
    cout << ans << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

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

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

using namespace std;
#define int long long


class ARightTriangle {
public:
    void solve(std::istream &in, std::ostream &out) {
      int a, b, c;
      in >> a >> b >> c;
      out << (int) (0.5 * a * b) << endl;
    }
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
  ARightTriangle solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    double n, m;
    double x, y;
    cin >> n >> m >> x >> y;
    cout << n * m / 2.0;
    if ((int) n % 2 == 0 && x == n / 2 && 
        (int) m % 2 == 0 && y == m / 2)
        cout << " 1";
    else
        cout << " 0";
    return 0;
}


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

using namespace std;

int main() {
    int N;
    cin >> N;
    int input[N];
    int max = 0;
    int index = 0;
    int sum = 0;
    for (int i = 0; i < N; ++i) {
        cin >> input[i];
        if (input[i] > max) {
            max = input[i];
            index = i;
        }
        sum += input[i];
    }
    sum -= input[index];

    if (input[index] < sum) {
        cout << "Yes";
    } else {
        cout << "No";
    }
}

Measured memory_bytes: 256
//ABC128B
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<tuple<string,int,int>> c(n);
	for(int i=0;i<n;i++){
		string s;
		int p;
		cin >> s >> p;
		c.at(i) = make_tuple(s,-p,i+1);
	}
	sort(c.begin(),c.end());
	for(int i=0;i<n;i++){
		cout << get<2>(c.at(i)) << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;

#define MOD 1000000007
#define INF 1000000
#define PI 3.14159265358979323846264338327950L
#define MAX_N 200010
#define lb lower_bound //[2,4)=lb(4)-lb(2);

#define REP(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl

/*
0,0,0,0というやつを
水やりして
1,2,2,1にする
*/

bool isnull(vector<int> h)
{
  int n=h.size();
  for (int i=0;i<n;i++)
  { 
    if (h[i]!=0) return (false);
  }
  return (true);
}
 
int main()
{
  int N;cin>>N;
  vector<int> h(N);
  for (int i=0;i<N;i++)
    cin>>h[i];
  
  int i=0;
  int count=0;
  while (!isnull(h))
  {
    i=0;
    while (h[i]==0)
    {
      i++; 
    }
    while (h[i]>=1)
    {
      h[i]-=1;
      i++;
    }
    count++;
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
def solve():
    A, B, C, X, Y = [int(i) for i in input().split()]
    ans1 = A * X + B * Y
    ans2 = C * 2 * X + B * (Y - X) if X < Y else C * 2 * Y + A * (X - Y)
    ans3 = C * 2 * max(X, Y)
    print(min(ans1, ans2, ans3))

if __name__ == "__main__":
    solve()

Measured memory_bytes: 61996
#include <iostream>
#include <vector>

using namespace std;

int main(){
	while(true){
		int n, p, q;
		cin >> n >> p >> q;
		if(n == 0 && p == 0 && q == 0){ break; }
		vector<int> num(q);
		for(int i = 0; i < n; ++i){
			int m;
			cin >> m;
			while(m--){
				int a, b;
				cin >> a >> b;
				for(int j = a; j < b; j += (j % 100 == 59 ? 41 : 1)){ ++num[j]; }
			}
		}
		int answer = 0, prev = 0;
		for(int i = p; i < q; i += (i % 100 == 59 ? 41 : 1)){
			if(num[i] == n){
				num[i] = 0;
			}else if(i == p){
				num[i] = 1;
			}else{
				num[i] = prev + 1;
			}
			prev = num[i];
			answer = max(answer, num[i]);
		}
		cout << answer << endl;
	}
	return 0;
}

Measured memory_bytes: 0