akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int inf = 1e9;
const int maxn = 1e5+5;
int n,k,A[maxn];

int main()
{
    while (cin >> n >> k) {
        FOR(i,0,n)
            cin >> A[i];
        queue<int> Q;
        FOR(i,0,k)
            Q.push(A[i]);
        int ans = inf;
        int i = k;
        while (Q.size() == k) {
            const int a = Q.front();
            const int b = Q.back();
            if (a < 0 && b < 0) {
                ans = min(ans,abs(a));
            }
            else if (a < 0 && b > 0) {
                const int x = abs(a)*2 + b;
                const int y = abs(a) + b*2;
                ans = min(ans,min(x,y));
            }
            else
                ans = min(ans,b);
            Q.pop();
            if (i < n) {
                Q.push(A[i++]);
            }
        }
        cout << ans << endl;
    }
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  const int mid= N/2;

  vector<int> data(N);
  for(int i=0; i<N; i++){
    cin >> data.at(i);
  }

  vector<int> buf= data;
  sort(buf.begin(), buf.end());

  int median_without_small= buf.at(mid);
  int median_without_large= buf.at(mid-1);

  for(auto elem:data){
    int ans= (elem < buf.at(mid)) ? median_without_small
                                  : median_without_large;
    cout << ans << endl;
  }
}

Measured memory_bytes: 3712
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int a = s.nextInt();
        int b = s.nextInt();
        int c = s.nextInt();
        int d = s.nextInt();
        while(a >= 0 || c >= 0){
            c = c - b;
            if(c <= 0){
                System.out.println("Yes");
                break;
            }
            a = a - d;
            if(a <= 0){
                System.out.println("No");
                break;
            }
        }
    }
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 111;

PII A[MAX];
PII B[MAX];

int main(int argc, char* argv[])
{
	//ios::sync_with_stdio(false); cin.tie(0);

	int n;
	scanf("%d", &n);
	FOR (i, 0, n)
	{
		scanf("%d%d", &A[i].first, &A[i].second);
	}

	FOR (i, 0, n)
	{
		scanf("%d%d", &B[i].first, &B[i].second);
	}

	sort(A, A+n);
	sort(B, B+n);

	set<int> S;
	int res = 0;

	RFOR(i, n, 0)
	{
		while(n > 0 && B[n-1].first > A[i].first)
		{
			S.insert(B[n-1].second);
			n--;
		}

		set<int>::iterator it = S.upper_bound(A[i].second);

		if (it == S.end()) continue;

		S.erase(it);
		res++;
	}

	cout<<res<<endl;

}


Measured memory_bytes: 256
a,b=map(int, input().split())

if a == 1 or b == 1:
    print(1)
if a != 1 and b != 1 and a*b%2== 0:
    print(a*b//2)
if a != 1 and b != 1 and a*b%2!= 0:
    print(a*b//2+1)

Measured memory_bytes: 9204
#include<string>
#include <iostream>
#include<vector>
#define T long long

int main(void){
	T n;
	std::cin >>n;
	std::vector<T> result;
	result.resize(n);
	for(int i=1;i<n;i++){
		T tmp;
		std::cin>>tmp;
		result[tmp-1]++;
	}
	for(int i=0;i<n;i++){
		std::cout<<result[i]<<std::endl;
	}
}


Measured memory_bytes: 4844
s = input()
sum = int(s)
length = len(s)
inputlist = list(s)
#print(s)

for i in range(1,2**(length-1)):
    addlist = []
    addflag = format(i,'0'+str(len(s)-1)+'b')
#    print('---cut point :{}---'.format(addflag))
    begin = 0
    for j in range(length-1):#max 9 items : index:0-8
        if addflag[j] == '1':
            addlist.append(s[begin:j+1])
            begin = j+1
        if j == length-2:#last index
            addlist.append(s[begin::])
#    print(addlist)
    for item in addlist:
        sum += int(item)
print(sum)


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int l = a + b, r = c + d;
  if (l > r) {
    cout << "Left" << endl;
  } else if (l == r) {
    cout << "Balanced" << endl;
  } else {
    cout << "Right" << endl;
  }
}


Measured memory_bytes: 256
import java.util.*
import kotlin.math.min

fun main() = abc167c()

@OptIn(ExperimentalStdlibApi::class)
fun abc167c() {
    data class Book(val price: Long, val exp: List<Long>)

    val (n, m, x) = readLine()!!.split(' ').map { it.toLong() }
    val books = (1..n).map {
        val line = readLine()!!.split(' ').map { it.toLong() }
        Book(line[0], line.drop(1))
    }

    var answer = Long.MAX_VALUE
    val patterns = arrayOf(true, false)

    dfs(n.toInt(), patterns) { pattern ->
        val filtered = books.filterIndexed { index, _ -> pattern[index] }

        val experiences = LongArray(m.toInt())
        filtered.forEach { it.exp.forEachIndexed { index, l -> experiences[index] += l } }

        if (experiences.all { it >= x }) {
            answer = min(answer, filtered.map { it.price }.sum())
        }
    }

    println(answer.takeIf { it < Long.MAX_VALUE } ?: -1)
}

@OptIn(ExperimentalStdlibApi::class)
private fun <T> dfs(
    length: Int,
    patterns: Array<T>,
    list: MutableList<T> = mutableListOf(),
    operation: (List<T>) -> Unit
) {
    if (list.size == length) return operation(list)

    patterns.forEach {
        list.add(it)
        dfs(length, patterns, list, operation)
        list.removeLast()
    }
}


Measured memory_bytes: 42240
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


# 桁数*9 + 総和が 9 ずつ減る
M = int(sys.stdin.buffer.readline())
DC = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]

