akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    var(i64, N);
    i64 ans = LINF;

    for (i64 i = 1; i * i <= N; ++i) {
        if (N % i != 0) continue;
        const i64 x = i;
        const i64 y = N / x;
        dump(x, y, x + y - 2);
        chmin(ans, x + y - 2);
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]

A.sort()
BC.sort(key=lambda x:x[1], reverse=True)

pos = 0
for b, c in BC:
    end = (pos + b) if pos + b <= n else n
    for i in range(pos, end):
        if A[i] < c:
            A[i] = c
        else:
            break
    pos = i + 1
    if pos >= n:
        break

print(sum(A))

Measured memory_bytes: 32964
use std::str::FromStr;
use std::io::{stdin, BufRead};

fn read<T: FromStr>() -> T {
    let mut s = String::new();
    let stdin = stdin();
    let mut input = stdin.lock();
    input.read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub struct Foo {
    ch: char
}

pub struct ParseCharError {
    kind: CharErrorKind,
}

impl ParseCharError {
    pub fn __description(&self) -> &str {
        match self.kind {
            CharErrorKind::EmptyString => "cannot parse char from empty string",
            CharErrorKind::TooManyChars => "too many characters in string",
        }
    }
}

enum CharErrorKind {
    EmptyString,
    TooManyChars,
}

impl FromStr for Foo {
    type Err = ParseCharError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let mut chars = s.chars();
        match (chars.next(), chars.next()) {
            (None, _) => Err(ParseCharError { kind: CharErrorKind::EmptyString }),
            (Some(c), None) => Ok(Foo { ch: c }),
            _ => Err(ParseCharError { kind: CharErrorKind::TooManyChars }),
        }
    }
}

fn main() {
    let n: u32 = read();
    println!("{}" , n / 2 + n % 2);
}



Measured memory_bytes: 4352
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    int[] l = new int[N];
    for (int i = 0; i < N; i++) {
      l[i] = sc.nextInt();
    }
    Arrays.sort(l);
    int ans = 0;
    for (int i = 0; i < K; i++) {
      ans += l[l.length - 1 - i];
    }
    System.out.println(ans);
  }
}

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

int main(){
	int num;
	cin >> num;
	num = num % 10;
	if(num == 2 || num == 4 || num == 5 || num == 7 || num == 9){
		cout << "hon" << "\n";
	} else if(num ==3){
		cout << "bon" << "\n";
	} else {
		cout << "pon" << "\n";
	}
}

Measured memory_bytes: 3636
#include <stdio.h>
 
int main(void){
  int i,sum;
  char num[1001];
 
  for(;;){
    scanf("%s", &num);
    if(num[0] == '0') break;
     
    sum = 0;
    for(i=0;num[i]!='\0';i++)
      sum += num[i] - '0';
    printf("%d\n", sum);
  }
   
  return 0;
}


Measured memory_bytes: 2040
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

a,b = inpl()
print(a*b)

