akhauriyash/Code-Regression huggingface dataset:
def p(a):
    for i in a[:-1]:
        print(i,end=' ')
    print(a[-1])


def insertion_sort(a):
    for i in range(1,len(a)):
        p(a)
        d = a[i]
        j = i-1
        while j>=0 and d<a[j]:
            a[j+1] = a[j]
            j = j-1
        a[j+1] = d


n = int(input())
l = list(map(int,input().split()))
insertion_sort(l)
p(l)


Measured memory_bytes: 5984
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt(),a=sc.nextInt(),b=sc.nextInt(),count1=0,count2=0,count3=0;
    for(int i=0;i<n;i++) {
    	int buff=sc.nextInt();
    	if(buff<=a) {
    		count1++;
    	}else if(buff<=b) {
    		count2++;
    	}else {
    		count3++;
    	}
    }
    System.out.println((int)Math.min(count1, Math.min(count2, count3)));
  }
}


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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

LL gcd(LL a, LL b) {
    if(b == 0) return a;
    return gcd(b, a % b);
}

LL lcm(LL a, LL b) {
    return a * b / gcd(a, b);
}

void solve(long long A, long long B){
    cout << lcm(A, B) << endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 2 * 1000 * 1234;
const int mod = (int) 1e9 + 7;

int r1, c1, r2, c2;
long long f[MAXN];

int subMod(int a, int b) {
  int res = a - b;
  return res < 0 ? res + mod : res;
}

long long binpow(long long x, long long p) {
  long long res = 1;
  while (p) {
    if (p & 1) {
      res = (res * x) % mod;
      p--;
    } else {
      x = (x * x) % mod;
      p /= 2;
    }
  }
  return res % mod;
}

long long inv(long long x) {
  return binpow(x, mod - 2);
}

long long calc(int r, int c) {
  if (c == 0 || r == 0) {
    return max(c + 1, r + 1);
  }
  
  long long res = 0;
  
  long long cur = 1;
  for (int i = 2; i < 2 + c; i++) {
    cur = cur * i % mod;
  }
  res = cur;

  for (int i = 1; i <= r; i++) {
    cur = cur * (2 + c + i - 1) % mod;
    cur = cur * inv(2 + i - 1) % mod;
    res = (res + cur) % mod;
  }

  res = res * inv(f[c]) % mod;
  return res;
}

long long calc(int r1, int c1, int r2, int c2) {
  long long res = calc(r2, c2);
  if (r1 > 0) {
    res = subMod(res, calc(r1 - 1, c2));
  }
  if (c1 > 0) {
    res = subMod(res, calc(r2, c1 - 1));
  }
  if (r1 > 0 && c1 > 0) {
    res = (res + calc(r1 - 1, c1 - 1)) % mod;
  }
  return res;
}

int main() { 

  cin >> r1 >> c1 >> r2 >> c2;

  f[0] = 1;
  for (int i = 1; i <= r2 + c2; i++) {
    f[i] = f[i - 1] * i % mod;
  }

  cout << calc(r1, c1, r2, c2) << endl;

  return 0;
}


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

int main(){
    int N; cin>>N;
    vector<ll> A(N);
    rep(i,N) cin>>A[i];

    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());

    ll sum=0;
    for(int i=0; i<N-1; i++){
        if(i==0){
            sum += A[0];
        }else{
            sum += A[(i+1)/2];
        }
    }
    
    /*
    for(int i=0; i<A.size()-1; i++){
        sum += A[i];
    }
    */
    cout << sum << endl;
}