s = 0
l = 0
for d, c in DC:
    l += c
    s += d * c
ans = (l * 9 + s - 1) // 9 - 1
print(ans)


Measured memory_bytes: 45428
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
long long x;
int main(){
	ios::sync_with_stdio(false);
	cin>>x;
	long long ans=(x/500)*1000+((x%500)/5)*5;
	cout<<ans<<endl;
	return 0;
}

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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;

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

  int a, b;
  cin >> a >> b;

  if (a > 0 && a < 10 && b > 0 && b < 10)
    cout << a * b << endl;
  else
    cout << -1 << endl;


	return 0;
}


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

int main() {
	int a, b, x;
	cin >> a >> b >> x;
	if (a + b >= x&&a<=x) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		int N = sc.nextInt();
		int[] ary = new int[N];

		for (int i = 0; i < N; i++)
		{
			ary[i] = sc.nextInt();
		}

		boolean flag = true;
		int numSwap = 0;
		while (flag)
		{
			flag = false;

			for (int i = N - 1; i >= 1; i--)
			{
				if (ary[i] < ary[i - 1])
				{
					int temp = ary[i];
					ary[i] = ary[i - 1];
					ary[i - 1] = temp;

					numSwap++;
					flag = true;
				}
			}
		}

		for (int i = 0; i < N; i++)
		{
			System.out.print(ary[i]);
			if (i < N - 1)
			{
				System.out.print(" ");
			}
		}
		System.out.println("");
		System.out.println(numSwap);
	}
}



Measured memory_bytes: 26292
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"

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

const long long MOD = 1e9+7;

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 T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