Measured memory_bytes: 10524
#include<stdio.h>
int main(void){
  int x=0;
  int y=0;
  while(1){
    scanf("%d %d",&x,&y);
    if(x==0 && y==0 ){
      break;
    };
    if(x<y){
         printf("%d %d\n",x,y);
    }else{
       printf("%d %d\n",y,x);
    };
  }
 return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef long long lli;
lli n;
vector<lli> r,l;
priority_queue<lli> pqr;
priority_queue<lli,vector<lli>,greater<lli> > pql;
lli ans;
int main(){
    cin >> n;
    r = vector<lli> (n);
    l = vector<lli> (n);
    for(lli i = 0;i < n;i++) 
        cin >> l[i] >> r[i];
    
    pqr.push(l[0]);
    pql.push(l[0]);
    
    lli tr = 0,tl = 0;
    ans = 0;
    for(lli i = 1;i < n;i++){
        tl += r[i-1] - l[i-1];
        tr -= r[i] - l[i];
        if(pqr.top() > l[i] - tr) 
            {
                ans += abs(pqr.top() - (l[i] - tr));
                pqr.push(l[i] - tr);
                pqr.push(l[i] - tr);
                pql.push(pqr.top() + tr - tl);
                pqr.pop();
            }
        else if(pql.top() < l[i] - tl) 
            {
                ans += abs(pql.top() - (l[i] - tl));
                pql.push(l[i] - tl);
                pql.push(l[i] - tl);
                pqr.push(pql.top() + tl - tr);
                pql.pop();
            }
        else 
            {
                pqr.push(l[i] - tr);
                pql.push(l[i] - tl);
            }
        //cout << pqr.top() + tr << " " << pql.top() + tl << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3572
import math

if __name__ == '__main__':
    x = int(input())
    limit = math.ceil(x ** 0.2) + 100
    count = 0
    for a in range(limit):
        if a ** 5 < x:
            # -
            for b in range(0, -limit, -1):
                if a ** 5 - b ** 5 == x:
                    print(a, b)
                    exit(0)
        else:
            for b in range(limit):
                if a ** 5 - b ** 5 == x:
                    print(a, b)
                    exit(0)


Measured memory_bytes: 9452
#include <stdio.h>
#include <iostream>
#include <sstream>
using namespace std;
 
int main() {
  int A, B;
  cin >> A;
  cin >> B;
 
  if (A > 8 || B > 8){
    cout << ":(" << endl;
  }else{
    cout << "Yay!" << endl;
  }
 
  return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <functional>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;


int main(void) {
	int x, y, z;
	cin >> x >> y >> z;
	int tmp;
	tmp = x;
	x = y;
	y = tmp;
	tmp = x;
	x = z;
	z = tmp;
	cout << x << " " << y << " " << z << endl;
	return 0;
}

Measured memory_bytes: 256
/*
ID: wangjun30
LANG: C++11
TASK:
*/
#include<iostream>
#include<algorithm>
#include<array>
#include<unordered_map>
#include<map>
#include<set>
#include<list>
#include<unordered_set>
#include<vector>
#include<bitset>
#include<queue>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
//#include<fstream>
#define int long long
using namespace std;
//ifstream cin(".in");
//ofstream cout(".out");
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	string str;
	cin>>str;
	if(str[0]==str[1] && str[1]==str[2])
		cout<<"No";
	else
		cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
import math
def yakusuu(a):
  x=[]
  b=math.ceil(math.sqrt(a))
  for i in  range(1,b+1):
    if a%i==0:
      x.append((i,int(a/i)))
  return(x)
N=int(input())
oddlist=[i for i in range(1,N+1,2)]
ans=[]
for i in oddlist:
  x=yakusuu(i)
  if len(x)==4:
    ans.append(i)
print(len(ans))

Measured memory_bytes: 3064
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n := next()

	for _, c := range n {
		if c == '7' {
			puts("Yes")
			return
		}
	}
	puts("No")
}


Measured memory_bytes: 1764
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    double S=0;
    cin >> N;
    
    vector<double> A(N);
    for (int i=0;i<N;i++){
        cin >> A.at(i);
    }
    
    vector<double> B(N);
    for (int i=0;i<N;i++){
        B.at(i) = 1 / A.at(i);
        S = S + B.at(i);
        
    }
    
    double I = 1/S;
    cout << I << endl;
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e15;
const ll MOD = 1e9+7;
const ll LINF = 1e18;


signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  vll a(5);
  rep(i,n){
    string s; cin>>s;
    if(s[0]=='M') a[0]++;
    if(s[0]=='A') a[1]++;
    if(s[0]=='R') a[2]++;
    if(s[0]=='C') a[3]++;
    if(s[0]=='H') a[4]++;
  }
  ll ans=0;
  rep(i,5){
    irep(j,i+1,5){
      irep(k,j+1,5){
        ans+=a[i]*a[j]*a[k];
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>
#include<functional>
#include<queue>

using ll = long long;

using namespace std;

ll mod = 1e9 + 7;
//ll mod = 998244353;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	//t %= mod;
	if (n % 2 == 1)t *= a;
	return t /*% mod*/;
}

//const int INF = 1001001001;
const ll INF = 1e18;

int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };

ll cal_gcd(ll a, ll b) {
	ll m = max(a, b);
	ll n = min(a, b);
	while (m%n != 0) {
		ll b = m % n;
		m = n;
		n = b;
	}
	return n;
}

vector<pair<ll, ll>> prime_factorize(ll N) {
	vector<pair<ll, ll>> res;
	for (long long a = 2; a * a <= N; ++a) {
		if (N % a != 0) continue;
		long long ex = 0;
		while (N % a == 0) {
			++ex;
			N /= a;
		}
		res.push_back({ a, ex });
	}
	if (N != 1) res.push_back({ N, 1 });
	return res;
}


int main() {
	int n, k;
	cin >> n >> k;
	vector<ll>a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll score = 1;
	for (int i = 0; i < n; i++) {
		if (i < k)continue;
		if (a[i-k] < a[i]) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 4840
line = input().split()
k =int(line[0])
s =int(line[1])
data =[0,0,0]
out =0

for i in range(k+1):
  for t in range(i,1+k):
    data[0] =i
    data[1] =t
    data[2] =s-data[1]-data[0]
    
    if data[2] >=0 and data[2] <=k and data[2]>=t :
     
      if data[0] ==data[1] and data[0] ==data[2] and data[1] ==data[2]:
        out +=1
      elif data[0] !=data[1] and data[0] !=data[2] and data[1] !=data[2]:
        out +=6
      else:
        out +=3
print(out)




Measured memory_bytes: 3064
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(x) cout << fixed << setprecision(x);
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

int main(){
  ll a,n; cin >> a >> n;
  if(a >= 13) cout << n << endl;
  else if(a <= 5) cout << 0 << endl;
  else cout << n/2 << endl;
}

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
chk = []
ans = [0]*2
if a[0] >= 3200:
  ans[0] = 1
  ans[1] = n
else:
  for i in range(n):
    if a[i] < 400:
      chk.append('hai')
    elif 399 < a[i] < 800:
      chk.append('cha')
    elif 799 < a[i] < 1200:
      chk.append('mi')
    elif 1199 < a[i] < 1600:
      chk.append('miz')
    elif 1599 < a[i] < 2000:
      chk.append('ao')
    elif 1999 < a[i] < 2400:
      chk.append('ki')
    elif 2399 < a[i] < 2800:
      chk.append('dai')
    elif 2799 < a[i] < 3200:
      chk.append('aka')
    else:
      ans[1] += 1
  if 'hai' in chk:
    ans[0] += 1
    ans[1] += 1
  if 'cha' in chk:
    ans[0] += 1
    ans[1] += 1
  if 'mi' in chk:
    ans[0] += 1
    ans[1] += 1
  if 'miz' in chk:
    ans[0] += 1
    ans[1] += 1
  if 'ao' in chk:
    ans[0] += 1
    ans[1] += 1
  if 'ki' in chk:
    ans[0] += 1
    ans[1] += 1
  if 'aka' in chk:
    ans[0] += 1
    ans[1] += 1
  if 'dai' in chk:
    ans[0] += 1
    ans[1] += 1
print(' '.join(map(str,ans)))

Measured memory_bytes: 3188
import math

a, b, c = map(float, input().split())
S =  0.5 * a * b * math.sin(c * math.pi / 180)
L = a + b + (a ** 2 + b ** 2 - 2 * a * b * math.cos(c * math.pi / 180)) ** 0.5
h = 2 * S / a

print("%f\n%f\n%f" % (S, L, h))

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

int main(){

    int N;
    cin >> N;
    vector<string> S(N);
    for(int i = 0; i < N; i++) cin >> S[i];

    set<string> m_name, a_name, r_name, c_name, h_name;
    for(int i = 0; i < N; i++){
        if(S[i].front() == 'M') m_name.insert(S[i]);
        if(S[i].front() == 'A') a_name.insert(S[i]);
        if(S[i].front() == 'R') r_name.insert(S[i]);
        if(S[i].front() == 'C') c_name.insert(S[i]);
        if(S[i].front() == 'H') h_name.insert(S[i]);
    }

    cout << m_name.size() * a_name.size() * r_name.size()
    + m_name.size() * a_name.size() * c_name.size()
    + m_name.size() * a_name.size() * h_name.size()
    + m_name.size() * r_name.size() * c_name.size()
    + m_name.size() * r_name.size() * h_name.size()
    + m_name.size() * c_name.size() * h_name.size()
    + a_name.size() * r_name.size() * c_name.size()
    + a_name.size() * r_name.size() * h_name.size()
    + a_name.size() * c_name.size() * h_name.size()
    + r_name.size() * c_name.size() * h_name.size() << endl;

    return 0;
}

Measured memory_bytes: 15616
n = int(input())
s = input()

w, e = 0, 0
W = [0]*n
E = [0]*n
for i in range(n):
    if s[i] == 'W':
        w += 1
        W[i] += w 
        E[i] = e
    else:
        e += 1
        E[i] += e
        W[i] = w

count_min = E[-1]
for i in range(1, n):
    count = W[i-1] + (E[-1] - E[i]) 
    count_min = min(count_min, count)

print(count_min)

Measured memory_bytes: 22304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const ll mod=1000000007,MAX=200005,INF=1<<30;

int par[MAX],size[MAX],edgesize[MAX];

void init(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
        size[i]=1;
        edgesize[i]=0;
    }
}

int root(int a){
    if(par[a]==a) return a;
    else return par[a]=root(par[a]);
}

void unite(int a,int b){
    if(root(a)!=root(b)){
        size[root(a)]+=size[root(b)];
        edgesize[root(a)]+=edgesize[root(b)];
        par[root(b)]=root(a);
    }
}

bool check(int a,int b){
    return root(a)==root(b);
}

struct edge{
    int from;
    int to;
    ll cost;
};

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,H,W;cin>>N>>H>>W;
    init(H+W);
    
    vector<edge> S(N);
    for(int i=0;i<N;i++){
        cin>>S[i].from>>S[i].to>>S[i].cost;
        S[i].from--;
        S[i].to--;
        S[i].to+=H;
    }
    sort(all(S),[](edge a,edge b){
        return a.cost>b.cost;
    });
    
    ll ans=0;
    
    for(int i=0;i<N;i++){
        int a=S[i].from,b=S[i].to;
        ll c=S[i].cost;
        if(check(a,b)){
            if(size[root(a)]==edgesize[root(a)]) continue;
            else{
                edgesize[root(a)]++;
                ans+=c;
            }
        }else{
            if(size[root(a)]+size[root(b)]>edgesize[root(a)]+edgesize[root(b)]){
                unite(a,b);
                edgesize[root(a)]++;
                ans+=c;
            }
        }
    }
    
    cout<<ans<<endl;
    
}


Measured memory_bytes: 4992
from fractions import gcd
a, b = [int(i) for i in input().split(' ')]
gcd = gcd(a, b)

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

if gcd == 1:
    print(1)
else:
    print(len(factorization(gcd)) + 1)


Measured memory_bytes: 5088
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N, W;
    cin >> N >> W;
    vector <ll> weights(N+1), values(N+1);
    loop(i,1,N+1) cin >> weights[i] >> values[i];
    vector < vector<ll> > dp(N+1, vector <ll> (W+1));
    loop(i,0,W+1) dp[0][i]=0;
    loop(i,1,N+1)
    {
        loop(j,1,W+1)
        {
            if (weights[i]>j) dp[i][j]=dp[i-1][j];
            else dp[i][j] = max(dp[i-1][j], dp[i-1][j-weights[i]] + values[i]);
        }
    }
    cout << dp[N][W] << "\n";
    return 0;
}

Measured memory_bytes: 80256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>

using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	int ans = -1;
	for (int i = 0; i < 1300; i++) {
		int n = i * 0.08;
		int m = i * 0.1;
		if (n == a && m == b) {
			ans = i;
			i = 1300;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.util.Arrays;
import java.util.Collections;
import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.Comparator;

public class Main {
    // 標準入力
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    // 標準入力数値配列用 int
    static int[] inputval() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        int[] intarray = new int[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    // 標準入力数値リスト用 int
    static List<Integer> inputIntList() throws Exception {
        List<String> strList = Arrays.asList(br.readLine().trim().split(" "));
        List<Integer> intList = new ArrayList<Integer>();
        for (String elem : strList){
            intList.add(Integer.parseInt(elem));
        }
        return intList;
    }

    // 標準入力数値配列用 integer ソート用
    static Integer[] inputvalInteger() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        Integer[] intarray = new Integer[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Integer.parseInt(strarray[i]);
        }
        return intarray;
    }

    public static void main(String[] args) throws Exception {
        // write your code here
        String s = br.readLine().trim();
        String ans = "";
        for (int i=0; i<s.length(); i++){
            if (i%2 == 0){
                ans += s.charAt(i);
            }
        }
        System.out.println(ans);

    }

}



Measured memory_bytes: 55048
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
struct ModInt {
    static const ll MOD = 1000000007;

    // constructors etc
    ModInt() :num(1ll) {}
    ModInt(ll num_) :num(num_%MOD) {}
    ModInt(const ModInt& modint) :num(modint.num%MOD) {}
    ll get()const { return num; }

    // operator etc
    // operator ll() const { return num; }
    // ll operator*() { return num; }
    ModInt& operator+=(const ModInt& r) { (num += r.num) %= MOD; return *this; }
    ModInt& operator-=(const ModInt& r) { (num += -r.num + MOD) %= MOD; return *this; }
    ModInt& operator*=(const ModInt& r) { (num *= r.num) %= MOD; return *this; }
    ModInt& operator/=(const ModInt& r) { (num *= r.inv().num) %= MOD; return *this; }
    ModInt pow(const ModInt& r)const {
        ll res = 1;
        ll x = num;
        ll n = r.num;
        while (n > 0) {
            if (n & 1)res = (res*x) % MOD;
            x = (x*x) % MOD;
            n >>= 1;
        }
        return res;
    }
    ModInt inv()const { return this->pow(MOD - 2); }

    ModInt operator+(const ModInt& r)const { return ModInt(*this) += r; }
    ModInt operator-(const ModInt& r)const { return ModInt(*this) -= r; }
    ModInt operator*(const ModInt& r)const { return ModInt(*this) *= r; }
    ModInt operator/(const ModInt& r)const { return ModInt(*this) /= r; }
    ModInt operator+(const ll& r)const { return *this + ModInt(r); }
    ModInt operator-(const ll& r)const { return *this - ModInt(r); }
    ModInt operator*(const ll& r)const { return *this * ModInt(r); }
    ModInt operator/(const ll& r)const { return *this / ModInt(r); }

private:
    ll num;
};
ostream& operator<<(ostream& stream, const ModInt& val) { stream << val.get(); return stream; }

// ============ template finished ============

int main()
{
    constexpr ll MAX_N = 302;
    ll N, M;
    cin >> N >> M;
    array<array<array<ModInt, MAX_N>, MAX_N>, MAX_N> dp;
    rep(i, MAX_N)rep(j, MAX_N)rep(k, MAX_N)dp[i][j][k] = 0;
    dp[0][0][0] = 1;
    rep(alpha, MAX_N - 1)rep(beta, MAX_N - 1)rep(gamma, MAX_N - 1) if (beta <= gamma) {
        auto D = dp[alpha][beta][gamma];
        if (beta == gamma) {
            dp[alpha + 1][beta][gamma] += D * (beta + 1);
            dp[alpha + 1][beta][gamma + 1] += D;
        }
        else {
            dp[alpha + 1][gamma][gamma] += D * (beta + 1);
            dp[alpha + 1][beta][gamma] += D * (gamma - beta);
            dp[alpha + 1][beta][gamma + 1] += D;
        }
    }
    auto res = dp[M][N - 1][N - 1];
    REP(i, 1, N)res *= i;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 218820
// 2020-08-13 21:26:49
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

const ll inf = 1e9;
struct Data {
  ll l[3], r[3];

  Data() {
    rep(i, 3) {
      l[i] = inf;
      r[i] = -inf;
    }
  }

  void add(ll x, int d) {
    d++;
    chmin(l[d], x);
    chmax(r[d], x);
  }

  vector<ld> ts() {
    vector<ld> res;
    res.push_back(0);
    rep(i, 2) REP(j, i+1, 3) {
      if(l[i] < inf && l[j] < inf && l[j] < l[i]) {
        res.push_back(ld(l[i] - l[j]) / ld(j - i));
      }
      if(r[i] > -inf && r[j] > -inf && r[j] < r[i]) {
        res.push_back(ld(r[i] - r[j]) / ld(j - i));
      }
    }
    return res;
  }

  ld calc(ld t) {
    ld lx = inf, rx = -inf;
    rep(i, 3) {
      if(l[i] < inf)  chmin(lx, t * i + l[i]);
      if(r[i] > -inf) chmax(rx, t * i + r[i]);
    }
    return rx - lx;
  }
};

void answer() {
  int n;
  cin >> n;
  Data X, Y;
  rep(i, n) {
    ll x, y;
    char d;
    cin >> x >> y >> d;
    if(d == 'R') X.add(x, 1),  Y.add(y, 0);
    if(d == 'L') X.add(x, -1), Y.add(y, 0);
    if(d == 'U') Y.add(y, 1),  X.add(x, 0);
    if(d == 'D') Y.add(y, -1), X.add(x, 0);
  }
  ld ans = 1e18;
  for(const ld t : X.ts()) chmin(ans, X.calc(t) * Y.calc(t));
  for(const ld t : Y.ts()) chmin(ans, X.calc(t) * Y.calc(t));
  cout << fixed << setprecision(15) << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 3848
#include <stdio.h>

#define _USE_MATH_DEFINES

#include <math.h>



int main(){

    int a, b, angle;

    double s, l, h;



    scanf("%d %d %d", &a, &b, &angle);

  

    h=b*sin(angle*M_PI/180.0);

    s=a*h/2;

    l=a+b+sqrt((a*a+b*b-2*a*b*cos(angle*M_PI/180.0)));

    printf("%f\n", s);

    printf("%f\n", l);

    printf("%f\n", h);



    return 0;

}


Measured memory_bytes: 2972
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] H = new int[N];
        for (int i = 0; i < N; i++) {
            H[i] = sc.nextInt();
        }
        Arrays.sort(H);
        int ans = 1000000000;
        for (int i = 0; i <= N - K; i++) {
            if (ans > H[i + K - 1] - H[i]) ans = H[i + K - 1] - H[i];
        }
        System.out.println(ans);
        sc.close();
    }
}

Measured memory_bytes: 50732
/**
 *     author: qodjf
 *     created: 04.22.2020 20:59:57
 */
#include <bits/stdc++.h>
using namespace std;

#define mst(x, a) memset(x, a, sizeof(x))

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const ll MOD = 1e9 + 7;

int N, Z, W;
vector<int> a;

int g(int pos, int X);

// pos < N
int f(int pos, int rival, int X) {
  if (pos + 1 == N) {
    return abs(rival - a[N - 1]);
  }
  if (X) {
    return max(abs(rival - a[N - 1]), g(pos, X));
  } else {
    return min(abs(rival - a[N - 1]), g(pos, X));
  }
}

int dp[2][2010];
// pos + 1 < N
int g(int pos, int X) {
  if (dp[X][pos] != -1) return dp[X][pos];

  if (X) {
    int ans = max(f(pos + 1, a[pos], 1 - X), pos + 2 < N ? g(pos + 1, X) : 0);
    return dp[X][pos] = ans;
  } else {
    int ans = min(f(pos + 1, a[pos], 1 - X), pos + 2 < N ? g(pos + 1, X) : INF);
    return dp[X][pos] = ans;
  }
}

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

  cin >> N >> Z >> W;
  a.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }

  mst(dp, -1);
  cout << f(0, W, 1) << endl;
}


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

int main(void) {
    string S;
    cin >> S;
    int N = S.length();
    bool flag = true;
    for (int i = 0; i < (N - 1) / 2; i++) {
        if (S[i] != S[(N - 1) / 2 - 1 - i]) {
            flag = false;
            printf("No\n");
            return 0;
        }
    }
    for (int i = (N + 3) / 2 - 1; i < N; i++) {
        if (S[i] != S[N - 1 - i]) {
            flag = false;
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ms(x,y) memset(x, y, sizeof(x))
#define lowbit(x) ((x)&(-x))
#define sqr(x) ((x)*(x))
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

const LL MOD = 1e9+7;
const int maxn = 2e6+5;

LL F[maxn], invF[maxn], inv[maxn];

LL comb(int n, int m) {
    if(m < 0 || n < m) return 0;
    return F[n]*invF[n-m]%MOD*invF[m]%MOD;
}

void run_case() {
    int r1, c1, r2, c2, n;
    cin >> r1 >> c1 >> r2 >> c2;
    n = r2 + c2 + 2;
    inv[1] = 1;
    for(int i = 2; i <= n; ++i)
        inv[i] = (MOD - MOD / i) * 1LL * inv[MOD % i] % MOD;
    F[0] = invF[0] = 1;
    for(int i = 1; i <= n; ++i) {
        F[i] = F[i-1] * 1LL * i % MOD;
        invF[i] = invF[i-1] * inv[i] % MOD;
    }
    LL ans1 = 0, ans2 = 0, ans3 = 0, ans4 = 0;
    for(int i = 0; i <= c2; ++i) (ans1 += comb(r2+i+1, r2)) %= MOD;
    for(int i = 0; i <= c2; ++i) (ans2 += comb(r1+i, r1-1)) %= MOD;
    for(int i = 0; i <= c1-1; ++i) (ans3 += comb(r2+i+1, r2)) %= MOD;
    for(int i = 0; i <= c1-1; ++i) (ans4 += comb(r1+i, r1-1)) %= MOD;
    cout << (ans1+ans4-ans3-ans2+MOD)%MOD;
}


int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(9);
    //int t; cin >> t;
    //while(t--)
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 47104
#include <string>
#include <iostream>
#include <set>
#include <map>
 
long long cnt(long long x){
    
    return x * (x-1) / 2;
}

int main(){
 
  long long int n = 0;
  std::cin >> n;
  

    std::map<char, long long int> ttmp;
  std::map<decltype(ttmp), long long > mp2;

  for(int i = 0; i < n ; ++i){
    
    std::map<char, long long int> mp;
  	std::string t;
    std::cin >> t;
    
    for(auto c: t){
      mp[c]++;
    }

    mp2[mp]++;
  
  }
  long long count = 0;
  for(auto m: mp2){
    	count += cnt(m.second);
  }
  
  std::cout << count << std::endl;
  
  return 0;
}

Measured memory_bytes: 60800
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10**9)
mod = 10**9+7

N,K = I()
if K%2 == 0:
    num = N//(K//2)     
    if num%2 == 0:
        num1 = num//2
        num2 = num//2
    else:
        num1 = num//2+1
        num2 = num//2
    print(num1**3+num2**3)
else:
    num = N//K
    print(num**3)

Measured memory_bytes: 77368
#![allow(unused_imports)]
use proconio::{input, fastout};
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
    n: usize,
    d: i64,
    xy: [(i64, i64); n]
    }
    let mut ans = 0;
    for i in 0..n {
        if d * d >= xy[i].0.pow(2) + xy[i].1.pow(2) {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 7824
import java.util.*;

public class Main {
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		int[]n = new int [5];
		for(int i = 1;i < 5;i++){
			int t = in.nextInt();
			n[t] = in.nextInt();
			if(t == 1){
				System.out.println(6000*n[1]);
			}else if(t == 2){
				System.out.println(4000*n[2]);
			}else if(t == 3){
				System.out.println(3000*n[3]);
			}else{
				System.out.println(2000*n[4]);
			}
		}
	}
}

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

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(),x.end()

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

    int ans = 0;
    for(int i=1;i<=N;i++){
        if((1<=i&&i<=9)||(100<=i&&i<=999)||(10000<=i&&i<=99999))ans++;
    }

    cout << ans << endl;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
bool used[30][30][4][16];
int dx[]={0,1,0,-1};
int dy[]={-1,0,1,0};
string s[30];
int h,w;
void END(){
  cout<<"YES"<<endl;
  exit(0);
}
void dfs(int x,int y,int d,int m,int D){
  if(!D){
    if(s[y][x]=='<'){d=3;}
    else if(s[y][x]=='>'){d=1;}
    else if(s[y][x]=='^'){d=0;}
    else if(s[y][x]=='v'){d=2;}
    else if(s[y][x]=='_'){
      if(m)d=3;
      else d=1;
    }
    else if(s[y][x]=='|'){
      if(m)d=0;
      else d=2;
    }
    else if(s[y][x]=='?'){
      r(i,4)dfs(x,y,i,m,1);
    }
    else if(s[y][x]=='.'){}
    else if(s[y][x]=='@'){END();}
    else if(s[y][x]=='-'){m=(m-1+16)%16;}
    else if(s[y][x]=='+'){m=(m+1)%16;}
    else if(isdigit(s[y][x])){m=s[y][x]-'0';}
  }
  while(1){
    if(used[y][x][d][m])return ;
    used[y][x][d][m]=1;
    x+=dx[d];
    y+=dy[d];
    x+=w;
    y+=h;
    x%=w;
    y%=h;
    if(s[y][x]=='<'){d=3;}
    else if(s[y][x]=='>'){d=1;}
    else if(s[y][x]=='^'){d=0;}
    else if(s[y][x]=='v'){d=2;}
    else if(s[y][x]=='_'){
      if(m)d=3;
      else d=1;
    }
    else if(s[y][x]=='|'){
      if(m)d=0;
      else d=2;
    }
    else if(s[y][x]=='?'){
      r(i,4)dfs(x,y,i,m,1);
    }
    else if(s[y][x]=='.'){}
    else if(s[y][x]=='@'){END();}
    else if(s[y][x]=='-'){m=(m-1+16)%16;}
    else if(s[y][x]=='+'){m=(m+1)%16;}
    else if(isdigit(s[y][x])){m=s[y][x]-'0';}
  }
}
int main(){
  cin>>h>>w;
  r(i,h)cin>>s[i];
  dfs(0,0,1,0,0);
  cout<<"NO"<<endl;
}


Measured memory_bytes: 4924
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    char c;
    cin>>c;
    char a;
    switch (c)
    {
        case 'A' : 
            a='T';
            break;
        case 'T' :
            a='A';
            break;
        case 'C' :
            a='G';
            break;
        case 'G' :
            a='C';
            break;
        default:
            break;
    }
    cout<<a<<endl;
    
    return 0;
    
}



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

int n;
int w[310], dp[310][310];

int rec(int i, int j) {
    if (dp[i][j] >= 0) return dp[i][j];
    if (i >= j) return dp[i][j] = 0;
    int res = 0;
    for (int k = i + 1; k < j; ++k) {
        res = max(res, rec(i, k) + rec(k, j));
    }
    if ((j - i) % 2 == 0 && abs(w[i] - w[j - 1]) <= 1) {
        if (rec(i + 1, j - 1) == j - i - 2) {
            res = max(res, dp[i + 1][j - 1] + 2);
        }
    }
    return dp[i][j] = res;
}

int main() {
    while (cin >> n, n) {
        for (int i = 0; i < n; ++i) {
            cin >> w[i];
        }
        memset(dp, -1, sizeof(dp));
        cout << rec(0, n) << endl;
    }
}


Measured memory_bytes: 3488
program test
implicit none

integer(8) :: i,j,ans,a(200000)=0,n,count1=0,count0=0
character(len=200000) :: s
read(*,*) s

n=len_trim(s)

do i=1,n
	if(s(i:i) == "1")then
		a(i) = 1
		count1 = count1 + 1
	else
		a(i) = 0
		count0 = count0 + 1
	endif
enddo




write(*,*) min(count1*2,count0*2)





















contains
subroutine heapsort_down(n,y1,y2)
 
	implicit none
	integer(8),intent(in) :: n
	integer(8),intent(inout) :: y1(1:n)
	integer(8),intent(inout) :: y2(1:n)
	integer(8) :: i,k,j,l
	integer(8) :: t1,t2
	
	l = n/2+1
	k = n
 
	do while (k /= 1)
		 if(l > 1) then
				l = l-1
				t1 = y1(l)
				t2 = y2(l)
				
		 else
				t1 = y1(k)
				t2 = y2(k)
				y1(k) = y1(1)
				y2(k) = y2(1)
				k = k-1
				if(k == 1) then
					 y1(1) = t1
					 y2(1) = t2
					 exit
				endif
		 endif
 
		 i = l
		 j = l+l
 
		 do while(j <= k)
				if(j < k) then
					 if(y1(j) > y1(j+1)) j = j+1
				endif
				
				if (t1 > y1(j)) then
					 y1(i) = y1(j)
					 y2(i) = y2(j)
					 i = j
					 j = j+j
				else
					 j = k+1
				endif
		 
		 enddo
		 
		 y1(i) = t1
		 y2(i) = t2
	
	enddo
	return
 
end subroutine heapsort_down
 
subroutine heapsort_up(n,y1,y2)
 
	implicit none
	integer(8),intent(in) :: n
	integer(8),intent(inout) :: y1(1:n)
	integer(8),intent(inout) :: y2(1:n)
	integer(8) :: i,k,j,l
	integer(8) :: t1,t2
	
	l = n/2+1
	k = n
 
	do while (k /= 1)
		 if(l > 1) then
				l = l-1
				t1 = y1(l)
				t2 = y2(l)
				
		 else
				t1 = y1(k)
				t2 = y2(k)
				y1(k) = y1(1)
				y2(k) = y2(1)
				k = k-1
				if(k == 1) then
					 y1(1) = t1
					 y2(1) = t2
					 exit
				endif
		 endif
 
		 i = l
		 j = l+l
 
		 do while(j <= k)
				if(j < k) then
					 if(y1(j) < y1(j+1)) j = j+1
				endif
				
				if (t1 < y1(j)) then
					 y1(i) = y1(j)
					 y2(i) = y2(j)
					 i = j
					 j = j+j
				else
					 j = k+1
				endif
		 
		 enddo
		 
		 y1(i) = t1
		 y2(i) = t2
	
	enddo
	return
 
end subroutine heapsort_up
 
end program

Measured memory_bytes: 1828
n = int(input())
lst = [list(map(int,input().split())) for i in range(n)]
lst_num = [lst[i][0] for i in range(n)]
A = []
B = []
C = []

def Insertion_Sort(arg_lst, arg_lst_num, arg_n):
    for i in range(1,arg_n):
        v = arg_lst_num[i]
        w = arg_lst[i]
        j = i-1
        while j>=0 and arg_lst_num[j]>v:
            arg_lst_num[j+1]=arg_lst_num[j]
            arg_lst[j+1]=arg_lst[j]
            j-=1
        arg_lst_num[j+1]=v
        arg_lst[j+1]=w

def find_root(arg_lst):
    TMP = []
    for i in range(n):
        TMP.extend(arg_lst[i][1:])
    for i in range(n):
        if not i in TMP:
            return i

def Preorder(arg_Q, arg_lst, arg_num):
    arg_Q.append(arg_num)
    if lst[arg_num][1] != -1:
        Preorder(arg_Q, arg_lst, lst[arg_num][1])
    if lst[arg_num][2] != -1:
        Preorder(arg_Q, arg_lst, lst[arg_num][2])

def Inorder(arg_Q, arg_lst, arg_num):
    if lst[arg_num][1] != -1:
        Inorder(arg_Q, arg_lst, lst[arg_num][1])
    arg_Q.append(arg_num)
    if lst[arg_num][2] != -1:
        Inorder(arg_Q, arg_lst, lst[arg_num][2])

def Postorder(arg_Q, arg_lst, arg_num):
    if lst[arg_num][1] != -1:
        Postorder(arg_Q, arg_lst, lst[arg_num][1])
    if lst[arg_num][2] != -1:
        Postorder(arg_Q, arg_lst, lst[arg_num][2])
    arg_Q.append(arg_num)

Insertion_Sort(lst, lst_num, n)
root = find_root(lst)
Preorder(A, lst, root)
print("Preorder")
for i in A:
    print(f" {i}",end="")
print()
Inorder(B, lst, root)
print("Inorder")
for i in B:
    print(f" {i}",end="")
print()
Postorder(C, lst, root)
print("Postorder")
for i in C:
    print(f" {i}",end="")
print()


Measured memory_bytes: 5632
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using ll=long long;

int main() {
	int n,minv=1e9,count=0;
	cin >> n;
	vector<int>a(n);
	ll sum = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		sum += abs(a[i]);
		if (a[i] < 0)++count;
		minv = min(minv, abs(a[i]));
	}
	cout << sum - (count % 2 == 1) * minv * 2 << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl
#define int ll

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int M = 1e9 + 7, N = 4e5 + 7;

int inv[N], f[N], fi[N];

int C(int n, int k) {
	return f[n] * fi[k] % M * fi[n-k] % M;
}
int H(int n, int k) {
	return C(n + k - 1, k);
}

signed main()
{
	IO_OP;
	
	f[0] = 1;
	for(int i=1;i<N;i++)
		f[i] = f[i-1] * i % M;
	inv[1] = 1;
	for(int i=2;i<N;i++)
	    inv[i] = (M - M / i) * inv[M % i] % M;
	fi[0] = 1;
	for(int i=1;i<N;i++) 
		fi[i] = fi[i-1] * inv[i] % M;
	int n, k;
	cin >> n >> k;
	int ans = 0;
	for(int i = 0; i <= min(n, k); i++) {
		ans += C(n, i) * H(n - i, i) % M;
	}
	cout << ans % M << endl;
}





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

int main()
{
 
  
  int n;
  cin>>n;
  int dp[n+1];
  dp[1]=0;

  int h[n+1];
  
  for(int i=1;i<=n;i++)
    cin>>h[i];
  dp[2]=abs(h[2]-h[1]);
  for(int i=3;i<=n;i++)
  {
    dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
  }
  cout<<dp[n];
  return 0;  
}   

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


int main() {
    string S;
    cin >>S;
    map<char,int>mp;
    bool judge =false;
    rep(i,3) mp[S[i]]++;
   for (auto p:mp){
        if(p.second!=1) judge =true;
    }
    if(judge)cout<< "No"<<endl;
    else cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 2000000000;
using namespace std;

int main(){
    int n, m;
    while(cin >> n >> m, n||m){
        vector<pair<int, int>> v;
        rep(i,n){
            int a, b;
            cin >> a >> b;
            v.emplace_back(make_pair(b, a));
        }
        sort(all(v), greater<pair<int, int>>());

        long long ans = 0;
        rep(i,v.size()){
            if(m == 0){
                ans += v[i].first * v[i].second;
            }else if(v[i].second <= m){
                m -= v[i].second;
            }else if(v[i].second > m){
                v[i].second-=m;
                ans += v[i].first * v[i].second;
                m = 0;
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3052
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 0
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;

int n,W,ans;
int w[111],v[111];
signed main(){
	cin>>n>>W;
	rep(i,n)cin>>w[i]>>v[i];
	vector<int> s[4];
	rep(i,n){
		s[w[i]-w[0]].push_back(v[i]);
	}
	rep(i,4){
		sort(s[i].begin(),s[i].end(),greater<>());	
	}
	int sum0=0;
	rep(i,s[0].size()+1){
		int sum1=0;
		if(i!=0)sum0+=s[0][i-1];
		rep(j,s[1].size()+1){
			int sum2=0;
			if(j!=0)sum1+=s[1][j-1];
			rep(k,s[2].size()+1){
				if(k!=0)sum2+=s[2][k-1];
				int sum=sum0+sum1+sum2,sum3=0,cnt=0;
				rep(l,s[3].size()){
					if(i*w[0]+j*(w[0]+1)+k*(w[0]+2)+(l+1)*(w[0]+3)>W){
						cnt=l;
						break;
					}
					sum3+=s[3][l];
				}
				sum+=sum3;
				if(i*w[0]+j*(w[0]+1)+k*(w[0]+2)+cnt*(w[0]+3)<=W)ans=max(ans,sum);
			//	cout<<i<<" "<<j<<" "<<k<<" "<<cnt<<" "<<"sum:"<<sum<<endl;
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
// -*- compile-command: "g++ -g -Wno-return-type -Wall -Wextra -DLOCAL -std=c++11 -D_GLIBCXX_DEBUG d.cpp -od && ./d " -*-
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
#define int LL
#define vc vector
#define pb push_back
#define pr pair
#define fi first
#define se second
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define f(i,n) for(int i=0;i<(n);i++)
#define fr(i,n) for(int i=(n);i--;)
#define fv(i,v) f(i,sz(v))
     
main(){
	ios::sync_with_stdio(0),cin.tie(0);
	int n,z,w;
	cin>>n>>z>>w;
	vc<int> a(n);
	f(i,n) cin>>a[i];
	int r=-2e9;
	r=max(r,abs(a[n-1]-w));
	if(n>1) r=max(r,abs(a[n-2]-a[n-1]));
	cout<<r<<'\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0;
#define ll long long

int a, b;
char grid[101][101];
int mxcol = 100, mxrow = 100;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    for(int i = 0 ; i <= mxrow ; i++)
        for(int j = 0 ; j <= mxcol ; j++)
            grid[i][j] = 'e';
    cin >> a >> b;
    int row = 1, col = 1;
    while(a){
        while(a && col <= mxcol){
            grid[row][col] = 'W';
            col += 2;
            a--;
        }
        col = 1;
        row += 2;
    }
    row -= 2;
    for(int i = 1 ; i <= row ; i++)
        for(int j = 1 ; j <= mxcol ; j++)
            if(grid[i][j] == 'e') grid[i][j] = 'B';
    row++;
    grid[row][1] = 'W';
    for(int j = 2 ; j <= mxcol ; j++)
        grid[row][j] = 'B';
    b--;
    row++;
    for(int j = 1 ; j <= mxcol ; j++)
        grid[row][j] = 'W';
    row++;
    col = 1;
    while(b){
        while(b && col <= mxcol){
            grid[row][col] = 'B';
            col += 2;
            b--;
        }
        col = 1;
        row += 2;
    }
    for(int i = 1 ; i <= mxrow ; i++)
        for(int j = 1 ; j <= mxcol ; j++)
            if(grid[i][j] == 'e') grid[i][j] = 'W';
    cout << 100 << " " << 100 << endl;
    for(int i = 1 ; i <= mxrow ; i++){
        for(int j = 1 ; j <= mxcol ; j++)
            if(grid[i][j] == 'W') cout << '.';
            else cout << '#';
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256