Measured memory_bytes: 4848
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;
int a[100010],b[100010];
map<ll,ll>mp;
int main(){
    int n,m;
    cin>>n>>m;
    vector<vector<int>>v(100010);

    for (int i = 0; i < n; i++)
    {
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);

    }
    priority_queue<int>q;
    ll ans=0;
    for (int i = 1; i <= m; i++)
    {
        for(auto &u: v[i] ){
        q.push(u);
        }
        if(q.empty())continue;
        int x=q.top();
        q.pop();
        ans+=x;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5632
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
vector<int> a;
vector<bool> isok;
int mod = 1000000007;
int main(void){
    int n,m;
    cin >> n >> m;
    a.resize(m);
    isok.assign(n+1,true);
    for(int i = 0;i < m;i++){
        cin >> a[i];
        isok[a[i]] = false;
    }
    
    vector<int> dp(100010,0);
    dp[0] = 1;
    if(isok[1]) dp[1] = 1;
    
    for(int i = 2;i <= n;i++){
        if(isok[i-2]){
            dp[i] += dp[i-2];
            dp[i] %= mod;
        }
        if(isok[i-1]){
            dp[i] += dp[i-1];
            dp[i] %= mod;
        }
    }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 1024
n = raw_input()
n = int(n)

n_dict = {n:1}
cont = 1
while n_dict[n]<=1:
	if n%2==0:
		n = n/2
	else:
		n = 3*n+1
	n_dict[n] = n_dict.get(n,0)+1
	cont += 1
print(cont)

Measured memory_bytes: 2568
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
 
const int INF = 1 << 24;
 
typedef unsigned long long ull;
 
int N, M;
std::vector<int> friends[510];
std::set<int> result;
 
void twinkle2(int index, int depth){
    if(depth > 0 && index != 1){
        result.insert(index);
    }
    
    if(depth >= 2){
        return;
    }
 
    REP(i, friends[index].size()){
        twinkle2(friends[index][i], depth+1);
    }
}
 
int main(){
    while(std::cin >> N >> M, N){
        REP(i, 510){
            friends[i].clear();
        }
        result.clear();
 
        REP(i, M){
            int a, b;
            std::cin >> a >> b;
            friends[a].push_back(b);
            friends[b].push_back(a);
        }
 
        twinkle2(1, 0);
        std::cout << result.size() << std::endl;
    }
}

Measured memory_bytes: 1372
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int inf = 2e17;
const int mod = 1e9 + 7;

signed main() {
    int N;
    cin >> N;
    vector<int> A(N, 0), sorting(N);
    cin >> A;
    copy(A.begin(), A.end(), sorting.begin());
    sort(sorting.begin(), sorting.end());
    int ans = 0;
    map<int, int> co;
    for (int i = 0; i < N; i++) co[sorting[i]] = i;
    for (int i = 0; i < N; i++) {
        if (abs(co[A[i]] - i) % 2 == 1) ++ans;
    }

    cout << ans / 2 << endl;
}

Measured memory_bytes: 8064
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#define mod 1000000007
using namespace std;
int main(){
	int n;
	vector<int> x,y;
	cin>>n;
	for(int i=0; i<n; i++){
		int t;
		cin>>t;
		x.push_back(t);
		y.push_back(t);
	}
	sort(y.begin(),y.end());
	int small = y[n/2 - 1];
	int big = y[n/2];
	for(int i=0;i<n;i++){
		if(x[i]<=small){
			cout<<big<<endl;
		}
		else{
			cout<<small<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3948
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    string s; cin >> s;
    if (s[2] == s[3] && s[4] == s[5])
        cout << "Yes\n";
    else
        cout << "No\n";

}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void)
{
    int n, s[1000];

    while(scanf("%d", &n))
    {
        if(n == 0)
        {
            return 0;
        }

        double m = 0;
        
        int i;
        for(i = 0; i < n; ++i)
        {
            scanf("%d", &s[i]);
            m += s[i];
        }
        
        m /= n;
        
        double a = 0;
        for(i = 0; i < n; ++i)
        {
            a += pow(s[i] - m, 2);
        }
        
        printf("%f\n", sqrt(a / n));
    }
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
#define INF 10000000001
#define DIM 200001
#define mod 1000000007
#define PI 3.1415926535897932384626433
#define se second
#define fi first
#define pb push_back
#define T true
#define F false
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define endl "\n"
typedef char ch;
typedef bool boll;
typedef string st;
typedef long long ll;
typedef long double ld;
typedef set <string>sst;
typedef set <long long>sl;
typedef queue <long long>que;
typedef vector <long long>vec;
typedef unsigned long long ull;
typedef map <long long,long long>mll;
typedef pair <long long,long long>pll;
typedef vector <pair<long long,long long> >vpl;
typedef pair <long long, unsigned long long > pul;
ll n,z,x,c,s=6;
int main()
{
    cin>>x;
    z+=x;
    cin>>x;
    z+=x;
    cout<<s-z<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll X, Y;
  cin >> X >> Y;

  ll ans = kMod * 1000;
  if (X <= Y) {
    ans = min(ans, Y - X);
  }
  if (-X <= Y) {
    ans = min(ans, Y + X + 1);
  }
  if (X <= -Y) {
    ans = min(ans, (-Y) - X + 1);
  }
  if (-X <= -Y) {
    ans = min(ans, (-Y) - (-X) + 2);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(clippy::many_single_char_names)]
#![allow(clippy::suspicious_arithmetic_impl)]

// using Rust(1.42.0)
// My Library Repo is at "https://github.com/Loptall/prcn_lib"
// check available crates on AtCoder at "https://atcoder.jp/contests/language-test-202001"

/*
    AtCoder Language Update 2020204 お疲れ様でした! 有難いです
*/

// Dep crates are...
use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque};
use std::mem::swap;
use std::ops::*;
use std::{i128, i16, i32, i64, i8, isize, u128, u16, u32, u64, u8, usize};

use itertools::*;
use itertools_num::*;
use lazy_static::lazy_static;
use maplit::{btreemap, btreeset, hashmap, hashset};
use num_bigint::{BigInt, BigUint};
use num_integer::{binomial, gcd, lcm, Integer};
use permutohedron::Heap;
use proconio::{fastout, input, is_stdin_empty, marker::*};
use rand::random;

// code...
fn main() {
    input! { s: String }
    if s == "ABC".to_string() {
        println!("ARC");
    } else {
        println!("ABC");
    }
}


Measured memory_bytes: 2080
#include <bits/stdc++.h>
#define ll long long
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define f(i, a, b) for(ll i=a; i<b; i++)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define endl "\n"
#define PI 3.141592653589793
using namespace std;

bool sortbysec(const pair<ll,ll> &a, 
              const pair<ll,ll> &b) 
{ 
    return (a.second < b.second); 
} 

ll maxSubArraySum(ll a[], ll size) 
{ 
    ll max_so_far = INT_MIN, max_ending_here = 0; 
  
    for (ll i = 0; i < size; i++) 
    { 
        max_ending_here = max_ending_here + a[i]; 
        if (max_so_far < max_ending_here) 
            max_so_far = max_ending_here; 
  
        if (max_ending_here < 0) 
            max_ending_here = 0; 
    } 
    return max_so_far; 
} 

ll findSubarraySum(ll arr[], ll n, ll sum = 0) 
{
    unordered_map<ll, ll> prevSum;
    ll res = 0;
    ll currsum = 0;
    for (ll i = 0; i < n; i++)
    {
        currsum += arr[i];
        if (currsum == sum) res++;
        if (prevSum.find(currsum - sum) != prevSum.end()) res += (prevSum[currsum - sum]);
        prevSum[currsum]++;
    }
    return res; 
} 
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
  
ll powmp(ll x, ll y, ll p) 
{ 
    ll res = 1;     x = x % p;   
    while (y > 0) 
    {  
        if (y & 1)  res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
} 

int main()
{
    FAST
    ll n;cin>>n;
    ll m=1e18;
    ll a[n];
    int f=0;
    f(i,0,n)
    {
        cin>>a[i];
        if(a[i]==0) f++;
    }
    if(f)
    {
        cout<<0;
        return 0;
    }
    ll ans=1;
    f(i,0,n)
    {
        if(ans>m/a[i])
        {
            cout<<-1;
            return 0;
        }
        ans*=a[i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4444
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
using namespace std;
typedef long long ll;

const int maxN = 1e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b){return !b ? a : gcd(b, a % b);}
ll modP(ll a, ll b) {return (!b ? 1 : (modP(a, b / 2) * modP(a, b / 2) * (b % 2 ? a : 1)) % MOD);}

ll n, i, j;
ll W, v[maxN], w[maxN];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> W;
	for (i = 0; i < n; i++){
		cin >> w[i] >> v[i];
	}
	ll dp[n + 1][W + 1];
	for (i = 0; i <= n; i++){
		for (j = 0; j <= W; j++){
			if (i == 0 || j == 0){
				dp[i][j] = 0;
				continue;
			}
			dp[i][j] = dp[i - 1][j];
			if (w[i - 1] <= j){
				dp[i][j] = max(dp[i][j], v[i - 1] + dp[i - 1][j - w[i - 1]]);
			}
		}
	}
	cout << dp[n][W] << endl;
	return 0;
}



Measured memory_bytes: 79232
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        // 入力
        string s = Console.ReadLine();
        string ans = "";
        for (int i = 0; i < s.Length; i++)
        {
            ans += "x";
        }
        Console.WriteLine(ans);

    }
}

Measured memory_bytes: 13140
package main

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

func scanInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanInt64() int64 {
	sc.Scan()
	i, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return i
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func scanInts64(n int) []int64 {
	res := make([]int64, n)
	for i := range res {
		res[i] = scanInt64()
	}
	return res
}

func scanText() string {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Scan()
	return sc.Text()
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	n, k := scanInt(), scanInt()
	a := map[int]int{}
	for i := 0; i < k; i++ {
		d := scanInt()
		for j := 0; j < d; j++ {
			p := scanInt()
			a[p] = 1
		}
	}
	fmt.Println(n - len(a))
}


Measured memory_bytes: 1796
extern crate proconio;

use proconio::*;
use proconio::marker::Bytes;

fn main() {
    input! {
        a: u64,
        s: Bytes,
    }
    let mut val = 0;
    for s in s.iter() {
        if b'0' <= *s && *s <= b'9' {
            val = 10 * val + (*s - b'0') as u64;
        }
    }
    let ans = val * a / 100;
    println!("{}", ans);
}


Measured memory_bytes: 2132
import math
a, b, h, m = [int(i) for i in input().split()]
ka = 30 * h + 0.5 * m
kb = 6 * m
if ka > kb:
    ka, kb = kb, ka
    a, b = b, a
diff = min(kb - ka, 360 - kb + ka)
diff = math.pi * (diff / 180)
r = math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(diff))
# print(diff)
print(r)


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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++) 
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));

const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD = INF + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

const int N = 16;

int n;
int a[N][N];

bool read () {
	if (scanf("%d", &n) != 1)
		return false;
	forn(i, n) forn(j, n)
		scanf("%d", &a[i][j]);
	return true;
}

li sum[1 << N];
li dp[1 << N];

void solve() {	
	sum[0] = 0;
	forn(mask, 1 << n) forn(i, n) if (!((mask >> i) & 1)){
		sum[mask ^ (1 << i)] = sum[mask];
		forn(j, n) if ((mask >> j) & 1)
			sum[mask ^ (1 << i)] += a[i][j];
	}
	
	forn(mask, 1 << n) dp[mask] = sum[mask];
	forn(mask, 1 << n) for (int smask = mask; smask > 0; smask = (smask - 1) & mask)
		dp[mask] = max(dp[mask], dp[smask] + sum[mask ^ smask]);
	
	printf("%lld\n", dp[(1 << n) - 1]);
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	
	int tt = clock();
	
#endif
	
	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

	while(read()) {	
		solve();
		
#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define MAX 499500
#define inf 100000000011
#define LOG 20
using namespace std;

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);	
	int a,b;
	cin>>a>>b;
	a *= 2;
	b *= 2;
	int d = b - a;
	for(int i = 1; i < 1000 ; i++){
		if ( 2 * (i + 1) == d){
			cout<< i * (i + 1) / 2  - a/2;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
N,A,B,C = map(int,input().split())
L = [int(input()) for _ in range(N)]

def dps(a,b,c,index):
  if index == N:
    return abs(a-A) + abs(b-B) + abs(c-C) if min(a,b,c) != 0 else float('infinity')
  
  take = L[index]
  mp1 = dps(a,b,c,index+1)
  mp2 = dps(a+take,b,c,index+1) + 10
  mp3 = dps(a,b+take,c,index+1) + 10
  mp4 = dps(a,b,c+take,index+1) + 10

  return min(mp1,mp2,mp3,mp4)


print(dps(0,0,0,0)-30)

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

int main(){
  int n, k;
  cin >> n >> k;
  vi h(n+1);
  rep(i,n) cin >> h[i+1];
  vi dp(n+1);
  dp[0] = 0; dp[1] = 0;
  for(int i=2; i<=n; i++){
    dp[i] = dp[i-1] + abs(h[i]-h[i-1]);
    for(int j=1; j<=k; j++){
      if(i-j <= 0) continue;
      dp[i] = min(dp[i], dp[i-j] + abs(h[i]-h[i-j]));
    }
  }
  cout << dp[n] << endl;
}


Measured memory_bytes: 3984
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;

int apoint[200000], bcount[200000] = { 0 };
struct Ship {
	int a;
	int b;
	bool operator <(const Ship& b)const {
		return a < b.a;
	}
};
Ship f[200000];
int main()
{
	int N, M, j = 0;
	scanf("%d%d", &N, &M);
	for (int i = 0; i < M; i++) {
		scanf("%d%d", &f[i].a, &f[i].b);
		if (f[i].b == N) {
			bcount[f[i].a]++;
		}
		if (f[i].a == 1) {
			apoint[j] = f[i].b;
			j++;
		}
	}

	/*for (int i = 0; i < j; i++) {
		printf("%d\n", apoint[i]);
	}
	puts("");
	for (int i =0 ; i < 5; i++) {
		printf("%d\n", bcount[i]);
	}*/

	for (int i = 0; i < j; i++) {
		if (bcount[apoint[i]] != 0) {
			printf("POSSIBLE");
			return 0;
		}
	}
	printf("IMPOSSIBLE");
	return 0;
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
//ll MOD = 1000000007;
ll MOD = 998244353;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
  gearup;
  ll a,p; cin >> a >> p;
  p+=a*3;
  out(p/2);
}


Measured memory_bytes: 256
a = []
a += list(map(int, input().split()))
a += list(map(int, input().split()))
a += list(map(int, input().split()))

for i in range(1, 5):
    c = a.count(i)
    if c == 0 or c >= 3:
        print("NO")
        exit(0)

print("YES")


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

int main() {

  int A, B, C, D;
  cin >> A >> B >> C >> D;

  int a = ceil((double) A / D);
  int b = ceil((double) C / B);

  if (b <= a) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;

}

Measured memory_bytes: 3628
#include<iostream>
#include<cstdlib>
#include<vector>
#include<unordered_map>
#include<climits>
#include<string>
#include<algorithm>
#include<unordered_set>
//#include<>

using namespace std;


int minimumChar(string S1, string S2)
{
	int n = S1.size(), m = S2.size();

	int ans = INT_MAX;

	for (int i = 0; i < m - n + 1; i++) {
		int minRemovedChar = 0;

		for (int j = 0; j < n; j++) {
			if (S1[j] != S2[i + j]) {
				minRemovedChar++;
			}
		}

		ans = min(minRemovedChar, ans);
	}

	return ans;
}

int main()
{
	string s, t;
	cin >> s;
	cin >> t;
	cout << minimumChar(t,s);

	return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main(){
    FIN;
    int n,m;
    ll x;
    cin >> n >> m >> x;
    vector<vector<ll>> a(n,vector<ll>(m,0));
    vector<ll> c(n,0);

    for(int i=0;i<n;i++){
        cin >> c[i];
        for(int j=0;j<m;j++){
            cin >> a[i][j];
        }
    }



    ll ans = INF;
    for(int bit=0; bit < (1<<n); bit++){
        vector<ll> cur(m,0);
        ll C = 0;
        for(int i=0;i<n;i++){
            if(bit&(1<<i)){
                for(int j=0;j<m;j++){
                    cur[j] += a[i][j];
                }
                C += c[i];
            }
        }
        
        bool ok = true;
        for(int i=0;i<m;i++){
            if(cur[i] < x) ok = false;
        }

        if(ok) ans = min(ans,C);
    }

    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3684
// Aizu Vol-6 0611: Silk Road
// 2017.9.23 bal4u@uu

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

int dp[2][1003];		// m??\???????????????????????????
int d[1003], c[1003];	// ?????¢??¨??????????????????

int main()
{
	int n, m, i, j, k1, k2, t;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++) scanf("%d", d+i);
	for (i = 0; i < m; i++) scanf("%d", c+i+1);		// 1??\?????????


	memset(dp[0], -1, sizeof(dp[0])); 	// ????????????????????§?????????
	dp[0][0] = 0;						// ??????????????§??????

	for (k1 = 0, k2 = 1, i = 1; i <= m; i++, k1 = k2, k2 = !k2) {
		memset(dp[k2], -1, sizeof(dp[k2]));	// ?????????

		// ?§???????????????´???
		for (j = 0; j <= n; j++) dp[k2][j] = dp[k1][j];
		
		// ?§????????????´???
		for (j = 0; j < n; j++) {
			if (dp[k1][j] >= 0) {
				t = dp[k1][j] + c[i] * d[j];
				if (dp[k2][j+1] < 0 || t < dp[k2][j+1]) dp[k2][j+1] = t;
			}
		}
	}

	printf("%d\n", dp[k1][n]);
	return 0;
}

Measured memory_bytes: 1796
import numpy as np


def solve(n, m):
    def prepare(n, m):
        f = 1
        for i in range(1, n + 1):
            f = f * i % m
        fn = f
        f = pow(f, m - 2, m)
        invs = [1] * (n + 1)
        invs[n] = f
        for i in range(n, 0, -1):
            f = f * i % m
            invs[i - 1] = f

        return fn, invs

    def nik(n2, k, m):
        ret = 1
        yield ret
        for _ in range(k):
            ret = ret * n2 % m
            yield ret

    fn, invs = prepare(n, m)
    np_range = np.arange(2, n + 3, dtype=np.int64)
    dp = np.zeros(n + 2, dtype=np.int64)
    dp[0] = 1

    nn2 = [2]
    for i in range(n):
        nn2.append(nn2[-1] ** 2 % m)

    ans = 0
    parity = 1

    for i in range(n + 1):
        coef = np.fromiter(nik(pow(2, n - i, m), i, m), dtype=np.int64)
        ncr = fn * invs[i] * invs[n - i] % m
        left = (dp[:i + 1] * coef % m).sum() % m
        ans = (ans + ncr * left % m * nn2[n - i] % m * parity) % m
        dp[1:i + 2] = (dp[1:i + 2] * np_range[:i + 1] + dp[:i + 1]) % m
        parity *= -1

    return ans


n, m = map(int, input().split())
print(solve(n, m))


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

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define inf 100000000000010
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
#define all(x) (x).begin(), (x).end()

typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> pi;

bool isprime(ll n)
{
    if(n<=1)return false;
    if(n<=3)return true;
    if(n%2==0||n%3==0)return false;
    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0||n%(i+2)==0)return false;
    }
    return true;
}

ll modexp(ll a,ll b,ll m)
{
    ll r=1;
    a=a%m;
    while(b>0)
    {
        if(b&1)r=(r*a)%m;
        b = b>>1;
        a=(a*a)%m;
    }
    return r%m;
}

struct CustomCompare
{
    bool operator()(const int& lhs, const int& rhs)
    {
        return lhs < rhs;
    }
};


ll builtin_popcount(ll x)
{
    ll cnt = 0;
    for(ll i=60;i>=0;i--)
    {
        if((1LL<<i)&x)cnt++;
    }
    return cnt;
}

ll addmod(ll a,ll b,ll r)
{
    a%=r;
    b%=r;
    return (a+b)%r;
}
ll mulmod(ll a,ll b,ll r)
{
    a%=r;
    b%=r;
    return (a*b)%r;
}

const int mxn = 5*(1e6) +10;
vi spf(mxn);
void sieve()
{
    for(ll i =0;i<mxn;i++)spf[i]  = i;
    for(ll i=2;i<mxn;i+=2)spf[i] = 2;
    for(ll i = 3;i*i<mxn;i++)
    {
        if(spf[i]==i)
        {
            for(ll j = i*i;j<mxn;j+=i)
            {
                if(spf[j]==j)spf[j] = i;
            }
        }
    }
}

ll gcd(ll a, ll b)
{
   if (b == 0)
      return a;
   return gcd(b, a % b);
}
ll n;
vi arr;
bool check_coprime()
{
    vi fact(1e6+1,0);
    bool flag = true;
    for(ll i=n-1;i>=0;i--)
    {
        ll res = arr[i],prev = 0;
        while(res!=1)
        {
            if(fact[spf[res]]&&prev!=spf[res]&&spf[res]!=1)flag = false;
            fact[spf[res]]++;
            prev = spf[res];
            res/=spf[res];
        }
    }
    return flag;
}

bool check_set()
{
    ll ans = arr[0];
    rep(i,1,n)ans = gcd(ans,arr[i]);
    return ans==1;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
sieve();
cin>>n;
arr = vi(n);
rep(i,0,n)cin>>arr[i];
if(check_coprime())cout<<"pairwise coprime\n";
else if(check_set())cout<<"setwise coprime\n";
else cout<<"not coprime\n";
return 0;
}
/*
1
4
1 2
2 3
3 4
2
2 2
*/


Measured memory_bytes: 57832
#include <bits/stdc++.h>
#include <math.h>
typedef long long int ll;
#define pb         push_back
#define mp         make_pair
#define F          first
#define S          second
#define fl(i,a,b)  for(ll i=a;i<b;i++)
#define pll        pair<ll,ll>
#define pii        pair<int,int>
#define all(v)     v.begin(),v.end()
#define M          1000000007
#define M2         1000000009
#define M3         1000000000000007

using namespace std;
bool isPrime(ll n)
{
    if(n<=1)
        return false;
    if(n<=3)
        return true;
    if(n%2==0 || n%3==0)
        return false;

    for(ll i=5;i*i<=n;i=i+6)
        if(n%i==0|| n%(i+2)==0)
            return false;

    return true;
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b,a%b);

}

bool sortbydesc(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
    if(a.S < b.S)
        return true;
    else
        return false;
}


int main()
{
 ios::sync_with_stdio(0);
 cin.tie(0);
 cout.tie(0);
 ll n,k;
 cin>>n>>k;
 ll a;
 vector<ll> v;
 v.pb(0);
 fl(i,0,n)
 {
    cin>>a;
    v.pb(a);
 }
 ll dp[n+1][k+1];
 dp[1][0]=1;
 fl(i,1,k+1)
 {
    if(i<=v[1])
        dp[1][i]=(dp[1][i-1]%M+1)%M;
    else
        dp[1][i]=dp[1][i-1]%M;
 }
 fl(i,2,n+1)
 {
    fl(j,0,k+1)
    {
        if(j==0)
            dp[i][j]=1;
        else
        {
            if(j-v[i]<=0)
                dp[i][j]=(dp[i][j-1]%M+dp[i-1][j]%M)%M;
            else
                dp[i][j]=(dp[i][j-1]%M+(dp[i-1][j]%M-dp[i-1][j-v[i]-1]%M +M)%M)%M;
        }
    }
 }
 /*fl(i,1,n+1)
 {{fl(j,0,k+1)
 cout << dp[i][j] << " ";}
 cout << endl;
}*/
 if(k==0)
    cout<<dp[n][k]%M;
 else
    cout<<(dp[n][k]%M-dp[n][k-1]%M+M)%M;
}






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

using namespace std;

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

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	int n;
	cin >> n;
	n %= 10;
	if(n == 3) cout << "bon" << endl;
	else if(n == 0 || n == 1 || n == 6 || n == 8) cout << "pon" << endl;
	else cout << "hon" << endl;
	
}





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

using namespace std;

typedef long long ll;

// DPテーブル
const int MAX_N = 15;
const int MAX_W = 110000;
int dp[MAX_N][MAX_W]; // 12 種類だが余裕をもつ

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

    // 品物を列挙 (価値はすべて 1)
    vector<int> weight;
    for (int i = 1; i <= W; i *= 6) weight.push_back(i);
    for (int i = 9; i <= W; i *= 9) weight.push_back(i); // 1 が重複しないように (しても問題はない)
    int n = (int)weight.size();

    // DP初期条件: dp[i][0] = 0
    for (int i = 0; i < MAX_N; ++i) for (int w = 0; w < MAX_W; ++w) dp[i][w] = 1 << 29; // INF
    for (int i = 0; i <= n; ++i) dp[i][0] = 0;

    // DPループ
    for (int i = 0; i < n; ++i) {
        for (int w = 0; w <= W; ++w) {
            dp[i + 1][w] = dp[i][w];
            if (w >= weight[i]) dp[i + 1][w] = min(dp[i + 1][w], dp[i + 1][w - weight[i]] + 1);
        }
    }

    cout << dp[n][W] << endl;
}

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    string s;
    cin >> s;
    if(s == "ABC") cout << "ARC" << endl;
    else if(s == "ARC") cout << "ABC" << endl;
    return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define Rep(var,init,cnt) for(int (var)=(init); (var)<(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(rall(v))
#define SUM(v) accumulate(all(v),0)
#define tget(tp,idx) get<idx>(tp)
#define TF(flag) (flag)?1:0
#define yn(f) cout<<(f?"yes":"no")<<endl
#define Yn(f) cout<<(f?"Yes":"No")<<endl
#define YN(f) cout<<(f?"YES":"NO")<<endl
#define COUT(x) cout<<(x)<<endl
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ================================================

// Template End ======================================================

constexpr int MOD=1e9+7;

int main(void){
  int a,b,c; cin>>a>>b>>c; COUT((a-b)%c);
}













Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define mod 1000000007
using namespace std;

int n, m, i;
long long ans;

int main()
{
    scanf("%d%d", &n, &m);
    if (n > m)
        swap(m, n);
    if (n != m && n != m - 1)
    {
        printf("0");
        return 0;
    }
    if (n == m)
        ans = 2;
    else ans = m;
    for (int i = 2; i <= n; i++)
        ans = (((ans * i) % mod) * i) % mod;
    printf("%lld", ans);
}


Measured memory_bytes: 256
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0 }, dy[] = { 0,1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1;
	while (b) {
		if (b & 1) { res = res * a%MOD; }
		a = a * a%MOD;
		b >>= 1;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑

int main() {
	int a, b;
	string h;
	cin >> a >> h >> b;
	char mon = h[b - 1];
	for (int i = 0; i < h.length(); ++i) {
		if (h[i] == mon) { cout << h[i]; }
		else { cout << "*"; }
	}
	cout << endl;
}

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

int main(){
    int N, W;
    cin >> N >> W;
    vector<int> v(N), w(N);
    for(int i = 0; i < N; i++) cin >> v[i] >> w[i];

    vector<int> dp(W+1, 0);
    for(int i = 0; i < N; i++){
        for(int wei = W; wei > 0; wei--){
            if(wei - w[i] < 0) continue;
            dp[wei] = max(dp[wei], dp[wei - w[i]] + v[i]); 
        }
    }

    cout << dp[W] << endl;
}


Measured memory_bytes: 3148
n, m, d = map(int, input().split())

# d==0のとき、隣り合う2数が同じ数字であるときに美しい
# これは、n**2通りの選び方からn通りのみ存在するので、
# 1つの隣り合う項について、n/n**2の期待値である
# 全部でm-1項存在するので、これをかけたものが答え

if d==0:
    ans = (m-1) / n

# d!=0のとき、隣り合う2数の差がdのとき美しい
# これは、(1,1+d), .., (n-d, n), (n, n-d), .., (1+d, 1)の2(n-d)通り
# 上と同様に、n**2で割ってm-1項をかけたものが答え

else:
    ans = 2*(n-d)*(m-1)/(n**2)

print(ans)

Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
ll mod = 1e9 + 7;

using namespace std;



int main()
{
	int N, x, y;

	cin >> N;
	x = N * 800;
	y = (N / 15) * 200;
	cout << x - y << endl;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    c = input()
    r = deque()
    for i in range(n)[::-1]:
        if c[i] == "R":
            r.append(i)
    if len(r) in (0, n):
        print(0)
        return
    ans = 0
    for i in range(n):
        if c[i] == "W":
            while r:
                j = r.popleft()
                if j > i:
                    break
            else:
                print(ans)
                return
            ans += 1
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 68540
// abc169_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e9)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    long double A, B;
    cin >> A >> B;

    long double c = A * B;
    ll ans = (ll)c;

    print(ans);


    return 0;
}


Measured memory_bytes: 3744
from collections import Counter
import sys
import math
from functools import cmp_to_key

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)


def main():
    s = input()
    if s[-1] == "s":
        print(s + "es")
    else:
        print(s + "s")

main()


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


def solve(A: int, B: int):
    print(A * B)
    return


# Generated by 1.1.7.1 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()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9184
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define st first
#define nd second
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
template <class T> T read(T &a) {
    a=0;char x=getchar();bool f=0;
    for(;x<'0'||x>'9';x=getchar())f|=x=='-';
	for(;x>='0'&&x<='9';x=getchar())a=(a<<3)+(a<<1)+x-'0';
    if(f)a=-a;
    return a;
}
using namespace std;



int main() {
	LL n, x;
	read(n), read(x);
	LL gcd = __gcd(n, x);
	n /= gcd;
	cout << (n * 3 - 3) * gcd; 
    return 0;
}


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

const int MAXN = 2005;

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

int n, a[MAXN], vis[MAXN];
int b[MAXN], d[MAXN];

vector<int> nxt, cur;

struct node {
	int to, next;
} edge[MAXN];
int head[MAXN], top = 0;
inline void push(int i, int j)
{ d[j]++, edge[++top] = (node) {j, head[i]}, head[i] = top; }

void dfs(int nd)
{
	vis[nd] = 1;
	for (int i = 1; i <= n; i++)
		if (!vis[i] && gcd(a[i], a[nd]) > 1)
			push(nd, i), dfs(i);
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	sort(a+1, a+n+1);
	for (int i = 1; i <= n; i++)
		if (!vis[i])
			dfs(i);
	memset(vis, 0, sizeof vis);
	for (int i = 1; i <= n; i++) {
		for (int j = n; j >= 1; j--)
			if (!vis[j] && !d[j]) {
				vis[j] = 1;
				cout << a[j] << " ";
				for (int k = head[j]; k; k = edge[k].next) {
					int to = edge[k].to;
					d[to]--;
				}
				break;
			}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
long long MOD = (long long)1e9 + 7;

long long quickpow(long long b, int e)
{
	return e ? ((e & 1 ? b : 1)*quickpow((b*b) % MOD, e >> 1)) % MOD : 1;
}

int p, a[3000], fac[3000], inv[3000], b[3000], cnt, dat[3000][3000];

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> p;
	MOD = p;
	for (int i = 0; i < p; i++) {
		cin >> a[i];
		if (a[i] == 1) cnt++;
	}
	fac[0] = 1;
	for (int i = 1; i < p; i++) {
		fac[i] = i * fac[i - 1];
		fac[i] %= p;
	}
	for (int i = 0; i < p; i++) {
		inv[i] = quickpow(fac[i], p - 2);
		dat[i][0] = 1;
		for (int j = 1; j < p; j++) {
			dat[i][j] = dat[i][j - 1]*i;
			dat[i][j] %= p;
		}
	}
	for (int i = 0; i < p; i++) {
		int tmp = 0;
		for (int j = 0; j < p; j++) {
			if (a[j] == 0) continue;
			b[i] = fac[p - 1];
			b[i] *= inv[i];
			b[i] %= p;
			b[i] *= inv[p - 1 - i];
			b[i] %= p;
			b[i] *= dat[(p - j)%p][p - 1 - i];
			b[i] %= p;
			b[i] = p - b[i];
			b[i] %= p;
			tmp += b[i];
			tmp %= p;
		}
		b[i] = tmp;
	}
	b[0] += cnt;
	b[0] %= p;
	for (int i = 0; i < p; i++) {
		cout << b[i] << " ";
	}
	//system("pause");
	return 0;
}

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

int main(){
	int x,y;
	cin >> x >> y;
	while(!(x==0&&y==0)){
		if(x<y) cout << x << " " << y << endl;
		else cout << y << " " << x << endl;
		cin >> x >> y;
	}
	return 0;
}



Measured memory_bytes: 3088
while True:
    try:
        n=int(input())
        if n==-1:
            break
        x=n/2
        y=n*10**-5
        while abs(x**3-n)>=y:
            x = (2 * x ** 3 + n) / (3 * x ** 2)
        print(f'{x:.6f}')
    except EOFError:
        break
        
        


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

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

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

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

using namespace std;

int main(){
  long long b;
  while(true){
    cin >> b;
    if(b == 0) break;
    pair<int,int> ans;
    FOR(n,1, sqrt(2*b) ){
      //b = n(2a+n-1)/2
      //2b/n = 2a + n - 1
      // (2b/n - n + 1)/2 = a
      //cout << " n :" << n;
      long long a = ((2 * b) / n - n + 1) / 2;
      //cout << " a: " << a << endl;
      if((2 * b == n * (2*a + n - 1))  ){
        //cout << a << ' ' << a + n - 1 << endl;
        ans.first = a;
        ans.second = n;
      }
    }
    cout << ans.first << ' ' << ans.second << endl;
  }
  return 0;
}



Measured memory_bytes: 3020