int main() {
    string s;
    cin >> s;
    if (s == "AAA" || s == "BBB") cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define MOD 1000000007
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(v) (v).begin() , (v).end()
#define sumof(v) accumulate(all(v), 0LL, plus<ll>())
#define maxof(v) max_element(all(v))
#define minof(v) min_element(all(v))
#define inf INT_MAX

int main(){
    FASTIO
    int testCases = 1;
    // cin>>testCases;
    while(testCases--){
        ll N; cin>>N;
        vector<ll> a(N);
        for(int i=0; i<N; ++i) cin>>a[i];
        vector<ll> prefixPro(N), suffixPro(N);
        prefixPro[0] = a[0]%MOD;
        suffixPro[N-1] = a[N-1]%MOD;
        for(int i=1; i<N; ++i) prefixPro[i] = (a[i]+prefixPro[i-1])%MOD;
        for(int i=N-2; i>=0; i--) suffixPro[i] = (a[i]+suffixPro[i+1])%MOD;
        ll ans = 0;
        for(int i=0; i<N; ++i){
            ll left = 0;
            if(i-1>=0) left = prefixPro[i-1];
            // cout<<"Left = "<<left<<endl;
            // cout<<a[i]<<endl;
            // if(i+1<N) right = suffixPro[i+1];
            ans = ans + (a[i]*left)%MOD;
            ans = ans%MOD;
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 7948
import collections
n, k, q = map(int, input().split())
u = [int(input()) for jjj in range(q)]
c = collections.Counter(u)
m = {h: hh for h, hh in c.most_common()}
u = set(u)
for x in range(1, n+1):
    if x not in u:
        if k - q > 0:
            print('Yes')
        else:
            print('No')
        continue
    if k - (q - m[x]) > 0:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 20860
line = input().split()
num = int(line[3])
a = int(line[0])
b = int(line[1])
c = int(line[2])

if a < num:
  maxi = a
elif a >= num:
  maxi = num

if a + b < num:
  maxi = a -  (num - (a + b))
  
print(maxi)

Measured memory_bytes: 9208
def resolve():
    n=int(input())

    def f(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(cnt)

        if temp != 1:
            arr.append(1)

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

        return arr
    if n==1:
        print(0)
    else:
        a=f(n)
        ans=0
        for i in a:
            k=1
            while i>=k:
                i-=k
                k+=1
            ans+=k-1
        print(ans)
resolve()

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<ll> sum(2);
    vector<ll> a(n);
    bool flg = 1;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (a[i] > 0) sum[i % 2] += a[i];
        flg &= a[i] <= 0;
    }
    vector<int> ops;
    if (flg) {
        int p = max_element(a.begin(), a.end()) - a.begin();
        cout << a[p] << '\n';
        for (int i = 0; i < p; ++i)
            ops.push_back(1);
        int now = n - p;
        for (int i = n - 1; i > p; --i) {
            ops.push_back(now);
            --now;
        }
        cout << ops.size() << '\n';
        for (auto o : ops) cout << o << '\n';
        return 0;
    }
    ll ans = max(sum[0], sum[1]);
    vector<int> pos;
    int type = 0;
    if (sum[1] > sum[0]) type = 1;
    for (int i = 0; i < n; ++i)
        if (a[i] > 0 && i % 2 == type) {
            pos.push_back(i);
        }
    // cerr << "pos: {";
    // for (int i = 0; i < (int) pos.size(); ++i) {
        // if (i) cerr << ", ";
        // cerr << pos[i];
    // }
    // cerr << "}\n";
    for (int i = 0; i < pos[0]; ++i) {
        ops.push_back(1);
    }
    int now = n - pos[0];
    for (int i = n - 1; i > pos.back(); --i) {
        ops.push_back(now);
        --now;
    }
    for (int i = 1; i < (int) pos.size(); ++i) {
        int l = pos[i - 1], r = pos[i];
        int k = r - l + 1;
        while (k > 1) {
            ops.push_back(k / 2 + 1);
            k -= 2;
        }
    }
    cout << ans << '\n';
    cout << ops.size() << '\n';
    for (auto o : ops) cout << o << '\n';
    return 0;
}

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

using namespace std;

typedef pair<int, int> P_ii;
typedef pair<string, int> P_si;

int main() {
    int n;
    cin >> n;
    vector<string> S;
    map<char, int> mp;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        S.push_back(s);
    }

    for (char c = 'a'; c <= 'z'; ++c) {
        mp[c] = INT32_MAX;
    }

    for (int i = 0; i < n; ++i) {
        for (char c = 'a'; c <= 'z'; ++c) {
            int cnt = count(S[i].begin(), S[i].end(), c);
            mp[c] = min(mp[c], cnt);
        }
    }
    string ans;
    for (char c = 'a'; c <= 'z'; c++) {
        if (mp[c] == INT32_MAX) continue;
        for (int i = 0; i < mp[c]; ++i) {
            ans += c;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 28;
int H, W;
int dp[1000005]; //0 ?°????, 1??\??? ???????????????
int X[1000005], Y[1000005];
int mas[1005][1005];
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};

int main()
{
    int ans = 0;
    fill_n(*mas, 1005 * 1005, INF);
    scanf("%d %d", &H, &W);
    for(int i = 1; i <= H; i++) {
        for(int j = 1; j <= W; j++) {
            scanf("%d", &mas[i][j]);
            Y[mas[i][j]] = i;
            X[mas[i][j]] = j;
        }
    }

    for(int i = 1; i <= H * W; i++) {
        int c = -1;
        for(int j = 0; j < 4; j++) {
            int ny = Y[i] + dy[j], nx = X[i] + dx[j];
            if(mas[ny][nx] < i && c != 0) {
                if(c == -1) c = dp[mas[ny][nx]];
                else if(c != dp[mas[ny][nx]]) c = 0;
            }
        }
        if(c == -1) dp[i] = i;
        else dp[i] = c;
        ans += dp[i] == 0;
    }

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

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

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

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

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

int a[100000+10];
unordered_map<int,int> hm;

int N;
int main(){
    ios::sync_with_stdio(false);
    cin >> N;
    REP(i, N) {
        cin >> a[i];
        hm[a[i]]=i%2;
    }
    sort(a,a+N);
    ll ans = 0;
    REP(i,N) {
        if (hm[a[i]] != i%2) ans++;
    }
    
    cout << ans/2 << endl;
    
    return 0;
}

Measured memory_bytes: 4772
#!users\bin\perl
chomp(my $Day = <STDIN>);
my %Whatdays = (
    'SUN' => 7,
    'SAT' => 1,
    'FRI' => 2,
    'THU' => 3,
    'WED' => 4,
    'TUE' => 5,
    'MON' => 6
);

#print $Day;
print $Whatdays{$Day};

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

int N;
int A[100010];
int main(){
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> A[i];
	}
	int ans = 0;
	for(int i=0;i<N;i++){
		while(A[i]%2==0){
			ans++;
			A[i] /= 2;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P pair<int,int>
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

signed main(){
  int n;
  cin >> n;
  if(n % 1000 != 0) cout << 1000 - n%1000 << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 3632
s=input()
if s=="SUN":
    print(7)
elif s=="MON":
    print(6)
elif s=="TUE":
    print(5)
elif s=="WED":
    print(4)
elif s=="THU":
    print(3)
elif s=="FRI":
    print(2)
elif s=="SAT":
    print(1)

Measured memory_bytes: 2940
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

const int MAX_N = 100000;
int n, t;
int a[MAX_N];
multiset<int> s;

int main() {
    fastio();

    cin >> n >> t;
    forn(i, n) {
        cin >> a[i];
        s.insert(a[i]);
    }

    int d = 0;
    int m = 0;
    for (int i = n - 1; i >= 0; i--) {
        chmax(d, m - a[i]);
        chmax(m, a[i]);
    }

    assert(d >= 1);

    int ans = 0;
    for (int i = 0; i < n; i++) {
        auto it = s.find(a[i]);
        if (it != s.end()) s.erase(it);
        while ((it = s.find(a[i] + d)) != s.end()) {
            ans++;
            s.erase(it);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define int long long
#define range(i, a, b) for(auto i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;
const int INF = sizeof(int) == sizeof(long long) ? LONG_LONG_MAX : INT_MAX;
const int MOD = 1000000007;
const long double EPS = 1e-8;

class Warshall {
	private:
		vector <vector <int>> G;

	public:
		Warshall(int v) {
			G = vector <vector <int>> (v, vector <int> (v));
			for(int i = 0; i < G.size(); i++)
				for(int j = 0; j < G.size(); j++)
					G[i][j] = i == j ? 0 : INF;
		}

		void addEdge(int start, int end, int cost) {
			G[start][end] = cost;
		}

		int dist(int start, int end) {
			return G[start][end];
		}

		bool checkNegativeCircle() {
			bool flag = false;
			for (int i = 0; i < G.size(); i++)
				if(G[i][i] < 0)
					flag = true;
			return flag;
		}

		void execute() {
			for(int k = 0; k < G.size(); k++)
				for(int i = 0; i < G.size(); i++)
					for(int j = 0; j < G.size(); j++)
						if(G[i][k] != INF && G[k][j] != INF)
							G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
		}

};

signed main() {
	int n, m, r;
	cin >> n >> m >> r;
	Warshall war(n);
	vector <int> needVisit(r);
	rep (i, r) cin >> needVisit[i];
	rep (i, m) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		war.addEdge(a, b, c);
		war.addEdge(b, a, c);
	}
	war.execute();
	sort(needVisit.begin(), needVisit.end());
	int ans = INF;
	do {
		int sum = 0;
		rep (i, r - 1) sum += war.dist(needVisit[i] - 1, needVisit[i + 1] - 1);
		ans = min(ans, sum);
	} while (next_permutation(needVisit.begin(), needVisit.end()));
	cout << ans << endl;
	return 0;
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()
#define fcout cout << setprecision(10)

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    vector<long long int> H(N);
    REP(i, N) {
        cin >> H[i];
    }
    sort(ALL(H), greater<long long int>());
    long long int ans = 0;
    REP(i, N) {
        if (i < K) {
            continue;
        }
        ans += H[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
using namespace std;
int prime(int);
int main(){
    int a,sum;
    int b[999999];
    b[0]=0;
    for(int i=1;i<999999;i++){
        b[i]=prime(i+1);
    }
    while ( cin >> a){
        sum =0;
        for (int i=1;i<a;i++){
            sum +=b[i];
        }
        cout << sum << endl;
    }
}
int prime(int x){
    if(x==1)
        return 0;
    if(x==2 || x==3 || x==5 || x==7)
        return 1;
    if(x%2==0 || x%3==0)
        return 0;
    for (int i=5;i<=sqrt(x)+1;i+=6){
        if(x%i==0 || x%(i+2)==0)
            return 0;
    }
    return 1;
}

Measured memory_bytes: 5064
import scala.collection.mutable

object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val N, M = sc.nextInt()
  val (acs, was) = List
    .fill(M)(sc.nextInt() -> sc.next())
    .foldLeft((mutable.HashMap.empty[Int, Int], mutable.HashMap.empty[Int, Int])) {
      case ((acs, was), (p, result)) =>
        if (!acs.contains(p)) result match {
          case "AC" => acs.update(p, 0)
          case "WA" => was.update(p, was.getOrElseUpdate(p, 0) + 1)
        }
        acs -> was
    }
  println(s"${acs.size} ${was.filter { case (i, _) => acs.contains(i) }.values.sum}")
}


Measured memory_bytes: 74428
//list index out of rangeエラー表示用
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

int main(){
  int d,t,s;
  cin >> d >> t >> s;
  if(t*s >= d){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
}

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

int main(){
    string s, t;
    cin >> s >> t;
    vector<char> sv;
    vector<char> tv;
    for(auto i : s) sv.push_back(i);
    for(auto i : t) tv.push_back(i);
    
    int q = s.size();

    while(q--){
        reverse(sv.begin(), sv.end());
        reverse(sv.begin()+1, sv.end());
        if(sv==tv){
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
#define INT_MAX 1<<30
const ll mod = 1e9+7;

vvl G;
bool visit[100005];

ll dfs(ll u){
	ll res = 0;
	visit[u] = true;
	for(auto v : G[u]){
		if(visit[v]) continue;
		res ^= dfs(v) + 1;
	}
	return res;
}

int main(){
	ll n; cin >> n;
	G.resize(n);
	rep(i,n-1){
		ll a,b; cin >> a >> b; a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	ll ans = dfs(0);
	if(ans) puts("Alice");
	else puts("Bob");
}

Measured memory_bytes: 8960
import sys
W,H,N=map(int,input().split())
wide=[0,W]
height=[0,H]
# white sphere calculate
for i in range(N):
    x,y,a=map(int,input().split())
    if a==1:
        wide[0]=max(wide[0],x)
    elif a==2:
        wide[1]=min(wide[1],x)
    elif a==3:
        height[0]=max(height[0],y)
    elif a==4:
        height[1]=min(height[1],y)
w_len=wide[1]-wide[0]
h_len=height[1]-height[0]
s=w_len*h_len
if h_len<0 or w_len<0:
    print(0)
else:
    print(s)

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

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int dis(int x){ 
  return x%=10;
}

int main(){
  int x[5];
  for(int i=0; i<5; ++i) cin >> x[i];
  int mn = 10, cnt = 0;
  for(int i=0; i<5; ++i){
    if(x[i]%10==0) continue;
    if(mn>dis(x[i])){
      mn = min(mn, dis(x[i]));
    }
  }
  for(int i=0; i<5; ++i){
    if(x[i]%10==0) cnt+=x[i];
    else cnt += x[i] + abs(10-dis(x[i]));
  }

  cout << cnt - abs(10-mn) << endl;
  return 0;
}

Measured memory_bytes: 3468
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

#define N 5010
ll dp[2][N];

ll inv[N], fact[N], ifact[N];
 
void init_fact(ll n = N){
    inv[1] = 1;
    for(int i = 2; i < n;i++) inv[i] = inv[mod%i] * (mod - mod/i) % mod;
	fact[0] = ifact[0] = 1;
	for(int i = 1; i < n; i++){
		fact[i] = (fact[i-1]*i)%mod;
		ifact[i]=(ifact[i-1]*inv[i])%mod;
	}
}

ll pow_mod(ll a, ll r, ll m){
	ll x = 1;
	while(r){
		if(r&1) (x*=a)%=m;
		(a*=a)%=m;
		r>>=1;
	}
	return x;
}

int main(){
	int n;
	string s;
	cin>>n>>s;
	init_fact();
	dp[0][0] = pow_mod(inv[2], s.size(), mod);
	rep(i, n){
		int t = i%2;
		fill(dp[!t], dp[!t]+N, 0);
		rep(j, n){
			(dp[!t][j+1]+=2*dp[t][j])%=mod;
			(dp[!t][max(j-1, 0)]+=dp[t][j])%=mod;
		}
	}
	cout<<dp[n%2][s.size()]<<endl;
	return 0;
}


Measured memory_bytes: 512
N = int(input())
A = [int(input()) for _ in range(N)]

used = [0]*N
ans = 0
i = 0
for _ in range(N):
  used[i] = 1
  i = A[i]-1
  ans += 1
  if used[i] == 1:
    ans = -1
    break
  if i == 1:
    break
print(ans)

Measured memory_bytes: 7852
#include <stdio.h>

int main(void) {
    int a, b;
    scanf("%d %d", &a, &b);
    
    if (a > b) {
        printf("a > b\n");
    } else if (a == b) {
        printf("a == b\n");
    } else {
        printf("a < b\n");
    }
    
    return 0;
}


Measured memory_bytes: 2068
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3
#define LINF 0x3f3f3f3f3f3f3f
#define MAXN int(1e5)+5
#define ll long long
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define max3(x, y, z) max(x, max(y, z))
#define ull long long
using namespace std;
using namespace __gnu_pbds;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<unsigned ll, pair<int, int> > piii;
typedef pair<pair<int, int>, int> piii2;
typedef tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	ll n, m;
	cin >> n >> m;
	vector<ll> v(n+2);
	ll s = 0;
	for(int i = 0; i < n; i++) {
		cin >> v[i];
		s += v[i];
	}
	ll k = (4*m-1+s)/(4*m);
	
	for(ll i = 0; i < n; i++) {
		if(v[i] >= k) m--;
	}
	cout << (m <= 0 ? "Yes" : "No") << endl;
}


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


using namespace std;

int main()
{
	unsigned int a, b;
	string sa,sb;
	while (cin >> a && cin >> b)
	{
		stringstream ss;
		ss << (a + b);
		cout << ss.str().size() << endl;
	}
	return 0;
}

Measured memory_bytes: 1204
#include <stdio.h>

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

  int A[N];
  int flag[N];
  for(int i = 0;i < N;i++) scanf("%d",&A[i]),flag[i] = 0;

  int button = 0;
  int counter = 0;
  while(1){
    if(button == 1){
      printf("%d\n",counter);
      break;
    }
    if(flag[button]){
      printf("-1\n");
      break;
    }
    flag[button] = 1;
    button = A[button]-1;
    counter++;
  }

  return 0;
}

Measured memory_bytes: 896
n,k = map(int,input().split())
X = list(map(int,input().split()))

min_cost = 10**15
for i in range(n-k+1):
  left =  abs(X[i])    + abs(X[i]-X[i+k-1])
  right = abs(X[i+k-1])+ abs(X[i]-X[i+k-1])  
  min_cost = min(left,right,min_cost)
  
print(min_cost)  

Measured memory_bytes: 14384
// AOJ 1315: Gift from the Goddess of Programming
// 2017.10.4 bal4u@uu

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

#define MAX(a,b) ((a)>=(b)?(a):(b))

int tm[1002], s[1002];
char in[1002];

int main()
{
	int n, i, hh, mm, t, p, max, ans;
	char date[10], time[10], e[5];

	while (scanf("%d", &n) && n > 0) {
		max = 0; memset(in, 0, sizeof(in)), memset(s, 0, sizeof(s));
		while (n-- > 0) {
			scanf("%s%s%s%d", date, time, e, &p);
			hh = atoi(time), mm = atoi(time+3);
			t = hh*60 + mm;
			if (*e == 'I') tm[p] = t, in[p] = 1;
			else {
				in[p] = 0;
				if (p == 0) {
					for (i = 1; i <= max; i++) {
						if (in[i]) s[i] += t - MAX(tm[0], tm[i]);
					}
				} else if (in[0]) s[p] += t - MAX(tm[0], tm[p]);
			}
			if (p > max) max = p;
		}
		for (ans = 0, i = 1; i <= max; i++) if (s[i] > ans) ans = s[i];
		printf("%d\n", ans);
	}
	return 0;
}

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

int main()
{
	int N;
	cin >> N;
	bool flag = false;
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			if (i * j == N) flag = true;
		}
	}
	puts(flag ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

int main(){
  int N,H;
  cin >> N >> H;
  vector<int> a(N),b(N);
  for(int i=0; i<N; i++){
    cin >> a[i] >> b[i];
  }
  int swing_max = *max_element(a.begin(),a.end());
  sort(b.begin(),b.end(),greater<int>());
  int ans = 0;
  for(int i=0; i<N; i++){
    if(b[i] <= swing_max) break;
    H -= b[i];
    ans++;
    if(H <= 0) break;
  }
  if(H>0){
    ans += (H+swing_max-1)/swing_max;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
import Control.Monad
import Data.List
import Data.Ord
import Data.Maybe

main=do
    [d,go]<-map read.words<$>getLine::IO[Int]
    pcs<-replicateM d $ map read.words<$>getLine:: IO [[Int]]
    -- 全完時のボーナス付きの得点
    let cmps = map f $ zip [1..] pcs
    --
    print.minimum.mapMaybe (g go cmps).flip (!!) d.iterate fts $ [[]]

fts s = concatMap (\x->map (x:) s) [True,False]

-- i問目の全完時の得点
f :: (Int,[Int]) -> (Int, Int)
f (i, (p:c:_)) = (p, p*i*100 + c)

-- (問題数, 全完得点) -> 使う -> 得点加算, 問題数加算
--                    -> 使わない -> 問題番号を更新
g go cmps ftx = g' go (zip [1..] cmps) ftx 0 0 0 0

g' :: Int -> [(Int,(Int,Int))] -> [Bool] -> Int -> Int -> Int -> Int -> Maybe Int -- 得点に達した場合の問題数
g' go [] [] pn psum lt lp
    | go <= psum = Just pn
    | go <= psum + (lt*lp*100) = Just (pn + ((go-psum+((lt*100-1)))`div`(lt*100)))
    | otherwise = Nothing
g' go ((i,(p,cp)):cmps) (ft:ftx) pn psum lt lp
    | ft = g' go cmps ftx (pn+p) (psum+cp) lt lp
    | otherwise = g' go cmps ftx pn psum i p


Measured memory_bytes: 1020
#include<iostream>
using namespace std;
int main(){
    int a,b,c,d,e,f,g,h,x=0,y=0;
    while(cin >> a >> b >> c >> d >> e >> f >> g >> h){
        x=0;
        y=0;
        if (a==e){x=x+1;e=e+10;} 
        if (b==f){x=x+1;f=f+10;} 
        if (c==g){x=x+1;g=g+10;}
        if (d==h){x=x+1;h=h+10;}
        if (e==a || e==b || e==c || e==d){y=y+1;}
        if (f==a || f==b || f==c || f==d){y=y+1;}
        if (g==a || g==b || g==c || g==d){y=y+1;}
        if (h==a || h==b || h==c || h==d){y=y+1;}
        cout << x << " " << y << endl;
    }  
return 0 ;
}


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

int main(){
  int K;
  cin >> K;
  int k = K/2;
  
  if(K % 2 == 0){
    int ans = k*k;
    cout << ans << endl;
  }else{
    int ans = k*(k+1);
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Main
{
    class Program
    {
        static void Main(string[] arg)
        {
            var answer = 0.0;
            int n = int.Parse(Console.ReadLine());
            //var xList = new List<double>();
            //var uList = new List<string>();

            for(int i = 0; i < n; i++)
            {
                var line = Console.ReadLine().Split(' ');
                string u = line[1];
                double x = u == "JPY" ? double.Parse(line[0]) : double.Parse(line[0]) * 380000.0;
                answer += x;

            }

            Console.WriteLine(answer);
            Console.ReadLine();

        }
        private static int[] GetIntList(string line)
        {
            return line.Split(' ').Select(x => int.Parse(x)).ToArray();

        }
    }
}


Measured memory_bytes: 11092
inf = 10**15
mod = 10**9+7
n,m = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(m)]
ab.sort(key=lambda x:x[1])
pre = -inf
ans=0
for tmp in ab:
    a,b = tmp
    if a >= pre:
        ans+=1
        pre=b
print(ans)

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

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

//#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>


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

const int MAX = 1e5 + 6;
const ll MOD = 998244353;
ll dp[106][MAX];
ll v[106], w[106];

int main(){

    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    ll N, W;
    cin >> N >> W;

    for(int i=1; i<=N; i++) cin >> w[i] >> v[i];

    for(ll i=1; i<=N; i++){
        for(ll wt=0; wt<=W; wt++){
            if(w[i] > wt) dp[i][wt] = dp[i-1][wt];
            else dp[i][wt] = max(v[i] + dp[i-1][wt-w[i]], dp[i-1][wt]);
        }
    }

    cout << dp[N][W];


}

Measured memory_bytes: 79360
#include <iostream>

using namespace std;

int main()
{
    int n,i,j;
    cin>>n;
   for(i=0;i<25;i++)
   {
       for(j=0;j<15;j++)
       {
           if(4*i+7*j==n)
           {
               cout<<"Yes\n";
               return 0;
           }
       }
   }
   cout<<"No\n";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int r, c;
    int rc[110][110];
    int i, j;
    int sum;
    
    scanf("%d %d\n", &r, &c);
    
    for(i=1; i<=r; i++) {
        for(j=1; j<=c; j++) {
            scanf("%d", &rc[i][j]);
        }
    }
    for(i=1; i<=r+1; i++) {
        sum=0;
        for(j=1; j<=c; j++) {
            sum += rc[i][j];
        }
        rc[i][c+1] = sum;
    }
    for(i=1; i<=c+1; i++) {
        sum=0;
        for(j=1; j<=r; j++) {
            sum += rc[j][i];
        }
        rc[r+1][i] = sum;
    }
    
    for(i=1; i<=r+1; i++) {
        for(j=1; j<=c+1; j++) {
            if(j != 1) printf(" ");
            printf("%d", rc[i][j]);
        }
        printf("\n");
    }
    return 0;
}



Measured memory_bytes: 2056
#include <bits/stdc++.h> 
using namespace std; 
typedef long long ll;
const int mxN=1e5;
const ll mod = 1e9+7;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
    int n,w;
    cin>>n>>w;

    vector<vector<int>> v(n,vector<int>(2));

    for(int i=0;i<n;i++){
        cin>>v[i][0]>>v[i][1];
    }

    ll dp[n+1][w+1];

    memset(dp,0,sizeof(dp));
    
    for(int i=1;i<=w;i++) dp[0][i]=-1;

    for(int i=1;i<=n;i++){
        for(int j=1;j<=w;j++){
            if(j<v[i-1][0]){
                dp[i][j]=dp[i-1][j];
                continue;
            }
            if(dp[i-1][j-v[i-1][0]]!=-1)dp[i][j]= max(dp[i-1][j],dp[i-1][j-v[i-1][0]]+v[i-1][1]);
            else dp[i][j]= dp[i-1][j];
        }
    }

    ll ans = 0;

    for(int i=0;i<=w;i++) ans=max(ans,dp[n][i]);
    cout<<ans;
    
}

Measured memory_bytes: 82564
n = int(input())
import itertools
keta = len(str(n))
l = []
for i in range(3,keta + 1):
    l = l + list(itertools.product([7,5,3], repeat = i))
l = list(l)
l = map(lambda x: "".join(list(map(str, x))), l)
l = map(int, l)
l = list(l)
l = filter(lambda x: x <= n, l)
l = filter(lambda x: str(x).find("3") != -1, l)
l = filter(lambda x: str(x).find("5") != -1, l)
l = filter(lambda x: str(x).find("7") != -1, l)
l = list(l)
print(len(l))

Measured memory_bytes: 7912
S = input()

cnt = 0
max_cnt=0

if S[0] == 'R':
    cnt += 1

for i in range(1,3):
    if S[i] == 'R':
        cnt+=1
        # print('i')
    else:
        if cnt > max_cnt:
            max_cnt = cnt
        cnt = 0
if cnt > max_cnt:
    max_cnt = cnt        
if S[len(S)-1] == 'R' and max_cnt == 0:
    max_cnt = 1

print(max_cnt)

Measured memory_bytes: 8972
#include <iostream>
#include <cstdio>
#define EPS 1e-10
using namespace std;

int main(void) {
    
    double a, b, c, d, e, f;
    
    while(scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f) != EOF) {
        double y = ((c*d - a*f) / (b*d - a*e));
        if(b*d-a*e == 0) y += EPS;
        double x = (c - b*y) / a;
        if(a == 0) y += EPS;
    
        printf("%.3f %.3f\n", x, y);
    }
    return(0);
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n; cin >> n;
  vector<ll> a(n), b(n);
  ll asum=0, bsum=0;
  REP(i,n){
      cin >> a[i];
      asum += a[i];
  }
  REP(i,n){
      cin >> b[i];
      bsum += b[i];
  }
  if(asum<bsum){
      cout << -1 << endl;;
      return 0;
  }
  priority_queue<ll> p;
  ll msum = 0;
  ll ans = 0;
  REP(i,n){
      if(a[i]>b[i]){
         p.push(a[i]-b[i]); 
      }else if(a[i]<b[i]){
          msum += b[i]-a[i];
          ans++;
      }
  }
  while(msum>0){
      ll tmp = p.top();p.pop();
      msum -= tmp;
      ans++;
  }
  cout << ans << endl;

}

Measured memory_bytes: 2428
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//vector<vector<int> > s1,s2,s3;
int s[4][2017][2017];
string ma[2017];
int cal(int lx,int ly,int hx,int hy,int id){
	int ret=s[id][hx][hy];
	if(lx>0) ret-=s[id][lx-1][hy];
	if(ly>0) ret-=s[id][hx][ly-1];
	if(lx>0 && ly>0) ret+=s[id][lx-1][ly-1];
	return ret;
}
int main()
{
	int n,m,q,lx,ly,hx,hy;
	cin>>n>>m>>q;
	rep(i,n) cin>>ma[i];
	vector<int> tmp(2017,0);
	//rep(i,2017) s1.pb(tmp),s2.pb(tmp),s3.pb(tmp);
	memset(s,0,sizeof(s));
	rep(i,n) rep(j,m){
		if(ma[i][j]=='1') s[0][i][j]++;
		if(i>0) s[0][i][j]+=s[0][i-1][j];
		if(j>0) s[0][i][j]+=s[0][i][j-1];
		if(i>0 && j>0) s[0][i][j]-=s[0][i-1][j-1];
	}
	rep(i,n) rep(j,m){
		if(i>0 && ma[i][j]=='1' && ma[i-1][j]=='1') s[1][i][j]++;
		if(i>0) s[1][i][j]+=s[1][i-1][j];
		if(j>0) s[1][i][j]+=s[1][i][j-1];
		if(i>0 && j>0) s[1][i][j]-=s[1][i-1][j-1];
		//cout<<i<<' '<<j<<' '<<s[1][i][j]<<endl;
	}
	rep(i,n) rep(j,m){
		if(j>0 && ma[i][j]=='1' && ma[i][j-1]=='1') s[2][i][j]++;
		if(i>0) s[2][i][j]+=s[2][i-1][j];
		if(j>0) s[2][i][j]+=s[2][i][j-1];
		if(i>0 && j>0) s[2][i][j]-=s[2][i-1][j-1];
		//cout<<i<<' '<<j<<' '<<s[2][i][j]<<endl;
	}
	rep(i,q){
		scanf("%d %d %d %d",&lx,&ly,&hx,&hy);
		//cin>>lx>>ly>>hx>>hy;
		lx--;ly--;hx--;hy--;
		cout<<cal(lx,ly,hx,hy,0)-cal(lx+1,ly,hx,hy,1)-cal(lx,ly+1,hx,hy,2)<<endl;
	}
}


Measured memory_bytes: 69504
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

int main() {
  int H,W,h,w; cin >> H >> W >> h >> w;
  cout << H * W - h * W - w * H + h * w << endl;
}

Measured memory_bytes: 256
function Main(input: string) {
  // 1行目がinput[0], 2行目がinput[1], …に入る
  const args = input.split(" ");

  const M: number = parseInt(args[0], 10);
  const D: number = parseInt(args[1], 10);
  if (D < 22) return console.log(0);

  let count: number = 0;
  for (let i = 2; i <= 9; i++) {
    // 10
    for (let j = 2; j <= 9; j++) {
      // 1
      const today = i * 10 + j;

      if (today <= D) {
        if (i * j <= M) {
          count += 1;
        }
      }
    }
  }
  console.log(count);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
const int MAXN=100000+10;
vector<int>edge[MAXN];//用邻接表来实现树的存储
int n,cnt[3];//cnt用来记录颜色数量
int tree[MAXN];//tree数组储存每个节点的颜色，1是指black，2指white
void bfs()
{
    queue<int>q;
    q.push(1),q.push(n);//Fennec先，Snuke后，所以先后入队
    while(!q.empty())
    {
        int temp=q.front();
        q.pop();
        cnt[tree[temp]]++;//注意位置！！
        for(int i=0;i<edge[temp].size();++i)//枚举所有节点
        {
            int v=edge[temp][i];
            if(tree[v])continue;
            else tree[v]=tree[temp];//判断是否涂过色
            q.push(v);
        }
    }
}
int main()
{
    memset(tree,0,sizeof(tree));
    cin>>n;
    for(int i=1;i<n;++i)
    {
        int x,y;
        cin>>x>>y;
        edge[x].push_back(y);
        edge[y].push_back(x);//邻接表建树
    }
    tree[1]=1,tree[n]=2;
    bfs();
    if(cnt[2]>=cnt[1]){
		cout<<"Snuke"<<endl;
	}//因为Fennec先手，所以如果最终结果相同，很明显是Snuke赢了
    else{
    	cout<<"Fennec"<<endl;
	}
    return 0;
}

Measured memory_bytes: 6272
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
    n = ni()
    ans = 0
    for i in range(1, n+1):
        v = n // i
        ans += v * (v + 1) // 2 * i
    print(ans)
    return

solve()


Measured memory_bytes: 9084
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int A, B;
    cin >> A >> B;

    if ((A + B) % 2 == 0) {
        cout << (A + B) / 2 << "\n";
    } else {
        cout << "IMPOSSIBLE\n";
    }

    return 0;
}

Measured memory_bytes: 888